diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index afd2ce53da..c1357b8f9a 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -527,17 +527,27 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { } else { var cleanCode = code.removeLines("#line"); var cCompiler = new CCompiler(targetConfig, fileConfig, messageReporter, cppMode); + var success = false; try { - if (!cCompiler.runCCompiler(this, context)) { + success = cCompiler.runCCompiler(this, context); + } catch (IOException e) { + messageReporter.nowhere().error("Unexpected error during compilation."); + } finally { + if (!success) { // If compilation failed, remove any bin files that may have been created. + messageReporter.nowhere().error("Compilation was unsuccessful."); CUtil.deleteBinFiles(fileConfig); context.unsuccessfulFinish(); } else { + try { + cleanCode.writeToFile(targetFile); + } catch (IOException e) { + messageReporter + .nowhere() + .warning("Generated code may still contain line directives."); + } context.finish(GeneratorResult.Status.COMPILED, null); } - cleanCode.writeToFile(targetFile); - } catch (IOException e) { - messageReporter.nowhere().warning("Generated code may still contain line directives."); } } } diff --git a/core/src/main/java/org/lflang/generator/docker/RtiDockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/RtiDockerGenerator.java index 65e75710b7..fb863eed4c 100644 --- a/core/src/main/java/org/lflang/generator/docker/RtiDockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/RtiDockerGenerator.java @@ -22,7 +22,8 @@ protected String generateDockerFileContent() { COPY include /reactor-c/include WORKDIR /reactor-c/core/federated/RTI %s - RUN mkdir -p build && \\ + RUN rm -rf build && \\ + mkdir build && \\ cd build && \\ cmake ../ && \\ make && \\