diff --git a/examples/riot/coap_federated_lf/CoapFederatedLF/r1/Makefile b/examples/riot/coap_federated_lf/CoapFederatedLF/r1/Makefile index 5f3a8d65..fcc72613 100644 --- a/examples/riot/coap_federated_lf/CoapFederatedLF/r1/Makefile +++ b/examples/riot/coap_federated_lf/CoapFederatedLF/r1/Makefile @@ -1,11 +1,6 @@ LF_MAIN ?= CoapFederatedLF LF_FED ?= r1 -# Execute the LF compiler if build target is "all" -ifeq ($(firstword $(MAKECMDGOALS)),all) - _ := $(shell $(REACTOR_UC_PATH)/lfc/bin/lfc-dev $(CURDIR)/../../src/$(LF_MAIN).lf -n -o $(CURDIR)) -endif - # ---- RIOT specific configuration ---- # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/RIOT diff --git a/examples/riot/coap_federated_lf/CoapFederatedLF/r1/generate.sh b/examples/riot/coap_federated_lf/CoapFederatedLF/r1/generate.sh new file mode 100755 index 00000000..c2c0502c --- /dev/null +++ b/examples/riot/coap_federated_lf/CoapFederatedLF/r1/generate.sh @@ -0,0 +1,4 @@ +#!/bin/bash +LF_MAIN=CoapFederatedLF + +$REACTOR_UC_PATH/lfc/bin/lfc-dev ../../src/$LF_MAIN.lf -n -o . \ No newline at end of file diff --git a/examples/riot/coap_federated_lf/CoapFederatedLF/r2/Makefile b/examples/riot/coap_federated_lf/CoapFederatedLF/r2/Makefile index 3ee43fe5..5f4e44ae 100644 --- a/examples/riot/coap_federated_lf/CoapFederatedLF/r2/Makefile +++ b/examples/riot/coap_federated_lf/CoapFederatedLF/r2/Makefile @@ -1,11 +1,6 @@ LF_MAIN ?= CoapFederatedLF LF_FED ?= r2 -# Execute the LF compiler if build target is "all" -ifeq ($(firstword $(MAKECMDGOALS)),all) - _ := $(shell $(REACTOR_UC_PATH)/lfc/bin/lfc-dev $(CURDIR)/../../src/$(LF_MAIN).lf -n -o $(CURDIR)) -endif - # ---- RIOT specific configuration ---- # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/RIOT diff --git a/examples/riot/coap_federated_lf/CoapFederatedLF/r2/generate.sh b/examples/riot/coap_federated_lf/CoapFederatedLF/r2/generate.sh new file mode 100755 index 00000000..c2c0502c --- /dev/null +++ b/examples/riot/coap_federated_lf/CoapFederatedLF/r2/generate.sh @@ -0,0 +1,4 @@ +#!/bin/bash +LF_MAIN=CoapFederatedLF + +$REACTOR_UC_PATH/lfc/bin/lfc-dev ../../src/$LF_MAIN.lf -n -o . \ No newline at end of file diff --git a/examples/riot/coap_federated_lf/build.sh b/examples/riot/coap_federated_lf/build.sh index a17d6d25..0920470e 100755 --- a/examples/riot/coap_federated_lf/build.sh +++ b/examples/riot/coap_federated_lf/build.sh @@ -1,7 +1,17 @@ #!/bin/bash LF_MAIN=CoapFederatedLF +# Generate configuration templates if they don't exist already $REACTOR_UC_PATH/lfc/bin/lfc-dev --gen-fed-templates src/$LF_MAIN.lf -PORT=tap0 make all -C ./CoapFederatedLF/r1 -PORT=tap1 make all -C ./CoapFederatedLF/r2 +# Generate and build r1 sources +pushd ./$LF_MAIN/r1 + ./generate.sh + PORT=tap0 make all +popd + +# Generate and build r2 sources +pushd ./$LF_MAIN/r2 + ./generate.sh + PORT=tap1 make all +popd diff --git a/lfc/cli/lfc/src/main/java/org/lflang/cli/Lfc.java b/lfc/cli/lfc/src/main/java/org/lflang/cli/Lfc.java index bd0dcdca..bca809cd 100644 --- a/lfc/cli/lfc/src/main/java/org/lflang/cli/Lfc.java +++ b/lfc/cli/lfc/src/main/java/org/lflang/cli/Lfc.java @@ -143,9 +143,9 @@ public class Lfc extends CliBase { private Boolean noSourceMapping; @Option( - names = {"--gen-fed-templates"}, - arity = "0", - description = "Generate project templates for each federate. Skip existing templates.") + names = {"--gen-fed-templates"}, + arity = "0", + description = "Generate project templates for each federate. Skip existing templates.") private Boolean genFedTemplates; /** Mutually exclusive options related to threading. */ @@ -353,8 +353,6 @@ private Integer getWorkers() { return workers; } - - /** Check the values of the commandline arguments and return them. */ public GeneratorArguments getArgs() { @@ -369,8 +367,6 @@ public GeneratorArguments getArgs() { genFedTemplates != null, List.of( new Argument<>(BuildTypeProperty.INSTANCE, getBuildType()), - new Argument<>(NoCompileProperty.INSTANCE, noCompile) - ) - ); + new Argument<>(NoCompileProperty.INSTANCE, noCompile))); } } diff --git a/lfc/core/src/main/java/org/lflang/AttributeUtils.java b/lfc/core/src/main/java/org/lflang/AttributeUtils.java index 2335ad65..ca1f5b46 100644 --- a/lfc/core/src/main/java/org/lflang/AttributeUtils.java +++ b/lfc/core/src/main/java/org/lflang/AttributeUtils.java @@ -37,7 +37,6 @@ import org.eclipse.xtext.resource.XtextResource; import org.lflang.ast.ASTUtils; import org.lflang.lf.*; -import org.lflang.target.property.PlatformProperty; import org.lflang.target.property.type.PlatformType; import org.lflang.util.StringUtil; @@ -337,9 +336,9 @@ public static PlatformType.Platform getFederatePlatform(Instantiation node) { return PlatformType.Platform.NATIVE; } else if (findAttributeByName(node, "platform_riot") != null) { return PlatformType.Platform.RIOT; - } else if (findAttributeByName(node, "platform_zephyr") != null) { - return PlatformType.Platform.ZEPHYR; - } else { + } else if (findAttributeByName(node, "platform_zephyr") != null) { + return PlatformType.Platform.ZEPHYR; + } else { return PlatformType.Platform.AUTO; } } diff --git a/lfc/core/src/main/java/org/lflang/target/Target.java b/lfc/core/src/main/java/org/lflang/target/Target.java index c921a772..2e5df96c 100644 --- a/lfc/core/src/main/java/org/lflang/target/Target.java +++ b/lfc/core/src/main/java/org/lflang/target/Target.java @@ -439,7 +439,9 @@ public boolean supportsInheritance() { return true; } - public boolean supportsGenFedTemplates() {return this.equals(Target.UC);} + public boolean supportsGenFedTemplates() { + return this.equals(Target.UC); + } /** Return true if the target supports multiports and banks of reactors. */ public boolean supportsMultiports() { diff --git a/lfc/core/src/main/kotlin/org/lflang/generator/uc/UcFederatedProjectTemplateGenerator.kt b/lfc/core/src/main/kotlin/org/lflang/generator/uc/UcFederatedProjectTemplateGenerator.kt index 7027a171..75156fa9 100644 --- a/lfc/core/src/main/kotlin/org/lflang/generator/uc/UcFederatedProjectTemplateGenerator.kt +++ b/lfc/core/src/main/kotlin/org/lflang/generator/uc/UcFederatedProjectTemplateGenerator.kt @@ -10,6 +10,8 @@ import org.lflang.target.property.type.PlatformType import org.lflang.util.FileUtil import java.nio.file.Files import java.nio.file.Path +import java.nio.file.attribute.PosixFilePermission +import kotlin.io.path.setPosixFilePermissions class UcFederatedTemplateGenerator(private val mainDef: Instantiation, private val federate: UcFederate, private val targetConfig: TargetConfig, private val projectsRoot: Path, private val messageReporter: MessageReporter) { @@ -17,6 +19,21 @@ class UcFederatedTemplateGenerator(private val mainDef: Instantiation, private v private val projectRoot = projectsRoot.resolve(federate.name) private val S = '$' // a little trick to escape the dollar sign with $S + private fun generateFilesCommon() { + val make = """ + |#!/bin/bash + |LF_MAIN=${mainDef.name} + | + |${S}REACTOR_UC_PATH/lfc/bin/lfc-dev ../../src/${S}LF_MAIN.lf -n -o . + """.trimMargin() + val filePath = projectRoot.resolve("generate.sh") + FileUtil.writeToFile(make, filePath) + filePath.setPosixFilePermissions(setOf( + PosixFilePermission.OWNER_READ, + PosixFilePermission.OWNER_WRITE, + PosixFilePermission.OWNER_EXECUTE, + )) + } private fun generateCmake(init: String, mainTargetName: String, createMainTarget: Boolean) = """ @@ -73,11 +90,6 @@ class UcFederatedTemplateGenerator(private val mainDef: Instantiation, private v |LF_MAIN ?= ${mainDef.name} |LF_FED ?= ${federate.name} | - |# Execute the LF compiler if build target is "all" - |ifeq ($S(firstword $S(MAKECMDGOALS)),all) - | _ := $S(shell $S(REACTOR_UC_PATH)/lfc/bin/lfc-dev $S(CURDIR)/../../src/$S(LF_MAIN).lf -n -o $S(CURDIR)) - |endif - | |# ---- RIOT specific configuration ---- |# This has to be the absolute path to the RIOT base directory: |RIOTBASE ?= $S(CURDIR)/RIOT @@ -116,6 +128,9 @@ class UcFederatedTemplateGenerator(private val mainDef: Instantiation, private v } FileUtil.createDirectoryIfDoesNotExist(projectRoot.toFile()) + + generateFilesCommon() + val platform = if (federate.platform == PlatformType.Platform.AUTO) targetConfig.get(PlatformProperty.INSTANCE).platform else federate.platform when (platform) { PlatformType.Platform.NATIVE -> generateFilesNative()