@@ -1320,11 +1320,11 @@ algorithm
13201320 case (cache,env,"buildEncryptedPackage" , {Values . CODE (Absyn . C_TYPENAME (className)),Values . BOOL (b)},_)
13211321 algorithm
13221322 p := SymbolTable . getAbsyn();
1323- (b1, str) := buildEncryptedPackage(className, b, p);
1324- then (cache,Values . TUPLE ({ Values . BOOL (b1), Values . STRING (str)} ));
1323+ b1 := buildEncryptedPackage(className, b, p);
1324+ then (cache,Values . BOOL (b1));
13251325
13261326 case (cache,_,"buildEncryptedPackage" ,_,_)
1327- then (cache,Values . TUPLE ({ Values . BOOL (false ), Values . STRING ( "" )} ));
1327+ then (cache,Values . BOOL (false ));
13281328
13291329 case (cache,env,"translateModelXML" ,{Values . CODE (Absyn . C_TYPENAME (className)),Values . STRING (filenameprefix)},_)
13301330 equation
@@ -3562,47 +3562,65 @@ protected function buildEncryptedPackage
35623562 input Boolean encrypt;
35633563 input Absyn . Program inProgram;
35643564 output Boolean success;
3565- output String commandOutput;
35663565protected
35673566 Absyn . Class cls;
3568- String fileName, omhome, pd, str1, str2, str3, call, logFile;
3567+ String fileName, logFile, omhome, pd, ext, packageTool, packageToolArgs, command;
3568+ Boolean runCommand;
3569+ String molName, dirPath, rmCommand, cdCommand, mvCommand, dirOrFileName, zipCommand;
35693570algorithm
35703571 cls := Interactive . getPathedClassInProgram(className, inProgram);
35713572 fileName := Absyn . classFilename(cls);
3573+ logFile := "buildEncryptedPackage.log" ;
3574+ runCommand := true ;
35723575 if (System . regularFileExists(fileName)) then
35733576 // get OPENMODELICAHOME
35743577 omhome := Settings . getInstallationDirectoryPath();
35753578 pd := System . pathDelimiter();
3576- str1 := if System . os() == "Windows_NT" then ".exe" else "" ;
3577- // create the path till packagetool
3578- str2 := stringAppendList({omhome,pd,"lib" ,pd,"omc" ,pd,"SEMLA" ,pd,"packagetool" ,str1});
3579- if System . regularFileExists(str2) then
3580- // create the list of arguments for packagetool
3581- str3 := "-librarypath \" " + System . dirname(fileName) + " \" -version \" 1.0 \" -language \" 3.2 \" -encrypt \" " + boolString(encrypt) + " \" " ;
3582- call := stringAppendList({str2," " ,str3});
3583- logFile := "packagetool.log" ;
3579+ ext := if System . os() == "Windows_NT" then ".exe" else "" ;
3580+ if encrypt then
3581+ // create the path till packagetool
3582+ packageTool := stringAppendList({omhome,pd,"lib" ,pd,"omc" ,pd,"SEMLA" ,pd,"packagetool" ,ext});
3583+ if System . regularFileExists(packageTool) then
3584+ // create the list of arguments for packagetool
3585+ packageToolArgs := "-librarypath \" " + System . dirname(fileName) + " \" -version \" 1.0 \" -language \" 3.2 \" -encrypt \" " + boolString(encrypt) + " \" " ;
3586+ command := stringAppendList({packageTool," " ,packageToolArgs});
3587+ else
3588+ Error . addMessage(Error . ENCRYPTION_NOT_SUPPORTED , {packageTool});
3589+ success := false ;
3590+ runCommand := false ;
3591+ end if ;
3592+ else
3593+ molName := Absyn . pathString(className) + ".mol" ;
3594+ dirPath := System . dirname(fileName);
3595+ // commands
3596+ rmCommand := "rm -f \" " + molName + " \" " ;
3597+ cdCommand := "cd \" " + dirPath + " \" " ;
3598+ mvCommand := "mv \" " + molName + " \" \" " + System . pwd() + " \" " ;
3599+
3600+ if (Util . endsWith(fileName, "package.mo" )) then
3601+ dirOrFileName := System . basename(dirPath);
3602+ zipCommand := "zip -r \" " + System . pwd() + pd + molName + " \" \" " + dirOrFileName + " \" " ;
3603+ command := stringAppendList({rmCommand, " && " , cdCommand, " && cd .. && " , zipCommand});
3604+ else
3605+ dirOrFileName := System . basename(fileName);
3606+ zipCommand := "zip -r \" " + System . pwd() + pd + molName + " \" \" " + dirOrFileName + " \" " ;
3607+ command := stringAppendList({rmCommand, " && " , cdCommand, " && " , zipCommand});
3608+ end if ;
3609+ end if ;
3610+
3611+ if runCommand then
35843612 // remove the logFile if it already exists.
35853613 if System . regularFileExists(logFile) then
35863614 System . removeFile(logFile);
35873615 end if ;
3588- // run the packagetool command
3589- if 0 == System . systemCall(call, logFile) then
3590- success := true ;
3591- else
3592- success := false ;
3616+ // run the command
3617+ success := 0 == System . systemCall(command, logFile);
3618+ if not (success) then
3619+ Error . addCompilerError("Command failed: " + command);
35933620 end if ;
3594- // read the logFile
3595- if System . regularFileExists(logFile) then
3596- commandOutput := System . readFile(logFile);
3597- end if ;
3598- else
3599- Error . addMessage(Error . ENCRYPTION_NOT_SUPPORTED , {str2});
3600- commandOutput := "" ;
3601- success := false ;
36023621 end if ;
36033622 else
36043623 Error . addMessage(Error . FILE_NOT_FOUND_ERROR , {fileName});
3605- commandOutput := "" ;
36063624 success := false ;
36073625 end if ;
36083626end buildEncryptedPackage;
0 commit comments