Skip to content

Commit

Permalink
Refactor some compile.gi things
Browse files Browse the repository at this point in the history
  • Loading branch information
mtorpey committed Sep 11, 2024
1 parent e4324af commit 242af5e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
22 changes: 8 additions & 14 deletions gap/compile.gi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function(name)
fi;

# Locate the package
name := LowercaseString(name);
info := PKGMAN_UserPackageInfo(name : warnIfNone, warnIfMultiple);

# Package not installed
Expand All @@ -22,7 +21,7 @@ end);

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

info := PKGMAN_GetPackageInfo(dir);
if info = fail then
Expand All @@ -39,32 +38,27 @@ function(dir)

# Check requirements, and prepare command
pkg_dir := Filename(Directory(dir), "..");
scr := PKGMAN_Sysinfo;
if scr = fail then
Info(InfoPackageManager, 1, "No sysinfo.gap found");
gap_root := PKGMAN_GapRootDir();
if gap_root = fail then
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
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
exec := PKGMAN_Exec(pkg_dir, PKGMAN_BuildPackagesScript, gap_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, "'");
Info(InfoPackageManager, 1, "(package may still be usable)");
Info(InfoPackageManager, 2, exec.output);
PKGMAN_InfoWithIndent(2, exec.output, 2);
return false;
else
Info(InfoPackageManager, 3, exec.output);
PKGMAN_InfoWithIndent(3, exec.output, 2);
fi;
Info(InfoPackageManager, 4, "Compilation was successful");
return true;
Expand Down
1 change: 1 addition & 0 deletions gap/directories.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DeclareGlobalFunction("PKGMAN_InsertPackageDirectory");
DeclareGlobalFunction("PKGMAN_IsValidTargetDir");
DeclareGlobalFunction("PKGMAN_RemoveDirOptional");
DeclareGlobalFunction("PKGMAN_RemoveDir");
DeclareGlobalFunction("PKGMAN_GapRootDir");

PKGMAN_CustomPackageDir := "";
PKGMAN_Sysinfo := Filename(DirectoriesLibrary(""), "sysinfo.gap");
11 changes: 11 additions & 0 deletions gap/directories.gi
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,14 @@ function(dir)
PKGMAN_RefreshPackageInfo();
fi;
end);

InstallGlobalFunction(PKGMAN_GapRootDir,
function()
local sysinfo;
sysinfo := PKGMAN_Sysinfo;
if sysinfo = fail then
Info(InfoPackageManager, 1, "No sysinfo.gap found");
return fail;
fi;
return sysinfo{[1 .. Length(sysinfo) - Length("/sysinfo.gap")]};
end);

0 comments on commit 242af5e

Please sign in to comment.