Skip to content

Commit

Permalink
Make test utils able to clean more generated files
Browse files Browse the repository at this point in the history
This is necessary since Cppruntime statically links its runtime system
with the simulation. It caused the library testing server to have 50GB
of unused files lying around. It is less crucial for the C runtime since
the executable is always cleaned (this is an so-file for cppruntim
which was not cleaned up), and because the objects were small (few kB
instead of 10MB).
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Nov 18, 2016
1 parent a343431 commit 555ce77
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -54,6 +54,7 @@ import SimCode;

// protected imports
protected
import AvlSetString;
import BackendDAECreate;
import Builtin;
import ClockIndexes;
Expand Down Expand Up @@ -608,23 +609,28 @@ protected
partial function PartialRunTpl
output tuple<Boolean,list<String>> res;
end PartialRunTpl;
AvlSetString.Tree generatedObjects=AvlSetString.EMPTY();
algorithm
setGlobalRoot(Global.optionSimCode, SOME(simCode));
_ := match target
local
String str, guid;
list<PartialRunTpl> codegenFuncs;
Integer numThreads;
Integer numThreads, n;
list<tuple<Boolean,list<String>>> res;
list<String> strs, tmp;
list<String> strs, tmp, matches;

case "CSharp" equation
Tpl.tplNoret(CodegenCSharp.translateModel, simCode);
then ();

case "Cpp" equation
callTargetTemplatesCPP(simCode);
then ();
case "Cpp"
algorithm
callTargetTemplatesCPP(simCode);
for str in {"CalcHelperMain.o\n",".so\n"} loop
generatedObjects := AvlSetString.add(generatedObjects, "OMCpp" + simCode.fileNamePrefix + str);
end for;
then ();

case "Adevs" equation
Tpl.tplNoret(CodegenAdevs.translateModel, simCode);
Expand Down Expand Up @@ -668,6 +674,14 @@ algorithm
} loop
(func,str) := f;
codegenFuncs := (function runTplWriteFile(func=function func(a_simCode=simCode), file=simCode.fileNamePrefix + str)) :: codegenFuncs;
(n,matches) := System.regex(str, "\\(.*\\)[.]c$", 2, false, false);
if n==2 then
_::str::_ := matches;
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str + ".o\n");
end if;
end for;
for str in {"_11mix.o\n","_functions.o\n","_info.json\n","_init.xml\n"} loop
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str);
end for;
codegenFuncs := (function runTpl(func=function CodegenC.simulationFile_mixAndHeader(a_simCode=simCode, a_modelNamePrefix=simCode.fileNamePrefix))) :: codegenFuncs;
codegenFuncs := (function runTplWriteFile(func=function CodegenC.simulationFile(in_a_simCode=simCode, in_a_guid=guid, in_a_isModelExchangeFMU=false), file=simCode.fileNamePrefix + ".c")) :: codegenFuncs;
Expand All @@ -687,6 +701,14 @@ algorithm
strs := List.append_reverse(tmp, strs);
end for;
strs := listReverse(strs);
// Some files are only sometimes generated, like initialization when it has >2000 equations
for str in strs loop
(n,matches) := System.regex(str, "\\(.*\\)[.]c$", 2, false, false);
if n==2 then
_::str::_ := matches;
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str + ".o\n");
end if;
end for;
// write the makefile last!
Tpl.closeFile(Tpl.tplCallWithFailError3(CodegenC.simulationMakefile,Config.simulationCodeTarget(),simCode,strs,txt=Tpl.redirectToFile(Tpl.emptyTxt, simCode.fileNamePrefix+".makefile")));
then ();
Expand Down Expand Up @@ -716,6 +738,9 @@ algorithm
Error.addMessage(Error.INTERNAL_ERROR, {str});
then fail();
end match;
if Config.getRunningTestsuite() then
System.appendFile(Config.getRunningTestsuiteFile(), stringAppendList(AvlSetString.listKeys(generatedObjects)));
end if;
setGlobalRoot(Global.optionSimCode, NONE());
end callTargetTemplates;

Expand Down

0 comments on commit 555ce77

Please sign in to comment.