From f8e680ebf70dd6680c207d458ffd7180d1da8d06 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 19 Jun 2024 18:17:52 -0700 Subject: [PATCH 01/15] Make files available in Docker runner image --- .../generator/docker/DockerGenerator.java | 23 +++++++++++ .../RuntimeFilesPropertyContainerized.lf | 39 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 test/C/src/docker/RuntimeFilesPropertyContainerized.lf diff --git a/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java index 40f9fa7f37..20b7c45fb7 100644 --- a/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java @@ -11,6 +11,7 @@ import org.lflang.target.property.BuildCommandsProperty; import org.lflang.target.property.DockerProperty; import org.lflang.target.property.DockerProperty.DockerOptions; +import org.lflang.target.property.FilesProperty; import org.lflang.util.StringUtil; /** @@ -49,6 +50,7 @@ protected String generateDockerFileContent() { "WORKDIR /lingua-franca", "RUN mkdir scripts", generateCopyOfScript(), + generateCopyOfUserFiles(), generateRunForMakingExecutableDir(), generateCopyOfExecutable(), generateEntryPoint(), @@ -150,6 +152,27 @@ protected String generateCopyOfScript() { return "# (No pre-run script provided.)"; } + /** + * Return zero or more COPY commands to copy files specified using the {@code files} target + * property from the builder to the runner. + */ + protected String generateCopyOfUserFiles() { + var files = context.getTargetConfig().get(FilesProperty.INSTANCE); + if (files == null) { + return ""; + } + var ret = new StringBuilder(); + for (var file : files) { + var p = Path.of(file); + var name = p.getName(p.getNameCount() - 1); + ret.append( + String.format( + "COPY --from=builder \"lingua-franca/%s/src-gen/%s\" \"./%s\"", + context.getFileConfig().name, name, name)); + } + return ret.toString(); + } + /** * Return a list of strings used to construct and entrypoint. If this is done for a federate, then * also include additional parameters to pass in the federation ID. diff --git a/test/C/src/docker/RuntimeFilesPropertyContainerized.lf b/test/C/src/docker/RuntimeFilesPropertyContainerized.lf new file mode 100644 index 0000000000..d80042d122 --- /dev/null +++ b/test/C/src/docker/RuntimeFilesPropertyContainerized.lf @@ -0,0 +1,39 @@ +target C { + files: "./RuntimeFilesPropertyContainerized.lf", + docker: true +} + +preamble {= + #include + #include + #include +=} + +main reactor { + reaction(startup) {= + FILE *f = fopen("RuntimeFilesPropertyContainerized.lf", "rb"); + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + fseek(f, 0, SEEK_SET); + + char *string = malloc(fsize + 1); + fread(string, fsize, 1, f); + fclose(f); + + string[fsize] = 0; + + printf("file contents:\n%s\n", string); + + // fail if the file contents are not the contents of this file + char* expected = "target C {\n files: \"./RuntimeFilesPropertyContainerized.lf\",\n docker: true\n}"; + string[strlen(expected)] = 0; + if (strcmp(string, expected) != 0) { + printf("file contents do not match expected contents\n"); + exit(1); + } else { + printf("file contents match expected contents\n"); + } + + free(string); + =} +} From 0c15a11d854054503dd7a3fd0f84802c087e1e0f Mon Sep 17 00:00:00 2001 From: Peter Donovan <33707478+petervdonovan@users.noreply.github.com> Date: Wed, 19 Jun 2024 23:16:38 -0700 Subject: [PATCH 02/15] Update core/src/main/java/org/lflang/generator/docker/DockerGenerator.java Co-authored-by: Marten Lohstroh --- .../main/java/org/lflang/generator/docker/DockerGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java index 20b7c45fb7..b512b80d54 100644 --- a/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java @@ -159,7 +159,7 @@ protected String generateCopyOfScript() { protected String generateCopyOfUserFiles() { var files = context.getTargetConfig().get(FilesProperty.INSTANCE); if (files == null) { - return ""; + return "# (No user-specified files to be copied.)"; } var ret = new StringBuilder(); for (var file : files) { From 2121a7e7beeeac612e39d6491cad713f4465bfa0 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 19 Jun 2024 23:19:16 -0700 Subject: [PATCH 03/15] Address comments from code review --- .../java/org/lflang/generator/docker/DockerGenerator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java index b512b80d54..ea10bc1032 100644 --- a/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java @@ -157,14 +157,17 @@ protected String generateCopyOfScript() { * property from the builder to the runner. */ protected String generateCopyOfUserFiles() { + if (!context.getTargetConfig().isSupported(FilesProperty.INSTANCE)) { + return ""; + } var files = context.getTargetConfig().get(FilesProperty.INSTANCE); if (files == null) { - return "# (No user-specified files to be copied.)"; + return "# (No user-specified files to be copied.)"; } var ret = new StringBuilder(); for (var file : files) { var p = Path.of(file); - var name = p.getName(p.getNameCount() - 1); + var name = p.getFileName().toString(); ret.append( String.format( "COPY --from=builder \"lingua-franca/%s/src-gen/%s\" \"./%s\"", From ecac132b0832132862c5e6ad7affa2abd3c413e1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 20 Jun 2024 13:20:38 +0200 Subject: [PATCH 04/15] don't generate custom docker files for testing, use the bin script --- .../java/org/lflang/tests/TestBase.java | 99 +------------------ 1 file changed, 4 insertions(+), 95 deletions(-) diff --git a/core/src/testFixtures/java/org/lflang/tests/TestBase.java b/core/src/testFixtures/java/org/lflang/tests/TestBase.java index 89ff40e517..fe724cad9c 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestBase.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestBase.java @@ -6,8 +6,6 @@ import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; -import java.io.BufferedWriter; -import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -15,7 +13,6 @@ import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URISyntaxException; -import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.Collections; @@ -53,7 +50,6 @@ import org.lflang.tests.LFTest.Result; import org.lflang.tests.TestRegistry.TestCategory; import org.lflang.tests.Transformers.Transformer; -import org.lflang.util.FileUtil; import org.lflang.util.LFCommand; /** @@ -568,104 +564,17 @@ public static String stackTraceToString(Throwable t) { return sw.toString(); } - /** Bash script that is used to execute docker tests. */ - private static final String DOCKER_RUN_SCRIPT = - """ - #!/bin/bash - - # exit when any command fails - set -e - - docker compose -f "$1" rm -f - docker compose -f "$1" up --build | tee docker_log.txt - docker compose -f "$1" down --rmi local - - errors=`grep -E "exited with code [1-9]" docker_log.txt | cat` - rm docker_log.txt - - if [[ $errors ]]; then - echo "====================================================================" - echo "ERROR: One or multiple containers exited with a non-zero exit code." - echo " See the log above for details. The following containers failed:" - echo $errors - exit 1 - fi - - exit 0 - """; - - /** Path to a bash script containing DOCKER_RUN_SCRIPT. */ - private static Path dockerRunScript = null; - - /** - * Return the path to a bash script containing DOCKER_RUN_SCRIPT. - * - *

If the script does not yet exist, it is created. - */ - private static synchronized Path getDockerRunScript() throws TestError { - if (dockerRunScript != null) { - return dockerRunScript; - } - - try { - var file = File.createTempFile("run_docker_test", "sh"); - file.deleteOnExit(); - file.setExecutable(true); - var path = file.toPath(); - try (BufferedWriter writer = Files.newBufferedWriter(path)) { - writer.write(DOCKER_RUN_SCRIPT); - } - dockerRunScript = path; - } catch (IOException e) { - throw new TestError("IO Error during test preparation.", Result.TEST_EXCEPTION, e); - } - - return dockerRunScript; - } - - /** Throws TestError if docker does not exist. Does nothing otherwise. */ - private void checkDockerExists() throws TestError { - if (LFCommand.get("docker", List.of()) == null) { - throw new TestError("Executable 'docker' not found", Result.NO_EXEC_FAIL); - } - if (LFCommand.get("docker-compose", List.of()) == null) { - throw new TestError("Executable 'docker-compose' not found", Result.NO_EXEC_FAIL); - } - } - - /** - * Return a ProcessBuilder used to test the docker execution. - * - * @param test The test to get the execution command for. - */ - private ProcessBuilder getDockerExecCommand(LFTest test) throws TestError { - checkDockerExists(); - var srcGenPath = test.getFileConfig().getSrcGenPath(); - var dockerComposeFile = FileUtil.globFilesEndsWith(srcGenPath, "docker-compose.yml").get(0); - return new ProcessBuilder(getDockerRunScript().toString(), dockerComposeFile.toString()); - } - /** * Return a preconfigured ProcessBuilder for executing the test program. * * @param test The test to get the execution command for. */ private ProcessBuilder getExecCommand(LFTest test) throws TestError { - - var srcBasePath = test.getFileConfig().srcPkgPath.resolve("src"); - var relativePathName = srcBasePath.relativize(test.getFileConfig().srcPath).toString(); - - // special case to test docker file generation - if (relativePathName.equalsIgnoreCase(TestCategory.DOCKER.getPath()) - || relativePathName.equalsIgnoreCase(TestCategory.DOCKER_FEDERATED.getPath())) { - return getDockerExecCommand(test); - } else { - LFCommand command = test.getFileConfig().getCommand(); - if (command == null) { - throw new TestError("File: " + test.getFileConfig().getExecutable(), Result.NO_EXEC_FAIL); - } - return new ProcessBuilder(command.command()).directory(command.directory()); + LFCommand command = test.getFileConfig().getCommand(); + if (command == null) { + throw new TestError("File: " + test.getFileConfig().getExecutable(), Result.NO_EXEC_FAIL); } + return new ProcessBuilder(command.command()).directory(command.directory()); } /** From d865caba3284bad0daa7a33481ef3fd1714e2996 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 20 Jun 2024 13:20:57 +0200 Subject: [PATCH 05/15] enable C++ docker tests --- .../java/org/lflang/tests/runtime/CppTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java b/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java index 59e26fca69..80f13185ed 100644 --- a/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java +++ b/core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java @@ -49,6 +49,11 @@ protected boolean supportsEnclaves() { return true; } + @Override + protected boolean supportsDockerOption() { + return true; + } + @Test @Override public void runBasicTests() { From d22bd6feba72a20c47a8b7bc8e0d4114abff4b11 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 20 Jun 2024 13:26:17 +0200 Subject: [PATCH 06/15] fix script generation for hierarchal bin --- .../lflang/generator/docker/DockerComposeGenerator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java b/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java index 2255f3ce3b..d63a733740 100644 --- a/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java @@ -128,16 +128,19 @@ public void createLauncher() { var binPath = fileConfig.binPath; FileUtil.createDirectoryIfDoesNotExist(binPath.toFile()); var file = binPath.resolve(fileConfig.name).toFile(); + + final var relPath = + FileUtil.toUnixString(fileConfig.binPath.relativize(fileConfig.getOutPath())); + var script = """ #!/bin/bash set -euo pipefail cd $(dirname "$0") - cd .. - cd "%s" + cd "%s/%s" docker compose up """ - .formatted(packageRoot.relativize(srcGenPath)); + .formatted(relPath, packageRoot.relativize(srcGenPath)); var messageReporter = context.getErrorReporter(); try { var writer = new BufferedWriter(new FileWriter(file)); From a6b898244deb124651859eb94964c2a7007a53b3 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 20 Jun 2024 14:57:27 +0200 Subject: [PATCH 07/15] fix C++ standalone docker generation for hierarchal bin --- .../generator/cpp/CppStandaloneGenerator.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt index 64fdf32ee0..4b57166f0c 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt @@ -26,6 +26,8 @@ class CppStandaloneGenerator(generator: CppGenerator) : const val DEFAULT_BASE_IMAGE: String = "alpine:latest" } + private val relativeBinDir = fileConfig.outPath.relativize(fileConfig.binPath).toUnixString() + override fun generatePlatformFiles() { // generate the main source file (containing main()) @@ -176,9 +178,7 @@ class CppStandaloneGenerator(generator: CppGenerator) : "cmake", cmakeArgs + additionalCmakeArgs + listOf( "-DCMAKE_INSTALL_PREFIX=${outPath.toUnixString()}", - "-DCMAKE_INSTALL_BINDIR=${ - if (outPath.isAbsolute) outPath.relativize(fileConfig.binPath).toUnixString() else fileConfig.binPath.fileName.toString() - }", + "-DCMAKE_INSTALL_BINDIR=$relativeBinDir", "-S", sourcesRoot ?: fileConfig.srcGenBasePath.toUnixString(), "-B", @@ -210,15 +210,17 @@ class CppStandaloneGenerator(generator: CppGenerator) : } } - override fun defaultEntryPoint(): List = listOf("./bin/" + context.fileConfig.name) + override fun defaultEntryPoint(): List = listOf("$relativeBinDir/${fileConfig.name}") - override fun generateCopyOfExecutable(): String = - """ - ${super.generateCopyOfExecutable()} + override fun generateCopyOfExecutable(): String { + val name = fileConfig.name + return """ + COPY --from=builder /lingua-franca/$name/$relativeBinDir/$name ./$relativeBinDir/$name COPY --from=builder /usr/local/lib /usr/local/lib COPY --from=builder /usr/lib /usr/lib COPY --from=builder /lingua-franca . """.trimIndent() + } override fun defaultBuildCommands(): List { val mkdirCommand = listOf("mkdir", "-p", "build") From 90e6828ef683522e1674d2a4384ab2fd4a4c3cb2 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 20 Jun 2024 15:15:40 +0200 Subject: [PATCH 08/15] also fix C++ ros2 docker generation --- .../generator/cpp/CppPlatformGenerator.kt | 2 ++ .../lflang/generator/cpp/CppRos2Generator.kt | 30 +++++++++++-------- .../generator/cpp/CppStandaloneGenerator.kt | 3 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt index 799d0125c2..83223c93ea 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt @@ -11,6 +11,7 @@ import org.lflang.target.property.NoRuntimeValidationProperty import org.lflang.target.property.PrintStatisticsProperty import org.lflang.target.property.TracingProperty import org.lflang.toDefinition +import org.lflang.toUnixString import java.nio.file.Path /** Abstract class for generating platform specific files and invoking the target compiler. */ @@ -24,6 +25,7 @@ abstract class CppPlatformGenerator(protected val generator: CppGenerator) { protected val mainReactor = generator.mainDef.reactorClass.toDefinition() open val srcGenPath: Path = generator.fileConfig.srcGenPath + protected val relativeBinDir = fileConfig.outPath.relativize(fileConfig.binPath).toUnixString() abstract fun generatePlatformFiles() diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt index 4be02961ef..7ff170c3de 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt @@ -39,7 +39,7 @@ class CppRos2Generator(generator: CppGenerator) : CppPlatformGenerator(generator ) val scriptPath = if (targetConfig.get(DockerProperty.INSTANCE).enabled) - fileConfig.srcGenPath.resolve("bin").resolve(fileConfig.name) + fileConfig.srcGenPath.resolve(relativeBinDir).resolve(fileConfig.name) else fileConfig.binPath.resolve(fileConfig.name) FileUtil.writeToFile(packageGenerator.generateBinScript(), scriptPath) @@ -58,7 +58,8 @@ class CppRos2Generator(generator: CppGenerator) : CppPlatformGenerator(generator return false } val colconCommand = commandFactory.createCommand( - "colcon", colconArgs(), fileConfig.outPath) + "colcon", colconArgs(), fileConfig.outPath + ) val returnCode = colconCommand?.run(context.cancelIndicator) if (returnCode != 0 && !messageReporter.errorsOccurred) { // If errors occurred but none were reported, then the following message is the best we can do. @@ -70,13 +71,13 @@ class CppRos2Generator(generator: CppGenerator) : CppPlatformGenerator(generator private fun colconArgs(): List { return listOf( - "build", - "--packages-select", - fileConfig.name, - packageGenerator.reactorCppName, - "--cmake-args", - "-DLF_REACTOR_CPP_SUFFIX=${packageGenerator.reactorCppSuffix}", - ) + cmakeArgs + "build", + "--packages-select", + fileConfig.name, + packageGenerator.reactorCppName, + "--cmake-args", + "-DLF_REACTOR_CPP_SUFFIX=${packageGenerator.reactorCppSuffix}", + ) + cmakeArgs } inner class CppDockerGenerator(context: LFGeneratorContext?) : DockerGenerator(context) { @@ -90,13 +91,16 @@ class CppRos2Generator(generator: CppGenerator) : CppPlatformGenerator(generator override fun generateRunForInstallingDeps(): String = "" - override fun defaultEntryPoint(): List = listOf(fileConfig.outPath.relativize(fileConfig.binPath).toUnixString() + "/" + fileConfig.name) + override fun defaultEntryPoint(): List = + listOf("$relativeBinDir/${fileConfig.name}") - override fun generateCopyOfExecutable(): String = - """ - ${super.generateCopyOfExecutable()} + override fun generateCopyOfExecutable(): String { + val name = fileConfig.name + return """ + COPY --from=builder /lingua-franca/$name/$relativeBinDir/$name ./$relativeBinDir/$name COPY --from=builder lingua-franca/${fileConfig.name}/install install """.trimIndent() + } override fun defaultBuildCommands(): List { val commands = listOf( diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt index 4b57166f0c..d245285035 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt @@ -26,8 +26,6 @@ class CppStandaloneGenerator(generator: CppGenerator) : const val DEFAULT_BASE_IMAGE: String = "alpine:latest" } - private val relativeBinDir = fileConfig.outPath.relativize(fileConfig.binPath).toUnixString() - override fun generatePlatformFiles() { // generate the main source file (containing main()) @@ -194,6 +192,7 @@ class CppStandaloneGenerator(generator: CppGenerator) : return cmd } + inner class StandaloneDockerGenerator(context: LFGeneratorContext?) : DockerGenerator(context) { override fun generateCopyForSources(): String = "COPY src-gen src-gen" From f8692c681118d827fcec65cc91fd23fdfd734d40 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 20 Jun 2024 11:53:03 -0700 Subject: [PATCH 09/15] Add missing type cast --- test/C/src/docker/RuntimeFilesPropertyContainerized.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/docker/RuntimeFilesPropertyContainerized.lf b/test/C/src/docker/RuntimeFilesPropertyContainerized.lf index d80042d122..b15fa63be3 100644 --- a/test/C/src/docker/RuntimeFilesPropertyContainerized.lf +++ b/test/C/src/docker/RuntimeFilesPropertyContainerized.lf @@ -16,7 +16,7 @@ main reactor { long fsize = ftell(f); fseek(f, 0, SEEK_SET); - char *string = malloc(fsize + 1); + char *string = (char*) malloc(fsize + 1); fread(string, fsize, 1, f); fclose(f); From d4cb99b1e28c7ff7ba60896b3a0beb1a70840a5b Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 20 Jun 2024 12:42:14 -0700 Subject: [PATCH 10/15] Address failing TypeScript Docker test. --- .../org/lflang/generator/ts/TSFileConfig.kt | 24 +++++++++++++------ .../org/lflang/generator/ts/TSGenerator.kt | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt index 2503d94629..f889086099 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt @@ -42,7 +42,7 @@ import java.nio.file.Path * @author Hokeun Kim */ class TSFileConfig( - resource: Resource, srcGenBasePath: Path, useHierarchicalBin: Boolean + resource: Resource, srcGenBasePath: Path, useHierarchicalBin: Boolean, var docker: Boolean? = null ) : FileConfig(resource, srcGenBasePath, useHierarchicalBin) { /** @@ -54,13 +54,23 @@ class TSFileConfig( FileUtil.deleteDirectory(srcGenPath) } + fun setDocker(dockerEnabled: Boolean) { + docker = dockerEnabled + } + override fun getCommand(): LFCommand { - return LFCommand.get( - "node", - listOf(srcPkgPath.relativize(executable).toString()), - true, - srcPkgPath - ) + if (docker == true) { + return super.getCommand() + } else if (docker == false) { + return LFCommand.get( + "node", + listOf(srcPkgPath.relativize(executable).toString()), + true, + srcPkgPath + ) + } else { + throw java.lang.IllegalStateException("The execute command cannot be determined because it is not known whether code generation is in Docker mode.") + } } override fun getExecutableExtension(): String { diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt index 91db8810e1..ca7b9ec4e8 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt @@ -112,7 +112,7 @@ class TSGenerator( override fun doGenerate(resource: Resource, context: LFGeneratorContext) { // Register the after delay transformation to be applied by GeneratorBase. registerTransformation(DelayedConnectionTransformation(TSDelayBodyGenerator, targetTypes, resource, true, true)) - + fileConfig.setDocker(targetConfig.get(DockerProperty.INSTANCE).enabled) super.doGenerate(resource, context) instantiationGraph From c00b05778b15e97521c6ba226a25fb40044c6111 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 20 Jun 2024 15:22:57 -0700 Subject: [PATCH 11/15] Fix Java compile error. --- core/src/main/java/org/lflang/generator/LFGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/LFGenerator.java b/core/src/main/java/org/lflang/generator/LFGenerator.java index f4e61e93d5..0e62c08c2c 100644 --- a/core/src/main/java/org/lflang/generator/LFGenerator.java +++ b/core/src/main/java/org/lflang/generator/LFGenerator.java @@ -60,7 +60,7 @@ public static FileConfig createFileConfig( case Python -> new PyFileConfig(resource, srcGenBasePath, useHierarchicalBin); case CPP -> new CppFileConfig(resource, srcGenBasePath, useHierarchicalBin); case Rust -> new RustFileConfig(resource, srcGenBasePath, useHierarchicalBin); - case TS -> new TSFileConfig(resource, srcGenBasePath, useHierarchicalBin); + case TS -> new TSFileConfig(resource, srcGenBasePath, useHierarchicalBin, null); }; } catch (IOException e) { throw new RuntimeException( From 7ce0feacfd7602909f1b6b51e0c87b6efde36f55 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 20 Jun 2024 15:41:00 -0700 Subject: [PATCH 12/15] Add comment --- core/src/main/java/org/lflang/generator/LFGenerator.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/java/org/lflang/generator/LFGenerator.java b/core/src/main/java/org/lflang/generator/LFGenerator.java index 0e62c08c2c..8ca19d67cf 100644 --- a/core/src/main/java/org/lflang/generator/LFGenerator.java +++ b/core/src/main/java/org/lflang/generator/LFGenerator.java @@ -60,6 +60,8 @@ public static FileConfig createFileConfig( case Python -> new PyFileConfig(resource, srcGenBasePath, useHierarchicalBin); case CPP -> new CppFileConfig(resource, srcGenBasePath, useHierarchicalBin); case Rust -> new RustFileConfig(resource, srcGenBasePath, useHierarchicalBin); + // null is passed to the docker argument because it is up to the TS Generator to tell the + // FileConfig whether Docker is enabled case TS -> new TSFileConfig(resource, srcGenBasePath, useHierarchicalBin, null); }; } catch (IOException e) { From 6828b222e4c39d5e48dcbeeab7886db1b09c4102 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 20 Jun 2024 16:06:54 -0700 Subject: [PATCH 13/15] Address test failures --- .../src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt index f889086099..0d8e4e74ae 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt @@ -74,10 +74,16 @@ class TSFileConfig( } override fun getExecutableExtension(): String { + if (docker == true) { + return super.getExecutableExtension() + } return ".js" } override fun getExecutable(): Path { + if (docker == true) { + return super.getExecutable() + } return srcGenPath.resolve("dist").resolve(name + executableExtension) } } From cf6c1f353966dbbbb8b4ed74e4ab8b295fa11f14 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 20 Jun 2024 21:34:21 -0700 Subject: [PATCH 14/15] Revert recent TSFileConfig changes and instead do not override --- .../org/lflang/generator/LFGenerator.java | 4 +-- .../org/lflang/generator/ts/TSFileConfig.kt | 35 +------------------ .../org/lflang/generator/ts/TSGenerator.kt | 2 +- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/LFGenerator.java b/core/src/main/java/org/lflang/generator/LFGenerator.java index 8ca19d67cf..f4e61e93d5 100644 --- a/core/src/main/java/org/lflang/generator/LFGenerator.java +++ b/core/src/main/java/org/lflang/generator/LFGenerator.java @@ -60,9 +60,7 @@ public static FileConfig createFileConfig( case Python -> new PyFileConfig(resource, srcGenBasePath, useHierarchicalBin); case CPP -> new CppFileConfig(resource, srcGenBasePath, useHierarchicalBin); case Rust -> new RustFileConfig(resource, srcGenBasePath, useHierarchicalBin); - // null is passed to the docker argument because it is up to the TS Generator to tell the - // FileConfig whether Docker is enabled - case TS -> new TSFileConfig(resource, srcGenBasePath, useHierarchicalBin, null); + case TS -> new TSFileConfig(resource, srcGenBasePath, useHierarchicalBin); }; } catch (IOException e) { throw new RuntimeException( diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt index 0d8e4e74ae..e04040f9b3 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt @@ -42,7 +42,7 @@ import java.nio.file.Path * @author Hokeun Kim */ class TSFileConfig( - resource: Resource, srcGenBasePath: Path, useHierarchicalBin: Boolean, var docker: Boolean? = null + resource: Resource, srcGenBasePath: Path, useHierarchicalBin: Boolean ) : FileConfig(resource, srcGenBasePath, useHierarchicalBin) { /** @@ -53,37 +53,4 @@ class TSFileConfig( super.doClean() FileUtil.deleteDirectory(srcGenPath) } - - fun setDocker(dockerEnabled: Boolean) { - docker = dockerEnabled - } - - override fun getCommand(): LFCommand { - if (docker == true) { - return super.getCommand() - } else if (docker == false) { - return LFCommand.get( - "node", - listOf(srcPkgPath.relativize(executable).toString()), - true, - srcPkgPath - ) - } else { - throw java.lang.IllegalStateException("The execute command cannot be determined because it is not known whether code generation is in Docker mode.") - } - } - - override fun getExecutableExtension(): String { - if (docker == true) { - return super.getExecutableExtension() - } - return ".js" - } - - override fun getExecutable(): Path { - if (docker == true) { - return super.getExecutable() - } - return srcGenPath.resolve("dist").resolve(name + executableExtension) - } } diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt index ca7b9ec4e8..91db8810e1 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt @@ -112,7 +112,7 @@ class TSGenerator( override fun doGenerate(resource: Resource, context: LFGeneratorContext) { // Register the after delay transformation to be applied by GeneratorBase. registerTransformation(DelayedConnectionTransformation(TSDelayBodyGenerator, targetTypes, resource, true, true)) - fileConfig.setDocker(targetConfig.get(DockerProperty.INSTANCE).enabled) + super.doGenerate(resource, context) instantiationGraph From ff1b0fe00372823ab7107243a0cbfb485ed788ee Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 21 Jun 2024 10:53:50 +0200 Subject: [PATCH 15/15] Fixed docker compose script so that it fails if any container fails --- .../org/lflang/generator/docker/DockerComposeGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java b/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java index d63a733740..2b8ce9a4ac 100644 --- a/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java @@ -138,7 +138,7 @@ public void createLauncher() { set -euo pipefail cd $(dirname "$0") cd "%s/%s" - docker compose up + docker compose up --abort-on-container-failure """ .formatted(relPath, packageRoot.relativize(srcGenPath)); var messageReporter = context.getErrorReporter();