Skip to content

Commit

Permalink
Separate compile.* files
Browse files Browse the repository at this point in the history
  • Loading branch information
mtorpey committed Aug 30, 2024
1 parent 580d0d5 commit 7509cf2
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 187 deletions.
1 change: 1 addition & 0 deletions doc/intro.autodoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ InstallPackage("https://github.com/gap-packages/curlInterface.git");
@EndExample

@Chapter Commands
@Chapter Compilation
32 changes: 0 additions & 32 deletions gap/PackageManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,6 @@ DeclareGlobalFunction("InstallPackage");
#! <K>true</K> or <K>false</K>
DeclareGlobalFunction("UpdatePackage");

#! @Description
#! Attempts to compile an installed package. Takes one argument <A>name</A>,
#! which should be a string specifying the name of a package installed in the
#! user &GAP; root (for example, one installed using <Ref
#! Func="InstallPackage" />), see <Ref BookName="ref" Sect="GAP Root
#! Directories"/>. Compilation is done automatically when a package is
#! installed or updated, so in most cases this command is not needed.
#! However, it may sometimes be necessary to recompile some packages if you
#! update or move your &GAP; installation.
#!
#! Compilation is done using the `etc/BuildPackages.sh` script bundled with
#! &PackageManager;. If the specified package does not have a compiled
#! component, this function should have no effect.
#!
#! Returns <K>true</K> if compilation was successful or if no compilation was
#! necessary. Returns <K>false</K> otherwise.
#!
#! @BeginExample
#! gap> CompilePackage("orb");
#! #I Running compilation script on /home/user/.gap/pkg/orb-4.8.3 ...
#! true
#! @EndExample
#!
#! @Arguments name
#! @Returns
#! <K>true</K> or <K>false</K>
DeclareGlobalFunction("CompilePackage");

#! @Description
#! Info class for the <Package>PackageManager</Package> package. Set this to
#! the following levels for different levels of information:
Expand Down Expand Up @@ -255,7 +227,6 @@ DeclareGlobalFunction("GetPackageURLs");
# Hidden functions
DeclareGlobalFunction("PKGMAN_InstallDependencies");
DeclareGlobalFunction("PKGMAN_CheckPackage");
DeclareGlobalFunction("PKGMAN_CompileDir");
DeclareGlobalFunction("PKGMAN_MakeDoc");
DeclareGlobalFunction("PKGMAN_Exec");
DeclareGlobalFunction("PKGMAN_NameOfGitRepo");
Expand Down Expand Up @@ -283,9 +254,6 @@ PKGMAN_DownloadCmds := [ [ "wget", ["--quiet", "-O", "-"] ],
PKGMAN_CurlIntReqVer :=
First(PackageInfo("PackageManager")[1].Dependencies.SuggestedOtherPackages,
item -> item[1] = "curlInterface")[2];
PKGMAN_BuildPackagesScript :=
Filename(DirectoriesPackageLibrary("PackageManager", "etc"),
"BuildPackages.sh");
PKGMAN_Sysinfo := Filename(DirectoriesLibrary(""), "sysinfo.gap");
PKGMAN_InstallQueue := []; # Queue of dependencies to install
PKGMAN_MarkedForInstall := []; # Packages currently halfway through installing
Expand Down
86 changes: 0 additions & 86 deletions gap/PackageManager.gi
Original file line number Diff line number Diff line change
Expand Up @@ -834,39 +834,6 @@ function(name, interactive...)
fi;
end);

InstallGlobalFunction(CompilePackage,
function(name)
local user_pkg_dir, allinfo, info;

# Check input
if not IsString(name) then
ErrorNoReturn("PackageManager: CompilePackage: ",
"<name> must be a string");
fi;

# Locate the package
name := LowercaseString(name);
user_pkg_dir := PKGMAN_PackageDir();
allinfo := PackageInfo(name);
info := Filtered(allinfo,
x -> IsMatchingSublist(x.InstallationPath, user_pkg_dir));

# Package not installed
if Length(info) = 0 then
Info(InfoPackageManager, 1,
"Package \"", name, "\" not installed in user package directory");
Info(InfoPackageManager, 2, "(currently set to ", PKGMAN_PackageDir(), ")");
if not IsEmpty(allinfo) then
Info(InfoPackageManager, 2, "installed at ",
List(allinfo, i -> i.InstallationPath), ", not in ", user_pkg_dir);
fi;
return false;
fi;

# Compile it
return PKGMAN_CompileDir(info[1].InstallationPath);
end);

InstallGlobalFunction(PKGMAN_CheckPackage,
function(dir)
local info, fname, html;
Expand Down Expand Up @@ -932,59 +899,6 @@ function(dir)
return true;
end);

InstallGlobalFunction(PKGMAN_CompileDir,
function(dir)
local prerequisites, exec, pkg_dir, scr, root, info;

info := PKGMAN_GetPackageInfo(dir);
if info = fail then
return false;
fi;

# Run the prerequisites file if it exists
# Note: this is mainly for installing Semigroups from GitHub
prerequisites := Filename(Directory(dir), "prerequisites.sh");
if IsReadableFile(prerequisites) then
Info(InfoPackageManager, 3,
"Running prerequisites.sh for ", info.PackageName, "...");
exec := PKGMAN_Exec(dir, prerequisites);
fi;

# Check requirements, and prepare command
pkg_dir := Filename(Directory(dir), "..");
scr := PKGMAN_Sysinfo;
if scr = fail then
Info(InfoPackageManager, 1, "No sysinfo.gap found");
return false;
fi;
root := scr{[1 .. Length(scr) - Length("/sysinfo.gap")]};

# Is the compilation script available?
if not (IsString(PKGMAN_BuildPackagesScript)
and IsReadableFile(PKGMAN_BuildPackagesScript)) then
Info(InfoPackageManager, 1, "Compilation script not found");
return false;
fi;

# Call the script
Info(InfoPackageManager, 3, "Running compilation script on ", dir, " ...");
exec := PKGMAN_Exec(pkg_dir, PKGMAN_BuildPackagesScript, root, dir);
if exec = fail or
exec.code <> 0 or
PositionSublist(exec.output, "Failed to build") <> fail then
Info(InfoPackageManager, 1,
"Compilation failed for package '",
info.PackageName,
"' (package may still be usable)");
Info(InfoPackageManager, 2, exec.output);
return false;
else
Info(InfoPackageManager, 3, exec.output);
fi;
Info(InfoPackageManager, 4, "Compilation was successful");
return true;
end);

InstallGlobalFunction(PKGMAN_MakeDoc,
function(dir)
local last_infogapdoc, last_infowarning, makedoc_g, doc_dir, doc_make_doc,
Expand Down
37 changes: 37 additions & 0 deletions gap/compile.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! @Chapter Compilation

#! @Section Manual compilation

#! @Description
#! Attempts to compile an installed package. Takes one argument <A>name</A>,
#! which should be a string specifying the name of a package installed in the
#! user &GAP; root (for example, one installed using <Ref
#! Func="InstallPackage" />), see <Ref BookName="ref" Sect="GAP Root
#! Directories"/>. Compilation is done automatically when a package is
#! installed or updated, so in most cases this command is not needed.
#! However, it may sometimes be necessary to recompile some packages if you
#! update or move your &GAP; installation.
#!
#! Compilation is done using the `etc/BuildPackages.sh` script bundled with
#! &PackageManager;. If the specified package does not have a compiled
#! component, this function should have no effect.
#!
#! Returns <K>true</K> if compilation was successful or if no compilation was
#! necessary. Returns <K>false</K> otherwise.
#!
#! @BeginExample
#! gap> CompilePackage("orb");
#! #I Running compilation script on /home/user/.gap/pkg/orb-4.8.3 ...
#! true
#! @EndExample
#!
#! @Arguments name
#! @Returns
#! <K>true</K> or <K>false</K>
DeclareGlobalFunction("CompilePackage");

DeclareGlobalFunction("PKGMAN_CompileDir");

PKGMAN_BuildPackagesScript :=
Filename(DirectoriesPackageLibrary("PackageManager", "etc"),
"BuildPackages.sh");
85 changes: 85 additions & 0 deletions gap/compile.gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
InstallGlobalFunction(CompilePackage,
function(name)
local user_pkg_dir, allinfo, info;

# Check input
if not IsString(name) then
ErrorNoReturn("PackageManager: CompilePackage: ",
"<name> must be a string");
fi;

# Locate the package
name := LowercaseString(name);
user_pkg_dir := PKGMAN_PackageDir();
allinfo := PackageInfo(name);
info := Filtered(allinfo,
x -> IsMatchingSublist(x.InstallationPath, user_pkg_dir));

# Package not installed
if Length(info) = 0 then
Info(InfoPackageManager, 1,
"Package \"", name, "\" not installed in user package directory");
Info(InfoPackageManager, 2, "(currently set to ", PKGMAN_PackageDir(), ")");
if not IsEmpty(allinfo) then
Info(InfoPackageManager, 2, "installed at ",
List(allinfo, i -> i.InstallationPath), ", not in ", user_pkg_dir);
fi;
return false;
fi;

# Compile it
return PKGMAN_CompileDir(info[1].InstallationPath);
end);

InstallGlobalFunction(PKGMAN_CompileDir,
function(dir)
local prerequisites, exec, pkg_dir, scr, root, info;

info := PKGMAN_GetPackageInfo(dir);
if info = fail then
return false;
fi;

# Run the prerequisites file if it exists
# Note: this is mainly for installing Semigroups from GitHub
prerequisites := Filename(Directory(dir), "prerequisites.sh");
if IsReadableFile(prerequisites) then
Info(InfoPackageManager, 3,
"Running prerequisites.sh for ", info.PackageName, "...");
exec := PKGMAN_Exec(dir, prerequisites);
fi;

# Check requirements, and prepare command
pkg_dir := Filename(Directory(dir), "..");
scr := PKGMAN_Sysinfo;
if scr = fail then
Info(InfoPackageManager, 1, "No sysinfo.gap found");
return false;
fi;
root := scr{[1 .. Length(scr) - Length("/sysinfo.gap")]};

# Is the compilation script available?
if not (IsString(PKGMAN_BuildPackagesScript)
and IsReadableFile(PKGMAN_BuildPackagesScript)) then
Info(InfoPackageManager, 1, "Compilation script not found");
return false;
fi;

# Call the script
Info(InfoPackageManager, 3, "Running compilation script on ", dir, " ...");
exec := PKGMAN_Exec(pkg_dir, PKGMAN_BuildPackagesScript, root, dir);
if exec = fail or
exec.code <> 0 or
PositionSublist(exec.output, "Failed to build") <> fail then
Info(InfoPackageManager, 1,
"Compilation failed for package '",
info.PackageName,
"' (package may still be usable)");
Info(InfoPackageManager, 2, exec.output);
return false;
else
Info(InfoPackageManager, 3, exec.output);
fi;
Info(InfoPackageManager, 4, "Compilation was successful");
return true;
end);
1 change: 1 addition & 0 deletions init.g
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
#

ReadPackage("PackageManager", "gap/PackageManager.gd");
ReadPackage("PackageManager", "gap/compile.gd");
ReadPackage("PackageManager", "gap/Interactive.gd");
1 change: 1 addition & 0 deletions read.g
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
#

ReadPackage("PackageManager", "gap/PackageManager.gi");
ReadPackage("PackageManager", "gap/compile.gi");
ReadPackage("PackageManager", "gap/Interactive.gi");
69 changes: 0 additions & 69 deletions tst/PackageManager.tst
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ true
gap> IsEmpty(PackageInfo("io"));
false

# Try to compile IO (which should be installed but not in the user pkg dir)
gap> CompilePackage("io");
#I Package "io" not installed in user package directory
false

# Try to compile something that's not there at all
gap> CompilePackage("madeUpPackage");
#I Package "madeuppackage" not installed in user package directory
false

# UpdatePackage for non-user packages
gap> UpdatePackage("GAPDoc", false);
#I Package "gapdoc" not installed in user package directory
Expand Down Expand Up @@ -119,12 +109,6 @@ gap> ForAny(DirectoryContents(PKGMAN_PackageDir()),
> f -> StartsWith(LowercaseString(f), "example"));
true

# Check package can be recompiled and removed
gap> CompilePackage("example");
true
gap> RemovePackage("example", false);
true

# RemovePackage failure
gap> RemovePackage(3);
Error, PackageManager: RemovePackage: <name> must be a string
Expand All @@ -147,12 +131,6 @@ Error, PackageManager: UpdatePackage: <interactive> must be true or false
gap> UpdatePackage("io", true, "master", "hello", Group(()), fail, []);
Error, PackageManager: UpdatePackage: requires 1 or 2 arguments (not 7)

# CompilePackage bad input
gap> CompilePackage(3);
Error, PackageManager: CompilePackage: <name> must be a string
gap> CompilePackage(true);
Error, PackageManager: CompilePackage: <name> must be a string

# Installing multiple versions
gap> InstallPackage("https://github.com/gap-packages/grpconst/releases/download/v2.6.4/grpconst-2.6.4.tar.gz");
true
Expand Down Expand Up @@ -280,49 +258,6 @@ fail
gap> PKGMAN_InsertPackageDirectory("/home"); # not ending in pkg
fail

# PKGMAN_CompileDir error: no shell
gap> InstallPackage("example");
true
gap> InstallPackage("example"); # latest version already installed
true
gap> progs := GAPInfo.DirectoriesPrograms;;
gap> GAPInfo.DirectoriesPrograms := [];; # terrible vandalism
gap> dir := PackageInfo("example")[1].InstallationPath;;
gap> PKGMAN_CompileDir(dir);
#I No shell available called "sh"
#I Compilation failed for package 'Example' (package may still be usable)
false
gap> GAPInfo.DirectoriesPrograms := progs;;

# PKGMAN_CompileDir error: no etc/BuildPackages.sh
gap> InstallPackage("example", false); # latest version already installed
true
gap> sysinfo_scr := PKGMAN_Sysinfo;;
gap> PKGMAN_Sysinfo := fail;;
gap> dir := PackageInfo("example")[1].InstallationPath;;
gap> PKGMAN_CompileDir(dir);
#I No sysinfo.gap found
false
gap> PKGMAN_Sysinfo := sysinfo_scr;;

# PKGMAN_CompileDir error: missing source
gap> InstallPackage("example"); # latest version already installed
true
gap> dir := PackageInfo("example")[1].InstallationPath;;
gap> RemoveFile(Filename(Directory(dir), "src/hello.c"));
true
gap> PKGMAN_CompileDir(dir);
#I Compilation failed for package 'Example' (package may still be usable)
false

# Missing BuildPackages script
gap> temp := PKGMAN_BuildPackagesScript;;
gap> PKGMAN_BuildPackagesScript := fail;;
gap> CompilePackage("example");
#I Compilation script not found
false
gap> PKGMAN_BuildPackagesScript := temp;;

# Missing curlInterface: use wget instead
gap> ver := PKGMAN_CurlIntReqVer;;
gap> PKGMAN_CurlIntReqVer := ">= 100.0";;
Expand Down Expand Up @@ -360,10 +295,6 @@ true
gap> InstallPackage("https://github.com/gap-packages/toric/releases/download/v1.9.5/Toric-1.9.5.tar.gz");
true

# Compile already compiled
gap> CompilePackage("toric");
true

# curl failure
gap> ver := PKGMAN_CurlIntReqVer;;
gap> PKGMAN_CurlIntReqVer := ">= 100.0";;
Expand Down
Loading

0 comments on commit 7509cf2

Please sign in to comment.