Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 04f1061

Browse files
adeas31OpenModelica-Hudson
authored andcommitted
Make buildEncryptedPackage export read-only packages
Belonging to [master]: - #2970
1 parent 56f218a commit 04f1061

File tree

3 files changed

+47
-30
lines changed

3 files changed

+47
-30
lines changed

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2485,7 +2485,6 @@ function buildEncryptedPackage
24852485
input TypeName className "the class that should encrypted";
24862486
input Boolean encrypt = true;
24872487
output Boolean success;
2488-
output String commandOutput "Output of the packagetool executable";
24892488
external "builtin";
24902489
annotation(preferredView="text");
24912490
end buildEncryptedPackage;

Compiler/Script/CevalScript.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,11 +1485,11 @@ algorithm
14851485
s1 = System.basename(filename);
14861486
s2 = Util.removeLast4Char(s1);
14871487
// possible .moc files to look for
1488-
filename1 = workdir + "/" + s2 + "/" + s2 + ".moc";
1488+
filename1 = workdir + "/" + s2 + ".moc";
14891489
filename2 = workdir + "/" + s2 + "/package.moc";
14901490
filename_1 = if System.regularFileExists(filename1) then filename1 else filename2;
14911491
// possible .mo files to look for
1492-
str1 = workdir + "/" + s2 + "/" + s2 + ".mo";
1492+
str1 = workdir + "/" + s2 + ".mo";
14931493
str2 = workdir + "/" + s2 + "/package.mo";
14941494
str = if System.regularFileExists(str1) then str1 else str2;
14951495
// check if .mol contains .moc or .mo files

Compiler/Script/CevalScriptBackend.mo

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
35663565
protected
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;
35693570
algorithm
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;
36083626
end buildEncryptedPackage;

0 commit comments

Comments
 (0)