Skip to content

Commit

Permalink
Cleanup log files in black box FMUs (#906)
Browse files Browse the repository at this point in the history
* cleanup black box FMUs
* fix issues with premature file quoting on Windows

Co-authored-by: Lennart Ochel <lennart.ochel@liu.se>
Co-authored-by: Adrian Pop <adrian.pop@liu.se>
  • Loading branch information
3 people committed May 28, 2020
1 parent 39008d0 commit c938f04
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
8 changes: 4 additions & 4 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -3802,17 +3802,17 @@ algorithm

for platform in platforms loop
configureLogFile := System.realpath(fmutmp)+"/resources/"+System.stringReplace(listGet(Util.stringSplitAtChar(platform," "),1),"/","-")+".log";
if isWindows then
configureLogFile := "\""+configureLogFile+"\"";
end if;
configureFMU(platform, fmutmp, configureLogFile, isWindows);
if Flags.getConfigEnum(Flags.FMI_FILTER) == Flags.FMI_BLACKBOX then
System.removeFile(configureLogFile);
end if;
ExecStat.execStat("buildModelFMU: Generate platform " + platform);
end for;

// check for '--fmiSource=false' or '--fmiFilter=blackBox' and remove the sources directory before packing the fmu
if not Flags.getConfigBool(Flags.FMI_SOURCES) or Flags.getConfigEnum(Flags.FMI_FILTER) == Flags.FMI_BLACKBOX then
if not System.removeDirectory(fmutmp + "/sources/") then
Error.addInternalError("Failed to remove directory: " + fmutmp , sourceInfo());
Error.addInternalError("Failed to remove directory: " + fmutmp, sourceInfo());
end if;
end if;

Expand Down
17 changes: 10 additions & 7 deletions OMCompiler/Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -266,7 +266,7 @@ protected
list<tuple<String, String>> program;
Integer numCheckpoints;
String fmuVersion;

algorithm
numCheckpoints:=ErrorExt.getNumCheckpoints();
try
Expand Down Expand Up @@ -514,7 +514,7 @@ algorithm
end for;
then ();



case "Adevs" equation
Tpl.tplNoret(CodegenAdevs.translateModel, simCode);
Expand Down Expand Up @@ -681,7 +681,7 @@ protected function callTargetTemplatesOMSICpp
protected
String fmuVersion;
String fmuType;

algorithm
fmuVersion:="2.0";
fmuType:="me";
Expand Down Expand Up @@ -745,8 +745,11 @@ algorithm
fail();
end if;
else
if 0 <> System.systemCall("mv '"+simCode.fileNamePrefix+"_info.json"+"' '" + fmutmp+"/resources/" + "'") then
Error.addInternalError("Failed to info.json file", sourceInfo());
// check for _info.json file in resource directory when --fmiFilter=blackBox is not set
if Flags.getConfigEnum(Flags.FMI_FILTER) <> Flags.FMI_BLACKBOX then
if 0 <> System.systemCall("mv '" + simCode.fileNamePrefix + "_info.json"+"' '" + fmutmp+"/resources/" + "'") then
Error.addInternalError("Failed to move " + simCode.fileNamePrefix + "_info.json file", sourceInfo());
end if;
end if;
end if;
SimCodeUtil.resetFunctionIndex();
Expand Down Expand Up @@ -840,10 +843,10 @@ algorithm
runTplWriteFile(func = function CodegenOMSIC.generateOMSIC(a_simCode=simCode), file=simCode.fullPathPrefix+"/"+fileprefix+"_omsic.c");

runTpl(func = function CodegenOMSI_common.generateEquationsCode(a_simCode=simCode, a_FileNamePrefix=fileprefix));

runTpl(func = function CodegenOMSICpp.translateModel(a_simCode=simCode, a_FMUVersion=FMUVersion, a_FMUType=FMUType));
then ();

case (_,"Cpp")
equation
if(Flags.isSet(Flags.HPCOM)) then
Expand Down
4 changes: 3 additions & 1 deletion OMCompiler/Compiler/Template/CodegenFMU.tpl
Expand Up @@ -1166,7 +1166,9 @@ match platform
<%\t%>$(LD) -o <%modelNamePrefix%>$(DLLEXT) $(OFILES) $(RUNTIMEFILES) <%dirExtra%> <%libsPos1%> @BSTATIC@ <%libsPos2%> @BDYNAMIC@ $(LDFLAGS)
<%\t%>cp <%fileNamePrefix%>$(DLLEXT) <%fileNamePrefix%>_FMU.libs ../binaries/$(FMIPLATFORM)/
endif
<%\t%>head -n20 Makefile > ../resources/$(FMIPLATFORM).summary
<%if intLt(Flags.getConfigEnum(Flags.FMI_FILTER), 4) then
'<%\t%>head -n20 Makefile > ../resources/$(FMIPLATFORM).summary'
%>
ifeq (@LIBTYPE_STATIC@,1)
<%\t%>rm -f <%modelNamePrefix%>.a
<%\t%>$(AR) -rsu <%modelNamePrefix%>.a $(OFILES) $(RUNTIMEFILES)
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/Template/SimCodeTV.mo
Expand Up @@ -3874,6 +3874,7 @@ package Flags
constant ConfigFlag ZEROMQ_JOB_ID;
constant ConfigFlag ZEROMQ_SERVER_ID;
constant ConfigFlag ZEROMQ_CLIENT_ID;
constant ConfigFlag FMI_FILTER;

function isSet
input DebugFlag inFlag;
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/runtime/systemimpl.c
Expand Up @@ -630,8 +630,8 @@ int SystemImpl__systemCall(const char* str, const char* outFile)
fflush(NULL); /* flush output so the testsuite is deterministic */
#if defined(__MINGW32__) || defined(_MSC_VER)
if (*outFile) {
char *command = (char *)omc_alloc_interface.malloc_atomic(strlen(str) + strlen(outFile) + 10);
sprintf(command, "%s >> %s 2>&1", str, outFile);
char *command = (char *)omc_alloc_interface.malloc_atomic(strlen(str) + strlen(outFile) + 12);
sprintf(command, "%s >> \"%s\" 2>&1", str, outFile);
status = runProcess(command);
GC_free((void*)command);
} else {
Expand Down
16 changes: 13 additions & 3 deletions OMCompiler/SimulationRuntime/c/util/omc_file.c
Expand Up @@ -78,15 +78,25 @@ int omc_stat(const char *filename, struct stat *statbuf)

int omc_unlink(const char *filename)
{
int result = 0;
#if defined(__MINGW32__) || defined(_MSC_VER)
MULTIBYTE_TO_WIDECHAR_LENGTH(filename, unicodeFilenameLength);
MULTIBYTE_TO_WIDECHAR_VAR(filename, unicodeFilename, unicodeFilenameLength);
int result = _wunlink(unicodeFilename);
result = _wunlink(unicodeFilename);
MULTIBYTE_OR_WIDECHAR_VAR_FREE(unicodeFilename);
return result;
#else /* unix */
return unlink(filename);
result = unlink(filename);
#endif
/* uncomment for debugging
if (result == -1)
{
const char* s = "Could not delete file: ";
char *msg = (char*)malloc(strlen(s) + strlen(filename) + 1);
sprintf(msg, "%s%s", s, filename);
perror(msg);
}
*/
return result;
}

#ifdef __cplusplus
Expand Down

0 comments on commit c938f04

Please sign in to comment.