-
Notifications
You must be signed in to change notification settings - Fork 180
WIP: gap root path unification #5941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
fingolfin
wants to merge
2
commits into
gap-system:master
Choose a base branch
from
fingolfin:mh/sysroot-unification
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| #include "sysroots.h" | ||
|
|
||
| #include "gaputils.h" | ||
| #include "listfunc.h" | ||
| #include "plist.h" | ||
| #include "stringobj.h" | ||
| #include "sysfiles.h" | ||
|
|
@@ -47,34 +48,28 @@ | |
| ** name of a library file 'strcat( SyGapRootPaths[i], "lib/init.g" );' must | ||
| ** be a valid filename. | ||
| */ | ||
| enum { MAX_GAP_DIRS = 16 }; | ||
| static Char SyGapRootPaths[MAX_GAP_DIRS][GAP_PATH_MAX]; | ||
| Obj SyGapRootPaths; | ||
|
|
||
|
|
||
| /**************************************************************************** | ||
| ** | ||
| *F SyFindGapRootFile( <filename>, <buf>, <size> ) . find file in system area | ||
| *F SyFindGapRootFile( <filename> ) . . . . . . . . find file in system area | ||
| ** | ||
| ** <buf> must point to a buffer of at least <size> characters. This function | ||
| ** then searches for a readable file with the name <filename> in the system | ||
| ** area. If sich a file is found then its absolute path is copied into | ||
| ** <buf>, and <buf> is returned. If no file is found or if <buf> is not big | ||
| ** enough, then <buf> is set to an empty string and NULL is returned. | ||
| ** This function searches for a readable file with the name <filename> in | ||
| ** the system area. If such a file is found then its absolute path is | ||
| ** returned as a string object. If no file is found then NULL is returned. | ||
| */ | ||
| Char * SyFindGapRootFile(const Char * filename, Char * buf, size_t size) | ||
| Obj SyFindGapRootFile(const Char * filename) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately changing |
||
| { | ||
| for (int k = 0; k < ARRAY_SIZE(SyGapRootPaths); k++) { | ||
| if (SyGapRootPaths[k][0]) { | ||
| if (gap_strlcpy(buf, SyGapRootPaths[k], size) >= size) | ||
| continue; | ||
| if (gap_strlcat(buf, filename, size) >= size) | ||
| continue; | ||
| if (SyIsReadableFile(buf) == 0) { | ||
| return buf; | ||
| } | ||
| int len = strlen(filename); | ||
| int npaths = LEN_PLIST(SyGapRootPaths); | ||
| for (int k = 1; k <= npaths; k++) { | ||
| Obj path = CopyToStringRep(ELM_PLIST(SyGapRootPaths, k)); | ||
| AppendCStr(path, filename, len); | ||
| if (SyIsReadableFile(CSTR_STRING(path)) == 0) { | ||
| return path; | ||
| } | ||
| } | ||
| buf[0] = '\0'; | ||
| return 0; | ||
| } | ||
|
|
||
|
|
@@ -99,10 +94,12 @@ | |
| */ | ||
| void SySetGapRootPath(const Char * string) | ||
| { | ||
| const Char * p; | ||
| Char * q; | ||
| Int i; | ||
| Int n; | ||
| Int pos = 1; | ||
|
|
||
| if (SyGapRootPaths == 0) { | ||
| SyGapRootPaths = NEW_PLIST(T_PLIST_EMPTY, 0); // FIXME | ||
| } | ||
|
|
||
|
|
||
| // set string to a default value if unset | ||
| if (string == 0 || *string == 0) { | ||
|
|
@@ -111,110 +108,79 @@ | |
|
|
||
| // check if we append, prepend or overwrite. | ||
| if (string[0] == ';') { | ||
| // Count the number of root directories already present. | ||
| n = 0; | ||
| while (SyGapRootPaths[n][0] != '\0') | ||
| n++; | ||
| // append | ||
| pos = LEN_PLIST(SyGapRootPaths) + 1; | ||
|
|
||
| // Skip leading semicolon. | ||
| string++; | ||
| } | ||
| else if (string[strlen(string) - 1] == ';') { | ||
| // Count the number of directories in 'string'. | ||
| n = 0; | ||
| p = string; | ||
| while (*p) | ||
| if (*p++ == ';') | ||
| n++; | ||
|
|
||
| // Find last root path. | ||
| for (i = 0; i < MAX_GAP_DIRS; i++) | ||
| if (SyGapRootPaths[i][0] == '\0') | ||
| break; | ||
| i--; | ||
|
|
||
| #ifdef HPCGAP | ||
| n *= 2; // for each root <ROOT> we also add <ROOT/hpcgap> as a root | ||
| #endif | ||
|
|
||
| // Move existing root paths to the back | ||
| if (i + n >= MAX_GAP_DIRS) | ||
| return; | ||
| while (i >= 0) { | ||
| memcpy(SyGapRootPaths[i + n], SyGapRootPaths[i], | ||
| sizeof(SyGapRootPaths[i + n])); | ||
| i--; | ||
| } | ||
|
|
||
| n = 0; | ||
| // prepend | ||
| } | ||
| else { | ||
| // Make sure to wipe out all possibly existing root paths | ||
| for (i = 0; i < MAX_GAP_DIRS; i++) | ||
| SyGapRootPaths[i][0] = '\0'; | ||
| n = 0; | ||
| SET_LEN_PLIST(SyGapRootPaths, 0); | ||
| RetypeBagSM(SyGapRootPaths, T_PLIST_EMPTY); | ||
| // TODO: also adjust filters... | ||
| } | ||
|
|
||
| // unpack the argument | ||
| p = string; | ||
| const Char * p = string; | ||
| while (*p) { | ||
| if (n >= MAX_GAP_DIRS) | ||
| return; | ||
|
|
||
| q = SyGapRootPaths[n]; | ||
| while (*p && *p != ';') { | ||
| *q = *p++; | ||
|
|
||
| #ifdef SYS_IS_CYGWIN32 | ||
| // change backslash to slash for Windows | ||
| if (*q == '\\') | ||
| *q = '/'; | ||
| #endif | ||
| Obj path; | ||
|
|
||
| // locate next semicolon or string end | ||
| const Char * q = p; | ||
| while (*q && *q != ';') { | ||
| q++; | ||
| } | ||
| if (q == SyGapRootPaths[n]) { | ||
| strxcpy(SyGapRootPaths[n], "./", sizeof(SyGapRootPaths[n])); | ||
| } | ||
| else if (q[-1] != '/') { | ||
| *q++ = '/'; | ||
| *q = '\0'; | ||
| } | ||
| else { | ||
| *q = '\0'; | ||
| } | ||
| if (*p) { | ||
| p++; | ||
|
|
||
| if (q == p) { | ||
| // empty string treated as ./ | ||
| path = MakeString("./"); | ||
| // TODO: insert output of getcwd?? | ||
| } else { | ||
| if (*p == '~') { | ||
| const char * userhome = getenv("HOME"); | ||
| if (!userhome) | ||
| userhome = ""; | ||
| path = MakeString(userhome); | ||
| p++; | ||
| AppendCStr(path, p, q - p); | ||
| } | ||
| else { | ||
| path = MakeStringWithLen(p, q - p); | ||
| } | ||
|
|
||
| Char * r = CSTR_STRING(path); | ||
| #ifdef SYS_IS_CYGWIN32 | ||
| while (*r) { | ||
| // change backslash to slash for Windows | ||
| if (*r == '\\') | ||
| *r = '/'; | ||
| r++; | ||
| } | ||
| #endif | ||
|
|
||
| // ensure path ends with a slash | ||
| r = CSTR_STRING(path) + GET_LEN_STRING(path) - 1; | ||
| if (*r != '/') { | ||
| AppendCStr(path, "/", 1); | ||
| } | ||
| } | ||
| n++; | ||
|
|
||
| p = *q ? q + 1 : q; | ||
|
|
||
| AddPlist3(SyGapRootPaths, path, pos); | ||
| pos++; | ||
|
|
||
| #ifdef HPCGAP | ||
| // for each root <ROOT> to be added, we first add <ROOT/hpcgap> as a root | ||
| if (n < MAX_GAP_DIRS) { | ||
| gap_strlcpy(SyGapRootPaths[n], SyGapRootPaths[n - 1], | ||
| sizeof(SyGapRootPaths[n])); | ||
| } | ||
| strxcat(SyGapRootPaths[n - 1], "hpcgap/", | ||
| sizeof(SyGapRootPaths[n - 1])); | ||
| n++; | ||
| #endif | ||
| } | ||
| path = CopyToStringRep(path); | ||
| AppendCStr(path, "hpcgap/", 7); | ||
|
|
||
| // replace leading tilde ~ by HOME environment variable | ||
| // TODO; instead of iterating over all entries each time, just | ||
| // do this for the new entries | ||
| char * userhome = getenv("HOME"); | ||
| if (!userhome || !*userhome) | ||
| return; | ||
| const UInt userhomelen = strlen(userhome); | ||
| for (i = 0; i < MAX_GAP_DIRS && SyGapRootPaths[i][0]; i++) { | ||
| const UInt pathlen = strlen(SyGapRootPaths[i]); | ||
| if (SyGapRootPaths[i][0] == '~' && | ||
| userhomelen + pathlen < sizeof(SyGapRootPaths[i])) { | ||
| SyMemmove(SyGapRootPaths[i] + userhomelen, | ||
| // don't copy the ~ but the trailing '\0' | ||
| SyGapRootPaths[i] + 1, pathlen); | ||
| memcpy(SyGapRootPaths[i], userhome, userhomelen); | ||
| } | ||
| AddPlist3(SyGapRootPaths, path, pos); | ||
| pos++; | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -225,12 +191,5 @@ | |
| */ | ||
| Obj SyGetGapRootPaths(void) | ||
| { | ||
| Obj tmp = NEW_PLIST_IMM(T_PLIST, MAX_GAP_DIRS); | ||
| for (int i = 0; i < MAX_GAP_DIRS; i++) { | ||
| if (SyGapRootPaths[i][0]) { | ||
| PushPlist(tmp, MakeImmString(SyGapRootPaths[i])); | ||
| } | ||
| } | ||
| MakeImmutableNoRecurse(tmp); | ||
| return tmp; | ||
| return SyGapRootPaths; | ||
fingolfin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've replaced this now with a loop that uses
Addto add each path separately. Various reasonsGAPInfo.RootPathsfrom a plist to an atomic list, whereAddis supported but notAppendAnyway this is of course also a natural place to turn relative paths in absolute ones, call
realpath, etc. -- but that goes beyond the scope of this PR