Skip to content

Commit

Permalink
Merge master into tracing-refactoring2
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Feb 18, 2024
2 parents c2aed67 + 150cf6a commit aceec43
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 29 deletions.
8 changes: 4 additions & 4 deletions .github/scripts/check-diff.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

changes() {
git diff --name-only HEAD $(git merge-base HEAD origin/master)
git diff --name-only HEAD $(git merge-base HEAD origin/$1)
}

if changes | grep "$1" | grep -q -v "^.*md\|txt$"; then
echo "changed_$2=1" >> $GITHUB_OUTPUT
if changes $1 | grep "$2" | grep -q -v "^.*md\|txt$"; then
echo "changed_$3=1" >> $GITHUB_OUTPUT
else
echo "changed_$2=0" >> $GITHUB_OUTPUT
echo "changed_$3=0" >> $GITHUB_OUTPUT
fi
14 changes: 7 additions & 7 deletions .github/workflows/check-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ jobs:
- id: do
name: Check which targets have changes
run: |
./check-diff.sh "lflang/generator/c\|resources/lib/c\|resources/lib/platform\|test/C" c
./check-diff.sh "lflang/generator/cpp\|resources/lib/cpp\|test/Cpp" cpp
./check-diff.sh "lflang/generator/python\|resources/lib/py\|test/Python" py
./check-diff.sh "lflang/generator/rust\|resources/lib/rs\|test/Rust" rs
./check-diff.sh "lflang/generator/ts\|resources/lib/ts\|test/TypeScript" ts
./check-diff.sh "util/tracing" tracing
./check-diff.sh ".*" any
./check-diff.sh master "lflang/generator/c\|resources/lib/c\|resources/lib/platform\|test/C" c
./check-diff.sh master "lflang/generator/cpp\|resources/lib/cpp\|test/Cpp" cpp
./check-diff.sh master "lflang/generator/python\|resources/lib/py\|test/Python" py
./check-diff.sh master "lflang/generator/rust\|resources/lib/rs\|test/Rust" rs
./check-diff.sh master "lflang/generator/ts\|resources/lib/ts\|test/TypeScript" ts
./check-diff.sh master "util/tracing" tracing
./check-diff.sh master ".*" any
shell: bash
working-directory: .github/scripts
- id: summarize
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/custom-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Custom build

# Trigger the workflow every day at 5 AM (UTC).
on:
workflow_dispatch:

jobs:
custom-build:
runs-on: ubuntu-latest
steps:
- name: Check out lingua-franca repository
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Prepare build environment
uses: ./.github/actions/prepare-build-env
- name: Modify property file to contain the commit SHA
shell: bash
run: |
TIMESTAMP="$(date +'%Y-%m-%d')"
SHA="$(git rev-parse --short HEAD)"
sed --regexp-extended --in-place "s/^(VERSION = .*)$/\1 ${SHA} ${TIMESTAMP}/" core/src/main/resources/org/lflang/StringsBundle.properties
- name: Build and package lf cli tools (nightly build)
shell: bash
run: |
export TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
echo "timestamp=$TIMESTAMP" >> "$GITHUB_ENV"
./gradlew build -Pnightly=$TIMESTAMP -PtargetOS=Linux -PtargetArch=x86_64
./gradlew assemble -Pnightly=$TIMESTAMP -PtargetOS=Linux -PtargetArch=aarch64
./gradlew assemble -Pnightly=$TIMESTAMP -PtargetOS=MacOS -PtargetArch=x86_64
./gradlew assemble -Pnightly=$TIMESTAMP -PtargetOS=MacOS -PtargetArch=aarch64
./gradlew assemble -Pnightly=$TIMESTAMP -PtargetOS=Windows -PtargetArch=x86_64
- name: Deploy nightly release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.NIGHTLY_BUILD }}"
automatic_release_tag: '${{ github.ref_name }}-${{ github.env.timestamp }}'
prerelease: true
draft: true
title: "Custom Lingua Franca build for ${{ github.ref_name }} branch"
files: |
build/distributions/*
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ public static void generateCMakeInclude(
"add_compile_definitions(LF_SOURCE_DIRECTORY=\"" + fileConfig.srcPath + "\")");
cmakeIncludeCode.pr(
"add_compile_definitions(LF_PACKAGE_DIRECTORY=\"" + fileConfig.srcPkgPath + "\")");

cmakeIncludeCode.pr(
"add_compile_definitions(LF_SOURCE_GEN_DIRECTORY=\"" + fileConfig.getSrcGenPath() + "\")");
try (var srcWriter = Files.newBufferedWriter(cmakeIncludePath)) {
srcWriter.write(cmakeIncludeCode.getCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void doGenerate(List<FederateInstance> federates, RtiConfig rtiConfig) {
target = user + "@" + host;
}

shCode.append("#### Host is ").append(host);
shCode.append("#### Host is ").append(host).append("\n");

// Launch the RTI in the foreground.
if (host.equals("localhost") || host.equals("0.0.0.0")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ CodeBuilder generateCMakeCode(
}
cMakeCode.newLine();

// Add definition of directory where the main CMakeLists.txt file resides because this is where
// any files specified by the `file` target directive will be put.
cMakeCode.pr(
"# Define directory in which files from the 'files' target directive will be put.");
cMakeCode.pr(
"target_compile_definitions(${LF_MAIN_TARGET} PUBLIC"
+ " LF_TARGET_FILES_DIRECTORY=\"${CMAKE_CURRENT_LIST_DIR}\")");

cMakeCode.pr(cMakeExtras);
cMakeCode.newLine();

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,13 @@ private static List<String> cmakeOptions(TargetConfig targetConfig, FileConfig f
String maybeQuote = ""; // Windows seems to require extra level of quoting.
String srcPath = fileConfig.srcPath.toString(); // Windows requires escaping the backslashes.
String rootPath = fileConfig.srcPkgPath.toString();
String srcGenPath = fileConfig.getSrcGenPath().toString();
if (separator.equals("\\")) {
separator = "\\\\\\\\";
maybeQuote = "\\\"";
srcPath = srcPath.replaceAll("\\\\", "\\\\\\\\");
rootPath = rootPath.replaceAll("\\\\", "\\\\\\\\");
srcGenPath = srcGenPath.replaceAll("\\\\", "\\\\\\\\");
}
arguments.addAll(
List.of(
Expand All @@ -242,6 +244,7 @@ private static List<String> cmakeOptions(TargetConfig targetConfig, FileConfig f
// Do not convert to Unix path
arguments.add("-DLF_SOURCE_DIRECTORY=\"" + maybeQuote + srcPath + maybeQuote + "\"");
arguments.add("-DLF_PACKAGE_DIRECTORY=\"" + maybeQuote + rootPath + maybeQuote + "\"");
arguments.add("-DLF_SOURCE_GEN_DIRECTORY=\"" + maybeQuote + srcGenPath + maybeQuote + "\"");
}
arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath()));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.lflang.generator.c;

import static org.lflang.util.StringUtil.addDoubleQuotes;

import java.nio.file.Path;
import java.util.HashMap;
import org.lflang.generator.CodeBuilder;
Expand Down Expand Up @@ -76,7 +74,6 @@ public static String generateDefineDirectives(TargetConfig targetConfig, Path sr
CodeBuilder code = new CodeBuilder();
// TODO: Get rid of all of these
code.pr("#define LOG_LEVEL " + logLevel);
code.pr("#define TARGET_FILES_DIRECTORY " + addDoubleQuotes(srcGenPath.toString()));
final var definitions = new HashMap<String, String>();
if (tracing.isEnabled()) {
definitions.put("LF_TRACE", tracing.traceFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) {

private fun Connection.getConnectionLambda(portType: String): String {
return """
[this]($portType left, $portType right) {
[&]($portType left, $portType right) {
left->environment()->draw_connection(left, right, $properties);
}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ class CppParameterGenerator(private val reactor: Reactor) {
* This is required for some code bodies (e.g. target code in parameter initializers) to have access to the local parameters.
*/
fun generateOuterAliasDeclarations() =
reactor.parameters.joinToString(separator = "") { "const typename Parameters::${it.typeAlias}& ${it.name} = __lf_inner.${it.name};\n" }
reactor.parameters.joinToString(prefix = "// parameter aliases for use in the outer scope\n", separator = "") {
"[[maybe_unused]] const typename Parameters::${it.typeAlias}& ${it.name} = __lf_inner.${it.name};\n"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi
${" | "..reactions.generateReactionViewForwardDeclarations()}
|
| class Inner: public lfutil::LFScope {
| const Inner& __lf_inner = *this;
| const Parameters __lf_parameters;
| [[maybe_unused]] const Inner& __lf_inner = *this;
| [[maybe_unused]] const Parameters __lf_parameters;
${" | "..parameters.generateInnerAliasDeclarations()}
${" | "..state.generateDeclarations()}
${" | "..methods.generateDeclarations()}
Expand Down
5 changes: 1 addition & 4 deletions test/C/src/federated/EnclaveFederatedRequestStop.lf
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/**
* Test that enclaves within federates all stop at the time requested by the first enclave to
* request a stop. Note that the test has no timeout because any finite timeout can, in theory,
* cause the test to fail. The first federate to request a stop does no at 50 ms, so the program
* cause the test to fail. The first federate to request a stop does so at 50 ms, so the program
* should terminate quickly if all goes well.
*/
target C

reactor Stop(
// Zero value here means "don't stop".
stop_time: time = 0) {
preamble {=
#include "platform.h" // Defines PRINTF_TIME
=}
timer t(stop_time)

reaction(t) {=
Expand Down
13 changes: 9 additions & 4 deletions test/C/src/federated/SmallDelayDecentralized.lf
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ reactor Print {
}
self->c++;
=} STP(1 sec) {=
lf_print_error_and_exit("STP violation at tag " PRINTF_TAG
". This should not happen because the STP offset is large.",
lf_print_warning("STP violation at tag " PRINTF_TAG
". This should not happen because the STP offset is large. Checking value anyway.",
lf_tag().time - lf_time_start(), lf_tag().microstep);
lf_print("-------- Received %d", in->value);
if (in->value != self->c) {
lf_print_error_and_exit("Expected to receive %d.", self->c);
}
self->c++;
=}

reaction(loop) {=
lf_print("checking self.checks, which is now %d...", self->checks);
reaction(loop) -> loop {=
lf_print("checking self->checks, which is now %d...", self->checks);
if (self->checks++ <= 3) {
lf_schedule(loop, 0);
}
Expand Down
42 changes: 42 additions & 0 deletions test/Cpp/src/multiport/MultiportToMultiportAfterParameterized.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Test multiport to multiport connections. See also MultiportToMultiport.
target Cpp

reactor Source(width: size_t = 2) {
output[width] out: size_t

reaction(startup) -> out {=
for (size_t i = 0; i < out.size(); i++) {
out[i].set(i);
}
=}
}

reactor Destination(width: size_t = 2) {
input[width] in: size_t

reaction(in) {=
for (size_t i = 0; i < in.size(); i++) {
if (in[i].is_present()) {
size_t value = *in[i].get();
std::cout << "Received on channel " << i << ": " << value << '\n';
// NOTE: For testing purposes, this assumes the specific
// widths instantiated below.
if (value != i % 3) {
std::cerr << "ERROR: expected " << i % 3 << '\n';
exit(1);
}
}
}
if (get_elapsed_logical_time() != 1s) {
std::cerr << "ERROR: Expected to receive input after one second.\n";
exit(2);
}
=}
}

main reactor(delay: time = 1 sec) {
a1 = new Source(width=3)
a2 = new Source(width=2)
b = new Destination(width=5)
a1.out, a2.out -> b.in after delay
}

0 comments on commit aceec43

Please sign in to comment.