From 242af5ead11e4b1c216cc7223bd12b98c5aaaefb Mon Sep 17 00:00:00 2001 From: Michael Young Date: Wed, 11 Sep 2024 16:34:25 +0100 Subject: [PATCH] Refactor some compile.gi things --- gap/compile.gi | 22 ++++++++-------------- gap/directories.gd | 1 + gap/directories.gi | 11 +++++++++++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/gap/compile.gi b/gap/compile.gi index 9068cb8..15fc91c 100644 --- a/gap/compile.gi +++ b/gap/compile.gi @@ -8,7 +8,6 @@ function(name) fi; # Locate the package - name := LowercaseString(name); info := PKGMAN_UserPackageInfo(name : warnIfNone, warnIfMultiple); # Package not installed @@ -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 @@ -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; diff --git a/gap/directories.gd b/gap/directories.gd index 7340a59..82718eb 100644 --- a/gap/directories.gd +++ b/gap/directories.gd @@ -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"); diff --git a/gap/directories.gi b/gap/directories.gi index df2a429..64f3003 100644 --- a/gap/directories.gi +++ b/gap/directories.gi @@ -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);