From a0032c482ae3aefd2dd4b98552399ab684fa99b1 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Wed, 20 Sep 2023 12:36:39 +0000 Subject: [PATCH] Remove separate source_urls wizard field Goes with https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/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). --- Project.toml | 2 +- src/wizard/deploy.jl | 16 +++++++--------- src/wizard/obtain_source.jl | 15 ++++++--------- src/wizard/state.jl | 1 - test/basic.jl | 3 +-- test/wizard.jl | 10 +++++----- 6 files changed, 20 insertions(+), 27 deletions(-) diff --git a/Project.toml b/Project.toml index 32087f568..8bdfbf55d 100644 --- a/Project.toml +++ b/Project.toml @@ -33,7 +33,7 @@ ghr_jll = "07c12ed4-43bc-5495-8a2a-d5838ef8d533" [compat] ArgParse = "1.1" -BinaryBuilderBase = "1.20" +BinaryBuilderBase = "1.26" GitHub = "5.1" HTTP = "0.8, 0.9, 1" JLD2 = "0.1.6, 0.2, 0.3, 0.4" diff --git a/src/wizard/deploy.jl b/src/wizard/deploy.jl index 9675b137c..4192eeaf8 100644 --- a/src/wizard/deploy.jl +++ b/src/wizard/deploy.jl @@ -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)") - if endswith(x[1], ".git") - "GitSource($(url_string), $(repr(x[2].hash)))" - elseif any(endswith(x[1], ext) for ext in BinaryBuilderBase.archive_extensions) - "ArchiveSource($(url_string), $(repr(x[2].hash)))" + url_string = replace(repr(source.url), string(state.version) => "\$(version)") + if endswith(source.url, ".git") + "GitSource($(url_string), $(repr(source.hash)))" + elseif any(endswith(source.url, ext) for ext in BinaryBuilderBase.archive_extensions) + "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) diff --git a/src/wizard/obtain_source.jl b/src/wizard/obtain_source.jl index c464e7475..7cb52adfd 100644 --- a/src/wizard/obtain_source.jl +++ b/src/wizard/obtain_source.jl @@ -54,7 +54,7 @@ function download_source(state::WizardState) """), "\n" => " ") new_entered_url = nonempty_line_prompt("URL", msg; ins=state.ins, outs=state.outs) if new_entered_url == "N" || new_entered_url == "n" - return new_entered_url, SetupSource(string(new_entered_url), "", "", "") + return nothing end # Early-exit for invalid URLs, using HTTP.URIs.parse_uri() to ensure # it is a valid URL @@ -82,8 +82,7 @@ function download_source(state::WizardState) end local source_hash - - if endswith(url, ".git") || startswith(url, "git://") + 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) @@ -136,7 +135,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 """ @@ -272,17 +271,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 diff --git a/src/wizard/state.jl b/src/wizard/state.jl index ce7cb3980..69bf7290d 100644 --- a/src/wizard/state.jl +++ b/src/wizard/state.jl @@ -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 diff --git a/test/basic.jl b/test/basic.jl index c8ac4c169..ea7850259 100644 --- a/test/basic.jl +++ b/test/basic.jl @@ -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")), diff --git a/test/wizard.jl b/test/wizard.jl index 395b969e6..f09f43b26 100644 --- a/test/wizard.jl +++ b/test/wizard.jl @@ -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]) @@ -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", ] @@ -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") @@ -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[]