Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 27740e1

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Use the FMI 2.0 resources directory for info.json
Belonging to [master]: - #2525
1 parent e3fba96 commit 27740e1

File tree

5 files changed

+54
-26
lines changed

5 files changed

+54
-26
lines changed

Compiler/Script/CevalScriptBackend.mo

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,7 @@ protected function buildModelFMU " author: Frenkel TUD
34233423
output Values.Value outValue;
34243424
protected
34253425
Boolean staticSourceCodeFMU, success;
3426-
String filenameprefix, fmutmp, logfile, dir;
3426+
String filenameprefix, fmutmp, logfile, dir, cmd;
34273427
String fmuTargetName;
34283428
GlobalScript.SimulationOptions defaulSimOpt;
34293429
SimCode.SimulationSettings simSettings;
@@ -3494,6 +3494,15 @@ algorithm
34943494
logfile := filenameprefix + ".log";
34953495
dir := fmutmp+"/sources/";
34963496

3497+
if listEmpty(platforms) then
3498+
cmd := "rm -f \"" + filenameprefix + ".fmu\" && cd \"" + fmutmp + "\" && zip -r \"../" + filenameprefix + ".fmu\" *";
3499+
if 0 <> System.systemCall(cmd, outFile=logfile) then
3500+
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {System.readFile(logfile)});
3501+
ExecStat.execStat("buildModelFMU failed for no platform");
3502+
end if;
3503+
return;
3504+
end if;
3505+
34973506
for platform in platforms loop
34983507
configureFMU(platform, fmutmp, logfile, isWindows);
34993508
try

Compiler/SimCode/SimCodeMain.mo

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ algorithm
543543
generatedObjects := AvlSetString.add(generatedObjects, simCode.fileNamePrefix + str);
544544
end for;
545545
codegenFuncs := (function runTpl(func=function CodegenC.simulationFile_mixAndHeader(a_simCode=simCode, a_modelNamePrefix=simCode.fileNamePrefix))) :: codegenFuncs;
546-
codegenFuncs := (function runTplWriteFile(func=function CodegenC.simulationFile(in_a_simCode=simCode, in_a_guid=guid, in_a_isModelExchangeFMU=false), file=simCode.fileNamePrefix + ".c")) :: codegenFuncs;
546+
codegenFuncs := (function runTplWriteFile(func=function CodegenC.simulationFile(in_a_simCode=simCode, in_a_guid=guid, in_a_isModelExchangeFMU=""), file=simCode.fileNamePrefix + ".c")) :: codegenFuncs;
547547
codegenFuncs := (function runTplWriteFile(func=function CodegenC.simulationFunctionsFile(a_filePrefix=simCode.fileNamePrefix, a_functions=simCode.modelInfo.functions), file=simCode.fileNamePrefix + "_functions.c")) :: codegenFuncs;
548548

549549
codegenFuncs := (function runToStr(func=function SerializeModelInfo.serialize(code=simCode, withOperations=Flags.isSet(Flags.INFO_XML_OPERATIONS)))) :: codegenFuncs;
@@ -673,6 +673,7 @@ algorithm
673673
end if;
674674
end if;
675675
Util.createDirectoryTree(fmutmp + "/sources/include/");
676+
Util.createDirectoryTree(fmutmp + "/resources/");
676677
resourcesDir := fmutmp + "/resources/";
677678
for path in simCode.modelInfo.resourcePaths loop
678679
newdir := resourcesDir + System.dirname(path);
@@ -689,10 +690,16 @@ algorithm
689690
end for;
690691
SerializeModelInfo.serialize(simCode, Flags.isSet(Flags.INFO_XML_OPERATIONS));
691692
str := fmutmp + "/sources/" + simCode.fileNamePrefix;
692-
b := System.covertTextFileToCLiteral(simCode.fileNamePrefix+"_info.json", str+"_info.c", Flags.getConfigString(Flags.TARGET));
693-
if not b then
694-
Error.addMessage(Error.INTERNAL_ERROR, {"System.covertTextFileToCLiteral failed. Could not write "+str+"_info.c\n"});
695-
fail();
693+
if FMUVersion == "1.0" then
694+
b := System.covertTextFileToCLiteral(simCode.fileNamePrefix+"_info.json", str+"_info.c", Flags.getConfigString(Flags.TARGET));
695+
if not b then
696+
Error.addMessage(Error.INTERNAL_ERROR, {"System.covertTextFileToCLiteral failed. Could not write "+str+"_info.c\n"});
697+
fail();
698+
end if;
699+
else
700+
if 0 <> System.systemCall("mv '"+simCode.fileNamePrefix+"_info.json"+"' '" + fmutmp+"/resources/" + "'") then
701+
Error.addInternalError("Failed to info.json file", sourceInfo());
702+
end if;
696703
end if;
697704
SimCodeUtil.resetFunctionIndex();
698705
Tpl.tplNoret3(CodegenFMU.translateModel, simCode, FMUVersion, FMUType);

Compiler/Template/CodegenC.tpl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -989,13 +989,13 @@ template simulationFile_inl(SimCode simCode)
989989
>>
990990
end simulationFile_inl;
991991

992-
template simulationFile(SimCode simCode, String guid, Boolean isModelExchangeFMU)
992+
template simulationFile(SimCode simCode, String guid, String isModelExchangeFMU)
993993
"Generates code for main C file for simulation target."
994994
::=
995995
match simCode
996996
case simCode as SIMCODE(modelInfo=MODELINFO(varInfo=varInfo as VARINFO(__)), hpcomData=HPCOMDATA(__)) then
997997
let modelNamePrefixStr = modelNamePrefix(simCode)
998-
let mainInit = if boolOr(isModelExchangeFMU, boolOr(Flags.isSet(Flags.PARMODAUTO), Flags.isSet(HPCOM))) then
998+
let mainInit = if boolOr(boolNot(stringEq("",isModelExchangeFMU)), boolOr(Flags.isSet(Flags.PARMODAUTO), Flags.isSet(HPCOM))) then
999999
<<
10001000
mmc_init_nogc();
10011001
omc_alloc_interface = omc_alloc_interface_pooled;
@@ -1024,7 +1024,7 @@ template simulationFile(SimCode simCode, String guid, Boolean isModelExchangeFMU
10241024
<%simulationFileHeader(simCode.fileNamePrefix)%>
10251025
#include "simulation/solver/events.h"
10261026

1027-
<% if boolNot(isModelExchangeFMU) then
1027+
<% if stringEq("",isModelExchangeFMU) then
10281028
<<
10291029
#define prefixedName_performSimulation <%symbolName(modelNamePrefixStr,"performSimulation")%>
10301030
#define prefixedName_updateContinuousSystem <%symbolName(modelNamePrefixStr,"updateContinuousSystem")%>
@@ -1139,7 +1139,7 @@ template simulationFile(SimCode simCode, String guid, Boolean isModelExchangeFMU
11391139
return 1;
11401140
}
11411141

1142-
<% if boolNot(isModelExchangeFMU) then
1142+
<% if stringEq("",isModelExchangeFMU) then
11431143
<<
11441144
#if defined(threadData)
11451145
#undef threadData
@@ -1183,7 +1183,7 @@ template simulationFileHeader(String fileNamePrefix)
11831183
>>
11841184
end simulationFileHeader;
11851185

1186-
template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String guid, DelayedExpression delayed, Boolean isModelExchangeFMU)
1186+
template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String guid, DelayedExpression delayed, String isModelExchangeFMU)
11871187
"Generates information for data.modelInfo struct."
11881188
::=
11891189
match modelInfo
@@ -1195,7 +1195,8 @@ template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String gu
11951195
data->modelData->resultFileName = NULL;
11961196
data->modelData->modelDir = "<%directory%>";
11971197
data->modelData->modelGUID = "{<%guid%>}";
1198-
<% if isModelExchangeFMU then
1198+
<% match isModelExchangeFMU
1199+
case "1.0" then
11991200
<<
12001201
data->modelData->initXMLData = NULL;
12011202
data->modelData->modelDataXml.infoXMLData =
@@ -1206,7 +1207,7 @@ template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String gu
12061207
#endif
12071208
;
12081209
>>
1209-
else
1210+
case "" then
12101211
<<
12111212
#if defined(OPENMODELICA_XML_FROM_FILE_AT_RUNTIME)
12121213
data->modelData->initXMLData = NULL;
@@ -1235,6 +1236,11 @@ template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String gu
12351236
#endif /* defined(_MSC_VER) */
12361237
#endif /* defined(OPENMODELICA_XML_FROM_FILE_AT_RUNTIME) */
12371238
>>
1239+
else
1240+
<<
1241+
data->modelData->initXMLData = NULL;
1242+
data->modelData->modelDataXml.infoXMLData = NULL;
1243+
>>
12381244
%>
12391245

12401246
data->modelData->nStates = <%varInfo.numStateVars%>;
@@ -1260,7 +1266,11 @@ template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String gu
12601266
data->modelData->nRelations = <%varInfo.numRelations%>;
12611267
data->modelData->nMathEvents = <%varInfo.numMathEventFunctions%>;
12621268
data->modelData->nExtObjs = <%varInfo.numExternalObjects%>;
1263-
data->modelData->modelDataXml.fileName = "<%fileNamePrefix%>_info.json";
1269+
<% match isModelExchangeFMU
1270+
case "1.0" then "data->modelData->modelDataXml.fileName = NULL;"
1271+
case "" then 'data->modelData->modelDataXml.fileName = "<%fileNamePrefix%>_info.json";'
1272+
else 'GC_asprintf(&data->modelData->modelDataXml.fileName, "%s/<%fileNamePrefix%>_info.json", data->modelData->resourcesDir);'
1273+
%>
12641274
data->modelData->modelDataXml.modelInfoXmlLength = 0;
12651275
data->modelData->modelDataXml.nFunctions = <%listLength(functions)%>;
12661276
data->modelData->modelDataXml.nProfileBlocks = 0;
@@ -1285,7 +1295,7 @@ template populateModelInfo(ModelInfo modelInfo, String fileNamePrefix, String gu
12851295
end match
12861296
end populateModelInfo;
12871297

1288-
template functionInitializeDataStruc(ModelInfo modelInfo, String fileNamePrefix, String guid, DelayedExpression delayed, String modelNamePrefix, Boolean isModelExchangeFMU)
1298+
template functionInitializeDataStruc(ModelInfo modelInfo, String fileNamePrefix, String guid, DelayedExpression delayed, String modelNamePrefix, String isModelExchangeFMU)
12891299
"Generates function in simulation file."
12901300
::=
12911301
<<

Compiler/Template/CodegenFMU.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ case sc as SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then
7272
let()= textFile(recordsFile(fileNamePrefix, recordDecls), '<%fileNamePrefixTmpDir%>_records.c')
7373
let()= textFile(simulationHeaderFile(simCode), '<%fileNamePrefixTmpDir%>_model.h')
7474

75-
let _ = generateSimulationFiles(simCode,guid,fileNamePrefixTmpDir)
75+
let _ = generateSimulationFiles(simCode,guid,fileNamePrefixTmpDir,FMUVersion)
7676

7777
let()= textFile(simulationInitFunction(simCode,guid), '<%fileNamePrefixTmpDir%>_init_fmu.c')
7878
let()= textFile(fmumodel_identifierFile(simCode,guid,FMUVersion), '<%fileNamePrefixTmpDir%>_FMU.c')
@@ -92,7 +92,7 @@ case sc as SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then
9292
"" // Return empty result since result written to files directly
9393
end translateModel;
9494

95-
/* public */ template generateSimulationFiles(SimCode simCode, String guid, String modelNamePrefix)
95+
/* public */ template generateSimulationFiles(SimCode simCode, String guid, String modelNamePrefix, String fmuVersion)
9696
"Generates code in different C files for the simulation target.
9797
To make the compilation faster we split the simulation files into several
9898
used in Compiler/Template/CodegenFMU.tpl"
@@ -172,7 +172,7 @@ end translateModel;
172172
// main file
173173
let()=tmpTickResetIndex(0, 0)
174174
let()=tmpTickResetIndex(0, 1)
175-
let()= textFileConvertLines(simulationFile(simCode,guid,true), '<%modelNamePrefix%>.c')
175+
let()= textFileConvertLines(simulationFile(simCode,guid,fmuVersion), '<%modelNamePrefix%>.c')
176176
""
177177
end match
178178
end generateSimulationFiles;

SimulationRuntime/fmi/export/fmi2/fmu2_model_interface.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,16 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
439439
comp->componentEnvironment = functions->componentEnvironment;
440440
comp->loggingOn = loggingOn;
441441
comp->state = modelInstantiated;
442+
443+
/* Add the resourcesDir */
444+
fmuResourceLocation = OpenModelica_parseFmuResourcePath(fmuResourceLocation);
445+
if (fmuResourceLocation) {
446+
comp->fmuData->modelData->resourcesDir = functions->allocateMemory(1 + strlen(fmuResourceLocation), sizeof(char));
447+
strcpy(comp->fmuData->modelData->resourcesDir, fmuResourceLocation);
448+
} else {
449+
FILTERED_LOG(comp, fmi2OK, LOG_STATUSWARNING, "fmi2Instantiate: Ignoring unknown resource URI: %s", fmuResourceLocation)
450+
}
451+
442452
/* intialize modelData */
443453
fmu2_model_interface_setupDataStruc(comp->fmuData, comp->threadData);
444454
useStream[LOG_STDOUT] = 1;
@@ -453,14 +463,6 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
453463
modelInfoInit(&(comp->fmuData->modelData->modelDataXml));
454464
#endif
455465

456-
/* Add the resourcesDir */
457-
fmuResourceLocation = OpenModelica_parseFmuResourcePath(fmuResourceLocation);
458-
if (fmuResourceLocation) {
459-
comp->fmuData->modelData->resourcesDir = functions->allocateMemory(1 + strlen(fmuResourceLocation), sizeof(char));
460-
strcpy(comp->fmuData->modelData->resourcesDir, fmuResourceLocation);
461-
} else {
462-
FILTERED_LOG(comp, fmi2OK, LOG_STATUSWARNING, "fmi2Instantiate: Ignoring unknown resource URI: %s", fmuResourceLocation)
463-
}
464466
/* read input vars */
465467
/* input_function(comp->fmuData); */
466468
#if !defined(OMC_NUM_NONLINEAR_SYSTEMS) || OMC_NUM_NONLINEAR_SYSTEMS>0

0 commit comments

Comments
 (0)