Skip to content

Commit

Permalink
Fixed loading of read only packages
Browse files Browse the repository at this point in the history
If the package follows a Modelica version naming convention just strip the version string and use the package name.
  • Loading branch information
adeas31 committed Jan 15, 2020
1 parent e6180d5 commit 1115afc
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 7 deletions.
9 changes: 6 additions & 3 deletions OMCompiler/Compiler/Script/CevalScript.mo
Expand Up @@ -1467,12 +1467,14 @@ algorithm

case (cache,_,"parseEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::_,_)
equation
vals = {};
if (System.regularFileExists(filename)) then
if (Util.endsWith(filename, ".mol")) then
workdir = if System.directoryExists(workdir) then workdir else System.pwd();
if (0 == System.systemCall("unzip -q -o -d \"" + workdir + "\" \"" + filename + "\"")) then
s1 = System.basename(filename);
s2 = Util.removeLast4Char(s1);
s2 = listGet(Util.stringSplitAtChar(s2," "),1);
// possible .moc files to look for
filename1 = workdir + "/" + s2 + "/" + s2 + ".moc";
filename2 = workdir + "/" + s2 + "/package.moc";
Expand All @@ -1491,7 +1493,7 @@ algorithm
(paths) = Interactive.parseFile(filename_1, "UTF-8");
vals = List.map(paths,ValuesUtil.makeCodeTypeName);
else
Error.addMessage(Error.ENCRYPTED_FILE_NOT_FOUND_ERROR, {filename1, filename2});
Error.addMessage(Error.PACKAGE_FILE_NOT_FOUND_ERROR, {filename1, filename2, str1, str2});
end if;
else
Error.addMessage(Error.UNABLE_TO_UNZIP_FILE, {filename});
Expand All @@ -1512,9 +1514,9 @@ algorithm
workdir = if System.directoryExists(workdir) then workdir else System.pwd();
b = false;
if (0 == System.systemCall("unzip -q -o -d \"" + workdir + "\" \"" + filename + "\"")) then
b = true;
s1 = System.basename(filename);
s2 = Util.removeLast4Char(s1);
s2 = listGet(Util.stringSplitAtChar(s2," "),1);
// possible .moc files to look for
filename1 = workdir + "/" + s2 + ".moc";
filename2 = workdir + "/" + s2 + "/package.moc";
Expand All @@ -1532,8 +1534,9 @@ algorithm
newp = loadFile(filename_1, "UTF-8", p, true);
execStat("loadFile("+filename_1+")");
SymbolTable.setAbsyn(newp);
b = true;
else
Error.addMessage(Error.ENCRYPTED_FILE_NOT_FOUND_ERROR, {filename1, filename2});
Error.addMessage(Error.PACKAGE_FILE_NOT_FOUND_ERROR, {filename1, filename2, str1, str2});
end if;
else
Error.addMessage(Error.UNABLE_TO_UNZIP_FILE, {filename});
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/Util/Error.mo
Expand Up @@ -1120,8 +1120,8 @@ public constant ErrorTypes.Message CONFLICTING_ALIAS_SET = ErrorTypes.MESSAGE(70
Gettext.gettext("The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts."));
public constant ErrorTypes.Message ENCRYPTION_NOT_SUPPORTED = ErrorTypes.MESSAGE(7018, ErrorTypes.SCRIPTING(), ErrorTypes.ERROR(),
Gettext.gettext("File not Found: %s. Compile OpenModelica with Encryption support."));
public constant ErrorTypes.Message ENCRYPTED_FILE_NOT_FOUND_ERROR = ErrorTypes.MESSAGE(7019, ErrorTypes.SCRIPTING(), ErrorTypes.ERROR(),
Gettext.gettext("No encrypted files found. Looked for %s and %s."));
public constant ErrorTypes.Message PACKAGE_FILE_NOT_FOUND_ERROR = ErrorTypes.MESSAGE(7019, ErrorTypes.SCRIPTING(), ErrorTypes.ERROR(),
Gettext.gettext("Unable to find the package definition file. Looked for \"%s\", \"%s\", \"%s\" and \"%s\"."));
public constant ErrorTypes.Message UNABLE_TO_UNZIP_FILE = ErrorTypes.MESSAGE(7020, ErrorTypes.SCRIPTING(), ErrorTypes.ERROR(),
Gettext.gettext("Unable to unzip the file: %s."));
public constant ErrorTypes.Message EXPECTED_ENCRYPTED_PACKAGE = ErrorTypes.MESSAGE(7021, ErrorTypes.SCRIPTING(), ErrorTypes.ERROR(),
Expand Down
4 changes: 2 additions & 2 deletions testsuite/openmodelica/interactive-API/Makefile
Expand Up @@ -81,8 +81,8 @@ Ticket5548.mos \
Ticket5571.mos \
Ticket5565.mos \
Ticket5680.mos \
Ticket5696.mos

Ticket5696.mos \
ReadOnlyPkg.mos

# test that currently fail. Move up when fixed.
# Run make testfailing
Expand Down
63 changes: 63 additions & 0 deletions testsuite/openmodelica/interactive-API/ReadOnlyPkg.mos
@@ -0,0 +1,63 @@
// name: ReadOnlyPkg.mos
// keywords: Tests the export and import of read only packages i.e, package.mol
// status: correct
// teardown_command: rm -rf buildEncryptedPackage.log "ReadOnlyPkg 1.1.mol"
//

loadFile("ReadOnlyPkg/package.mo");
getErrorString();
getClassNames();
getErrorString();

buildEncryptedPackage(ReadOnlyPkg, false);
getErrorString();
deleteClass(ReadOnlyPkg);
getErrorString();

parseEncryptedPackage("ReadOnlyPkg.mol");
getErrorString();
loadEncryptedPackage("ReadOnlyPkg.mol");
getErrorString();
getClassNames();
getErrorString();
deleteClass(ReadOnlyPkg);
getErrorString();

// create a versioned package
system("mv \"ReadOnlyPkg.mol\" \"ReadOnlyPkg 1.1.mol\"");
getErrorString();

// load a versioned package
parseEncryptedPackage("ReadOnlyPkg 1.1.mol");
getErrorString();
loadEncryptedPackage("ReadOnlyPkg 1.1.mol");
getErrorString();
getClassNames();
getErrorString();

// Result:
// true
// ""
// {ReadOnlyPkg}
// ""
// true
// ""
// true
// ""
// {ReadOnlyPkg}
// ""
// true
// ""
// {ReadOnlyPkg}
// ""
// true
// ""
// 0
// ""
// {ReadOnlyPkg}
// ""
// true
// ""
// {ReadOnlyPkg}
// ""
// endResult
6 changes: 6 additions & 0 deletions testsuite/openmodelica/interactive-API/ReadOnlyPkg/M.mo
@@ -0,0 +1,6 @@
within ReadOnlyPkg;

model M
equation

end M;
6 changes: 6 additions & 0 deletions testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/M1.mo
@@ -0,0 +1,6 @@
within ReadOnlyPkg.P1;

model M1
equation

end M1;
6 changes: 6 additions & 0 deletions testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/M2.mo
@@ -0,0 +1,6 @@
within ReadOnlyPkg.P1;

model M2
equation

end M2;
@@ -0,0 +1,4 @@
within ReadOnlyPkg;

package P1
end P1;
@@ -0,0 +1,2 @@
M1
M2
2 changes: 2 additions & 0 deletions testsuite/openmodelica/interactive-API/ReadOnlyPkg/package.mo
@@ -0,0 +1,2 @@
package ReadOnlyPkg
end ReadOnlyPkg;
@@ -0,0 +1,2 @@
M
P1

0 comments on commit 1115afc

Please sign in to comment.