Skip to content

Commit 555ce77

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Make test utils able to clean more generated files
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).
1 parent a343431 commit 555ce77

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

Compiler/SimCode/SimCodeMain.mo

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import SimCode;
5454

5555
// protected imports
5656
protected
57+
import AvlSetString;
5758
import BackendDAECreate;
5859
import Builtin;
5960
import ClockIndexes;
@@ -608,23 +609,28 @@ protected
608609
partial function PartialRunTpl
609610
output tuple<Boolean,list<String>> res;
610611
end PartialRunTpl;
612+
AvlSetString.Tree generatedObjects=AvlSetString.EMPTY();
611613
algorithm
612614
setGlobalRoot(Global.optionSimCode, SOME(simCode));
613615
_ := match target
614616
local
615617
String str, guid;
616618
list<PartialRunTpl> codegenFuncs;
617-
Integer numThreads;
619+
Integer numThreads, n;
618620
list<tuple<Boolean,list<String>>> res;
619-
list<String> strs, tmp;
621+
list<String> strs, tmp, matches;
620622

621623
case "CSharp" equation
622624
Tpl.tplNoret(CodegenCSharp.translateModel, simCode);
623625
then ();
624626

625-
case "Cpp" equation
626-
callTargetTemplatesCPP(simCode);
627-
then ();
627+
case "Cpp"
628+
algorithm
629+
callTargetTemplatesCPP(simCode);
630+
for str in {"CalcHelperMain.o\n",".so\n"} loop
631+
generatedObjects := AvlSetString.add(generatedObjects, "OMCpp" + simCode.fileNamePrefix + str);
632+
end for;
633+
then ();
628634

629635
case "Adevs" equation
630636
Tpl.tplNoret(CodegenAdevs.translateModel, simCode);
@@ -668,6 +674,14 @@ algorithm
668674
} loop
669675
(func,str) := f;
670676
codegenFuncs := (function runTplWriteFile(func=function func(a_simCode=simCode), file=simCode.fileNamePrefix + str)) :: codegenFuncs;
677+
(n,matches) := System.regex(str, "\\(.*\\)[.]c$", 2, false, false);
678+
if n==2 then
679+
_::str::_ := matches;
680+
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str + ".o\n");
681+
end if;
682+
end for;
683+
for str in {"_11mix.o\n","_functions.o\n","_info.json\n","_init.xml\n"} loop
684+
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str);
671685
end for;
672686
codegenFuncs := (function runTpl(func=function CodegenC.simulationFile_mixAndHeader(a_simCode=simCode, a_modelNamePrefix=simCode.fileNamePrefix))) :: codegenFuncs;
673687
codegenFuncs := (function runTplWriteFile(func=function CodegenC.simulationFile(in_a_simCode=simCode, in_a_guid=guid, in_a_isModelExchangeFMU=false), file=simCode.fileNamePrefix + ".c")) :: codegenFuncs;
@@ -687,6 +701,14 @@ algorithm
687701
strs := List.append_reverse(tmp, strs);
688702
end for;
689703
strs := listReverse(strs);
704+
// Some files are only sometimes generated, like initialization when it has >2000 equations
705+
for str in strs loop
706+
(n,matches) := System.regex(str, "\\(.*\\)[.]c$", 2, false, false);
707+
if n==2 then
708+
_::str::_ := matches;
709+
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str + ".o\n");
710+
end if;
711+
end for;
690712
// write the makefile last!
691713
Tpl.closeFile(Tpl.tplCallWithFailError3(CodegenC.simulationMakefile,Config.simulationCodeTarget(),simCode,strs,txt=Tpl.redirectToFile(Tpl.emptyTxt, simCode.fileNamePrefix+".makefile")));
692714
then ();
@@ -716,6 +738,9 @@ algorithm
716738
Error.addMessage(Error.INTERNAL_ERROR, {str});
717739
then fail();
718740
end match;
741+
if Config.getRunningTestsuite() then
742+
System.appendFile(Config.getRunningTestsuiteFile(), stringAppendList(AvlSetString.listKeys(generatedObjects)));
743+
end if;
719744
setGlobalRoot(Global.optionSimCode, NONE());
720745
end callTargetTemplates;
721746

0 commit comments

Comments
 (0)