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..ea10bc1032 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,30 @@ 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() { + 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.)"; + } + var ret = new StringBuilder(); + for (var file : files) { + var p = Path.of(file); + var name = p.getFileName().toString(); + 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..b15fa63be3 --- /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 = (char*) 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); + =} +}