From 9efd87571694065e07a22fc296f6cc1691e5525c Mon Sep 17 00:00:00 2001 From: Norayr Chilingarian Date: Sat, 19 Jul 2025 23:36:36 +0400 Subject: [PATCH] directory paths improved; local builds work for http/https as well. --- src/vpkHttp.Mod | 59 +++++++++++++++++++++++++++++++-------- src/vpkHttps.Mod | 51 ++++++++++++++++++++++++++++------ src/vpkLocalBuilder.Mod | 61 ++++++++++++++++++++++++++++------------- src/vpkdepTree.Mod | 2 +- 4 files changed, 133 insertions(+), 40 deletions(-) diff --git a/src/vpkHttp.Mod b/src/vpkHttp.Mod index ca3ce7c..ce83448 100644 --- a/src/vpkHttp.Mod +++ b/src/vpkHttp.Mod @@ -1,5 +1,5 @@ MODULE vpkHttp; -IMPORT Out, Platform, +IMPORT Out, Platform, Strings, List, strTypes, http, vpkdepTree, vpkTools, vpkMD5Checker, vpkEnv; @@ -8,20 +8,28 @@ VAR h: http.Client; answer: strTypes.pstring; 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; i, j: LONGINT; node: List.Node; bool, continueFetching: BOOLEAN; 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 + COPY(Platform.CWD, startingDir); COPY(dst, initialDst); + COPY("80", port); + COPY("", emptyName); i := 0; continueFetching := TRUE; 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^.obj(vpkdepTree.File) # NIL THEN Out.String("getting "); Out.String(node^.obj(vpkdepTree.File)^.URI); Out.Ln; @@ -29,20 +37,42 @@ BEGIN (* Extract domain for connection *) vpkTools.extractDomainFromUrl(node^.obj(vpkdepTree.File)^.URI, domain); Out.String("connecting to "); Out.String(domain); Out.Ln; - + (* Extract full repository path for directory structure *) 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; - + + (* 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.extractFilenameFromUrl(node^.obj(vpkdepTree.File)^.URI, filename); - (* Use full repository path instead of just domain *) - vpkEnv.mkPkgDirPath(repoPath, dep^.name^, dst); - - j := Platform.Chdir(dst); - - COPY(initialDst, dst); + (* Change to target directory *) + Out.String("will return to "); Out.Ln; + Out.String(targetDir); Out.Ln; + j := Platform.Chdir(targetDir); h := http.Create(domain, port, path); @@ -61,6 +91,11 @@ BEGIN h.Save(h); bool := vpkMD5Checker.checkMD5(filename, node^.obj(vpkdepTree.File)^.md5); 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 Out.String("node^.obj(vpkdepTree.File) is NIL"); Out.Ln; END; @@ -73,4 +108,4 @@ BEGIN END fetchFiles; -END vpkHttp. \ No newline at end of file +END vpkHttp. diff --git a/src/vpkHttps.Mod b/src/vpkHttps.Mod index 7bf77fc..5dca46b 100644 --- a/src/vpkHttps.Mod +++ b/src/vpkHttps.Mod @@ -1,5 +1,5 @@ MODULE vpkHttps; -IMPORT Out, Platform, +IMPORT Out, Platform, Strings, List, strTypes, https, vpkdepTree, vpkTools, vpkMD5Checker, vpkEnv; @@ -8,16 +8,23 @@ VAR h: https.TLSClient; answer: strTypes.pstring; 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; i, j: LONGINT; node: List.Node; bool, continueFetching: BOOLEAN; 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 + COPY(Platform.CWD, startingDir); Out.String("*** HTTPS: fetchFiles called"); Out.Ln; COPY(dst, initialDst); COPY("443", port); + COPY("", emptyName); i := 0; continueFetching := TRUE; @@ -33,17 +40,40 @@ BEGIN (* Extract full repository path for directory structure *) 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; + (* 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.extractFilenameFromUrl(node^.obj(vpkdepTree.File)^.URI, filename); - (* Use full repository path - DO NOT add package name again *) - vpkEnv.mkPkgDirPath(repoPath, dep^.name^, dst); - - j := Platform.Chdir(dst); - - COPY(initialDst, dst); + (* Change to target directory *) + Out.String("will cd to "); Out.Ln; + Out.String(targetDir); Out.Ln; + j := Platform.Chdir(targetDir); h := https.Create(domain, port, path); @@ -62,6 +92,11 @@ BEGIN h.Save(h); bool := vpkMD5Checker.checkMD5(filename, node^.obj(vpkdepTree.File)^.md5); 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 Out.String("node^.obj(vpkdepTree.File) is NIL"); Out.Ln; END; diff --git a/src/vpkLocalBuilder.Mod b/src/vpkLocalBuilder.Mod index b269adb..6129ce8 100644 --- a/src/vpkLocalBuilder.Mod +++ b/src/vpkLocalBuilder.Mod @@ -362,15 +362,15 @@ VAR repoPath: ARRAY 256 OF CHAR; node: List.Node; parentDir: ARRAY 8 OF CHAR; + lastSlash, idx: INTEGER; (* ADD: for filename removal *) BEGIN (* Resolve all dependencies for local project *) depTree := resolveLocal(projectFile); IF depTree.Count > 0 THEN - (* Set up build directory *) - COPY("./", buildDir); - Strings.Append(DefaultBuildDir, buildDir); - COPY("..", parentDir); (* Variable for Platform.Chdir *) + (* IMPROVED: Use simple build path *) + COPY("build", buildDir); + COPY("..", parentDir); i := 0; REPEAT @@ -391,16 +391,41 @@ BEGIN k := keys.GetString(keys, 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 vpkTools.extractRepoPathFromUrl(currentDep^.rmt.URI, repoPath); ELSIF currentDep^.rmt IS vpkdepTree.RemoteHttps THEN node := currentDep^.rmt(vpkdepTree.RemoteHttps)^.Files.Get(currentDep^.rmt(vpkdepTree.RemoteHttps)^.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; + 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; 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; (* Build source path - same logic as vpkInstaller *) @@ -410,24 +435,22 @@ BEGIN Out.String("Executing dependency build: "); Out.String(cmd^); 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); IF res # 0 THEN - Out.String("Failed to change directory to "); Out.String(buildDir); Out.Ln; - HALT(1); - END; + Out.String("Warning: Failed to change directory to "); Out.String(buildDir); Out.Ln; + ELSE + 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^); - IF res # 0 THEN - Out.String("Dependency build failed with code: "); Out.Int(res, 0); Out.Ln; - (* Try to return to parent directory *) + (* Return to parent directory *) res := Platform.Chdir(parentDir); - HALT(1); END; - (* Return to parent directory *) - res := Platform.Chdir(parentDir); - INC(j); UNTIL j = keys.Count; @@ -438,7 +461,7 @@ BEGIN INC(i); UNTIL i = depTree.Count; - Out.String("All dependencies fetched and built successfully!"); Out.Ln; + Out.String("All dependencies processed!"); Out.Ln; END; END buildDependencies; diff --git a/src/vpkdepTree.Mod b/src/vpkdepTree.Mod index 2ff0d59..ba0388d 100644 --- a/src/vpkdepTree.Mod +++ b/src/vpkdepTree.Mod @@ -55,7 +55,7 @@ TYPE Files* : List.TList; END; - RemoteHttps* = POINTER TO RemoteHttpDesc; + RemoteHttps* = POINTER TO RemoteHttpsDesc; RemoteHttpsDesc* = RECORD(RemoteDesc) Files* : List.TList; END;