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

Refactoring of target properties and their validation #2008

Merged
merged 151 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 147 commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
d56ecea
WIP towards refactoring target properties
lhstrh Sep 1, 2023
092d9ff
More work in progress
lhstrh Sep 16, 2023
15368c7
Incremental changes
lhstrh Sep 25, 2023
62f6d29
More refactoring
lhstrh Sep 27, 2023
ce8199a
Checkpoint after fixing most issues in TargetProperty
lhstrh Sep 27, 2023
413f8a1
Fixes and cleanups
lhstrh Sep 27, 2023
159b94a
Various fixes
lhstrh Sep 28, 2023
022a0b1
Merge branch 'master' into target-properties
lhstrh Sep 28, 2023
39b0161
Apply formatter
lhstrh Sep 28, 2023
3eb35de
Some fixes and a fixme
lhstrh Sep 28, 2023
a3531a1
fix NPE
cmnrd Sep 28, 2023
b7b457d
IntelliJ code suggestions
cmnrd Sep 28, 2023
c617b49
fix error reporting on estructural elements
cmnrd Sep 28, 2023
ed6d91b
correctly list all the valid target properties
cmnrd Sep 28, 2023
20d911b
null safety
cmnrd Sep 28, 2023
8bee8f7
Merge branch 'master' into target-properties
cmnrd Sep 28, 2023
b3e6d96
Fix conflict
lhstrh Sep 28, 2023
a22550b
Minor bugfixes
lhstrh Sep 29, 2023
44abb6b
Only generate docker when enabled
lhstrh Sep 29, 2023
43479be
clean up build types, no need for a separate config class
cmnrd Sep 29, 2023
d9a05a0
cleanup
cmnrd Sep 29, 2023
1760afc
Minor fixes
lhstrh Sep 29, 2023
341912d
Fix docker problem
lhstrh Sep 29, 2023
af92616
Another obscure nullcheck
lhstrh Sep 29, 2023
282b489
Remove negation
lhstrh Sep 29, 2023
dd2b6e8
Fix Rust issue
lhstrh Sep 29, 2023
79e3a6a
Point to epoch message-reporter branch
lhstrh Sep 30, 2023
3b216d8
Various bug fixes and improved, more localized error reporting
lhstrh Sep 30, 2023
20e7b3f
Apply formatter
lhstrh Sep 30, 2023
97a3924
Change CLI arg
lhstrh Sep 30, 2023
b560853
Adjust compiler CLI arg
lhstrh Oct 1, 2023
e98fc81
Improve API and add comments
lhstrh Oct 1, 2023
8703527
Address FIXME
lhstrh Oct 1, 2023
21ce2e4
Add comment
lhstrh Oct 1, 2023
c1b2ff7
Move TargetConfig class
lhstrh Oct 1, 2023
764bde2
Comments and minor changes
lhstrh Oct 1, 2023
f3aeb44
API rename
lhstrh Oct 1, 2023
1ec7765
Apply formatter
lhstrh Oct 1, 2023
881b4d6
Bugfix
lhstrh Oct 1, 2023
5194bf1
Fix another mysterious federated execution bug
lhstrh Oct 1, 2023
ba8b4d4
Typo fixes and address warning
lhstrh Oct 2, 2023
1dfa337
Fix state space explorer
lsk567 Oct 2, 2023
8e4feee
Fix rust tests
cmnrd Oct 2, 2023
f0b8186
fix Cpp build types
cmnrd Oct 2, 2023
1a31e11
fix test reports
cmnrd Oct 2, 2023
caa3bd8
map the Test build type to the debug cargo profile
cmnrd Oct 2, 2023
27a310b
move TargetProperty to org.lflang.target
cmnrd Oct 2, 2023
be85c7d
unify handling of C++ target properties
cmnrd Oct 2, 2023
aefe79f
fix test reporting
cmnrd Oct 2, 2023
ae16b45
fix "Test" build type for C++ on Windows
cmnrd Oct 2, 2023
0dce26a
create a cargo profile for LF tests
cmnrd Oct 2, 2023
845d32d
formatting
cmnrd Oct 2, 2023
f31c331
add changes to checked in Cargo.toml
cmnrd Oct 2, 2023
ce25d75
compare the value of the property, not the property
cmnrd Oct 2, 2023
b23f028
cleanup
cmnrd Oct 2, 2023
dbcc17f
build profile tests don't work, as we overwrite the profile to Test
cmnrd Oct 2, 2023
df803f6
cleanup
cmnrd Oct 2, 2023
2322dfd
keepalive is not supported in C++ anymore
cmnrd Oct 2, 2023
1370097
fast works fine with physical actions in C++
cmnrd Oct 2, 2023
6961686
rust also supports threading
cmnrd Oct 2, 2023
9362bb8
externa-runtime-path and runtime-version are supported by Rust
cmnrd Oct 2, 2023
66933e4
properly report unknown platforms
cmnrd Oct 2, 2023
6a85ee0
Address review comment
lhstrh Oct 2, 2023
5d499c8
Address another review comment
lhstrh Oct 2, 2023
876491c
Remove copypasta
lhstrh Oct 2, 2023
2a046f1
Debugging
lhstrh Oct 2, 2023
237b506
Mostly formatting
lhstrh Oct 2, 2023
f30a57f
Proof of concept of target properties without enum
lhstrh Oct 2, 2023
ec56234
Removal of enums
lhstrh Oct 3, 2023
45b31b8
Bugfixes and improvements in the handling of types
lhstrh Oct 4, 2023
2d47aeb
Custom types for composite target properties
lhstrh Oct 4, 2023
769afbd
More bugfixes
lhstrh Oct 4, 2023
8da3147
Fix unit tests
lhstrh Oct 4, 2023
902aa01
Redesign based on feedback from @oowekyala
lhstrh Oct 5, 2023
9aec152
Further refactoring. Next: fixes and cleanup.
lhstrh Oct 5, 2023
2c98113
Move Rust target properties
lhstrh Oct 6, 2023
23d65a5
Fix more failing unit tests
lhstrh Oct 13, 2023
a3effa1
Add missing hierarhical-bin target property
lhstrh Oct 13, 2023
062f31d
More fixes
lhstrh Oct 14, 2023
de53b8f
Fixes that illustrate the trouble with modifiable target properties. …
lhstrh Oct 15, 2023
f1f1735
API improvements
lhstrh Oct 15, 2023
f02ff3f
Address immutability exceptions
lhstrh Oct 15, 2023
32101a3
More immutability exceptions
lhstrh Oct 15, 2023
e4c3e06
More fixes
lhstrh Oct 16, 2023
1fc2af5
Fix compile definitions
lhstrh Oct 16, 2023
75e0c7f
Fixed CmakeInclude handling
lhstrh Oct 16, 2023
499e158
Address another FIXME
lhstrh Oct 16, 2023
a90f44e
Further refactoring
lhstrh Oct 16, 2023
7a63360
Address FIXME
lhstrh Oct 16, 2023
99c4cd1
Apply formatter
lhstrh Oct 16, 2023
c5ebef7
Merge pull request #2039 from lf-lang/stateless-target-properties
lhstrh Oct 16, 2023
409b72d
Merge branch 'master' into target-properties
lhstrh Oct 16, 2023
5134a47
Fix merge artifacts
lhstrh Oct 16, 2023
b802c78
Start registering target properties in code generator
lhstrh Oct 16, 2023
3e061d3
Apply formatter
lhstrh Oct 16, 2023
ea73eba
Adjustments to ensure proper initialization of the target config
lhstrh Oct 16, 2023
46eb4f9
Moved more property initializations
lhstrh Oct 17, 2023
f311534
Fix build problem
lhstrh Oct 17, 2023
2159a1e
Fix broken unit test
lhstrh Oct 17, 2023
d8a9ac8
More progress towards moving target property registration
lhstrh Oct 17, 2023
5d89828
Move registration of remaining target properties to Target class
lhstrh Oct 17, 2023
33dc1b1
Fixes to deal with PythonGenerator accessing (through CGenerator) pro…
lhstrh Oct 17, 2023
b131cba
Fix compilation
lhstrh Oct 17, 2023
47686d4
Minor fixes
lhstrh Oct 17, 2023
50e3780
Undo refactoring of CCmakeGenerator because its just too far gone
lhstrh Oct 18, 2023
3a7da58
More fixes
lhstrh Oct 18, 2023
0d5a49e
Move no-runtime-validation target property to cpp
lhstrh Oct 18, 2023
10ca8d7
Add auth to TypeScript
lhstrh Oct 18, 2023
b5c45f2
Add getOrDefault method as convenience
lhstrh Oct 18, 2023
e3926fc
Missed another get
lhstrh Oct 18, 2023
39588e6
Different way of addressing entanglement of Python and C codegen
lhstrh Oct 18, 2023
077e577
Resolving more Python/C issues
lhstrh Oct 18, 2023
a92232e
Fix issue that was masked by #1859; fixed #1859
lhstrh Oct 18, 2023
48f791c
Fix unit tests
lhstrh Oct 18, 2023
6b0637a
Move registration to main constructor
lhstrh Oct 18, 2023
6958d73
Only copy cmake includes if set
lhstrh Oct 18, 2023
3eaae53
Bring back reverted Python fix
lhstrh Oct 18, 2023
7223686
Fix bug that prevented files from being copied
lhstrh Oct 19, 2023
d889a9c
Address fixme
lhstrh Oct 19, 2023
3fd6519
Handling of JSON input
lhstrh Oct 29, 2023
82cc552
Merge branch 'master' into target-properties
lhstrh Oct 29, 2023
960f1ba
Minor fixes
lhstrh Oct 29, 2023
38f3377
Added missing class
lhstrh Oct 29, 2023
8a8c929
Fix merge artifact
lhstrh Oct 29, 2023
db5646d
Check for null
lhstrh Oct 30, 2023
5f74a13
Use release build type for Py/Win
lhstrh Oct 30, 2023
cab78d4
Set args before using them
lhstrh Oct 30, 2023
6df9434
Try building with Release again
lhstrh Oct 30, 2023
264393e
Bugfix and output useful for debugging
lhstrh Oct 30, 2023
78e992e
Minor fixes
lhstrh Oct 30, 2023
8cf3849
Reload after reconfiguration
lhstrh Oct 30, 2023
6fdf065
Attempt to fix threading problems in Python target
lhstrh Oct 30, 2023
79059cb
Python: Generated after-delay use mutex on env-struct
erlingrj Oct 30, 2023
d447e34
Use threading by default in Python
lhstrh Oct 30, 2023
c96a794
Clean up dealings with target configurations and transformation in th…
lhstrh Oct 31, 2023
9bca9a0
Fix NPE
lhstrh Oct 31, 2023
5ba0835
Exclude enclave tests from singleThreaded tests
lhstrh Oct 31, 2023
6d9b8d6
Merge branch 'master' into target-properties
lhstrh Oct 31, 2023
90eefeb
Zephyr tests: Do not touch the tracing parameter. Compile, but dont r…
erlingrj Oct 31, 2023
f69c705
Apply formatter
lhstrh Oct 31, 2023
8018f7f
Moved TargetProperty class and added validation for tracing target pr…
lhstrh Nov 1, 2023
06d575f
Point workflow back to Epoch master
lhstrh Nov 1, 2023
1287024
Address FIXME
lhstrh Nov 1, 2023
9603e4c
Revise GeneratorArguments and deal with JSON
lhstrh Nov 3, 2023
b0ba0b4
Add Argument class
lhstrh Nov 3, 2023
df817ee
Fix unit test
lhstrh Nov 3, 2023
b0bc88d
Update core/src/main/java/org/lflang/validation/LFValidator.java
lhstrh Nov 3, 2023
180ee52
Cleanup
lhstrh Nov 3, 2023
2b94c5d
Add back tests that were accidentally deleted
lhstrh Nov 3, 2023
335d028
Apply formatter
lhstrh Nov 3, 2023
a9f60c3
Do not touch build type of tests that explicitly set it
lhstrh Nov 3, 2023
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
4 changes: 2 additions & 2 deletions .github/scripts/run-zephyr-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ num_successes=0
num_failures=0
failed_tests=""

# Skip
skip=("FileReader" "FilePkgReader" "Tracing" "ThreadedThreaded")
# Skip tests doing file IO and tracing
skip=("FileReader" "FilePkgReader" "Tracing" "ThreadedThreaded" "CountTest" "AsyncCallback")

find_kconfig_folders() {
if [ -f "$folder/CMakeLists.txt" ]; then
Expand Down
156 changes: 78 additions & 78 deletions cli/base/src/main/java/org/lflang/cli/CliBase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.lflang.cli;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
Expand All @@ -17,8 +16,6 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
Expand Down Expand Up @@ -62,22 +59,21 @@ static class MutuallyExclusive {
protected List<Path> files;

@Option(names = "--json", description = "JSON object containing CLI arguments.")
private String jsonString;
String jsonString;

@Option(names = "--json-file", description = "JSON file containing CLI arguments.")
private Path jsonFile;
Path jsonFile;

@Option(names = "--stdin", description = "Read paths to Lingua Franca programs from stdin.")
private boolean stdin;
}

@ArgGroup(exclusive = true, multiplicity = "1")
@ArgGroup(multiplicity = "1")
MutuallyExclusive topLevelArg;

@Option(
names = {"-o", "--output-path"},
defaultValue = "",
fallbackValue = "",
description = "Specify the root output directory.")
private Path outputPath;

Expand All @@ -99,6 +95,8 @@ static class MutuallyExclusive {
/** Injected resource validator. */
@Inject private IResourceValidator validator;

private JsonObject jsonObject;

protected static void cliMain(
String toolName, Class<? extends CliBase> toolClass, Io io, String[] args) {
// Injector used to obtain Main instance.
Expand All @@ -123,27 +121,7 @@ public void doExecute(Io io, String[] args) {
* the Runnable interface, is instantiated.
*/
public void run() {
// If args are given in a json file, store its contents in jsonString.
if (topLevelArg.jsonFile != null) {
try {
topLevelArg.jsonString =
new String(Files.readAllBytes(io.getWd().resolve(topLevelArg.jsonFile)));
} catch (IOException e) {
reporter.printFatalErrorAndExit("No such file: " + topLevelArg.jsonFile);
}
}
// If args are given in a json string, unpack them and re-run
// picocli argument validation.
if (topLevelArg.jsonString != null) {
// Unpack args from json string.
String[] args = jsonStringToArgs(topLevelArg.jsonString);
// Execute application on unpacked args.
CommandLine cmd = spec.commandLine();
cmd.execute(args);
// If args are already unpacked, invoke tool-specific logic.
} else {
doRun();
}
doRun();
}

/*
Expand Down Expand Up @@ -183,6 +161,24 @@ protected List<Path> getInputPaths() {
}
if (line == null) return List.of();
return List.of(Path.of(line));
} else if (topLevelArg.jsonFile != null || topLevelArg.jsonString != null) {
paths = new ArrayList<>();
var filesObj = getJsonObject().get("src");
if (filesObj != null) {
if (filesObj.isJsonPrimitive()) {
paths = List.of(Path.of(filesObj.getAsString()));
} else if (filesObj.isJsonArray()) {
paths =
filesObj.getAsJsonArray().asList().stream()
.map(e -> Path.of(e.getAsString()))
.toList();
} else {
reporter.printFatalErrorAndExit(
"JSON Parse Exception: field \"src\" must be a string or an array of strings.");
}
} else {
reporter.printFatalErrorAndExit("JSON Parse Exception: field \"src\" not found.");
}
} else {
paths = topLevelArg.files.stream().map(io.getWd()::resolve).collect(Collectors.toList());
}
Expand All @@ -196,6 +192,29 @@ protected List<Path> getInputPaths() {
return paths;
}

protected final JsonObject getJsonObject() {
if (jsonObject != null) {
return jsonObject;
}
var jsonString = topLevelArg.jsonString;
// If args are given in a json file, store its contents in jsonString.
if (topLevelArg.jsonFile != null) {
try {
jsonString = new String(Files.readAllBytes(io.getWd().resolve(topLevelArg.jsonFile)));
} catch (IOException e) {
reporter.printFatalErrorAndExit("No such file: " + topLevelArg.jsonFile);
}
}
if (jsonString != null) {
try {
jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
} catch (JsonParseException e) {
messageReporter.nowhere().error(String.format("Invalid JSON string:%n %s", jsonString));
}
}
return jsonObject;
}

protected final boolean stdinMode() {
return topLevelArg.stdin;
}
Expand All @@ -207,23 +226,39 @@ protected final boolean stdinMode() {
*/
protected Path getOutputRoot() {
Path root = null;
Path path = null;

if (!outputPath.toString().isEmpty()) {
path = outputPath;
} else {
var json = getJsonObject();
if (json != null) {
var obj = json.get("out");
if (obj != null) {
path = Path.of(obj.getAsString());
}
}
}

if (path != null) {
root = io.getWd().resolve(outputPath).normalize();
if (!Files.exists(root)) { // FIXME: Create it instead?
if (!Files.exists(root)) {
reporter.printFatalErrorAndExit(root + ": Output location does not exist.");
}
if (!Files.isDirectory(root)) {
reporter.printFatalErrorAndExit(root + ": Output location is not a directory.");
}
}

return root;
}

/** If some errors were collected, print them and abort execution. Otherwise, return. */
protected void exitIfCollectedErrors() {
if (issueCollector.getErrorsOccurred()) {
// if there are errors, don't print warnings.

// Print warnings if there are any.
printWarningsIfAny();

List<LfIssue> errors = printErrorsIfAny();
String cause = errors.size() + " previous error";
if (errors.size() > 1) {
Expand All @@ -234,7 +269,18 @@ protected void exitIfCollectedErrors() {
}

/**
* If any errors were collected, print them, then return them.
* If any warnings were collected, print them, then return them.
*
* @return A list of collected warnings.
*/
public List<LfIssue> printWarningsIfAny() {
List<LfIssue> errors = issueCollector.getWarnings();
errors.forEach(reporter::printIssue);
return errors;
}

/**
* If any warnings were collected, print them, then return them.
*
* @return A list of collected errors.
*/
Expand Down Expand Up @@ -293,50 +339,4 @@ public Resource getResource(Path path) {
return null;
}
}

private String[] jsonStringToArgs(String jsonString) {
ArrayList<String> argsList = new ArrayList<>();
JsonObject jsonObject = new JsonObject();

// Parse JSON string and get top-level JSON object.
try {
jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
} catch (JsonParseException e) {
reporter.printFatalErrorAndExit(String.format("Invalid JSON string:%n %s", jsonString));
}
// Append input paths.
JsonElement src = jsonObject.get("src");
if (src == null) {
reporter.printFatalErrorAndExit("JSON Parse Exception: field \"src\" not found.");
}
assert src != null;
argsList.add(src.getAsString());
// Append output path if given.
JsonElement out = jsonObject.get("out");
if (out != null) {
argsList.add("--output-path");
argsList.add(out.getAsString());
}

// If there are no other properties, return args array.
JsonElement properties = jsonObject.get("properties");
if (properties != null) {
// Get the remaining properties.
Set<Entry<String, JsonElement>> entrySet = properties.getAsJsonObject().entrySet();
// Append the remaining properties to the args array.
for (Entry<String, JsonElement> entry : entrySet) {
String property = entry.getKey();
String value = entry.getValue().getAsString();

// Append option.
argsList.add("--" + property);
// Append argument for non-boolean options.
if (!value.equals("true") || property.equals("threading")) {
argsList.add(value);
}
}
}

return argsList.toArray(new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.inject.Inject;
import java.nio.file.Path;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.xtext.diagnostics.Severity;
import org.lflang.MessageReporterBase;
Expand All @@ -52,8 +53,9 @@ static Severity convertSeverity(DiagnosticSeverity severity) {
}

@Override
protected void reportOnNode(EObject node, DiagnosticSeverity severity, String message) {
issueAcceptor.accept(convertSeverity(severity), message, node, null, 0, null);
protected void reportOnNode(
EObject node, EStructuralFeature feature, DiagnosticSeverity severity, String message) {
issueAcceptor.accept(convertSeverity(severity), message, node, feature, 0, null);
}

@Override
Expand Down
10 changes: 7 additions & 3 deletions cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,21 @@ data class LfIssue(
@Singleton // one instance per injector
class IssueCollector {
private val map = mutableMapOf<Severity, MutableSet<LfIssue>>()
/** Whether any errors occurred.*/
/** Whether any errors occurred. */
val errorsOccurred: Boolean get() = map[Severity.ERROR]?.isNotEmpty() == true

fun accept(issue: LfIssue) {
val set = map.computeIfAbsent(issue.severity) { mutableSetOf() }
set += issue
}

/** Sorted list of all errors.*/
/** Sorted list of all errors. */
val errors: List<LfIssue> get() = map[Severity.ERROR].orEmpty().sorted()
/** Sorted list of all issues.*/

/** Sorted list of all warnings. */
val warnings: List<LfIssue> get() = map[Severity.WARNING].orEmpty().sorted()

/** Sorted list of all issues. */
val allIssues: List<LfIssue> get() = map.values.flatten().sorted()
}

Expand Down
Loading
Loading