diff --git a/OMCompiler/Compiler/Script/CevalScript.mo b/OMCompiler/Compiler/Script/CevalScript.mo index 0ba90ba21ea..fa360a23e4e 100644 --- a/OMCompiler/Compiler/Script/CevalScript.mo +++ b/OMCompiler/Compiler/Script/CevalScript.mo @@ -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"; @@ -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}); @@ -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"; @@ -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}); diff --git a/OMCompiler/Compiler/Util/Error.mo b/OMCompiler/Compiler/Util/Error.mo index df04094a194..8129cfa8e19 100644 --- a/OMCompiler/Compiler/Util/Error.mo +++ b/OMCompiler/Compiler/Util/Error.mo @@ -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(), diff --git a/testsuite/openmodelica/interactive-API/Makefile b/testsuite/openmodelica/interactive-API/Makefile index a016aaf5228..81f8fb57aa4 100644 --- a/testsuite/openmodelica/interactive-API/Makefile +++ b/testsuite/openmodelica/interactive-API/Makefile @@ -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 diff --git a/testsuite/openmodelica/interactive-API/ReadOnlyPkg.mos b/testsuite/openmodelica/interactive-API/ReadOnlyPkg.mos new file mode 100644 index 00000000000..17bede5c341 --- /dev/null +++ b/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 diff --git a/testsuite/openmodelica/interactive-API/ReadOnlyPkg/M.mo b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/M.mo new file mode 100644 index 00000000000..5933c3eda22 --- /dev/null +++ b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/M.mo @@ -0,0 +1,6 @@ +within ReadOnlyPkg; + +model M +equation + +end M; diff --git a/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/M1.mo b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/M1.mo new file mode 100644 index 00000000000..70159c19e11 --- /dev/null +++ b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/M1.mo @@ -0,0 +1,6 @@ +within ReadOnlyPkg.P1; + +model M1 +equation + +end M1; diff --git a/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/M2.mo b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/M2.mo new file mode 100644 index 00000000000..ca58cbf9916 --- /dev/null +++ b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/M2.mo @@ -0,0 +1,6 @@ +within ReadOnlyPkg.P1; + +model M2 +equation + +end M2; diff --git a/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/package.mo b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/package.mo new file mode 100644 index 00000000000..dbc41d5a554 --- /dev/null +++ b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/package.mo @@ -0,0 +1,4 @@ +within ReadOnlyPkg; + +package P1 +end P1; diff --git a/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/package.order b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/package.order new file mode 100644 index 00000000000..1392889bb41 --- /dev/null +++ b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/P1/package.order @@ -0,0 +1,2 @@ +M1 +M2 diff --git a/testsuite/openmodelica/interactive-API/ReadOnlyPkg/package.mo b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/package.mo new file mode 100644 index 00000000000..8077d7db3eb --- /dev/null +++ b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/package.mo @@ -0,0 +1,2 @@ +package ReadOnlyPkg +end ReadOnlyPkg; diff --git a/testsuite/openmodelica/interactive-API/ReadOnlyPkg/package.order b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/package.order new file mode 100644 index 00000000000..755039fa221 --- /dev/null +++ b/testsuite/openmodelica/interactive-API/ReadOnlyPkg/package.order @@ -0,0 +1,2 @@ +M +P1