@@ -8,6 +8,7 @@ using Artifacts
88using LazyArtifacts
99using UUIDs: UUID, uuid1
1010using RelocatableFolders
11+ using TOML
1112
1213export create_sysimage, create_app, create_library
1314
@@ -1055,6 +1056,40 @@ function pretty_byte_str(size)
10551056 return @sprintf (" %.3f %s" , bytes, Base. _mem_units[mb])
10561057end
10571058
1059+ # Copy pasted from Pkg since `collect_artifacts` doesn't allow lazy artifacts to get installed
1060+ function _collect_artifacts (pkg_root:: String ; platform:: Base.BinaryPlatforms.AbstractPlatform = HostPlatform (), include_lazy:: Bool )
1061+ # Check to see if this package has an (Julia)Artifacts.toml
1062+ artifacts_tomls = Tuple{String,Base. TOML. TOMLDict}[]
1063+
1064+ for f in Artifacts. artifact_names
1065+ artifacts_toml = joinpath (pkg_root, f)
1066+ if isfile (artifacts_toml)
1067+ selector_path = joinpath (pkg_root, " .pkg" , " select_artifacts.jl" )
1068+
1069+ # If there is a dynamic artifact selector, run that in an appropriate sandbox to select artifacts
1070+ if isfile (selector_path)
1071+ # Despite the fact that we inherit the project, since the in-memory manifest
1072+ # has not been updated yet, if we try to load any dependencies, it may fail.
1073+ # Therefore, this project inheritance is really only for Preferences, not dependencies.
1074+ code = try Pkg. Operations. gen_build_code (selector_path; inherit_project= true )
1075+ catch e
1076+ e isa MethodError || rethrow ()
1077+ Pkg. Operations. gen_build_code (selector_path)
1078+ end
1079+ select_cmd = Cmd (` $code $(Base. BinaryPlatforms. triplet (platform)) ` )
1080+ meta_toml = String (read (select_cmd))
1081+ push! (artifacts_tomls, (artifacts_toml, TOML. parse (meta_toml)))
1082+ else
1083+ # Otherwise, use the standard selector from `Artifacts`
1084+ artifacts = Pkg. Artifacts. select_downloadable_artifacts (artifacts_toml; platform, include_lazy)
1085+ push! (artifacts_tomls, (artifacts_toml, artifacts))
1086+ end
1087+ break
1088+ end
1089+ end
1090+ return artifacts_tomls
1091+ end
1092+
10581093function bundle_artifacts (ctx, dest_dir; include_lazy_artifacts:: Bool )
10591094 pkgs = load_all_deps (ctx)
10601095
@@ -1076,7 +1111,7 @@ function bundle_artifacts(ctx, dest_dir; include_lazy_artifacts::Bool)
10761111 pkg_source_path === nothing && continue
10771112 bundled_artifacts_pkg = Pair{String, String}[]
10781113 if isdefined (Pkg. Operations, :collect_artifacts )
1079- for (artifacts_toml, artifacts) in Pkg . Operations . collect_artifacts (pkg_source_path; platform)
1114+ for (artifacts_toml, artifacts) in _collect_artifacts (pkg_source_path; platform, include_lazy = include_lazy_artifacts )
10801115 for (name, data) in artifacts
10811116 Pkg. ensure_artifact_installed (name, artifacts[name], artifacts_toml; platform)
10821117 hash = Base. SHA1 (data[" git-tree-sha1" ])
0 commit comments