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

Bugfixes in handling of files target property #1725

Merged
merged 20 commits into from
May 5, 2023
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
3 changes: 2 additions & 1 deletion org.lflang/src/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ protected void setReactorsAndInstantiationGraph(LFGeneratorContext.Mode mode) {
* @param fileConfig The fileConfig used to make the copy and resolve paths.
*/
protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) {
FileUtil.copyFiles(targetConfig.files, this.context.getFileConfig().getSrcGenPath(), fileConfig, errorReporter);
var dst = this.context.getFileConfig().getSrcGenPath();
FileUtil.copyFilesOrDirectories(targetConfig.files, dst, fileConfig, errorReporter, false);
}

/**
Expand Down
36 changes: 19 additions & 17 deletions org.lflang/src/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,6 @@ protected boolean isOSCompatible() {
"LF programs with a CCpp target are currently not supported on Windows. " +
"Exiting code generation."
);
// FIXME: The incompatibility between our C runtime code and the
// Visual Studio compiler is extensive.
return false;
}
}
Expand Down Expand Up @@ -830,7 +828,7 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) {
// Must use class variable to determine destination!
var destination = this.fileConfig.getSrcGenPath();

FileUtil.copyFiles(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter);
FileUtil.copyFilesOrDirectories(targetConfig.cmakeIncludes, destination, fileConfig, errorReporter, true);

// FIXME: Unclear what the following does, but it does not appear to belong here.
if (!StringExtensions.isNullOrEmpty(targetConfig.fedSetupPreamble)) {
Expand Down Expand Up @@ -883,10 +881,11 @@ private void generateReactorDefinitions() throws IOException {
/** Generate user-visible header files for all reactors instantiated. */
private void generateHeaders() throws IOException {
FileUtil.deleteDirectory(fileConfig.getIncludePath());
FileUtil.copyDirectoryFromClassPath(
FileUtil.copyFromClassPath(
fileConfig.getRuntimeIncludePath(),
fileConfig.getIncludePath(),
false
false,
true
);
for (Reactor r : reactors) {
CReactorHeaderFileGenerator.doGenerate(
Expand All @@ -904,7 +903,7 @@ private void generateHeaders() throws IOException {
},
this::generateTopLevelPreambles);
}
FileUtil.copyDirectory(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false);
FileUtil.copyDirectoryContents(fileConfig.getIncludePath(), fileConfig.getSrcGenPath().resolve("include"), false);
}

/**
Expand Down Expand Up @@ -960,36 +959,39 @@ protected void copyTargetFiles() throws IOException {
Path dest = fileConfig.getSrcGenPath();
if (targetConfig.platformOptions.platform == Platform.ARDUINO) dest = dest.resolve("src");
if (coreLib != null) {
FileUtil.copyDirectory(Path.of(coreLib), dest, true);
FileUtil.copyDirectoryContents(Path.of(coreLib), dest, true);
} else {
FileUtil.copyDirectoryFromClassPath(
FileUtil.copyFromClassPath(
"/lib/c/reactor-c/core",
dest.resolve("core"),
true
dest,
true,
false
);
FileUtil.copyDirectoryFromClassPath(
FileUtil.copyFromClassPath(
"/lib/c/reactor-c/lib",
dest.resolve("lib"),
true
dest,
true,
false
);
}

// For the Zephyr target, copy default config and board files.
if (targetConfig.platformOptions.platform == Platform.ZEPHYR) {
FileUtil.copyDirectoryFromClassPath(
FileUtil.copyFromClassPath(
"/lib/platform/zephyr/boards",
fileConfig.getSrcGenPath().resolve("boards"),
fileConfig.getSrcGenPath(),
false,
false
);
FileUtil.copyFileFromClassPath(
"/lib/platform/zephyr/prj_lf.conf",
fileConfig.getSrcGenPath().resolve("prj_lf.conf"),
fileConfig.getSrcGenPath(),
true
);

FileUtil.copyFileFromClassPath(
"/lib/platform/zephyr/Kconfig",
fileConfig.getSrcGenPath().resolve("Kconfig"),
fileConfig.getSrcGenPath(),
true
);
}
Expand Down
11 changes: 5 additions & 6 deletions org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
package org.lflang.generator.cpp

import org.eclipse.emf.ecore.resource.Resource
import org.lflang.ErrorReporter
import org.lflang.Target
import org.lflang.generator.CodeMap
import org.lflang.generator.GeneratorBase
Expand Down Expand Up @@ -127,22 +126,22 @@ class CppGenerator(
// copy static library files over to the src-gen directory
val genIncludeDir = srcGenPath.resolve("__include__")
listOf("lfutil.hh", "time_parser.hh").forEach {
FileUtil.copyFileFromClassPath("$libDir/$it", genIncludeDir.resolve(it), true)
FileUtil.copyFileFromClassPath("$libDir/$it", genIncludeDir, true)
}
FileUtil.copyFileFromClassPath(
"$libDir/3rd-party/cxxopts.hpp",
genIncludeDir.resolve("CLI").resolve("cxxopts.hpp"),
true
)
genIncludeDir.resolve("CLI"),
true)

// copy or download reactor-cpp
if (targetConfig.externalRuntimePath == null) {
if (targetConfig.runtimeVersion != null) {
fetchReactorCpp()
} else {
FileUtil.copyDirectoryFromClassPath(
FileUtil.copyFromClassPath(
"$libDir/reactor-cpp",
fileConfig.srcGenBasePath.resolve("reactor-cpp-default"),
true,
true
)
}
Expand Down
23 changes: 12 additions & 11 deletions org.lflang/src/org/lflang/generator/python/PythonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.xbase.lib.Exceptions;

Expand All @@ -56,7 +55,6 @@
import org.lflang.generator.c.CGenerator;
import org.lflang.generator.c.CUtil;
import org.lflang.lf.Action;
import org.lflang.lf.Code;
import org.lflang.lf.Input;
import org.lflang.lf.Model;
import org.lflang.lf.Output;
Expand Down Expand Up @@ -661,20 +659,23 @@ private static String generatePythonFileName(String lfModuleName) {
@Override
protected void copyTargetFiles() throws IOException {
super.copyTargetFiles();
FileUtil.copyDirectoryFromClassPath(
FileUtil.copyFromClassPath(
"/lib/py/reactor-c-py/include",
fileConfig.getSrcGenPath().resolve("include"),
true
fileConfig.getSrcGenPath(),
true,
false
);
FileUtil.copyDirectoryFromClassPath(
FileUtil.copyFromClassPath(
"/lib/py/reactor-c-py/lib",
fileConfig.getSrcGenPath().resolve("lib"),
true
fileConfig.getSrcGenPath(),
true,
false
);
FileUtil.copyDirectoryFromClassPath(
FileUtil.copyFromClassPath(
"/lib/py/reactor-c-py/LinguaFrancaBase",
fileConfig.getSrcGenPath().resolve("LinguaFrancaBase"),
true
fileConfig.getSrcGenPath(),
true,
false
);
}

Expand Down
2 changes: 1 addition & 1 deletion org.lflang/src/org/lflang/generator/rust/RustEmitter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ object RustEmitter : RustEmitterBase() {
for (modPath in gen.crate.modulesToIncludeInMain) {
val target = fileConfig.srcGenPath.resolve("src").resolve(modPath.fileName)
if (Files.isDirectory(modPath)) {
FileUtil.copyDirectory(modPath, target)
FileUtil.copyDirectoryContents(modPath, target)
} else {
FileUtil.copyFile(modPath, target)
}
Expand Down
21 changes: 6 additions & 15 deletions org.lflang/src/org/lflang/generator/ts/TSGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import org.lflang.scoping.LFGlobalScopeProvider
import org.lflang.util.FileUtil
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.util.*

private const val NO_NPM_MESSAGE = "The TypeScript target requires npm >= 6.14.4. " +
Expand All @@ -61,7 +60,7 @@ class TSGenerator(


val fileConfig: TSFileConfig = context.fileConfig as TSFileConfig
var devMode = false;
private var devMode = false

companion object {

Expand Down Expand Up @@ -188,8 +187,6 @@ class TSGenerator(
val manifest = fileConfig.srcGenPath.resolve("package.json");
val rtRegex = Regex("(\"@lf-lang/reactor-ts\")(.+)")
if (rtPath != null) rtPath = formatRuntimePath(rtPath)
// FIXME: do better CLI arg validation upstream
// https://github.com/lf-lang/lingua-franca/issues/1429
if (rtPath != null || rtVersion != null) {
devMode = true;
}
Expand Down Expand Up @@ -223,19 +220,13 @@ class TSGenerator(
* as the source file, copy a default version from $LIB_PATH/.
*/
private fun copyConfigFiles() {
FileUtil.copyFromClassPath(LIB_PATH, fileConfig.srcGenPath, true, true)
for (configFile in CONFIG_FILES) {
val configFileDest = fileConfig.srcGenPath.resolve(configFile)
val configFileInSrc = fileConfig.srcPath.resolve(configFile)
if (configFileInSrc.toFile().exists()) {
println("Copying $configFileInSrc to $configFileDest")
Files.createDirectories(configFileDest.parent)
Files.copy(configFileInSrc, configFileDest, StandardCopyOption.REPLACE_EXISTING)
var override = FileUtil.findAndCopyFile(configFile, fileConfig.srcGenPath, fileConfig);
if (override != null) {
System.out.println("Using user-provided '" + override + "'");
} else {
println(
"No '" + configFile + "' exists in " + fileConfig.srcPath +
". Using default configuration."
)
FileUtil.copyFileFromClassPath("$LIB_PATH/$configFile", configFileDest)
System.out.println("Using default '" + configFile + "'");
}
}
}
Expand Down
Loading