Skip to content

Commit

Permalink
Merge pull request lf-lang#2377 from lf-lang/fix-python-docker
Browse files Browse the repository at this point in the history
Fixed docker support for the Python target
  • Loading branch information
cmnrd authored Jul 24, 2024
2 parents ee141f8 + ffdb9d6 commit d587b50
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected boolean supportsSingleThreadedExecution() {

@Override
protected boolean supportsDockerOption() {
return false; // FIXME: https://issues.lf-lang.org/1564
return true;
}

@Test
Expand Down
15 changes: 8 additions & 7 deletions core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,14 @@ public LFCommand compileCmakeCommand() {
private static List<String> cmakeOptions(TargetConfig targetConfig, FileConfig fileConfig) {
List<String> arguments = new ArrayList<>();
String separator = File.separator;
String maybeQuote = ""; // Windows seems to require extra level of quoting.
String srcPath = fileConfig.srcPath.toString(); // Windows requires escaping the backslashes.
String quote = "\"";
String srcPath = fileConfig.srcPath.toString();
String rootPath = fileConfig.srcPkgPath.toString();
String srcGenPath = fileConfig.getSrcGenPath().toString();
if (separator.equals("\\")) {
// Windows requires escaping the backslashes.
separator = "\\\\\\\\";
maybeQuote = "\\\"";
quote = "\\\"";
srcPath = srcPath.replaceAll("\\\\", "\\\\\\\\");
rootPath = rootPath.replaceAll("\\\\", "\\\\\\\\");
srcGenPath = srcGenPath.replaceAll("\\\\", "\\\\\\\\");
Expand All @@ -237,15 +238,15 @@ private static List<String> cmakeOptions(TargetConfig targetConfig, FileConfig f
"-DCMAKE_INSTALL_PREFIX=" + FileUtil.toUnixString(fileConfig.getOutPath()),
"-DCMAKE_INSTALL_BINDIR="
+ FileUtil.toUnixString(fileConfig.getOutPath().relativize(fileConfig.binPath)),
"-DLF_FILE_SEPARATOR=\"" + maybeQuote + separator + maybeQuote + "\""));
"-DLF_FILE_SEPARATOR='" + quote + separator + quote + "'"));
// Add #define for source file directory.
// Do not do this for federated programs because for those, the definition is put
// into the cmake file (and fileConfig.srcPath is the wrong directory anyway).
if (!fileConfig.srcPath.toString().contains("fed-gen")) {
// Do not convert to Unix path
arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + srcPath + maybeQuote + "\"");
arguments.add("-DLF_PACKAGE_DIRECTORY=\"" + maybeQuote + rootPath + maybeQuote + "\"");
arguments.add("-DLF_SOURCE_GEN_DIRECTORY=\"" + maybeQuote + srcGenPath + maybeQuote + "\"");
arguments.add("-DLF_SOURCE_DIRECTORY='" + quote + srcPath + quote + "'");
arguments.add("-DLF_PACKAGE_DIRECTORY='" + quote + rootPath + quote + "'");
arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'");
}
arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath()));

Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,11 @@ public void doGenerate(Resource resource, LFGeneratorContext context) {
context.getMode());
context.finish(GeneratorResult.Status.COMPILED, null);
} else if (dockerBuild.enabled()) {
boolean success = buildUsingDocker();
if (!success) {
context.unsuccessfulFinish();
if (targetConfig.target != Target.Python) {
boolean success = buildUsingDocker();
if (!success) {
context.unsuccessfulFinish();
}
}
} else {
var cleanCode = code.removeLines("#line");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.lflang.lf.Reaction;
import org.lflang.lf.Reactor;
import org.lflang.target.Target;
import org.lflang.target.property.DockerProperty;
import org.lflang.target.property.ProtobufsProperty;
import org.lflang.util.FileUtil;
import org.lflang.util.LFCommand;
Expand Down Expand Up @@ -394,6 +395,14 @@ public void doGenerate(Resource resource, LFGeneratorContext context) {
}
}

if (targetConfig.get(DockerProperty.INSTANCE).enabled()) {
boolean success = buildUsingDocker();
if (!success) {
context.unsuccessfulFinish();
return;
}
}

if (messageReporter.getErrorsOccurred()) {
context.unsuccessfulFinish();
} else {
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/java/org/lflang/util/LFCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ public File directory() {

/** Get a String representation of the stored command */
public String toString() {
return String.join(
" ",
(Iterable<String>)
() ->
processBuilder.command().stream().map(it -> it.replace("'", "'\"'\"'")).iterator());
return String.join(" ", processBuilder.command());
}

/**
Expand Down

0 comments on commit d587b50

Please sign in to comment.