diff --git a/src/vpkInstaller.Mod b/src/vpkInstaller.Mod index e7670de..9f8652f 100644 --- a/src/vpkInstaller.Mod +++ b/src/vpkInstaller.Mod @@ -62,15 +62,15 @@ END fetch; PROCEDURE build*(VAR package: ARRAY OF CHAR; prefix: ARRAY OF CHAR; VAR tree: ARRAY OF CHAR; a : BOOLEAN); VAR depTree: vpkdepTree.TdepTree; - dep: vpkdepTree.Tdep; - i, j: LONGINT; - keys, values: StringList.TStringList; - k, v: StringList.pstring; - b: BOOLEAN; - builddir, cmd, srcPath: StringList.pstring; - res: INTEGER; - domain: ARRAY 256 OF CHAR; - node: List.Node; + dep: vpkdepTree.Tdep; + i, j: LONGINT; + keys, values: StringList.TStringList; + k, v: StringList.pstring; + b: BOOLEAN; + builddir, cmd, srcPath: StringList.pstring; + res: INTEGER; + domain: ARRAY 256 OF CHAR; + node: List.Node; BEGIN IF prefix # "" THEN builddir := vpkEnv.mkBldDir(prefix) @@ -87,8 +87,23 @@ BEGIN b := FALSE; b := vpkJsonDepRetriever.getBuildInfo(dep, keys, values); IF b THEN + Out.String("Build info found for the package: "); Out.String(dep.name^); Out.Ln; + + (* Ensure keys and values are not NIL *) + IF keys = NIL THEN + Out.String("Error: keys list is NIL."); Out.Ln; + HALT(10); + END; + IF values = NIL THEN + Out.String("Error: values list is NIL."); Out.Ln; + HALT(10); + END; + + Out.String("keys.Count = "); Out.Int(keys.Count, 0); Out.Ln; + Out.String("values.Count = "); Out.Int(values.Count, 0); Out.Ln; j := 0; REPEAT + Out.String("Processing build step "); Out.Int(j, 0); Out.Ln; IF dep^.rmt IS vpkdepTree.RemoteGit THEN vpkTools.extractDomainFromUrl(dep^.rmt.URI, domain); ELSIF dep^.rmt IS vpkdepTree.RemoteHttps THEN @@ -97,25 +112,32 @@ BEGIN ELSE Out.String("WARNING: building for neither git nor https sources not supported yet"); Out.Ln; END; -k := keys.GetString(keys, j); + IF j >= keys.Count THEN + Out.String("Index out of bounds: keys.Count = "); Out.Int(keys.Count, 0); Out.String(", j = "); Out.Int(j, 0); Out.Ln; + HALT(10); + END; + k := keys.GetString(keys, j); v := values.GetString(values, j); + Out.String("Got key: "); Out.String(k^); Out.Ln; + Out.String("Got value: "); Out.String(v^); Out.Ln; srcPath := vpkEnv.getSrcRelPath(dep.name^, domain, v^); cmd := vpkEnv.mkCmd(k^, srcPath^); - Out.String(cmd^); Out.Ln; - Out.String("building in "); Out.String(builddir^); Out.Ln; + Out.String("Command: "); Out.String(cmd^); Out.Ln; + Out.String("Building in "); Out.String(builddir^); Out.Ln; res := Platform.Chdir(builddir^); IF res # 0 THEN - Out.String("failed to change directory to "); Out.String(builddir^); Out.Ln; Out.String("this should never happen."); Out.Ln; HALT(66); + Out.String("Failed to change directory to "); Out.String(builddir^); Out.Ln; Out.String("This should never happen."); Out.Ln; HALT(66); END; res := Platform.System(cmd^); - IF res # 0 THEN Out.String("failed to run build command"); Out.Ln END; + IF res # 0 THEN Out.String("Failed to run build command"); Out.Ln END; INC(j) UNTIL j = keys.Count; ELSE - Out.String("no build info found for the package: "); Out.String(dep.name^); Out.Ln; + Out.String("No build info found for the package: "); Out.String(dep.name^); Out.Ln; END; INC(i); UNTIL i = depTree.Count; END build; + END vpkInstaller. diff --git a/src/vpkJsonDepRetriever.Mod b/src/vpkJsonDepRetriever.Mod index 96187c8..eefb6b4 100644 --- a/src/vpkJsonDepRetriever.Mod +++ b/src/vpkJsonDepRetriever.Mod @@ -5,13 +5,27 @@ IMPORT Strings, Out, CONST ErrmessSize = 4096; +PROCEDURE ToLower(VAR stringVar: ARRAY OF CHAR); +VAR + i: INTEGER; +BEGIN + i := 0; + WHILE stringVar[i] # 0X DO + IF (stringVar[i] >= "A") & (stringVar[i] <= "Z") THEN + stringVar[i] := CHR(ORD(stringVar[i]) + 20H); + END; + INC(i); + END; +END ToLower; + + PROCEDURE getBuildInfo*(VAR d: vpkdepTree.Tdep; VAR k, v: StringList.TStringList): BOOLEAN; VAR jsonstr, errstr: strUtils.pstring; tree, buildValue, command, file: Json.Value; rootObj, buildStep: Json.Obj; buildArray: Json.Arr; - cm, fl, bl: Json.jString; + cm, fl, bl, cmLower, flLower: Json.jString; b: BOOLEAN; BEGIN k := NIL; v := NIL; @@ -21,70 +35,93 @@ BEGIN IF jsonstr # NIL THEN NEW(errstr, ErrmessSize); b := Json.Parse(tree, jsonstr^, errstr^); - (*build := jsonRecord.GetNonTerminal(jsonRecord, vpkSettings.bldType);*) IF b THEN - (*keys := NIL; values := NIL; - build.GetTerminalKeys(build, keys); - build.GetTerminalValues(build, values); - k := keys; v := values;*) - IF tree IS Json.Obj THEN - rootObj := tree(Json.Obj); - NEW(bl, Strings.Length(vpkSettings.bldType)+1); (* +1 for 0X *) - COPY(vpkSettings.bldType, bl^); - IF Json.ObjSelect(buildValue, rootObj, bl) THEN - IF buildValue IS Json.Arr THEN - buildArray := buildValue(Json.Arr); - WHILE buildArray # NIL DO - buildStep := buildArray.value(Json.Obj); - NEW(cm, Strings.Length(vpkSettings.bldCommand)+1); (* +1 for 0X *) - NEW(fl, Strings.Length(vpkSettings.bldFile)+1); (* +1 for 0X *) - COPY(vpkSettings.bldCommand, cm^); - COPY(vpkSettings.bldFile, fl^); - IF Json.ObjSelect(command, buildStep, cm) & - Json.ObjSelect(file, buildStep, fl) THEN - IF (command IS Json.Str) & (file IS Json.Str) THEN - IF k = NIL THEN k := StringList.Create() END; - IF v = NIL THEN v := StringList.Create() END; - k.AppendString(k, command(Json.Str).str^); - v.AppendString(v, file(Json.Str).str^); - ELSE - Out.String("command and file must be strings"); Out.Ln; - HALT(5); - END; - END; - buildArray := buildArray.next; + IF tree IS Json.Obj THEN + rootObj := tree(Json.Obj); + NEW(bl, Strings.Length(vpkSettings.bldType) + 1); (* +1 for 0X *) + COPY(vpkSettings.bldType, bl^); + IF Json.ObjSelect(buildValue, rootObj, bl) THEN + IF buildValue IS Json.Arr THEN + buildArray := buildValue(Json.Arr); + WHILE buildArray # NIL DO + buildStep := buildArray.value(Json.Obj); + Out.String("Examining build step object"); Out.Ln; + IF buildStep # NIL THEN + Out.String("buildStep keys: "); + rootObj := buildStep; + WHILE rootObj # NIL DO + Out.String(rootObj.name^); Out.String(" "); + rootObj := rootObj.next; END; - ELSE - Out.String("Build section is not an array."); Out.Ln; + Out.Ln; + ELSE + Out.String("buildStep is NIL"); Out.Ln; + END; + + NEW(cm, Strings.Length(vpkSettings.bldCommand) + 1); (* +1 for 0X *) + NEW(fl, Strings.Length(vpkSettings.bldFile) + 1); (* +1 for 0X *) + COPY(vpkSettings.bldCommand, cm^); + COPY(vpkSettings.bldFile, fl^); + + NEW(cmLower, Strings.Length(cm^) + 1); + NEW(flLower, Strings.Length(fl^) + 1); + COPY(cm^, cmLower^); + COPY(fl^, flLower^); + ToLower(cmLower^); + ToLower(flLower^); + + IF Json.ObjSelect(command, buildStep, cmLower) THEN + Out.String("Selected command: "); Out.String(command(Json.Str).str^); Out.Ln; + IF Json.ObjSelect(file, buildStep, flLower) THEN + Out.String("Selected file: "); Out.String(file(Json.Str).str^); Out.Ln; + IF (command IS Json.Str) & (file IS Json.Str) THEN + IF k = NIL THEN k := StringList.Create() END; + IF v = NIL THEN v := StringList.Create() END; + k.AppendString(k, command(Json.Str).str^); + v.AppendString(v, file(Json.Str).str^); + Out.String("Appended command: "); Out.String(command(Json.Str).str^); Out.Ln; + Out.String("Appended file: "); Out.String(file(Json.Str).str^); Out.Ln; + ELSE + Out.String("Command and file must be strings"); Out.Ln; + HALT(5); + END; + ELSE + Out.String("Failed to select 'file' from build step"); Out.Ln; + END; + ELSE + Out.String("Failed to select 'command' from build step"); Out.Ln; + END; + buildArray := buildArray.next; END; ELSE - Out.String("Build section not found."); Out.Ln; + Out.String("Build section is not an array."); Out.Ln; END; ELSE - Out.String("JSON root is not an object."); Out.Ln; + Out.String("Build section not found."); Out.Ln; END; + ELSE + Out.String("JSON root is not an object."); Out.Ln; + END; ELSE - Out.String("JSON parsing failed: "); Out.String(errstr^); Out.Ln; + Out.String("JSON parsing failed: "); Out.String(errstr^); Out.Ln; END; + ELSE + Out.String("No JSON string provided."); Out.Ln; END; RETURN b; END getBuildInfo; + PROCEDURE getURIandType*(VAR d: vpkdepTree.Tdep); VAR jsonstr, errstr: strUtils.pstring; - tree, singleValue, remoteValue: Json.Value; - rootObj, someObj, remoteObj, fileObj, fileObj2, authObj: Json.Obj; - filesArray, fileObjValue: Json.Value; - fileValue, urlValue, authTypeValue, md5Value, authCredsValue, userValue, passwordValue: Json.Value; + tree, remoteValue: Json.Value; + rootObj, someObj: Json.Obj; err: ARRAY ErrmessSize OF CHAR; - b, fndRemSec, fndTypeHttps, fndFiles: BOOLEAN; - key, val, u, t, br, remote, - url, authType, authTypeStr, - md5, authCr, authCrStr, - user, password : Json.jString; - httpsRemote: vpkdepTree.RemoteHttps; gitRemote: vpkdepTree.RemoteGit; - httpsFile: vpkdepTree.File; + b, fndRemSec: BOOLEAN; + key, val, remote, keyLower: Json.jString; + httpsRemote: vpkdepTree.RemoteHttps; + gitRemote: vpkdepTree.RemoteGit; BEGIN jsonstr := NIL; vpkStorage.json2pstring(d.name^, jsonstr); @@ -94,137 +131,76 @@ BEGIN IF b THEN IF tree IS Json.Obj THEN rootObj := tree(Json.Obj); - NEW(u, Strings.Length(vpkSettings.rmtTreeKey) + 1); COPY(vpkSettings.rmtTreeKey, u^); - NEW(t, Strings.Length(vpkSettings.rmtTypKey) + 1); COPY(vpkSettings.rmtTypKey, t^); - NEW(br, Strings.Length(vpkSettings.rmtTreeBranchKey) + 1); COPY(vpkSettings.rmtTreeBranchKey, br^); - NEW(remote, Strings.Length(vpkSettings.rmtType)+1); + NEW(remote, Strings.Length(vpkSettings.rmtType) + 1); COPY(vpkSettings.rmtType, remote^); fndRemSec := FALSE; - fndTypeHttps := FALSE; - REPEAT - IF rootObj.name^ = remote^ THEN + + (* Find the "Remote" section *) + WHILE (rootObj # NIL) & ~fndRemSec DO + NEW(keyLower, LEN(rootObj.name^) + 1); + COPY(rootObj.name^, keyLower^); + ToLower(keyLower^); + IF keyLower^ = "remote" THEN fndRemSec := TRUE; + ELSE + rootObj := rootObj.next; END; - IF ~fndRemSec THEN rootObj := rootObj.next END - UNTIL (rootObj = NIL) OR fndRemSec; + END; IF fndRemSec THEN - WHILE rootObj # NIL DO - remoteValue := rootObj.value; - IF remoteValue IS Json.Obj THEN - singleValue := remoteValue(Json.Obj); - - IF singleValue IS Json.Obj THEN - someObj := singleValue(Json.Obj); - key := someObj.name; - IF someObj.value IS Json.Str THEN - val := someObj.value(Json.Str).str; - IF key^ = vpkSettings.rmtTypKey THEN (* type *) - IF val^ = vpkSettings.rmtTypHttpsVal THEN - - NEW(httpsRemote); d^.rmt := httpsRemote; - d^.Type := vpkSettings.https; - httpsRemote^.Files := List.Create(); - d^.Type := vpkSettings.https; - WHILE singleValue # NIL DO - someObj := singleValue(Json.Obj); - - IF someObj.value IS Json.Arr THEN - - filesArray := someObj.value(Json.Arr); - WHILE filesArray # NIL DO - IF filesArray IS Json.Arr THEN - fileObjValue := filesArray(Json.Arr).value; - Out.Ln; - IF fileObjValue IS Json.Obj THEN - fileObj := fileObjValue(Json.Obj); - NEW(httpsFile); - httpsFile^.auth := FALSE; (* default *) - (* extract url *) - NEW(url, Strings.Length(vpkSettings.rmtFileURL)+1); - COPY(vpkSettings.rmtFileURL, url^); - IF Json.ObjSelect(urlValue, fileObj, url) & (urlValue IS Json.Str) THEN - COPY(urlValue(Json.Str).str^, httpsFile^.URI); - END; - fileObj2 := fileObj; - (* extract authtype *) - NEW(authType, Strings.Length(vpkSettings.rmtFileAuthType)+1); - COPY(vpkSettings.rmtFileAuthType, authType^); - IF Json.ObjSelect(authTypeValue, fileObj2, authType) - & (authTypeValue IS Json.Str) THEN - authTypeStr := authTypeValue(Json.Str).str; - IF authTypeValue(Json.Str).str^ = vpkSettings.rmtFileAuthValBasic THEN - httpsFile^.auth := TRUE; - (* extract auth credentials *) - NEW(authCr, Strings.Length(vpkSettings.rmtFileAuthCreds)+1); - COPY(vpkSettings.rmtFileAuthCreds, authCr^); - IF Json.ObjSelect(authCredsValue, fileObj2, authCr) & (authCredsValue IS Json.Obj) THEN - IF authCredsValue IS Json.Obj THEN - authObj := authCredsValue(Json.Obj); - NEW(user, Strings.Length(vpkSettings.rmtFileAuthUsr) + 1); - COPY(vpkSettings.rmtFileAuthUsr, user^); - IF Json.ObjSelect(userValue, authObj, user) & (userValue IS Json.Str) THEN - COPY(userValue(Json.Str).str^, httpsFile^.username); - END; - NEW(password, Strings.Length(vpkSettings.rmtFileAuthPwd) + 1); - COPY(vpkSettings.rmtFileAuthPwd, password^); - IF Json.ObjSelect(passwordValue, authObj, password) & (passwordValue IS Json.Str) THEN - COPY(passwordValue(Json.Str).str^, httpsFile^.password); - END; - END; (* if authcradsvalue is json.obj *) - END; (* if json objselect authcredsval *) - - ELSE - httpsFile^.auth := FALSE; - END - END; - (* extract md5 *) - NEW(md5, Strings.Length(vpkSettings.rmtFileMD5)+1); - COPY(vpkSettings.rmtFileMD5, md5^); - IF Json.ObjSelect(md5Value, fileObj, md5) & (md5Value IS Json.Str) THEN - COPY(md5Value(Json.Str).str^, httpsFile^.md5); - Out.String("found md5 "); Out.String(httpsFile^.md5); Out.Ln; - END; - httpsRemote^.Files.Append(httpsRemote^.Files, httpsFile); - (*Out.Int(d^.rmt(vpkdepTree.RemoteHttps)^.Files.Count, 0); Out.Ln;*) - END; (*fileobj is json.obj *) - END; (*filesarray is json arr *) - filesArray := filesArray(Json.Arr).next; - END; (* while filesarray # nil *) - - END; - singleValue := someObj.next; - END; - - - - ELSIF val^ = vpkSettings.rmtTypGitVal THEN - NEW(gitRemote); d^.rmt := gitRemote; - d^.Type := vpkSettings.git; - WHILE singleValue # NIL DO - IF singleValue IS Json.Obj THEN - someObj := singleValue(Json.Obj); - key := someObj.name; - val := someObj.value(Json.Str).str; - IF key^ = vpkSettings.rmtTreeBranchKey THEN - COPY(val^, d^.rmt(vpkdepTree.RemoteGit)^.branch); - END; - IF key^ = vpkSettings.rmtTreeKey THEN - COPY(val^, d^.rmt^.URI); - END; - END; - singleValue := someObj.next; - END; - ELSE - Out.String("unhandled remote type"); Out.Ln; HALT(5); - END; + Out.String("Found 'Remote' section"); Out.Ln; + remoteValue := rootObj.value; + IF remoteValue IS Json.Obj THEN + rootObj := remoteValue(Json.Obj); + (* Process the "Remote" object *) + WHILE rootObj # NIL DO + key := rootObj.name; + (* Convert key to lowercase *) + NEW(keyLower, LEN(key^) + 1); + COPY(key^, keyLower^); + ToLower(keyLower^); + IF rootObj.value IS Json.Str THEN + val := rootObj.value(Json.Str).str; + Out.String("Processing key: "); Out.String(key^); Out.Ln; + Out.String("Value: "); Out.String(val^); Out.Ln; + IF keyLower^ = "type" THEN (* type *) + IF val^ = vpkSettings.rmtTypHttpsVal THEN + NEW(httpsRemote); d^.rmt := httpsRemote; + d^.Type := vpkSettings.https; + Out.String("Set remote type to HTTPS"); Out.Ln; + ELSIF val^ = vpkSettings.rmtTypGitVal THEN + NEW(gitRemote); d^.rmt := gitRemote; + d^.Type := vpkSettings.git; + gitRemote^.branch[0] := 0X; (* Ensure branch is set to an empty string *) + Out.String("Set remote type to GIT"); Out.Ln; + ELSE + Out.String("Unhandled remote type: "); Out.String(val^); Out.Ln; HALT(5); END; + ELSIF keyLower^ = "tag" THEN + IF d^.rmt # NIL THEN + COPY(val^, d^.rmt(vpkdepTree.RemoteGit)^.tag); (* Use the tag field appropriately *) + Out.String("Set tag to "); Out.String(val^); Out.Ln; + ELSE + Out.String("d^.rmt is NIL when setting tag"); Out.Ln; + END; + ELSIF keyLower^ = "path" THEN + IF d^.rmt # NIL THEN + COPY(val^, d^.rmt^.URI); + Out.String("Set URI to "); Out.String(val^); Out.Ln; + ELSE + Out.String("d^.rmt is NIL when setting URI"); Out.Ln; + END; + ELSE + Out.String("Unhandled key: "); Out.String(key^); Out.Ln; END; - END; (* if single value is json.obj *) - END; (* if remotevalue is json.obj *) - - rootObj := rootObj.next - END; (* while rootObj # NIL *) + ELSE + Out.String("Value for key "); Out.String(key^); Out.String(" is not a string"); Out.Ln; + END; + rootObj := rootObj.next; + END; + ELSE + Out.String("Remote value is not an object"); Out.Ln; + END; ELSE Out.String("Remote section not found."); Out.Ln; END; @@ -237,8 +213,13 @@ BEGIN ELSE Out.String("No JSON string provided."); Out.Ln; END; + IF d^.rmt = NIL THEN + Out.String("deps remote is not set, this should not happen"); Out.Ln; + HALT(5); + END; END getURIandType; + PROCEDURE getDeps*(VAR d: vpkdepTree.Tdep; VAR depstrlist: StringList.TStringList): LONGINT; VAR jsonstr, errstr: strUtils.pstring; diff --git a/src/vpkSyncer.Mod b/src/vpkSyncer.Mod index 11142ca..9e48b90 100644 --- a/src/vpkSyncer.Mod +++ b/src/vpkSyncer.Mod @@ -26,28 +26,40 @@ END sync; PROCEDURE fetch*(VAR dep: vpkdepTree.Tdep; dst: ARRAY OF CHAR); VAR domain: ARRAY 64 OF CHAR; BEGIN - IF dep^.rmt # NIL THEN + Out.String("Starting fetch process..."); Out.Ln; + Out.String("Destination: "); Out.String(dst); Out.Ln; + IF dep = NIL THEN + Out.String("Dependency is NIL"); Out.Ln; + HALT(1); + END; + IF dep^.rmt = NIL THEN + Out.String("Dependency remote is NIL"); Out.Ln; + HALT(5); + ELSE IF dep^.rmt IS vpkdepTree.RemoteGit THEN + Out.String("Remote type is Git"); Out.Ln; vpkTools.extractDomainFromUrl(dep^.rmt^.URI, domain); + Out.String("Extracted domain: "); Out.String(domain); Out.Ln; (* dst is changed by mkdefPkgDirPath and mkPkgdirPath *) IF dst = "" THEN vpkEnv.mkdefPkgDirPath(domain, dep^.name^, dst); ELSE vpkEnv.mkPkgDirPath(domain, dep^.name^, dst); END; + Out.String("Final destination path: "); Out.String(dst); Out.Ln; + Out.String("Fetching repository..."); Out.Ln; vpkGit.fetchRepo(dep^.rmt^.URI, dst, dep^.rmt(vpkdepTree.RemoteGit).branch); ELSIF dep^.rmt IS vpkdepTree.RemoteHttps THEN + Out.String("Remote type is HTTPS"); Out.Ln; (* full dst will be determined in vpkHttps.fetchFiles for each file *) vpkHttps.fetchFiles(dep, dst); ELSE Out.String("TODO: neither git nor https url"); Out.Ln; Out.String("not handled"); Out.Ln; - END - ELSE - Out.String("deps remote is not set, this should not happen"); Out.Ln; - HALT(5); + END; END; + Out.String("Fetch process completed."); Out.Ln; END fetch; END vpkSyncer.