Skip to content

Commit

Permalink
Load libraries case insensitive on case sensitive OS
Browse files Browse the repository at this point in the history
Libraries where files are stored in the unexpected files will still give
warnings, but OpenModelica will load them regardless.

Belonging to [master]:
  - OpenModelica/OMCompiler#3064
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 24, 2019
1 parent b7a2c69 commit bdf89c3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
39 changes: 29 additions & 10 deletions Compiler/FrontEnd/ClassLoader.mo
Expand Up @@ -403,8 +403,12 @@ algorithm
end if;
(cl as Absyn.CLASS(name=cname,body=body,info=info))::{} := cs;
if not stringEqual(cname,pack) then
Error.addSourceMessage(Error.LIBRARY_UNEXPECTED_NAME, {pack,cname}, info);
fail();
if stringEqual(System.tolower(cname), System.tolower(pack)) then
Error.addSourceMessage(Error.LIBRARY_UNEXPECTED_NAME_CASE_SENSITIVE, {pack,cname}, info);
else
Error.addSourceMessage(Error.LIBRARY_UNEXPECTED_NAME, {pack,cname}, info);
fail();
end if;
end if;
s1 := Absyn.withinString(w1);
s2 := Absyn.withinString(w2);
Expand Down Expand Up @@ -437,7 +441,7 @@ algorithm
(po) := matchcontinue (cl,filename,mp,numError)
local
String contents, duplicatesStr, differencesStr, classFilename;
list<String> duplicates, namesToFind, mofiles, subdirs, differences, intersection;
list<String> duplicates, namesToFind, mofiles, subdirs, differences, intersection, caseInsensitiveFiles;
list<Absyn.ClassPart> cp;
SourceInfo info;
list<PackageOrder> po1, po2;
Expand Down Expand Up @@ -469,11 +473,12 @@ algorithm
mofiles = listAppend(subdirs,mofiles);
// check if all are present in the package.order
differences = List.setDifference(mofiles, namesToFind);
(po1) = getPackageContentNamesinParts(namesToFind,cp,{});
(po1,differences) = List.map3Fold(po1,checkPackageOrderFilesExist,mp,info,encrypted,differences);

// issue a warning if not all are present
differencesStr = stringDelimitList(differences, "\n\t");
Error.assertionOrAddSourceMessage(listEmpty(differences),Error.PACKAGE_ORDER_FILE_NOT_COMPLETE,{differencesStr},SOURCEINFO(filename,true,0,0,0,0,0.0));
po1 = getPackageContentNamesinParts(namesToFind,cp,{});
List.map3_0(po1,checkPackageOrderFilesExist,mp,info,encrypted);

po2 = List.map(differences, makeClassLoad);

Expand Down Expand Up @@ -525,18 +530,32 @@ algorithm
end makeClassLoad;

protected function checkPackageOrderFilesExist
input PackageOrder po;
input output PackageOrder po;
input String mp;
input SourceInfo info;
input Boolean encrypted = false;
input output list<String> differences;
algorithm
_ := match (po,mp,info)
local
String pd,str;
String pd,str,str2,str3,str4;
list<String> strs;
case (CLASSLOAD(str),_,_)
equation
pd = Autoconf.pathDelimiter;
Error.assertionOrAddSourceMessage(System.directoryExists(mp + pd + str) or System.regularFileExists(mp + pd + str + (if encrypted then ".moc" else ".mo")),Error.PACKAGE_ORDER_FILE_NOT_FOUND,{str},info);
algorithm
pd := Autoconf.pathDelimiter;
str2 := str + (if encrypted then ".moc" else ".mo");
if not (System.directoryExists(mp + pd + str) or System.regularFileExists(mp + pd + str2)) then
try
str3 := List.find(System.moFiles(mp), function Util.stringEqCaseInsensitive(str2=System.tolower(str2)));
else
Error.addSourceMessage(Error.PACKAGE_ORDER_FILE_NOT_FOUND,{str},info);
fail();
end try;
Error.addSourceMessage(Error.PACKAGE_ORDER_CASE_SENSITIVE, {str, str2, str3}, info);
str4 := Util.removeLastNChar(str3,if encrypted then 4 else 3);
differences := List.removeOnTrue(str4, stringEq, differences);
po := CLASSLOAD(str4);
end if;
then ();
else ();
end match;
Expand Down
8 changes: 6 additions & 2 deletions Compiler/Util/Error.mo
Expand Up @@ -598,7 +598,7 @@ public constant Message LIBRARY_ONE_PACKAGE_PER_FILE = MESSAGE(234, GRAMMAR(), E
Util.gettext("Modelica library files should contain exactly one package, but found the following classes: %s."));
public constant Message LIBRARY_UNEXPECTED_WITHIN = MESSAGE(235, GRAMMAR(), ERROR(),
Util.gettext("Expected the package to have %s but got %s."));
public constant Message LIBRARY_UNEXPECTED_NAME = MESSAGE(236, GRAMMAR(), ERROR(),
public constant Message LIBRARY_UNEXPECTED_NAME = MESSAGE(236, SCRIPTING(), ERROR(),
Util.gettext("Expected the package to have name %s, but got %s."));
public constant Message PACKAGE_MO_NOT_IN_ORDER = MESSAGE(237, GRAMMAR(), ERROR(),
Util.gettext("Elements in the package.mo-file need to be in the same relative order as the package.order file. Got element named %s but it was already added because it was not the next element in the list at that time."));
Expand Down Expand Up @@ -829,8 +829,12 @@ public constant Message WHEN_IF_VARIABLE_MISMATCH = MESSAGE(350, TRANSLATION(),
Util.gettext("The branches of an if-equation inside a when-equation must have the same set of component references on the left-hand side."));
public constant Message DIMENSION_DEDUCTION_FROM_BINDING_FAILURE = MESSAGE(351, TRANSLATION(), ERROR(),
Util.gettext("Dimension %s of ‘%s‘ could not be deduced from the component's binding equation ‘%s‘."));
public constant Message NON_REAL_FLOW_OR_STREAM = MESSAGE(351, TRANSLATION(), ERROR(),
public constant Message NON_REAL_FLOW_OR_STREAM = MESSAGE(352, TRANSLATION(), ERROR(),
Util.gettext("Invalid prefix ‘%s‘ on non-Real component ‘%s‘."));
public constant Message LIBRARY_UNEXPECTED_NAME_CASE_SENSITIVE = MESSAGE(353, SCRIPTING(), WARNING(),
Util.gettext("Expected the package to have name %s, but got %s. Proceeding since only the case of the names are different."));
public constant Message PACKAGE_ORDER_CASE_SENSITIVE = MESSAGE(354, SCRIPTING(), WARNING(),
Util.gettext("The package.order file contains a class %s, which is expected to be stored in file %s, but seems to be named %s. Proceeding since only the case of the names are different."));
public constant Message INITIALIZATION_NOT_FULLY_SPECIFIED = MESSAGE(496, TRANSLATION(), WARNING(),
Util.gettext("The initial conditions are not fully specified. %s."));
public constant Message INITIALIZATION_OVER_SPECIFIED = MESSAGE(497, TRANSLATION(), WARNING(),
Expand Down
15 changes: 15 additions & 0 deletions Compiler/Util/Util.mo
Expand Up @@ -1403,6 +1403,13 @@ algorithm
end match;
end stringBool2;

public function stringEqCaseInsensitive
input String str1, str2;
output Boolean eq;
algorithm
eq := stringEq(System.tolower(str1), System.tolower(str2));
end stringEqCaseInsensitive;

public function optionList<T>
"SOME(a) => {a}
NONE() => {}"
Expand Down Expand Up @@ -1566,6 +1573,14 @@ algorithm
outStr := substring(str,1,stringLength(str)-4);
end removeLast4Char;

public function removeLastNChar
input String str;
input Integer n;
output String outStr;
algorithm
outStr := substring(str,1,stringLength(str)-n);
end removeLastNChar;

public function stringNotEqual
input String str1;
input String str2;
Expand Down

0 comments on commit bdf89c3

Please sign in to comment.