Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert AbstractPlatform to Platform #3874

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
preserve::PreserveLevel=Operations.default_preserve(), platform::AbstractPlatform=HostPlatform(), kwargs...)
require_not_empty(pkgs, :develop)
Context!(ctx; kwargs...)
platform = convert(Platform, platform)::Platform

for pkg in pkgs
check_package_name(pkg.name, "develop")
Expand Down Expand Up @@ -257,6 +258,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}; preserve::PreserveLevel=Op
platform::AbstractPlatform=HostPlatform(), target::Symbol=:deps, kwargs...)
require_not_empty(pkgs, :add)
Context!(ctx; kwargs...)
platform = convert(Platform, platform)::Platform

for pkg in pkgs
check_package_name(pkg.name, "add")
Expand Down Expand Up @@ -1173,6 +1175,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
platform::AbstractPlatform=HostPlatform(), allow_build::Bool=true, allow_autoprecomp::Bool=true,
workspace::Bool=false, kwargs...)
Context!(ctx; kwargs...)
platform = convert(Platform, platform)::Platform
if Registry.download_default_registries(ctx.io)
copy!(ctx.registries, Registry.reachable_registries())
end
Expand Down
10 changes: 10 additions & 0 deletions src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ function bind_artifact!(artifacts_toml::String, name::String, hash::SHA1;
download_info::Union{Vector{<:Tuple},Nothing} = nothing,
lazy::Bool = false,
force::Bool = false)
if !isnothing(platform)
platform = convert(Platform, platform)::Platform
end
# First, check to see if this artifact is already bound:
if isfile(artifacts_toml)
artifact_dict = parse_toml(artifacts_toml)
Expand Down Expand Up @@ -263,6 +266,9 @@ Silently fails if no such binding exists within the file.
"""
function unbind_artifact!(artifacts_toml::String, name::String;
platform::Union{AbstractPlatform,Nothing} = nothing)
if !isnothing(platform)
platform = convert(Platform, platform)::Platform
end
artifact_dict = parse_toml(artifacts_toml)
if !haskey(artifact_dict, name)
return
Expand Down Expand Up @@ -395,6 +401,7 @@ function ensure_artifact_installed(name::String, artifacts_toml::String;
verbose::Bool = false,
quiet_download::Bool = false,
io::IO=stderr_f())
platform = convert(Platform, platform)::Platform
meta = artifact_meta(name, artifacts_toml; pkg_uuid=pkg_uuid, platform=platform)
if meta === nothing
error("Cannot locate artifact '$(name)' in '$(artifacts_toml)'")
Expand All @@ -409,6 +416,7 @@ function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::Str
verbose::Bool = false,
quiet_download::Bool = false,
io::IO=stderr_f())
platform = convert(Platform, platform)::Platform
hash = SHA1(meta["git-tree-sha1"])

if !artifact_exists(hash)
Expand Down Expand Up @@ -526,6 +534,7 @@ function ensure_all_artifacts_installed(artifacts_toml::String;
verbose::Bool = false,
quiet_download::Bool = false,
io::IO=stderr_f())
platform = convert(Platform, platform)::Platform
# This function should not be called anymore; use `select_downloadable_artifacts()` directly.
Base.depwarn("`ensure_all_artifacts_installed()` is deprecated; iterate over `select_downloadable_artifacts()` output with `ensure_artifact_installed()`.", :ensure_all_artifacts_installed)
# Collect all artifacts we're supposed to install
Expand All @@ -552,6 +561,7 @@ function extract_all_hashes(artifacts_toml::String;
platform::AbstractPlatform = HostPlatform(),
pkg_uuid::Union{Nothing,Base.UUID} = nothing,
include_lazy::Bool = false)
platform = convert(Platform, platform)::Platform
hashes = Base.SHA1[]
if !isfile(artifacts_toml)
return hashes
Expand Down
2 changes: 2 additions & 0 deletions src/BinaryPlatforms_compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ end

const PlatformUnion = Union{Linux,MacOS,Windows,FreeBSD}

Base.convert(::Type{Platform}, p::PlatformUnion) = p.p
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm highlighting this change.

Here we convert most of the AbstractPlatform subtypes to Platform by unwrapping them.

The one outlier is UnknownPlatform but there is another pull request to address that.


# First, methods we need to coerce to Symbol for backwards-compatibility
for f in (:arch, :libc, :call_abi, :cxxstring_abi)
@eval begin
Expand Down
5 changes: 5 additions & 0 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ function install_git(
end

function collect_artifacts(pkg_root::String; platform::AbstractPlatform=HostPlatform())
platform = convert(Platform, platform)::Platform
# Check to see if this package has an (Julia)Artifacts.toml
artifacts_tomls = Tuple{String,Base.TOML.TOMLDict}[]
for f in artifact_names
Expand Down Expand Up @@ -825,6 +826,7 @@ function download_artifacts(env::EnvCache;
julia_version = VERSION,
verbose::Bool=false,
io::IO=stderr_f())
platform = convert(Platform, platform)::Platform
pkg_roots = String[]
for (uuid, pkg) in env.manifest
pkg = manifest_info(env.manifest, uuid)
Expand All @@ -845,6 +847,7 @@ function download_artifacts(env::EnvCache;
end

function check_artifacts_downloaded(pkg_root::String; platform::AbstractPlatform=HostPlatform())
platform = convert(Platform, platform)::Platform
for (artifacts_toml, artifacts) in collect_artifacts(pkg_root; platform)
for name in keys(artifacts)
if !artifact_exists(Base.SHA1(artifacts[name]["git-tree-sha1"]))
Expand Down Expand Up @@ -1481,6 +1484,7 @@ end
function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=Set{UUID}();
preserve::PreserveLevel=default_preserve(), platform::AbstractPlatform=HostPlatform(),
target::Symbol=:deps)
platform = convert(Platform, platform)::Platform
assert_can_add(ctx, pkgs)
# load manifest data
for (i, pkg) in pairs(pkgs)
Expand Down Expand Up @@ -1544,6 +1548,7 @@ end
# Input: name, uuid, and path
function develop(ctx::Context, pkgs::Vector{PackageSpec}, new_git::Set{UUID};
preserve::PreserveLevel=default_preserve(), platform::AbstractPlatform=HostPlatform())
platform = convert(Platform, platform)::Platform
assert_can_add(ctx, pkgs)
# no need to look at manifest.. dev will just nuke whatever is there before
for pkg in pkgs
Expand Down