Skip to content

Commit 3955444

Browse files
authored
[AutoBuild] Fix default value of lazy_artifacts (#1191)
* [AutoBuild] Fix default value of `lazy_artifacts` * [AutoBuild] Simplify writing of files in `.pkg` directory * [AutoBuild] Add tests for platform augmentation
1 parent 28af078 commit 3955444

File tree

3 files changed

+63
-42
lines changed

3 files changed

+63
-42
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ RegistryTools = "d1eb7eb1-105f-429d-abf5-b0f65cb9e2c4"
2828
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2929
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
3030
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
31+
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
3132
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
3233
ghr_jll = "07c12ed4-43bc-5495-8a2a-d5838ef8d533"
3334

src/AutoBuild.jl

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export build_tarballs, autobuild, print_artifacts_toml, build, get_meta_json
22
import GitHub: gh_get_json, DEFAULT_API
33
import SHA: sha256, sha1
4-
using Pkg.TOML, Dates, UUIDs
4+
using TOML, Dates, UUIDs
55
using RegistryTools
66
import LibGit2
77
import PkgLicenses
@@ -104,7 +104,7 @@ const BUILD_HELP = (
104104
instead of actually building. Note that this can
105105
(and often does) output multiple JSON objects for
106106
multiple platforms, multi-stage builds, etc...
107-
107+
108108
--skip-audit Skips auditing of the output products.
109109
110110
--help Print out this message.
@@ -543,8 +543,8 @@ function register_jll(name, build_version, dependencies, julia_compat;
543543
code_dir=joinpath(Pkg.devdir(), "$(name)_jll"),
544544
gh_auth=Wizard.github_auth(;allow_anonymous=false),
545545
gh_username=gh_get_json(DEFAULT_API, "/user"; auth=gh_auth)["login"],
546-
lazy_artifacts::Bool=false,
547-
augment_platform_block="",
546+
augment_platform_block::String="",
547+
lazy_artifacts::Bool=!isempty(augment_platform_block) && minimum_compat(julia_compat) < v"1.7",
548548
kwargs...)
549549
if !isempty(augment_platform_block) && minimum_compat(julia_compat) < v"1.6"
550550
error("Augmentation blocks cannot be used with Julia v1.5-.\nChange `julia_compat` to require at least Julia v1.6")
@@ -622,9 +622,10 @@ function get_meta_json(
622622
products::Vector{<:Product},
623623
dependencies::Vector{<:AbstractDependency};
624624
julia_compat::String = DEFAULT_JULIA_VERSION_SPEC,
625-
lazy_artifacts::Bool = false,
626625
init_block::String = "",
627-
augment_platform_block::String = "")
626+
augment_platform_block::String = "",
627+
lazy_artifacts::Bool=!isempty(augment_platform_block) && minimum_compat(julia_compat) < v"1.7",
628+
)
628629

629630
dict = Dict(
630631
"name" => src_name,
@@ -654,7 +655,7 @@ function compose_debug_prompt(workspace)
654655
end
655656
end
656657
end
657-
658+
658659
if length(log_files) > 0
659660
log_files_str = join(log_files, "\n - ")
660661

@@ -1064,7 +1065,6 @@ function rebuild_jll_package(obj::Dict;
10641065
build_version = nothing,
10651066
gh_org::String = "JuliaBinaryWrappers",
10661067
verbose::Bool = false,
1067-
lazy_artifacts::Bool = false,
10681068
from_scratch::Bool = true)
10691069
if build_version === nothing
10701070
build_version = BinaryBuilder.get_next_wrapper_version(obj["name"], obj["version"])
@@ -1079,6 +1079,9 @@ function rebuild_jll_package(obj::Dict;
10791079
error("If download_dir is specified, you must specify upload_prefix as well!")
10801080
end
10811081

1082+
julia_compat = get(obj, "julia_compat", DEFAULT_JULIA_VERSION_SPEC)
1083+
augment_platform_block = get(obj, "augment_platform_block", "")
1084+
lazy_artifacts = get(obj, "lazy_artifacts", !isempty(augment_platform_block) && minimum_compat(julia_compat) < v"1.7")
10821085
return rebuild_jll_package(
10831086
obj["name"],
10841087
build_version,
@@ -1088,12 +1091,12 @@ function rebuild_jll_package(obj::Dict;
10881091
obj["dependencies"],
10891092
download_dir,
10901093
upload_prefix;
1091-
verbose=verbose,
1092-
lazy_artifacts = lazy_artifacts,
1093-
julia_compat = get(obj, "julia_compat", DEFAULT_JULIA_VERSION_SPEC),
1094+
verbose,
1095+
lazy_artifacts,
1096+
julia_compat,
10941097
init_block = get(obj, "init_block", ""),
1095-
augment_platform_block = get(obj, "augment_platform_block", ""),
1096-
from_scratch = from_scratch,
1098+
augment_platform_block,
1099+
from_scratch,
10971100
)
10981101
end
10991102

@@ -1196,8 +1199,8 @@ function build_jll_package(src_name::String,
11961199
bin_path::String;
11971200
verbose::Bool = false,
11981201
julia_compat::String = DEFAULT_JULIA_VERSION_SPEC,
1199-
init_block = "",
1200-
augment_platform_block = "",
1202+
init_block::String = "",
1203+
augment_platform_block::String = "",
12011204
# If we support versions older than Julia v1.7 the artifact
12021205
# should be lazy when we augment the platform.
12031206
lazy_artifacts::Bool = !isempty(augment_platform_block) && minimum_compat(julia_compat) < v"1.7",
@@ -1327,33 +1330,28 @@ function build_jll_package(src_name::String,
13271330
if !isempty(augment_platform_block)
13281331
pkg_dir = joinpath(code_dir, ".pkg")
13291332
!ispath(pkg_dir) && mkdir(pkg_dir)
1330-
open(joinpath(pkg_dir, "platform_augmentation.jl"), "w") do io
1331-
println(io, """
1332-
$(augment_platform_block)
1333-
""")
1334-
end
1333+
write(joinpath(pkg_dir, "platform_augmentation.jl"), augment_platform_block)
13351334

1336-
open(joinpath(pkg_dir, "select_artifacts.jl"), "w") do io
1337-
println(io, """
1338-
push!(Base.LOAD_PATH, dirname(@__DIR__))
1335+
write(joinpath(pkg_dir, "select_artifacts.jl"),
1336+
"""
1337+
push!(Base.LOAD_PATH, dirname(@__DIR__))
13391338
1340-
using TOML, Artifacts, Base.BinaryPlatforms
1341-
include("./platform_augmentation.jl")
1342-
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
1339+
using TOML, Artifacts, Base.BinaryPlatforms
1340+
include("./platform_augmentation.jl")
1341+
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
13431342
1344-
# Get "target triplet" from ARGS, if given (defaulting to the host triplet otherwise)
1345-
target_triplet = get(ARGS, 1, Base.BinaryPlatforms.host_triplet())
1343+
# Get "target triplet" from ARGS, if given (defaulting to the host triplet otherwise)
1344+
target_triplet = get(ARGS, 1, Base.BinaryPlatforms.host_triplet())
13461345
1347-
# Augment this platform object with any special tags we require
1348-
platform = augment_platform!(HostPlatform(parse(Platform, target_triplet)))
1346+
# Augment this platform object with any special tags we require
1347+
platform = augment_platform!(HostPlatform(parse(Platform, target_triplet)))
13491348
1350-
# Select all downloadable artifacts that match that platform
1351-
artifacts = select_downloadable_artifacts(artifacts_toml; platform, include_lazy=true)
1349+
# Select all downloadable artifacts that match that platform
1350+
artifacts = select_downloadable_artifacts(artifacts_toml; platform, include_lazy=true)
13521351
1353-
#Output the result to `stdout` as a TOML dictionary
1354-
TOML.print(stdout, artifacts)
1355-
""")
1356-
end
1352+
#Output the result to `stdout` as a TOML dictionary
1353+
TOML.print(stdout, artifacts)
1354+
""")
13571355
end
13581356

13591357
# Generate target-demuxing main source file.
@@ -1419,9 +1417,9 @@ function build_jll_package(src_name::String,
14191417
if is_yggdrasil()
14201418
println(io, """
14211419
The originating [`build_tarballs.jl`](https://github.com/JuliaPackaging/Yggdrasil/blob/$(yggdrasil_head())/$(ENV["PROJECT"])/build_tarballs.jl) script can be found on [`Yggdrasil`](https://github.com/JuliaPackaging/Yggdrasil/), the community build tree.")
1422-
1420+
14231421
## Bug Reports
1424-
1422+
14251423
If you have any issue, please report it to the Yggdrasil [bug tracker](https://github.com/JuliaPackaging/Yggdrasil/issues).
14261424
""")
14271425
end
@@ -1505,7 +1503,7 @@ function build_jll_package(src_name::String,
15051503
jllwrappers_compat = isempty(augment_platform_block) ? "1.2.0" : "1.4.0"
15061504
project = build_project_dict(src_name, build_version, dependencies, julia_compat; lazy_artifacts, jllwrappers_compat, augment_platform_block)
15071505
open(joinpath(code_dir, "Project.toml"), "w") do io
1508-
Pkg.TOML.print(io, project)
1506+
TOML.print(io, project)
15091507
end
15101508

15111509
# Add a `.gitignore`
@@ -1579,8 +1577,8 @@ end
15791577
function build_project_dict(name, version, dependencies::Array{Dependency},
15801578
julia_compat::String=DEFAULT_JULIA_VERSION_SPEC;
15811579
jllwrappers_compat::String=DEFAULT_JLLWRAPPERS_VERSION_SPEC,
1582-
lazy_artifacts::Bool=false,
1583-
augment_platform_block="",
1580+
augment_platform_block::String="",
1581+
lazy_artifacts::Bool=!isempty(augment_platform_block) && minimum_compat(julia_compat) < v"1.7",
15841582
kwargs...)
15851583
Pkg.Types.semver_spec(julia_compat) # verify julia_compat is valid
15861584
project = Dict(

test/jll.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using TOML
12
using JSON
23
using UUIDs
34
using GitHub
@@ -48,6 +49,17 @@ end
4849
platforms = [platform, freebsd]
4950
# We depend on Zlib_jll only on the host platform, but not on FreeBSD
5051
dependencies = [Dependency("Zlib_jll"; platforms=[platform])]
52+
# Augment platform
53+
augment_platform_block = """
54+
using Base.BinaryPlatforms
55+
function augment_platform!(platform::Platform)
56+
platform["test"] = "enabled"
57+
return platform
58+
end
59+
"""
60+
# Julia compat. Include Julia v1.6 to exercise the code path which forces lazy
61+
# artifacts when augmenting the platform
62+
julia_compat = "1.6"
5163
# The buffer where we'll write the JSON meta data
5264
buff = IOBuffer()
5365

@@ -65,6 +77,8 @@ end
6577
# The products we expect to be build
6678
libfoo_products,
6779
dependencies;
80+
julia_compat,
81+
augment_platform_block,
6882
)
6983
# Generate the JSON file
7084
println(buff, JSON.json(dict))
@@ -143,13 +157,21 @@ end
143157
@test occursin("MESON_TARGET_TOOLCHAIN", json_obj["script"])
144158
end
145159

146-
BinaryBuilder.rebuild_jll_package(json_obj; download_dir=download_dir, upload_prefix=upload_prefix, verbose=false, lazy_artifacts=json_obj["lazy_artifacts"], from_scratch=from_scratch)
160+
BinaryBuilder.rebuild_jll_package(json_obj; download_dir, upload_prefix, verbose=false, from_scratch)
147161
end
148162

149163
env_dir = joinpath(build_path, "foo")
150164
mkpath(env_dir)
151165
Pkg.activate(env_dir)
152166
Pkg.develop(PackageSpec(path=code_dir))
167+
@test isfile(joinpath(code_dir, ".pkg", "select_artifacts.jl"))
168+
@test read(joinpath(code_dir, ".pkg", "platform_augmentation.jl"), String) == augment_platform_block
169+
# Make sure the artifacts are lazy because we are augmenting the platform and
170+
# Julia compat includes versions before v1.7.
171+
artifacts_toml = TOML.parsefile(joinpath(code_dir, "Artifacts.toml"))
172+
for artifact in artifacts_toml["libfoo"]
173+
@test artifact["lazy"]
174+
end
153175
# Make sure we use Zlib_jll only in the wrapper for the host
154176
# platform and not the FreeBSD one.
155177
platform_wrapper = joinpath(code_dir, "src", "wrappers", triplet(platform) * ".jl")

0 commit comments

Comments
 (0)