From 82482d2671bc682a2f7e3de903017176943af2be Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 5 Nov 2024 12:18:41 -0800 Subject: [PATCH 1/6] Add cmake-init-include target property --- .../generator/FederationFileConfig.java | 3 +- .../lflang/generator/c/CCmakeGenerator.java | 6 +++ .../org/lflang/generator/c/CCompiler.java | 6 +-- .../org/lflang/generator/c/CGenerator.java | 10 ++++ .../main/java/org/lflang/target/Target.java | 3 ++ .../property/CmakeInitIncludeProperty.java | 47 +++++++++++++++++++ .../generator/cpp/CppRos2PackageGenerator.kt | 3 +- .../cpp/CppStandaloneCmakeGenerator.kt | 7 +-- 8 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java diff --git a/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java b/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java index c714c0586a..fd98d78c8e 100644 --- a/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java +++ b/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java @@ -33,6 +33,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.lflang.FileConfig; import org.lflang.target.property.CmakeIncludeProperty; +import org.lflang.target.property.CmakeInitIncludeProperty; import org.lflang.target.property.FilesProperty; import org.lflang.target.property.ProtobufsProperty; import org.lflang.util.FileUtil; @@ -102,7 +103,7 @@ public void doClean() throws IOException { * the generated .lf file for the federate. */ public void relativizePaths(FederateTargetConfig targetConfig) { - List.of(ProtobufsProperty.INSTANCE, FilesProperty.INSTANCE, CmakeIncludeProperty.INSTANCE) + List.of(ProtobufsProperty.INSTANCE, FilesProperty.INSTANCE, CmakeIncludeProperty.INSTANCE, CmakeInitIncludeProperty.INSTANCE) .forEach( p -> { if (targetConfig.isSet(p)) { diff --git a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java index 5931399052..d308856784 100644 --- a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java @@ -37,6 +37,7 @@ import org.lflang.target.property.AuthProperty; import org.lflang.target.property.BuildTypeProperty; import org.lflang.target.property.CmakeIncludeProperty; +import org.lflang.target.property.CmakeInitIncludeProperty; import org.lflang.target.property.CompileDefinitionsProperty; import org.lflang.target.property.CompilerProperty; import org.lflang.target.property.PlatformProperty; @@ -142,6 +143,11 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); + // Add the cmake-init-include files + for (String includeFile : targetConfig.getOrDefault(CmakeInitIncludeProperty.INSTANCE)) { + cMakeCode.pr("include(\"" + Path.of(includeFile).getFileName() + "\")"); + } + // Setup the project header for different platforms switch (platformOptions.platform()) { case ZEPHYR: diff --git a/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java index 12de4474dc..1467e9eb3c 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -244,9 +244,9 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f // 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='" + quote + srcPath + quote + "'"); - arguments.add("-DLF_PACKAGE_DIRECTORY='" + quote + rootPath + quote + "'"); - arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'"); + arguments.add("-DLF_SOURCE_DIRECTORY=" + srcPath); + arguments.add("-DLF_PACKAGE_DIRECTORY=" + rootPath); + arguments.add("-DLF_SOURCE_GEN_DIRECTORY=" + srcGenPath); } arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); 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 dda5c06d89..b08d269370 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -88,6 +88,7 @@ import org.lflang.target.TargetConfig; import org.lflang.target.property.BuildCommandsProperty; import org.lflang.target.property.CmakeIncludeProperty; +import org.lflang.target.property.CmakeInitIncludeProperty; import org.lflang.target.property.CompileDefinitionsProperty; import org.lflang.target.property.DockerProperty; import org.lflang.target.property.FedSetupProperty; @@ -788,6 +789,15 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) { true); } + if (targetConfig.isSet(CmakeInitIncludeProperty.INSTANCE)) { + FileUtil.copyFilesOrDirectories( + targetConfig.get(CmakeInitIncludeProperty.INSTANCE), + destination, + fileConfig, + messageReporter, + true); + } + try { var file = targetConfig.get(FedSetupProperty.INSTANCE); if (file != null) { diff --git a/core/src/main/java/org/lflang/target/Target.java b/core/src/main/java/org/lflang/target/Target.java index 30048f5a58..def719da17 100644 --- a/core/src/main/java/org/lflang/target/Target.java +++ b/core/src/main/java/org/lflang/target/Target.java @@ -34,6 +34,7 @@ import org.lflang.target.property.ClockSyncModeProperty; import org.lflang.target.property.ClockSyncOptionsProperty; import org.lflang.target.property.CmakeIncludeProperty; +import org.lflang.target.property.CmakeInitIncludeProperty; import org.lflang.target.property.CompileDefinitionsProperty; import org.lflang.target.property.CompilerProperty; import org.lflang.target.property.CoordinationOptionsProperty; @@ -589,6 +590,7 @@ public void initialize(TargetConfig config) { ClockSyncModeProperty.INSTANCE, ClockSyncOptionsProperty.INSTANCE, CmakeIncludeProperty.INSTANCE, + CmakeInitIncludeProperty.INSTANCE, CompileDefinitionsProperty.INSTANCE, CompilerProperty.INSTANCE, CoordinationOptionsProperty.INSTANCE, @@ -608,6 +610,7 @@ public void initialize(TargetConfig config) { case CPP -> config.register( BuildTypeProperty.INSTANCE, + CmakeInitIncludeProperty.INSTANCE, CmakeIncludeProperty.INSTANCE, CompilerProperty.INSTANCE, DockerProperty.INSTANCE, diff --git a/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java b/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java new file mode 100644 index 0000000000..2b9c903567 --- /dev/null +++ b/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java @@ -0,0 +1,47 @@ +package org.lflang.target.property; + +import java.util.List; + +import org.lflang.MessageReporter; +import org.lflang.ast.ASTUtils; +import org.lflang.lf.Element; + +/** + * Directive to specify cmake initialize files to be included at the very beginning of the + * generated CMakeLists.txt. Here the user can override things like the toolchain file + */ + +public final class CmakeInitIncludeProperty extends FileListProperty { + + /** Singleton target property instance. */ + public static final CmakeInitIncludeProperty INSTANCE = new CmakeInitIncludeProperty(); + + private CmakeInitIncludeProperty() { + super(); + } + + @Override + protected List fromAst(Element node, MessageReporter reporter) { + return ASTUtils.elementToListOfStrings(node); + } + + @Override + protected List fromString(String string, MessageReporter reporter) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Element toAstElement(List value) { + return ASTUtils.toElement(value); + } + + @Override + public String name() { + return "cmake-init-include"; + } + + @Override + public boolean loadFromFederate() { + return true; + } +} diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt index c3ce84c747..29bc4d83a3 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt @@ -4,6 +4,7 @@ import org.lflang.generator.PrependOperator import org.lflang.joinWithLn import org.lflang.target.property.BuildTypeProperty import org.lflang.target.property.CmakeIncludeProperty +import org.lflang.target.property.CmakeInitIncludeProperty import org.lflang.target.property.Ros2DependenciesProperty import org.lflang.target.property.RuntimeVersionProperty import org.lflang.toUnixString @@ -52,7 +53,7 @@ class CppRos2PackageGenerator(generator: CppGenerator, private val nodeName: Str fun generatePackageCmake(sources: List): String { // Resolve path to the cmake include files if any was provided - val includeFiles = targetConfig.get(CmakeIncludeProperty.INSTANCE)?.map { fileConfig.srcPath.resolve(it).toUnixString() } + val includeFiles = (targetConfig.get(CmakeIncludeProperty.INSTANCE) + targetConfig.get(CmakeInitIncludeProperty.INSTANCE))?.map { fileConfig.srcPath.resolve(it).toUnixString() } return with(PrependOperator) { with(CppGenerator) { diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt index 2c041fe6d2..8428493377 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt @@ -28,10 +28,7 @@ import org.lflang.FileConfig import org.lflang.target.TargetConfig import org.lflang.generator.PrependOperator import org.lflang.joinWithLn -import org.lflang.target.property.BuildTypeProperty -import org.lflang.target.property.CmakeIncludeProperty -import org.lflang.target.property.ExternalRuntimePathProperty -import org.lflang.target.property.RuntimeVersionProperty +import org.lflang.target.property.* import org.lflang.toUnixString import java.nio.file.Path @@ -140,7 +137,7 @@ class CppStandaloneCmakeGenerator(private val targetConfig: TargetConfig, privat fun generateCmake(sources: List): String { // Resolve path to the cmake include files if any was provided - val includeFiles = targetConfig.get(CmakeIncludeProperty.INSTANCE)?.map { fileConfig.srcPath.resolve(it).toUnixString() } + val includeFiles = (targetConfig.get(CmakeIncludeProperty.INSTANCE) + targetConfig.get(CmakeInitIncludeProperty.INSTANCE))?.map { fileConfig.srcPath.resolve(it).toUnixString() } val reactorCppTarget = when { targetConfig.isSet(ExternalRuntimePathProperty.INSTANCE) -> "reactor-cpp" From 0fd50deeac694a70865b330be0afee61a597e815 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 5 Nov 2024 18:11:41 -0800 Subject: [PATCH 2/6] Add LF_STRINGIFY macro --- core/src/main/resources/lib/c/reactor-c | 2 +- test/C/src/FilePkgReader.lf | 2 +- test/C/src/FileReader.lf | 2 +- test/C/src/federated/FederatedFilePkgReader.lf | 2 +- test/C/src/federated/FederatedFileReader.lf | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 3d7715c39f..9ac135a8b6 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 3d7715c39fc40ad3c4c29918e724dc5b96738ca5 +Subproject commit 9ac135a8b6fc86908b2381ae0664cdd8f07b2eb0 diff --git a/test/C/src/FilePkgReader.lf b/test/C/src/FilePkgReader.lf index d8bf41d9d6..ced5435d0b 100644 --- a/test/C/src/FilePkgReader.lf +++ b/test/C/src/FilePkgReader.lf @@ -6,7 +6,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_PACKAGE_DIRECTORY + LF_STRINGIFY(LF_PACKAGE_DIRECTORY) LF_FILE_SEPARATOR "src" LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; diff --git a/test/C/src/FileReader.lf b/test/C/src/FileReader.lf index e802baf115..473b47999c 100644 --- a/test/C/src/FileReader.lf +++ b/test/C/src/FileReader.lf @@ -6,7 +6,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_SOURCE_DIRECTORY + LF_STRINGIFY(LF_SOURCE_DIRECTORY) LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; diff --git a/test/C/src/federated/FederatedFilePkgReader.lf b/test/C/src/federated/FederatedFilePkgReader.lf index cf79291acf..c29358c83e 100644 --- a/test/C/src/federated/FederatedFilePkgReader.lf +++ b/test/C/src/federated/FederatedFilePkgReader.lf @@ -8,7 +8,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_PACKAGE_DIRECTORY + LF_STRINGIFY(LF_PACKAGE_DIRECTORY) LF_FILE_SEPARATOR "src" LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; diff --git a/test/C/src/federated/FederatedFileReader.lf b/test/C/src/federated/FederatedFileReader.lf index 617d34c3c8..91585502e5 100644 --- a/test/C/src/federated/FederatedFileReader.lf +++ b/test/C/src/federated/FederatedFileReader.lf @@ -9,7 +9,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_SOURCE_DIRECTORY + LF_STRINGIFY(LF_SOURCE_DIRECTORY) LF_FILE_SEPARATOR ".." LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; From 13e9e7d079dda2e7c39080b068cc71a506899e2b Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 5 Nov 2024 18:13:42 -0800 Subject: [PATCH 3/6] Bump reactor-c --- core/src/main/resources/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 9ac135a8b6..339dc57ded 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 9ac135a8b6fc86908b2381ae0664cdd8f07b2eb0 +Subproject commit 339dc57dedfcc968bcb57d62f9105ab3133eda94 From de5b96a0f75be4f295dbba5433894855c431b168 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 5 Nov 2024 18:14:33 -0800 Subject: [PATCH 4/6] Bump reactor-c --- core/src/main/resources/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 339dc57ded..75d46b604a 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 339dc57dedfcc968bcb57d62f9105ab3133eda94 +Subproject commit 75d46b604a032938de5d40ea282e8ce2208b926d From 4127893c0908fcf9207f012e10b887790a1b02b6 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 5 Nov 2024 18:20:15 -0800 Subject: [PATCH 5/6] Bump reactor-c --- core/src/main/resources/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 75d46b604a..a2397a8d63 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 75d46b604a032938de5d40ea282e8ce2208b926d +Subproject commit a2397a8d6389534ebc9024ae101112eec37bb2a2 From a6572dce69f43eced2570e44de7e73c5925e3ddd Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 5 Nov 2024 21:11:55 -0800 Subject: [PATCH 6/6] Get LF_SOURCE_DIRECTORY as a stirng --- .../lflang/federated/generator/FederationFileConfig.java | 6 +++++- core/src/main/java/org/lflang/generator/c/CCompiler.java | 2 +- .../lflang/target/property/CmakeInitIncludeProperty.java | 6 ++---- core/src/main/resources/lib/c/reactor-c | 2 +- test/C/src/FilePkgReader.lf | 2 +- test/C/src/FileReader.lf | 2 +- test/C/src/federated/FederatedFilePkgReader.lf | 2 +- test/C/src/federated/FederatedFileReader.lf | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java b/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java index fd98d78c8e..85b5af44ab 100644 --- a/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java +++ b/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java @@ -103,7 +103,11 @@ public void doClean() throws IOException { * the generated .lf file for the federate. */ public void relativizePaths(FederateTargetConfig targetConfig) { - List.of(ProtobufsProperty.INSTANCE, FilesProperty.INSTANCE, CmakeIncludeProperty.INSTANCE, CmakeInitIncludeProperty.INSTANCE) + List.of( + ProtobufsProperty.INSTANCE, + FilesProperty.INSTANCE, + CmakeIncludeProperty.INSTANCE, + CmakeInitIncludeProperty.INSTANCE) .forEach( p -> { if (targetConfig.isSet(p)) { diff --git a/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java index 1467e9eb3c..9150e1b6b9 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -246,7 +246,7 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f // Do not convert to Unix path arguments.add("-DLF_SOURCE_DIRECTORY=" + srcPath); arguments.add("-DLF_PACKAGE_DIRECTORY=" + rootPath); - arguments.add("-DLF_SOURCE_GEN_DIRECTORY=" + srcGenPath); + arguments.add("-DLF_SOURCE_GEN_DIRECTORY=" + srcGenPath); } arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath())); diff --git a/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java b/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java index 2b9c903567..a6964cabbe 100644 --- a/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java +++ b/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java @@ -1,16 +1,14 @@ package org.lflang.target.property; import java.util.List; - import org.lflang.MessageReporter; import org.lflang.ast.ASTUtils; import org.lflang.lf.Element; /** - * Directive to specify cmake initialize files to be included at the very beginning of the - * generated CMakeLists.txt. Here the user can override things like the toolchain file + * Directive to specify cmake initialize files to be included at the very beginning of the generated + * CMakeLists.txt. Here the user can override things like the toolchain file */ - public final class CmakeInitIncludeProperty extends FileListProperty { /** Singleton target property instance. */ diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index a2397a8d63..e0724b7cf2 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit a2397a8d6389534ebc9024ae101112eec37bb2a2 +Subproject commit e0724b7cf21f4b68ee02153a99f692d60a06aebe diff --git a/test/C/src/FilePkgReader.lf b/test/C/src/FilePkgReader.lf index ced5435d0b..d8bf41d9d6 100644 --- a/test/C/src/FilePkgReader.lf +++ b/test/C/src/FilePkgReader.lf @@ -6,7 +6,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_STRINGIFY(LF_PACKAGE_DIRECTORY) + LF_PACKAGE_DIRECTORY LF_FILE_SEPARATOR "src" LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; diff --git a/test/C/src/FileReader.lf b/test/C/src/FileReader.lf index 473b47999c..e802baf115 100644 --- a/test/C/src/FileReader.lf +++ b/test/C/src/FileReader.lf @@ -6,7 +6,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_STRINGIFY(LF_SOURCE_DIRECTORY) + LF_SOURCE_DIRECTORY LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; diff --git a/test/C/src/federated/FederatedFilePkgReader.lf b/test/C/src/federated/FederatedFilePkgReader.lf index c29358c83e..cf79291acf 100644 --- a/test/C/src/federated/FederatedFilePkgReader.lf +++ b/test/C/src/federated/FederatedFilePkgReader.lf @@ -8,7 +8,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_STRINGIFY(LF_PACKAGE_DIRECTORY) + LF_PACKAGE_DIRECTORY LF_FILE_SEPARATOR "src" LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt"; diff --git a/test/C/src/federated/FederatedFileReader.lf b/test/C/src/federated/FederatedFileReader.lf index 91585502e5..617d34c3c8 100644 --- a/test/C/src/federated/FederatedFileReader.lf +++ b/test/C/src/federated/FederatedFileReader.lf @@ -9,7 +9,7 @@ reactor Source { reaction(startup) -> out {= char* file_path = - LF_STRINGIFY(LF_SOURCE_DIRECTORY) + LF_SOURCE_DIRECTORY LF_FILE_SEPARATOR ".." LF_FILE_SEPARATOR "lib" LF_FILE_SEPARATOR "FileReader.txt";