Skip to content

Commit

Permalink
Remove separate source_urls wizard field
Browse files Browse the repository at this point in the history
Goes with JuliaPackaging/BinaryBuilderBase.jl#322.
Part of the problem with the current setup is that the WizardState doesn't
actually round trip properly, because the cache for archive downloads gets
deleted. It could be reconstituted from source_urls of course, but it would
be cleaner to just do that on-demand with the SetupSource (though this
commit doesn't do that yet).
  • Loading branch information
Keno committed Sep 20, 2023
1 parent d40ec61 commit 4bb7f6d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
12 changes: 5 additions & 7 deletions src/wizard/deploy.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
function print_build_tarballs(io::IO, state::WizardState)
urlfiles = zip(state.source_urls, state.source_files)

sources_strings = map(urlfiles) do x
sources_strings = map(state.source_files) do source
# Try to be smart and automatically replace version number with `$(version)`.
url_string = replace(repr(x[1]), string(state.version) => "\$(version)")
url_string = replace(repr(source.url), string(state.version) => "\$(version)")
if endswith(x[1], ".git")
"GitSource($(url_string), $(repr(x[2].hash)))"
"GitSource($(url_string), $(repr(source.hash)))"
elseif any(endswith(x[1], ext) for ext in BinaryBuilderBase.archive_extensions)
"ArchiveSource($(url_string), $(repr(x[2].hash)))"
"ArchiveSource($(url_string), $(repr(source.hash)))"
else
"FileSource($(url_string), $(repr(x[2].hash)))"
"FileSource($(url_string), $(repr(source.hash)))"
end
end
if !isempty(state.patches)
Expand Down
16 changes: 9 additions & 7 deletions src/wizard/obtain_source.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ function download_source(state::WizardState)

local source_hash

if endswith(url, ".git") || startswith(url, "git://")
if url == "N"
return nothing
end

if endswith(url, ".git") || startswith(url, "git://") || startswith(url, "ssh://")
source_path = cached_git_clone(url; progressbar=true, verbose=true)
# Clone the URL, record the current gitsha for the given branch
repo = GitRepo(source_path)
Expand Down Expand Up @@ -136,7 +140,7 @@ function download_source(state::WizardState)
end

# Spit back the url, local path and source hash
return url, SetupSource(url, source_path, source_hash, "")
return SetupSource(url, source_path, source_hash, "")
end

"""
Expand Down Expand Up @@ -272,17 +276,15 @@ function obtain_source(state::WizardState)

# These are the metadata we need to know about all the sources we'll be
# building over the course of this journey we're on together.
state.source_urls = String[]
state.source_files = SetupSource[]

while true
url, file = download_source(state)
if url != "N"
push!(state.source_urls, url)
file = download_source(state)
if file !== nothing
push!(state.source_files, file)
println(state.outs)
else
if isempty(state.source_urls)
if isempty(state.source_files)
printstyled(state.outs, "No URLs were given.\n", color=:yellow, bold=true)
continue
end
Expand Down
1 change: 0 additions & 1 deletion src/wizard/state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ necessary. It also holds all necessary metadata such as input/output streams.

# Filled in by step 2
workspace::Union{Nothing, String} = nothing
source_urls::Union{Nothing, Vector{String}} = nothing
source_files::Union{Nothing, Vector{SetupSource}} = nothing
dependencies::Union{Nothing, Vector{Dependency}} = nothing
compilers::Union{Nothing, Vector{Symbol}} = nothing
Expand Down
3 changes: 1 addition & 2 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ end
state = Wizard.WizardState()
state.step = :step34
state.platforms = [Platform("x86_64", "linux")]
state.source_urls = ["http://127.0.0.1:14444/a/source.tar.gz"]
state.source_files = [BinaryBuilder.SetupSource{ArchiveSource}("/tmp/source.tar.gz", bytes2hex(sha256("a")), "")]
state.source_files = [BinaryBuilder.SetupSource{ArchiveSource}("http://127.0.0.1:14444/a/source.tar.gz", "/tmp/source.tar.gz", bytes2hex(sha256("a")), "")]
state.name = "libfoo"
state.version = v"1.0.0"
state.dependencies = [Dependency(PackageSpec(;name="Zlib_jll")),
Expand Down
10 changes: 5 additions & 5 deletions test/wizard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ end
call_response(ins, outs, "Select the preferred LLVM version", "\e[B\e[B\e[B\r")
end
# Check that the state is modified appropriately
@test state.source_urls == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
@test getfield.(state.source_files, :url) == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
@test getfield.(state.source_files, :hash) == [libfoo_tarball_hash]
@test Set(state.compilers) == Set([:c, :rust, :go])
@test state.preferred_gcc_version == getversion(available_gcc_builds[1])
Expand All @@ -201,7 +201,7 @@ end
call_response(ins, outs, "Do you want to customize the set of compilers?", "N")
end
# Check that the state is modified appropriately
@test state.source_urls == [
@test getfield.(state.source_files, :url) == [
"http://127.0.0.1:$(port)/a/source.tar.gz",
"http://127.0.0.1:$(port)/b/source.tar.gz",
]
Expand Down Expand Up @@ -268,7 +268,7 @@ end
call_response(ins, outs, "Enter a version number", "1.0.0")
call_response(ins, outs, "Do you want to customize the set of compilers?", "N")
end
@test state.source_urls == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
@test getfield.(state.source_files, :url) == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
state = step2_state()
with_wizard_output(state, Wizard.step2) do ins, outs
call_response(ins, outs, "Please enter a URL", "N")
Expand All @@ -295,8 +295,8 @@ function step3_state()
state = Wizard.WizardState()
state.step = :step34
state.platforms = [Platform("x86_64", "linux")]
state.source_urls = ["http://127.0.0.1:$(port)/a/source.tar.gz"]
state.source_files = [BinaryBuilder.SetupSource{ArchiveSource}(libfoo_tarball_path, libfoo_tarball_hash, "")]
state.source_files = [BinaryBuilder.SetupSource{ArchiveSource}("http://127.0.0.1:$(port)/a/source.tar.gz",
libfoo_tarball_path, libfoo_tarball_hash, "")]
state.name = "libfoo"
state.version = v"1.0.0"
state.dependencies = Dependency[]
Expand Down

0 comments on commit 4bb7f6d

Please sign in to comment.