Skip to content

Commit

Permalink
Store url in SetupSource
Browse files Browse the repository at this point in the history
Otherwise the wizard needs to keep a separate 1-1 mapping of the urls,
which is somewhat silly.
  • Loading branch information
Keno committed Sep 20, 2023
1 parent 18e421f commit e766dce
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,29 @@ DirectorySource(path::String; target::String = "", follow_symlinks::Bool=false)
DirectorySource(path, target, follow_symlinks)

# Try to guess if a URL is a Git repository
isgitrepo(url::AbstractString) = endswith(url, ".git") || startswith(url, "git://")
isgitrepo(url::AbstractString) = endswith(url, ".git") || startswith(url, "git://") || startswith(url, "ssh://")

# This is not meant to be used as source in the `build_tarballs.jl` scripts but
# only to set up the source in the workspace.
struct SetupSource{T<:AbstractSource}
url::Union{String, Nothing}
path::String
hash::String
target::String
follow_symlinks::Bool
end
# `follow_symlinks` is used only for DirectorySource, let's have a method without it.
SetupSource{T}(path::String, hash::String, target::String) where {T} =
SetupSource{T}(path, hash, target, false)
SetupSource{T}(url::Nothing, path::String, hash::String, target::String) where {T} =
SetupSource{T}(url, path, hash, target, false)
# This is used in wizard/obtain_source.jl to automatically guess the parameter
# of SetupSource from the URL
function SetupSource(url::String, path::String, hash::String, target::String)
if isgitrepo(url)
return SetupSource{GitSource}(path, hash, target)
return SetupSource{GitSource}(url, path, hash, target)
elseif any(endswith(path, ext) for ext in archive_extensions)
return SetupSource{ArchiveSource}(path, hash, target)
return SetupSource{ArchiveSource}(url, path, hash, target)
else
return SetupSource{FileSource}(path, hash, target)
return SetupSource{FileSource}(url, path, hash, target)
end
end

Expand All @@ -173,7 +174,7 @@ function download_source(source::T; verbose::Bool = false, downloads_dir = stora
src_path = joinpath(downloads_dir, string(source.hash, "-", basename(source.url)))
download_verify(source.url, source.hash, src_path)
end
return SetupSource{T}(src_path, source.hash, gettarget(source))
return SetupSource{T}(source.url, src_path, source.hash, gettarget(source))
end

struct GitTransferProgress
Expand Down Expand Up @@ -245,7 +246,7 @@ end

function download_source(source::GitSource; kwargs...)
src_path = cached_git_clone(source.url; hash_to_check=source.hash, kwargs...)
return SetupSource{GitSource}(src_path, source.hash, source.unpack_target)
return SetupSource{GitSource}(source.url, src_path, source.hash, source.unpack_target)
end

function download_source(source::DirectorySource; verbose::Bool = false)
Expand All @@ -255,7 +256,7 @@ function download_source(source::DirectorySource; verbose::Bool = false)
if verbose
@info "Directory \"$(source.path)\" found"
end
return SetupSource{DirectorySource}(abspath(source.path), "", source.target, source.follow_symlinks)
return SetupSource{DirectorySource}(nothing, abspath(source.path), "", source.target, source.follow_symlinks)
end

"""
Expand Down

0 comments on commit e766dce

Please sign in to comment.