Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generate.sh file to generated fed templates #215

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions examples/riot/coap_federated_lf/CoapFederatedLF/r1/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
LF_MAIN=CoapFederatedLF

$REACTOR_UC_PATH/lfc/bin/lfc-dev ../../src/$LF_MAIN.lf -n -o .
5 changes: 0 additions & 5 deletions examples/riot/coap_federated_lf/CoapFederatedLF/r2/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
LF_MAIN=CoapFederatedLF

$REACTOR_UC_PATH/lfc/bin/lfc-dev ../../src/$LF_MAIN.lf -n -o .
14 changes: 12 additions & 2 deletions examples/riot/coap_federated_lf/build.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 4 additions & 8 deletions lfc/cli/lfc/src/main/java/org/lflang/cli/Lfc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -353,8 +353,6 @@ private Integer getWorkers() {
return workers;
}



/** Check the values of the commandline arguments and return them. */
public GeneratorArguments getArgs() {

Expand All @@ -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)));
}
}
7 changes: 3 additions & 4 deletions lfc/core/src/main/java/org/lflang/AttributeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 3 additions & 1 deletion lfc/core/src/main/java/org/lflang/target/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,30 @@ 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) {

private val targetName: String = federate.codeType
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) =
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Loading