Skip to content

Commit

Permalink
Use annotation __OpenModelica_commandLineOptions in buildModelFMU (#7478
Browse files Browse the repository at this point in the history
)

* Use annotation __OpenModelica_commandLineOptions in buildModelFMU

* Test setting the command line option via annotation
  • Loading branch information
lochel committed May 20, 2021
1 parent c5eac8a commit ea5cd0d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
46 changes: 44 additions & 2 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -3783,6 +3783,49 @@ algorithm
end configureFMU;

protected function buildModelFMU
input FCore.Cache inCache;
input FCore.Graph inEnv;
input Absyn.Path className "path for the model";
input String FMUVersion;
input String inFMUType;
input String inFileNamePrefix;
input Boolean addDummy "if true, add a dummy state";
input list<String> platforms = {"static"};
input Option<SimCode.SimulationSettings> inSimSettings = NONE();
output FCore.Cache cache;
output Values.Value outValue;
protected
Flags.Flag flags;
String commandLineOptions;
list<String> args;
Boolean haveAnnotation;
algorithm
if Config.ignoreCommandLineOptionsAnnotation() then
(cache, outValue) := callBuildModelFMU(inCache,inEnv,className,FMUVersion,inFMUType,inFileNamePrefix,addDummy,platforms,inSimSettings);
else
// read the __OpenModelica_commandLineOptions
Absyn.STRING(commandLineOptions) := Interactive.getNamedAnnotation(className, SymbolTable.getAbsyn(), Absyn.IDENT("__OpenModelica_commandLineOptions"), SOME(Absyn.STRING("")), Interactive.getAnnotationExp);
haveAnnotation := boolNot(stringEq(commandLineOptions, ""));
// backup the flags.
flags := if haveAnnotation then FlagsUtil.backupFlags() else FlagsUtil.loadFlags();
try
// apply if there are any new flags
if haveAnnotation then
args := System.strtok(commandLineOptions, " ");
FlagsUtil.readArgs(args);
end if;

(cache, outValue) := callBuildModelFMU(inCache,inEnv,className,FMUVersion,inFMUType,inFileNamePrefix,addDummy,platforms,inSimSettings);
// reset to the original flags
FlagsUtil.saveFlags(flags);
else
FlagsUtil.saveFlags(flags);
fail();
end try;
end if;
end buildModelFMU;

protected function callBuildModelFMU
" Author: Frenkel TUD
Translates a model into target code and writes also a makefile."
input FCore.Cache inCache;
Expand All @@ -3809,7 +3852,6 @@ protected
String FMUType = inFMUType;

algorithm

cache := inCache;
if not FMI.checkFMIVersion(FMUVersion) then
outValue := Values.STRING("");
Expand Down Expand Up @@ -3928,7 +3970,7 @@ algorithm
if not Flags.isSet(Flags.GEN_DEBUG_SYMBOLS) then
System.removeDirectory(fmutmp);
end if;
end buildModelFMU;
end callBuildModelFMU;

protected function buildEncryptedPackage
input Absyn.Path className "path for the model";
Expand Down
Expand Up @@ -9,10 +9,11 @@ model fmi_attributes_01
Real x(start=-1.0, fixed=true);
equation
(x + der(x))^2 = 3.0 - x^2 - der(x)^2;

annotation(__OpenModelica_commandLineOptions=\"-d=force-fmi-attributes\");
end fmi_attributes_01;
"); getErrorString();

setDebugFlags("force-fmi-attributes"); getErrorString();
translateModelFMU(fmi_attributes_01); getErrorString();

// unzip to console, quiet, extra quiet
Expand All @@ -26,8 +27,6 @@ readFile("fmi_attributes_01.xml"); getErrorString();
// Result:
// true
// ""
// true
// ""
// "fmi_attributes_01.fmu"
// ""
// 0
Expand Down

0 comments on commit ea5cd0d

Please sign in to comment.