1 2import Base: UUID 3import Pkg.Artifacts: artifact_meta, artifact_names, find_artifacts_toml, load_artifacts_toml, select_downloadable_artifacts 4import Pkg.BinaryPlatforms: AbstractPlatform, platform_key_abi, triplet 5import Pkg.Operations: gen_build_code 6import TOML 7 8pkg_uuid = UUID(ARGS[1]) 9dir = ARGS[2] 10 11artifacts_toml = find_artifacts_toml(dir) 12 13if artifacts_toml == nothing 14 print("") 15 exit() 16end 17 18platform = platform_key_abi() 19 20# Using collect_artifacts (from Pkg.jl) is more reliable than calling select_downloadable_artifacts directly. 21# collect_artifacts includes support for .pkg/select_artifacts.jl, which may produce different results. 22# If we use select_downloadable_artifacts here, then at depot build time it may try to download a different artifact 23# and fail. 24 25# However! The collect_artifacts from Pkg.jl doesn't allow us to pass lazy to select_downloadable_artifacts. 26# So we have to paste our own version in here :( 27 28function collect_artifacts(pkg_root::String; platform::AbstractPlatform) 29 # Check to see if this package has an (Julia)Artifacts.toml 30 artifacts_tomls = Tuple{String,Base.TOML.TOMLDict}[] 31 for f in artifact_names 32 artifacts_toml = joinpath(pkg_root, f) 33 if isfile(artifacts_toml) 34 selector_path = joinpath(pkg_root, ".pkg", "select_artifacts.jl") 35 36 # If there is a dynamic artifact selector, run that in an appropriate sandbox to select artifacts 37 if isfile(selector_path) 38 # Despite the fact that we inherit the project, since the in-memory manifest 39 # has not been updated yet, if we try to load any dependencies, it may fail. 40 # Therefore, this project inheritance is really only for Preferences, not dependencies. 41 select_cmd = Cmd(`$(gen_build_code(selector_path; inherit_project=true)) --startup-file=no $(triplet(platform))`) 42 meta_toml = String(read(select_cmd)) 43 res = TOML.tryparse(meta_toml) 44 if res isa TOML.ParserError 45 errstr = sprint(showerror, res; context=stderr) 46 pkgerror("failed to parse TOML output from running $(repr(selector_path)), got: \n$errstr") 47 else 48 push!(artifacts_tomls, (artifacts_toml, TOML.parse(meta_toml))) 49 end 50 else 51 # Otherwise, use the standard selector from `Artifacts` 52 artifacts = select_downloadable_artifacts(artifacts_toml; platform, include_lazy=true) 53 push!(artifacts_tomls, (artifacts_toml, artifacts)) 54 end 55 break 56 end 57 end 58 return artifacts_tomls 59end 60 61for (artifacts_toml, artifacts) in collect_artifacts(dir; platform) 62 TOML.print(artifacts) 63end