Skip to content

Commit

Permalink
Got rid of some code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Jun 16, 2024
1 parent 3b0cd7e commit 4c66716
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,7 @@ private void buildUsingDocker(LFGeneratorContext context, List<SubContext> subCo
try {
var dockerGen = new FedDockerComposeGenerator(context, rtiConfig.getHost());
dockerGen.writeDockerComposeFile(createDockerFiles(context, subContexts));
// Only build if requested
if (!context.getTargetConfig().get(DockerProperty.INSTANCE).noBuild()) {
if (dockerGen.build()) {
dockerGen.createLauncher();
} else {
context.getErrorReporter().nowhere().error("Docker build failed.");
}
}
dockerGen.buildIfRequested();
} catch (IOException e) {
context
.getErrorReporter()
Expand Down
11 changes: 1 addition & 10 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,16 +590,7 @@ private boolean buildUsingDocker() {
return false;
}
// Only build if requested
if (!context.getTargetConfig().get(DockerProperty.INSTANCE).noBuild()) {
var success = dockerCompose.build();
if (success) {
dockerCompose.createLauncher();
} else {
context.getErrorReporter().nowhere().error("Docker build failed.");
}
return success;
}
return true;
return dockerCompose.buildIfRequested();
}

private void generateCodeFor(String lfModuleName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Objects;
import java.util.stream.Collectors;
import org.lflang.generator.LFGeneratorContext;
import org.lflang.target.property.DockerProperty;
import org.lflang.util.FileUtil;
import org.lflang.util.LFCommand;

Expand Down Expand Up @@ -152,4 +153,19 @@ public void createLauncher() {
messageReporter.nowhere().warning("Unable to make launcher script executable.");
}
}

/**
* Build, unless building was disabled.
*
* @return {@code false} if building failed, {@code true} otherwise
*/
public boolean buildIfRequested() {
if (!context.getTargetConfig().get(DockerProperty.INSTANCE).noBuild()) {
if (build()) {
createLauncher();
} else context.getErrorReporter().nowhere().error("Docker build failed.");
return false;
}
return true;
}
}

0 comments on commit 4c66716

Please sign in to comment.