Skip to content
Merged
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
5 changes: 4 additions & 1 deletion lib/package.gi
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ BindGlobal( "AddPackageInfos", function( files, pkgdir, ignore )
" (user preference PackagesToIgnore)" ), "GAP" );
else
record.InstallationPath:= Filename( [ pkgdir ], file[2] );
# normalize to include trailing "/"
record.InstallationPath:= Filename( [ Directory( record.InstallationPath ) ], "" );
if not IsBound( record.PackageDoc ) then
record.PackageDoc:= [];
elif IsRecord( record.PackageDoc ) then
Expand Down Expand Up @@ -1746,7 +1748,8 @@ InstallGlobalFunction( SetPackagePath, function( pkgname, pkgpath )
pkgname:= LowercaseString( pkgname );
NormalizeWhitespace( pkgname );
if IsBound( GAPInfo.PackagesLoaded.( pkgname ) ) then
if GAPInfo.PackagesLoaded.( pkgname )[1] = pkgpath then
# compare using `Directory` to expand "~" and add trailing "/"
if Directory( GAPInfo.PackagesLoaded.( pkgname )[1] ) = Directory( pkgpath ) then
return;
fi;
Error( "another version of package ", pkgname, " is already loaded" );
Expand Down
35 changes: 32 additions & 3 deletions tst/testinstall/package.tst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#@local entry,equ,pair,sml,oldTermEncoding,pkginfo,info,mockpkgpath,p,n
#@local entry,equ,pair,sml,oldTermEncoding,pkginfo,info,tmp_dir,mockpkgpath,old_warning_level,p,n
gap> START_TEST("package.tst");

# CompareVersionNumbers( <supplied>, <required>[, \"equal\"] )
Expand Down Expand Up @@ -418,8 +418,17 @@ false
gap> IsPackageLoaded("mockpkg", ">=2.0");
false

#
gap> mockpkgpath := DirectoriesLibrary("tst/mockpkg")[1];;
# load mockpkg via a symlink in a directory called `pkg`
# so we can test ExtendRootDirectories below
# first create a temporary directory for all of this
gap> tmp_dir := DirectoryTemporary( );;

# create a subdirectory `<tmp_dir>/pkg`
gap> Exec( Concatenation( "mkdir -p ", Filename( tmp_dir, "/pkg" ) ) );

# make `<tmp_dir>/pkg/mockpkg` a symlink to `tst/mockpkg`
gap> Exec( Concatenation( "ln -sfn ", Filename( DirectoriesLibrary("tst/mockpkg"), "" )," ", Filename( tmp_dir, "pkg/mockpkg" ) ) );
gap> mockpkgpath := Directory( Filename( tmp_dir, "pkg/mockpkg" ) );;
gap> ValidatePackageInfo(Filename(mockpkgpath, "PackageInfo.g"));
true

Expand Down Expand Up @@ -473,9 +482,14 @@ gap> IsPackageLoaded("mockpkg", ">=2.0");
false

# instruct GAP to load the package, and record all its declarations
# the help book of mockpkg might already have been loaded in other tests
# -> we suppress a warning about this
gap> old_warning_level := InfoLevel( InfoWarning );;
gap> SetInfoLevel( InfoWarning, 0 );
gap> PackageVariablesInfo("mockpkg", "0.1");;
oops, should not print here
oops, should not print here
gap> SetInfoLevel( InfoWarning, old_warning_level );
gap> ShowPackageVariables("mockpkg");
new global functions:
mockpkg_GlobalFunction( )*
Expand Down Expand Up @@ -640,5 +654,20 @@ false
gap> IsPackageLoaded("mockpkg", ">=2.0");
false

# now add the temporary directory created above as a new root directory
gap> ExtendRootDirectories( [ Filename( tmp_dir, "" ) ] );

# make sure that the newly discovered installation path matches
# the path from which mockpkg was loaded above
gap> Last( GAPInfo.PackagesInfo.mockpkg ).InstallationPath =
> GAPInfo.PackagesLoaded.mockpkg[1];
true

#
gap> SetPackagePath( "mockpkg", Filename( tmp_dir, "pkg/mockpkg" ) );
gap> SetPackagePath( "mockpkg", Filename( tmp_dir, "pkg/mockpkg/" ) );
gap> SetPackagePath( "mockpkg", "/some/other/directory" );
Error, another version of package mockpkg is already loaded

#
gap> STOP_TEST( "package.tst", 1);