From f78a16add67f313e8774550ed035688eeb872a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Sun, 27 Feb 2022 20:50:09 +0000 Subject: [PATCH] [Prefix] Fix installation of dependencies from local directories (#225) If the provided dependency has already a path, propagate it to the list of installed JLLs in `setup_dependencies`. --- Project.toml | 2 +- src/Prefix.jl | 10 ++++++--- test/dependencies.jl | 50 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index 91bc6a31..67656349 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BinaryBuilderBase" uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e" authors = ["Elliot Saba "] -version = "1.6.0" +version = "1.6.1" [deps] CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193" diff --git a/src/Prefix.jl b/src/Prefix.jl index 71162a7a..f88b3c13 100644 --- a/src/Prefix.jl +++ b/src/Prefix.jl @@ -603,14 +603,16 @@ function setup_dependencies(prefix::Prefix, name=pkg.name, uuid, tree_hash=pkg.tree_hash, + path=pkg.path, ) for (uuid, pkg) in ctx.env.manifest if uuid ∈ installed_jll_uuids ] # Check for stdlibs lurking in the installed JLLs stdlib_pkgspecs = PackageSpec[] for dep in installed_jlls - # If the `tree_hash` is `nothing`, then this JLL was treated as an stdlib - if dep.tree_hash === nothing + # If the dependency doesn't have a path yet and the `tree_hash` is + # `nothing`, then this JLL is probably an stdlib. + if dep.path === nothing && dep.tree_hash === nothing # Figure out what version this stdlib _should_ be at for this version dep.version = stdlib_version(dep.uuid, julia_version) @@ -632,7 +634,9 @@ function setup_dependencies(prefix::Prefix, # Load their Artifacts.toml files for dep in installed_jlls name = getname(dep) - dep_path = Pkg.Operations.find_installed(name, dep.uuid, dep.tree_hash) + # If the package has a path, use it, otherwise ask Pkg where it + # should have been installed. + dep_path = dep.path !== nothing ? dep.path : Pkg.Operations.find_installed(name, dep.uuid, dep.tree_hash) # Skip dependencies that didn't get installed? if dep_path === nothing diff --git a/test/dependencies.jl b/test/dependencies.jl index 02e94b41..af99fad4 100644 --- a/test/dependencies.jl +++ b/test/dependencies.jl @@ -1,8 +1,9 @@ using Test using Pkg, Base.BinaryPlatforms using BinaryBuilderBase -using BinaryBuilderBase: getname, getpkg, dependencify, destdir, PKG_VERSIONS, get_addable_spec +using BinaryBuilderBase: getname, getpkg, dependencify, destdir, PKG_VERSIONS, get_addable_spec, cached_git_clone using JSON +using LibGit2 # Define equality between dependencies, in order to carry out the tests below Base.:(==)(a::AbstractDependency, b::AbstractDependency) = getpkg(a) == getpkg(b) @@ -179,7 +180,7 @@ end platform = Platform("x86_64", "linux"; julia_version=v"1.5") # Test that a particular version of GMP is installed - ap = @test_logs setup_dependencies(prefix, getpkg.(dependencies), platform) + @test_logs setup_dependencies(prefix, getpkg.(dependencies), platform) @test isfile(joinpath(destdir(dir, platform), "lib", "libgmp.so.10.3.2")) end @@ -190,7 +191,7 @@ end platform = Platform("x86_64", "linux"; julia_version=v"1.6") # Test that a particular version of GMP is installed - ap = @test_logs setup_dependencies(prefix, getpkg.(dependencies), platform) + @test_logs setup_dependencies(prefix, getpkg.(dependencies), platform) @test isfile(joinpath(destdir(dir, platform), "lib", "libgmp.so.10.4.0")) end @@ -204,16 +205,53 @@ end # Test that this is not instantiatable with either Julia v1.5 or v1.6 platform = Platform("x86_64", "linux"; julia_version=v"1.5") - ap = @test_throws Pkg.Resolve.ResolverError setup_dependencies(prefix, getpkg.(dependencies), platform) + @test_throws Pkg.Resolve.ResolverError setup_dependencies(prefix, getpkg.(dependencies), platform) platform = Platform("x86_64", "linux"; julia_version=v"1.6") - ap = @test_throws Pkg.Resolve.ResolverError setup_dependencies(prefix, getpkg.(dependencies), platform) + @test_throws Pkg.Resolve.ResolverError setup_dependencies(prefix, getpkg.(dependencies), platform) # If we don't give a `julia_version`, then we are FULLY UNSHACKLED. platform = Platform("x86_64", "linux") - ap = @test_logs setup_dependencies(prefix, getpkg.(dependencies), platform) + @test_logs setup_dependencies(prefix, getpkg.(dependencies), platform) @test isfile(joinpath(destdir(dir, platform), "lib", "libgmp.so.10.3.2")) @test isfile(joinpath(destdir(dir, platform), "lib", "libmpfr.so.6.1.0")) end + + # Dependency as a local directory + with_temp_project() do dir + mktempdir() do pkgdir + prefix = Prefix(dir) + # Clone if necessary the remote repository and check out its + # working directory in a temporary space. + cache_dir = cached_git_clone("https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl") + LibGit2.with(LibGit2.clone(cache_dir, pkgdir)) do repo + LibGit2.checkout!(repo, "c7f2e95d9c04e218931c14954ecd31ebde72cca5") + end + dependencies = [ + PackageSpec( + name="HelloWorldC_jll", + path=pkgdir, + ), + ] + platform = Platform("x86_64", "linux"; libc="glibc") + @test_logs setup_dependencies(prefix, dependencies, platform) + @test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"] + end + end + + # Dependency as a remote repository + with_temp_project() do dir + prefix = Prefix(dir) + dependencies = [ + PackageSpec( + name="HelloWorldC_jll", + url="https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl", + rev="c7f2e95d9c04e218931c14954ecd31ebde72cca5", + ), + ] + platform = Platform("x86_64", "linux"; libc="glibc") + @test_logs setup_dependencies(prefix, dependencies, platform) + @test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"] + end end end