Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GAP.Packages.build(name) #1066

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GAP.Packages.load
GAP.Packages.install
GAP.Packages.update
GAP.Packages.remove
GAP.Packages.build
GAP.Packages.locate_package
```

49 changes: 49 additions & 0 deletions src/packages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,55 @@ function remove(spec::String; interactive::Bool = true, quiet::Bool = false,
end
end

"""
build(name::String; quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = GAP.Packages.DEFAULT_PKGDIR[])

Build the GAP package with name `name` that is installed in the
`pkgdir` directory.

If no package with name `name` is installed in `pkgdir` but there is a version of
`name` bundled with the GAP package distro, this version is copied to `pkgdir` and built.

Return `true` if the build was successful, and `false` otherwise.

The function uses [the function `CompilePackage` from GAP's package
`PackageManager`](GAP_ref(PackageManager:CompilePackage)).
The info messages shown by this function can be suppressed by passing
`true` as the value of `quiet`.
"""
function build(name::String; quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = DEFAULT_PKGDIR[])
# point PackageManager to the given pkg dir
Globals.PKGMAN_CustomPackageDir = GapObj(pkgdir)
mkpath(pkgdir)

gname = GapObj(name)
allinfo = collect(Globals.PackageInfo(gname))
userinfo = filter(info -> startswith(String(info.InstallationPath), pkgdir), allinfo)
isempty(allinfo) && error("package not found")
length(userinfo) > 1 && error("multiple installations of package found in pkgdir")
if isempty(userinfo)
length(allinfo) > 1 && error("multiple installations of package found")
info = only(allinfo)
oldpath = String(info.InstallationPath)
newpath = joinpath(pkgdir, name * "-" * String(info.Version))
cp(oldpath, newpath)
end
if quiet || debug
oldlevel = Wrappers.InfoLevel(Globals.InfoPackageManager)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, quiet ? 0 : 3)
end
Globals.PKGMAN_RefreshPackageInfo()
res = Globals.CompilePackage(gname)
if quiet || debug
Wrappers.SetInfoLevel(Globals.InfoPackageManager, oldlevel)
end
return res
end

"""
locate_package(name::String)

Expand Down
Loading