From 8b5e98ac3da1706e92a78f939a36edc30b9d43f4 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 6 Mar 2024 23:19:28 -0800 Subject: [PATCH] Address feedback from code review --- .../org/lflang/generator/c/CGenerator.java | 18 ++++++++++++++---- .../generator/docker/RtiDockerGenerator.java | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) 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 && \\