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

Improved handling of files target property #2333

Merged
merged 8 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 0 additions & 2 deletions core/src/main/java/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ public void doGenerate(Resource resource, LFGeneratorContext context) {
}

// Process target files. Copy each of them into the src-gen dir.
// FIXME: Should we do this here? This doesn't make sense for federates the way it is
// done here.
copyUserFiles(this.targetConfig, context.getFileConfig());
lhstrh marked this conversation as resolved.
Show resolved Hide resolved

// Collect reactors and create an instantiation graph.
Expand Down
22 changes: 20 additions & 2 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.target.property.DockerProperty;
import org.lflang.target.property.FedSetupProperty;
import org.lflang.target.property.FileListProperty;
import org.lflang.target.property.LoggingProperty;
import org.lflang.target.property.NoCompileProperty;
import org.lflang.target.property.NoSourceMappingProperty;
Expand Down Expand Up @@ -582,6 +583,7 @@ private void generateCodeFor(String lfModuleName) throws IOException {
code.pr(new CMainFunctionGenerator(targetConfig).generateCode());
// Generate code for each reactor.
generateReactorDefinitions();
copyUserFiles(targetConfig, fileConfig);

// Generate main instance, if there is one.
// Note that any main reactors in imported files are ignored.
Expand Down Expand Up @@ -710,7 +712,8 @@ private void inspectReactorEResource(ReactorDecl reactor) {
if (lfResource != null) {
var config = lfResource.getTargetConfig();
// FIXME: this should not happen here, but once, after collecting all the files.
copyUserFiles(config, lfResource.getFileConfig());
// copyUserFiles(config, lfResource.getFileConfig());
byeonggiljun marked this conversation as resolved.
Show resolved Hide resolved
String basePath = lfResource.getFileConfig().srcPath.toString();

var pairs = convertToEmptyListIfNull(config.extractTargetDecl().getConfig().getPairs());
pairs.forEach(
Expand All @@ -719,7 +722,22 @@ private void inspectReactorEResource(ReactorDecl reactor) {
if (p.isPresent()) {
var property = p.get();
if (property.loadFromImport()) {
property.update(this.targetConfig, pair, messageReporter);
if (property instanceof FileListProperty) {
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
var list = (List<?>) config.get(p.get());
List<String> paths = new ArrayList<>();
for (var s : list) {
if (s instanceof String) {
Path path = Paths.get((String) s);
if (!path.isAbsolute()) {
path = Paths.get(basePath, path.toString());
}
paths.add(path.toString());
}
}
((FileListProperty) property).update(this.targetConfig, paths);
} else {
property.update(this.targetConfig, pair, messageReporter);
}
}
}
});
Expand Down
Loading