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

FileConfig cleanups #978

Merged
merged 34 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
26c0a34
Merge branch 'master' into fileconfig-cleanup
cmnrd Feb 25, 2022
6020548
avoid the copy constructor in FileConfig
cmnrd Feb 25, 2022
1e164d7
move cleanIfNeeded to generator base
cmnrd Feb 25, 2022
574dadc
remove unused function from GeneratorBase
cmnrd Feb 25, 2022
8f87e15
move Mode enum to LFGeneratorContext (where it is used)
cmnrd Feb 25, 2022
58f1427
don't use fileConfig.context in code generators
cmnrd Feb 25, 2022
dea2128
remove dependency on context from EclipseErrorReporter
cmnrd Feb 25, 2022
ce23d5b
remove context from FileConfig
cmnrd Feb 25, 2022
b7c27ca
fix test code
cmnrd Feb 25, 2022
2ca537e
delete unused functions
cmnrd Feb 25, 2022
462e062
avoid federation specific code in FileConfig
cmnrd Feb 25, 2022
f5e6d32
move C-specific function deleteBinFiles() to CUtil
cmnrd Feb 25, 2022
d93657e
bugfix
cmnrd Feb 25, 2022
3610b66
Create new class FileUtil and move some methods from FileConfig
cmnrd Feb 25, 2022
b972a6d
make various copy methods static
cmnrd Feb 25, 2022
8b00182
move all copy methods to FileUtil
cmnrd Feb 25, 2022
1bc3210
copyUserFiles is only ever used in the CGenerator...
cmnrd Feb 25, 2022
3dd7033
move C specific FileUtil functions to CUtil
cmnrd Feb 25, 2022
e246f92
move getIResource methods to FileUtil
cmnrd Feb 25, 2022
4313e3f
remove redundant getName()
cmnrd Feb 25, 2022
4e01e55
getSubPkgPath should not be static
cmnrd Feb 25, 2022
7ae443e
fix diagrams
cmnrd Feb 25, 2022
7609663
files is only used in C, CCpp and Python
cmnrd Feb 25, 2022
51e0aad
automatically add the src directory to the C++ includes
cmnrd Feb 25, 2022
98f8abb
copy user files before invoking proto-c
cmnrd Feb 25, 2022
7f30061
uncomment copyUserFiles
cmnrd Feb 25, 2022
21ab9a9
revert an accidental change
cmnrd Feb 26, 2022
18a968e
Merge branch 'master' into fileconfig-cleanup
cmnrd Feb 28, 2022
6d9168a
port changes to the Python generator
cmnrd Feb 28, 2022
ce4b600
move methods for file writing to FileUtil
cmnrd Feb 28, 2022
a7e8f50
rename JavaGeneratorUtils -> GeneratorUtils
cmnrd Feb 28, 2022
6e40eea
Merge branch 'master' into fileconfig-cleanup
cmnrd Feb 28, 2022
b12df01
fix compilation error in tests
cmnrd Feb 28, 2022
18df2e7
Merge remote-tracking branch 'origin/master' into fileconfig-cleanup
cmnrd Mar 2, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
import org.lflang.lf.Connection;
import org.lflang.lf.Model;
import org.lflang.lf.Reactor;
import org.lflang.util.FileUtil;

/**
* Diagram synthesis for Lingua Franca programs.
Expand Down Expand Up @@ -985,7 +986,7 @@ private String createReactorLabel(ReactorInstance reactorInstance) {
}
if (reactorInstance.isMainOrFederated()) {
try {
b.append(FileConfig.nameWithoutExtension(reactorInstance.reactorDeclaration.eResource()));
b.append(FileUtil.nameWithoutExtension(reactorInstance.reactorDeclaration.eResource()));
} catch (Exception e) {
throw Exceptions.sneakyThrow(e);
}
Expand Down
6 changes: 3 additions & 3 deletions org.lflang.lfc/src/org/lflang/lfc/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import org.lflang.FileConfig;
import org.lflang.LFRuntimeModule;
import org.lflang.LFStandaloneSetup;
import org.lflang.TargetConfig.Mode;
import org.lflang.generator.LFGeneratorContext;
import org.lflang.generator.MainContext;
import org.lflang.util.FileUtil;

import com.google.inject.Inject;
import com.google.inject.Injector;
Expand Down Expand Up @@ -285,7 +285,7 @@ private void runGenerator(List<Path> files, Injector injector) {
exitIfCollectedErrors();

LFGeneratorContext context = new MainContext(
Mode.STANDALONE,CancelIndicator.NullImpl, (m, p) -> {}, properties, false,
LFGeneratorContext.Mode.STANDALONE, CancelIndicator.NullImpl, (m, p) -> {}, properties, false,
fileConfig -> injector.getInstance(ErrorReporter.class)
);

Expand Down Expand Up @@ -346,7 +346,7 @@ public Resource getValidatedResource(Path path) {
issueCollector.accept(new LfIssue(issue.getMessage(), issue.getSeverity(),
issue.getLineNumber(), issue.getColumn(),
issue.getLineNumberEnd(), issue.getColumnEnd(),
issue.getLength(), FileConfig.toPath(uri)));
issue.getLength(), FileUtil.toPath(uri)));
} catch (IOException e) {
reporter.printError("Unable to convert '" + uri + "' to path." + e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.eclipse.xtext.validation.EObjectDiagnosticImpl;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;

import org.lflang.FileConfig;
import org.lflang.util.FileUtil;

import com.google.inject.Inject;

Expand Down Expand Up @@ -57,7 +57,7 @@ void accept(Severity severity, String message, EObject object, EStructuralFeatur
private Path getPath(EObjectDiagnosticImpl diagnostic) {
Path file = null;
try {
file = FileConfig.toPath(diagnostic.getUriToProblem());
file = FileUtil.toPath(diagnostic.getUriToProblem());
} catch (IOException e) {
// just continue with null
}
Expand Down
4 changes: 2 additions & 2 deletions org.lflang.tests/src/org/lflang/tests/Configurators.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface Configurator {
* @return True if successful, false otherwise.
*/
public static boolean useSingleThread(LFTest test) {
test.getContext().getArgs().setProperty("threads", "0");
test.context.getArgs().setProperty("threads", "0");
return true;
}

Expand All @@ -63,7 +63,7 @@ public static boolean useSingleThread(LFTest test) {
* @return True if successful, false otherwise.
*/
public static boolean useFourThreads(LFTest test) {
test.getContext().getArgs().setProperty("threads", "4");
test.context.getArgs().setProperty("threads", "4");
return true;
}

Expand Down
11 changes: 3 additions & 8 deletions org.lflang.tests/src/org/lflang/tests/LFTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class LFTest implements Comparable<LFTest> {
/** Object used to determine where the code generator puts files. */
public FileConfig fileConfig;

/** Context provided to the code generators */
public LFGeneratorContext context;

/** Path of the test program relative to the package root. */
private final Path relativePath;

Expand Down Expand Up @@ -113,14 +116,6 @@ public boolean hasFailed() {
return result != Result.TEST_PASS;
}

/**
* Return the context stored in this test's file configuration.
* @return The context for this test, to be passed to the code generator.
*/
public LFGeneratorContext getContext() {
return this.fileConfig.context;
}

/**
* Compile a string that contains all collected errors and return it.
* @return A string that contains all collected errors.
Expand Down
10 changes: 5 additions & 5 deletions org.lflang.tests/src/org/lflang/tests/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.lflang.LFRuntimeModule;
import org.lflang.LFStandaloneSetup;
import org.lflang.Target;
import org.lflang.TargetConfig.Mode;
import org.lflang.generator.GeneratorResult;
import org.lflang.generator.LFGenerator;
import org.lflang.generator.LFGeneratorContext;
Expand Down Expand Up @@ -366,7 +365,7 @@ private static void checkAndReportFailures(Set<LFTest> tests) {
*/
private LFGeneratorContext configure(LFTest test, Configurator configurator, TestLevel level) throws IOException {
var context = new MainContext(
Mode.STANDALONE, CancelIndicator.NullImpl, (m, p) -> {}, new Properties(), true,
LFGeneratorContext.Mode.STANDALONE, CancelIndicator.NullImpl, (m, p) -> {}, new Properties(), true,
fileConfig -> new DefaultErrorReporter()
);

Expand All @@ -380,7 +379,8 @@ private LFGeneratorContext configure(LFTest test, Configurator configurator, Tes
}

fileAccess.setOutputPath(FileConfig.findPackageRoot(test.srcFile, s -> {}).resolve(FileConfig.DEFAULT_SRC_GEN_DIR).toString());
test.fileConfig = new FileConfig(r, FileConfig.getSrcGenRoot(fileAccess), context);
test.context = context;
test.fileConfig = new FileConfig(r, FileConfig.getSrcGenRoot(fileAccess), context.useHierarchicalBin());

// Set the no-compile flag the test is not supposed to reach the build stage.
if (level.compareTo(TestLevel.BUILD) < 0) {
Expand Down Expand Up @@ -437,8 +437,8 @@ protected void addExtraLfcArgs(Properties args) {
private GeneratorResult generateCode(LFTest test) {
GeneratorResult result = GeneratorResult.NOTHING;
if (test.fileConfig.resource != null) {
generator.doGenerate(test.fileConfig.resource, fileAccess, test.fileConfig.context);
result = test.fileConfig.context.getResult();
generator.doGenerate(test.fileConfig.resource, fileAccess, test.context);
result = test.context.getResult();
if (generator.errorsOccurred()) {
test.result = Result.CODE_GEN_FAIL;
throw new AssertionError("Code generation unsuccessful.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ private void runTest(SchedulerOption scheduler, EnumSet<TestCategory> categories
Message.DESC_SCHED_SWAPPING + scheduler.toString() +".",
categories::contains,
test -> {
test.getContext()
.getArgs()
test.context.getArgs()
.setProperty(
"scheduler",
scheduler.toString()
Expand Down
Loading