From e406640ae5729eb5604cf241c42d463877969b4d Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 13 Sep 2026 02:22:46 +0200 Subject: [PATCH] Handle Windows paths AUTODOC_CurrentDirectory ran the pwd program, which under MSYS2 prints a path such as /c/gap2 that native Windows programs cannot use. Several places also took a path to be absolute only if it starts with a slash, so on Windows they prefixed an absolute C:/... path with that directory, yielding /c/gap2/C:/gap2/... . Use GAP_getcwd, and recognize drive paths as absolute via the new AUTODOC_IsAbsolutePath. Assisted-by: Claude Code (Opus 5) --- gap/AutoDocMainFunction.gi | 2 +- gap/ToolFunctions.gd | 1 + gap/ToolFunctions.gi | 21 +++++++++++++-------- tst/autodoctest-manual.tst | 2 +- tst/errorwithpos.tst | 2 +- tst/misc.tst | 2 +- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/gap/AutoDocMainFunction.gi b/gap/AutoDocMainFunction.gi index 7100adf7..f022d441 100644 --- a/gap/AutoDocMainFunction.gi +++ b/gap/AutoDocMainFunction.gi @@ -446,7 +446,7 @@ function( pkgname, pkgdir, docdir, main, files, opt, roots ) AppendTo(output, "gap> START_TEST(\"", basename, "\");\n\n"); for a in ch do location := a[2][1]; - if not StartsWith(location, "/") then + if not AUTODOC_IsAbsolutePath(location) then # Already reproducible: AutoDoc recorded this position itself, # or GAPDoc resolved it relative to the documentation dir. comment := location; diff --git a/gap/ToolFunctions.gd b/gap/ToolFunctions.gd index a090e033..af5886a0 100644 --- a/gap/ToolFunctions.gd +++ b/gap/ToolFunctions.gd @@ -12,6 +12,7 @@ DeclareGlobalFunction( "AUTODOC_StageDirectory" ); DeclareGlobalFunction( "AUTODOC_SourceMarker" ); DeclareGlobalFunction( "AUTODOC_RemapSourcePositions" ); DeclareGlobalFunction( "AUTODOC_CurrentDirectory" ); +DeclareGlobalFunction( "AUTODOC_IsAbsolutePath" ); DeclareGlobalFunction( "AUTODOC_LineStartsCDATA" ); DeclareGlobalFunction( "AUTODOC_LineEndsCDATA" ); DeclareGlobalFunction( "AUTODOC_EscapeCDATAContent" ); diff --git a/gap/ToolFunctions.gi b/gap/ToolFunctions.gi index 104a4cc4..f06da7ad 100644 --- a/gap/ToolFunctions.gi +++ b/gap/ToolFunctions.gi @@ -120,18 +120,23 @@ function(d) return true; end ); +# Not DirectoryCurrent: its cached value goes stale when the directory is +# changed other than by ChangeDirectoryCurrent. Not the `pwd` program either, +# which under MSYS2 prints a path native Windows programs cannot use. InstallGlobalFunction( "AUTODOC_CurrentDirectory", function(args...) - local pwd, result; - pwd := Filename( DirectoriesSystemPrograms(), "pwd" ); - if pwd = fail then - Error("failed to locate 'pwd' tool"); - fi; - result := ""; - Process(DirectoryCurrent(), pwd, InputTextNone(), OutputTextString(result, true), []); - return Chomp(result); + return GAP_getcwd(); end); +# Whether is absolute: it starts with a slash, or on Windows with a +# drive, as in `C:/`. +InstallGlobalFunction( "AUTODOC_IsAbsolutePath", +function( path ) + return StartsWith( path, "/" ) or + ( ARCH_IS_WINDOWS() and Length( path ) >= 3 and + path[2] = ':' and path[3] in "/\\" ); +end ); + InstallGlobalFunction( "AUTODOC_LineStartsCDATA", function(line) # Phase 1 keeps CDATA encoded as raw strings; Parser.gi still injects such diff --git a/tst/autodoctest-manual.tst b/tst/autodoctest-manual.tst index 5dc36616..dbc1ab76 100644 --- a/tst/autodoctest-manual.tst +++ b/tst/autodoctest-manual.tst @@ -19,7 +19,7 @@ gap> olddir := AUTODOC_CurrentDirectory();; gap> pkgdir := DirectoriesPackageLibrary( "AutoDoc", "tst/AutoDocTest" );; gap> pkgdir := pkgdir[1];; gap> pkgdir := Filename( pkgdir, "" );; -gap> if not StartsWith( pkgdir, "/" ) then +gap> if not AUTODOC_IsAbsolutePath( pkgdir ) then > pkgdir := Concatenation( olddir, "/", pkgdir ); > fi; gap> ReadPackage( "AutoDoc", "tst/utils.g" ); diff --git a/tst/errorwithpos.tst b/tst/errorwithpos.tst index 00a84c83..585fe580 100644 --- a/tst/errorwithpos.tst +++ b/tst/errorwithpos.tst @@ -1,7 +1,7 @@ # # test parser error reporting with ErrorWithPos gap> autodoc_pkgroot := Filename( DirectoriesPackageLibrary( "AutoDoc", "" ), "" );; -gap> if not StartsWith( autodoc_pkgroot, "/" ) then +gap> if not AUTODOC_IsAbsolutePath( autodoc_pkgroot ) then > autodoc_pkgroot := Filename( > Directory( AUTODOC_CurrentDirectory() ), > autodoc_pkgroot diff --git a/tst/misc.tst b/tst/misc.tst index 5e86aa3a..52013005 100644 --- a/tst/misc.tst +++ b/tst/misc.tst @@ -173,7 +173,7 @@ true # AutoDoc_Parser_ReadFiles: multiline InstallMethod parsing # gap> autodoc_pkgroot := Filename( DirectoriesPackageLibrary( "AutoDoc", "" ), "" );; -gap> if not StartsWith( autodoc_pkgroot, "/" ) then +gap> if not AUTODOC_IsAbsolutePath( autodoc_pkgroot ) then > autodoc_pkgroot := Filename( > Directory( AUTODOC_CurrentDirectory() ), > autodoc_pkgroot