directory paths improved; local builds work for http/https as well.

This commit is contained in:
Norayr Chilingarian 2025-07-19 23:36:36 +04:00
parent d9a2cd19f0
commit 9efd875716
4 changed files with 133 additions and 40 deletions

View file

@ -1,5 +1,5 @@
MODULE vpkHttp; MODULE vpkHttp;
IMPORT Out, Platform, IMPORT Out, Platform, Strings,
List, strTypes, http, List, strTypes, http,
vpkdepTree, vpkTools, vpkMD5Checker, vpkEnv; vpkdepTree, vpkTools, vpkMD5Checker, vpkEnv;
@ -8,20 +8,28 @@ VAR
h: http.Client; h: http.Client;
answer: strTypes.pstring; answer: strTypes.pstring;
domain, path: ARRAY 128 OF CHAR; port: ARRAY 8 OF CHAR; domain, path: ARRAY 128 OF CHAR; port: ARRAY 8 OF CHAR;
repoPath: ARRAY 256 OF CHAR; (* Added for full repository path *) repoPath: ARRAY 256 OF CHAR;
filename: ARRAY 64 OF CHAR; filename: ARRAY 64 OF CHAR;
i, j: LONGINT; i, j: LONGINT;
node: List.Node; node: List.Node;
bool, continueFetching: BOOLEAN; bool, continueFetching: BOOLEAN;
initialDst: ARRAY 512 OF CHAR; initialDst: ARRAY 512 OF CHAR;
targetDir: ARRAY 512 OF CHAR;
lastSlash: LONGINT;
emptyName: ARRAY 1 OF CHAR;
depthCount: INTEGER;
startingDir: ARRAY 256 OF CHAR;
BEGIN BEGIN
COPY(Platform.CWD, startingDir);
COPY(dst, initialDst); COPY(dst, initialDst);
COPY("80", port); COPY("80", port);
COPY("", emptyName);
i := 0; i := 0;
continueFetching := TRUE; continueFetching := TRUE;
WHILE continueFetching DO WHILE continueFetching DO
node := dep^.rmt(vpkdepTree.RemoteHttps)^.Files.Get(dep^.rmt(vpkdepTree.RemoteHttps)^.Files, i); node := dep^.rmt(vpkdepTree.RemoteHttp)^.Files.Get(dep^.rmt(vpkdepTree.RemoteHttp)^.Files, i);
IF node # NIL THEN IF node # NIL THEN
IF node^.obj(vpkdepTree.File) # NIL THEN IF node^.obj(vpkdepTree.File) # NIL THEN
Out.String("getting "); Out.String(node^.obj(vpkdepTree.File)^.URI); Out.Ln; Out.String("getting "); Out.String(node^.obj(vpkdepTree.File)^.URI); Out.Ln;
@ -29,20 +37,42 @@ BEGIN
(* Extract domain for connection *) (* Extract domain for connection *)
vpkTools.extractDomainFromUrl(node^.obj(vpkdepTree.File)^.URI, domain); vpkTools.extractDomainFromUrl(node^.obj(vpkdepTree.File)^.URI, domain);
Out.String("connecting to "); Out.String(domain); Out.Ln; Out.String("connecting to "); Out.String(domain); Out.Ln;
(* Extract full repository path for directory structure *) (* Extract full repository path for directory structure *)
vpkTools.extractRepoPathFromUrl(node^.obj(vpkdepTree.File)^.URI, repoPath); vpkTools.extractRepoPathFromUrl(node^.obj(vpkdepTree.File)^.URI, repoPath);
(* Remove filename to get directory path *)
lastSlash := -1;
j := 0;
WHILE (j < Strings.Length(repoPath)) & (repoPath[j] # 0X) DO
IF repoPath[j] = '/' THEN lastSlash := j; END;
INC(j);
END;
IF lastSlash > 0 THEN
repoPath[lastSlash] := 0X;
END;
Out.String("repo path: "); Out.String(repoPath); Out.Ln; Out.String("repo path: "); Out.String(repoPath); Out.Ln;
(* Use COPY of initialDst, not dst that gets modified *)
COPY(initialDst, targetDir);
vpkEnv.mkPkgDirPath(repoPath, emptyName, targetDir);
(* Calculate return path by counting directory levels *)
depthCount := 1; (* for "deps" *)
j := 0;
WHILE (j < Strings.Length(repoPath)) & (repoPath[j] # 0X) DO
IF repoPath[j] = '/' THEN INC(depthCount); END;
INC(j);
END;
vpkTools.extractPathFromUrl(node^.obj(vpkdepTree.File)^.URI, path); vpkTools.extractPathFromUrl(node^.obj(vpkdepTree.File)^.URI, path);
vpkTools.extractFilenameFromUrl(node^.obj(vpkdepTree.File)^.URI, filename); vpkTools.extractFilenameFromUrl(node^.obj(vpkdepTree.File)^.URI, filename);
(* Use full repository path instead of just domain *) (* Change to target directory *)
vpkEnv.mkPkgDirPath(repoPath, dep^.name^, dst); Out.String("will return to "); Out.Ln;
Out.String(targetDir); Out.Ln;
j := Platform.Chdir(dst); j := Platform.Chdir(targetDir);
COPY(initialDst, dst);
h := http.Create(domain, port, path); h := http.Create(domain, port, path);
@ -61,6 +91,11 @@ BEGIN
h.Save(h); h.Save(h);
bool := vpkMD5Checker.checkMD5(filename, node^.obj(vpkdepTree.File)^.md5); bool := vpkMD5Checker.checkMD5(filename, node^.obj(vpkdepTree.File)^.md5);
IF bool THEN Out.String("correct!") ELSE Out.String("incorrect!"); END; Out.Ln; IF bool THEN Out.String("correct!") ELSE Out.String("incorrect!"); END; Out.Ln;
(* Return to initial directory using calculated relative path *)
Out.String("will return to "); Out.Ln;
Out.String(startingDir); Out.Ln;
j := Platform.Chdir(startingDir);
ELSE ELSE
Out.String("node^.obj(vpkdepTree.File) is NIL"); Out.Ln; Out.String("node^.obj(vpkdepTree.File) is NIL"); Out.Ln;
END; END;
@ -73,4 +108,4 @@ BEGIN
END fetchFiles; END fetchFiles;
END vpkHttp. END vpkHttp.

View file

@ -1,5 +1,5 @@
MODULE vpkHttps; MODULE vpkHttps;
IMPORT Out, Platform, IMPORT Out, Platform, Strings,
List, strTypes, https, List, strTypes, https,
vpkdepTree, vpkTools, vpkMD5Checker, vpkEnv; vpkdepTree, vpkTools, vpkMD5Checker, vpkEnv;
@ -8,16 +8,23 @@ VAR
h: https.TLSClient; h: https.TLSClient;
answer: strTypes.pstring; answer: strTypes.pstring;
domain, path: ARRAY 128 OF CHAR; port: ARRAY 8 OF CHAR; domain, path: ARRAY 128 OF CHAR; port: ARRAY 8 OF CHAR;
repoPath: ARRAY 256 OF CHAR; (* Added for full repository path *) repoPath: ARRAY 256 OF CHAR;
filename: ARRAY 64 OF CHAR; filename: ARRAY 64 OF CHAR;
i, j: LONGINT; i, j: LONGINT;
node: List.Node; node: List.Node;
bool, continueFetching: BOOLEAN; bool, continueFetching: BOOLEAN;
initialDst: ARRAY 512 OF CHAR; initialDst: ARRAY 512 OF CHAR;
targetDir: ARRAY 512 OF CHAR;
lastSlash: LONGINT;
emptyName: ARRAY 1 OF CHAR;
depthCount: INTEGER;
startingDir: ARRAY 256 OF CHAR;
BEGIN BEGIN
COPY(Platform.CWD, startingDir);
Out.String("*** HTTPS: fetchFiles called"); Out.Ln; Out.String("*** HTTPS: fetchFiles called"); Out.Ln;
COPY(dst, initialDst); COPY(dst, initialDst);
COPY("443", port); COPY("443", port);
COPY("", emptyName);
i := 0; i := 0;
continueFetching := TRUE; continueFetching := TRUE;
@ -33,17 +40,40 @@ BEGIN
(* Extract full repository path for directory structure *) (* Extract full repository path for directory structure *)
vpkTools.extractRepoPathFromUrl(node^.obj(vpkdepTree.File)^.URI, repoPath); vpkTools.extractRepoPathFromUrl(node^.obj(vpkdepTree.File)^.URI, repoPath);
(* Remove filename to get directory path *)
lastSlash := -1;
j := 0;
WHILE (j < Strings.Length(repoPath)) & (repoPath[j] # 0X) DO
IF repoPath[j] = '/' THEN lastSlash := j; END;
INC(j);
END;
IF lastSlash > 0 THEN
repoPath[lastSlash] := 0X;
END;
Out.String("repo path: "); Out.String(repoPath); Out.Ln; Out.String("repo path: "); Out.String(repoPath); Out.Ln;
(* Use COPY of initialDst, not dst that gets modified *)
COPY(initialDst, targetDir);
vpkEnv.mkPkgDirPath(repoPath, emptyName, targetDir);
(* Calculate return path by counting directory levels *)
depthCount := 1; (* for "deps" *)
j := 0;
WHILE (j < Strings.Length(repoPath)) & (repoPath[j] # 0X) DO
IF repoPath[j] = '/' THEN INC(depthCount); END;
INC(j);
END;
vpkTools.extractPathFromUrl(node^.obj(vpkdepTree.File)^.URI, path); vpkTools.extractPathFromUrl(node^.obj(vpkdepTree.File)^.URI, path);
vpkTools.extractFilenameFromUrl(node^.obj(vpkdepTree.File)^.URI, filename); vpkTools.extractFilenameFromUrl(node^.obj(vpkdepTree.File)^.URI, filename);
(* Use full repository path - DO NOT add package name again *) (* Change to target directory *)
vpkEnv.mkPkgDirPath(repoPath, dep^.name^, dst); Out.String("will cd to "); Out.Ln;
Out.String(targetDir); Out.Ln;
j := Platform.Chdir(dst); j := Platform.Chdir(targetDir);
COPY(initialDst, dst);
h := https.Create(domain, port, path); h := https.Create(domain, port, path);
@ -62,6 +92,11 @@ BEGIN
h.Save(h); h.Save(h);
bool := vpkMD5Checker.checkMD5(filename, node^.obj(vpkdepTree.File)^.md5); bool := vpkMD5Checker.checkMD5(filename, node^.obj(vpkdepTree.File)^.md5);
IF bool THEN Out.String("correct!") ELSE Out.String("incorrect!"); END; Out.Ln; IF bool THEN Out.String("correct!") ELSE Out.String("incorrect!"); END; Out.Ln;
(* Return to initial directory using calculated relative path *)
Out.String("will return to "); Out.Ln;
Out.String(startingDir); Out.Ln;
j := Platform.Chdir(startingDir);
ELSE ELSE
Out.String("node^.obj(vpkdepTree.File) is NIL"); Out.Ln; Out.String("node^.obj(vpkdepTree.File) is NIL"); Out.Ln;
END; END;

View file

@ -362,15 +362,15 @@ VAR
repoPath: ARRAY 256 OF CHAR; repoPath: ARRAY 256 OF CHAR;
node: List.Node; node: List.Node;
parentDir: ARRAY 8 OF CHAR; parentDir: ARRAY 8 OF CHAR;
lastSlash, idx: INTEGER; (* ADD: for filename removal *)
BEGIN BEGIN
(* Resolve all dependencies for local project *) (* Resolve all dependencies for local project *)
depTree := resolveLocal(projectFile); depTree := resolveLocal(projectFile);
IF depTree.Count > 0 THEN IF depTree.Count > 0 THEN
(* Set up build directory *) (* IMPROVED: Use simple build path *)
COPY("./", buildDir); COPY("build", buildDir);
Strings.Append(DefaultBuildDir, buildDir); COPY("..", parentDir);
COPY("..", parentDir); (* Variable for Platform.Chdir *)
i := 0; i := 0;
REPEAT REPEAT
@ -391,16 +391,41 @@ BEGIN
k := keys.GetString(keys, j); k := keys.GetString(keys, j);
v := values.GetString(values, j); v := values.GetString(values, j);
(* Get the repository path for building *) (* IMPROVED: Support Git, HTTPS, and HTTP sources *)
IF currentDep^.rmt IS vpkdepTree.RemoteGit THEN IF currentDep^.rmt IS vpkdepTree.RemoteGit THEN
vpkTools.extractRepoPathFromUrl(currentDep^.rmt.URI, repoPath); vpkTools.extractRepoPathFromUrl(currentDep^.rmt.URI, repoPath);
ELSIF currentDep^.rmt IS vpkdepTree.RemoteHttps THEN ELSIF currentDep^.rmt IS vpkdepTree.RemoteHttps THEN
node := currentDep^.rmt(vpkdepTree.RemoteHttps)^.Files.Get(currentDep^.rmt(vpkdepTree.RemoteHttps)^.Files, 0); node := currentDep^.rmt(vpkdepTree.RemoteHttps)^.Files.Get(currentDep^.rmt(vpkdepTree.RemoteHttps)^.Files, 0);
IF node # NIL THEN IF node # NIL THEN
vpkTools.extractRepoPathFromUrl(node^.obj(vpkdepTree.File)^.URI, repoPath); vpkTools.extractRepoPathFromUrl(node^.obj(vpkdepTree.File)^.URI, repoPath);
(* IMPROVED: Remove filename for HTTP sources *)
lastSlash := -1;
idx := 0;
WHILE (idx < Strings.Length(repoPath)) & (repoPath[idx] # 0X) DO
IF repoPath[idx] = '/' THEN lastSlash := idx; END;
INC(idx);
END;
IF lastSlash > 0 THEN
repoPath[lastSlash] := 0X;
END;
END;
ELSIF currentDep^.rmt IS vpkdepTree.RemoteHttp THEN (* ADD: HTTP support *)
node := currentDep^.rmt(vpkdepTree.RemoteHttp)^.Files.Get(currentDep^.rmt(vpkdepTree.RemoteHttp)^.Files, 0);
IF node # NIL THEN
vpkTools.extractRepoPathFromUrl(node^.obj(vpkdepTree.File)^.URI, repoPath);
(* IMPROVED: Remove filename for HTTP sources *)
lastSlash := -1;
idx := 0;
WHILE (idx < Strings.Length(repoPath)) & (repoPath[idx] # 0X) DO
IF repoPath[idx] = '/' THEN lastSlash := idx; END;
INC(idx);
END;
IF lastSlash > 0 THEN
repoPath[lastSlash] := 0X;
END;
END; END;
ELSE ELSE
Out.String("WARNING: building for neither git nor https sources not supported yet"); Out.Ln; Out.String("WARNING: unsupported source type"); Out.Ln;
END; END;
(* Build source path - same logic as vpkInstaller *) (* Build source path - same logic as vpkInstaller *)
@ -410,24 +435,22 @@ BEGIN
Out.String("Executing dependency build: "); Out.String(cmd^); Out.Ln; Out.String("Executing dependency build: "); Out.String(cmd^); Out.Ln;
Out.String("Building dependency in: "); Out.String(buildDir); Out.Ln; Out.String("Building dependency in: "); Out.String(buildDir); Out.Ln;
(* Change to build directory and execute *) (* IMPROVED: Continue on errors instead of HALT *)
res := Platform.Chdir(buildDir); res := Platform.Chdir(buildDir);
IF res # 0 THEN IF res # 0 THEN
Out.String("Failed to change directory to "); Out.String(buildDir); Out.Ln; Out.String("Warning: Failed to change directory to "); Out.String(buildDir); Out.Ln;
HALT(1); ELSE
END; res := Platform.System(cmd^);
IF res # 0 THEN
Out.String("Warning: Dependency build failed with code: "); Out.Int(res, 0); Out.Ln;
ELSE
Out.String("Dependency build successful"); Out.Ln;
END;
res := Platform.System(cmd^); (* Return to parent directory *)
IF res # 0 THEN
Out.String("Dependency build failed with code: "); Out.Int(res, 0); Out.Ln;
(* Try to return to parent directory *)
res := Platform.Chdir(parentDir); res := Platform.Chdir(parentDir);
HALT(1);
END; END;
(* Return to parent directory *)
res := Platform.Chdir(parentDir);
INC(j); INC(j);
UNTIL j = keys.Count; UNTIL j = keys.Count;
@ -438,7 +461,7 @@ BEGIN
INC(i); INC(i);
UNTIL i = depTree.Count; UNTIL i = depTree.Count;
Out.String("All dependencies fetched and built successfully!"); Out.Ln; Out.String("All dependencies processed!"); Out.Ln;
END; END;
END buildDependencies; END buildDependencies;

View file

@ -55,7 +55,7 @@ TYPE
Files* : List.TList; Files* : List.TList;
END; END;
RemoteHttps* = POINTER TO RemoteHttpDesc; RemoteHttps* = POINTER TO RemoteHttpsDesc;
RemoteHttpsDesc* = RECORD(RemoteDesc) RemoteHttpsDesc* = RECORD(RemoteDesc)
Files* : List.TList; Files* : List.TList;
END; END;