Commit ef53c7bc authored by Evgeny Kusmenko's avatar Evgeny Kusmenko
Browse files

Merge branch 'OptionsFix' into 'master'

Options fix

See merge request !43
parents 0a9c6fbd afb46548
Pipeline #363129 passed with stages
in 7 minutes and 9 seconds
......@@ -4,6 +4,7 @@ package de.monticore.lang.monticar.emadl.generator;
import de.monticore.ModelingLanguageFamily;
import de.monticore.io.paths.ModelPath;
import de.monticore.lang.embeddedmontiarc.LogConfig;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathLanguage;
import de.monticore.lang.embeddedmontiarc.helper.ConstantPortHelper;
import de.monticore.lang.monticar.emadl._symboltable.EMADLLanguage;
import de.monticore.lang.monticar.emadl.tagging.dltag.DataPathTagSchema;
......@@ -54,6 +55,7 @@ public class EMADLAbstractSymtab {
EMADLLanguage montiArcLanguage = new EMADLLanguage();
fam.addModelingLanguage(montiArcLanguage);
fam.addModelingLanguage(new EmbeddedMontiArcMathLanguage());
fam.addModelingLanguage(new StreamUnitsLanguage());
fam.addModelingLanguage(new StructLanguage());
fam.addModelingLanguage(new EnumLangLanguage());
......
......@@ -32,10 +32,7 @@ import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.MathCommandRegister;
import de.monticore.lang.monticar.generator.cmake.CMakeConfig;
import de.monticore.lang.monticar.generator.cmake.CMakeFindModule;
import de.monticore.lang.monticar.generator.cpp.ArmadilloHelper;
import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
import de.monticore.lang.monticar.generator.cpp.SimulatorIntegrationHelper;
import de.monticore.lang.monticar.generator.cpp.TypesGeneratorCPP;
import de.monticore.lang.monticar.generator.cpp.*;
import de.monticore.lang.monticar.generator.cpp.converter.TypeConverter;
import de.monticore.lang.monticar.generator.pythonwrapper.GeneratorPythonWrapperFactory;
import de.monticore.lang.monticar.generator.pythonwrapper.GeneratorPythonWrapperStandaloneApi;
......@@ -43,9 +40,12 @@ import de.monticore.lang.monticar.generator.pythonwrapper.symbolservices.data.Co
import de.monticore.lang.tagging._symboltable.TagSymbol;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.Names;
import de.se_rwth.commons.Splitters;
import de.se_rwth.commons.logging.Log;
import freemarker.template.TemplateException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import javax.xml.bind.DatatypeConverter;
import java.io.*;
......@@ -62,7 +62,7 @@ import java.util.stream.Collectors;
public class EMADLGenerator implements EMAMGenerator {
private boolean generateCMake = true;
private boolean generateCMake = false;
private CMakeConfig cMakeConfig = new CMakeConfig("");
private GeneratorCPP emamGen;
private CNNArchGenerator cnnArchGenerator;
......@@ -125,12 +125,20 @@ public class EMADLGenerator implements EMAMGenerator {
generateFiles(symtab, instance, pythonPath, forced);
if (doCompile) {
if (!generateCMake) // do it either way
generateCMakeFiles(instance);
compile();
}
processedArchitecture = null;
}
private EMAComponentInstanceSymbol resolveComponentInstanceSymbol(String qualifiedName, TaggingResolver symtab) {
String simpleName = Names.getSimpleName(qualifiedName);
if (!Character.isUpperCase(simpleName.charAt(0))) {
String packageName = qualifiedName.substring(0, qualifiedName.length() - simpleName.length() - 1);
qualifiedName = Names.getQualifiedName(packageName, StringUtils.capitalize(simpleName));
}
EMAComponentSymbol component = symtab.<EMAComponentSymbol>resolve(qualifiedName, EMAComponentSymbol.KIND).orElse(null);
List<String> splitName = Splitters.DOT.splitToList(qualifiedName);
......@@ -151,7 +159,11 @@ public class EMADLGenerator implements EMAMGenerator {
public void compile() throws IOException {
File tempScript = createTempScript();
try {
ProcessBuilder pb = new ProcessBuilder("bash", tempScript.toString());
ProcessBuilder pb;
if (!SystemUtils.IS_OS_WINDOWS)
pb = new ProcessBuilder("bash", tempScript.toString());
else
pb = new ProcessBuilder("cmd", tempScript.toString());
pb.inheritIO();
Process process = pb.start();
int returnCode = process.waitFor();
......@@ -169,21 +181,41 @@ public class EMADLGenerator implements EMAMGenerator {
public File createTempScript() throws IOException{
File tempScript = File.createTempFile("script", null);
try{
Writer streamWriter = new OutputStreamWriter(new FileOutputStream(
tempScript));
PrintWriter printWriter = new PrintWriter(streamWriter);
printWriter.println("#!/bin/bash");
printWriter.println("cd " + getGenerationTargetPath());
printWriter.println("mkdir -p build");
printWriter.println("cd build");
printWriter.println("cmake ..");
printWriter.println("make");
printWriter.close();
}catch(Exception e){
System.out.println(e);
if (!SystemUtils.IS_OS_WINDOWS) {
try {
Writer streamWriter = new OutputStreamWriter(new FileOutputStream(
tempScript));
PrintWriter printWriter = new PrintWriter(streamWriter);
printWriter.println("#!/bin/bash");
printWriter.println("cd " + getGenerationTargetPath());
printWriter.println("mkdir -p build");
printWriter.println("cd build");
printWriter.println("rm -r -f *");
printWriter.println("cmake ..");
printWriter.println("make");
printWriter.close();
} catch (Exception e) {
System.out.println(e);
}
} else {
try {
Writer streamWriter = new OutputStreamWriter(new FileOutputStream(
tempScript));
PrintWriter printWriter = new PrintWriter(streamWriter);
printWriter.println("cd " + getGenerationTargetPath());
printWriter.println("if exist build del /F /Q /S build");
printWriter.println("mkdir build");
printWriter.println("cd build");
printWriter.println("cmake ..");
printWriter.println("cmake --build . --config release");
printWriter.close();
} catch (Exception e) {
System.out.println(e);
}
}
return tempScript;
......@@ -391,11 +423,20 @@ public class EMADLGenerator implements EMAMGenerator {
}
List<FileContent> fileContents = new ArrayList<>();
// Add Helpers
if (emamGen.usesArmadilloBackend()) {
fileContents.add(ArmadilloHelper.getArmadilloHelperFileContent());
}
emamGen.searchForCVEverywhere(componentInstanceSymbol, taggingResolver);
if (emamGen.isGenerateCV) {
fileContents.add(ConversionHelper.getConversionHelperFileContent(emamGen.isGenerateTests()));
}
processedArchitecture = new HashMap<>();
generateComponent(fileContents, allInstances, taggingResolver, componentInstanceSymbol);
String instanceName = componentInstanceSymbol.getComponentType().getFullName().replaceAll("\\.", "_");
fileContents.addAll(generateCNNTrainer(allInstances, instanceName));fileContents.add(ArmadilloHelper.getArmadilloHelperFileContent());
fileContents.addAll(generateCNNTrainer(allInstances, instanceName));
TypesGeneratorCPP tg = new TypesGeneratorCPP();
fileContents.addAll(tg.generateTypes(TypeConverter.getTypeSymbols()));
......@@ -858,28 +899,23 @@ public class EMADLGenerator implements EMAMGenerator {
}
private void mergeCMakeConfigs() {
List<String> cmakeCommandList = emamGen.getCMakeConfig().getCMakeListsViewModel().getCmakeCommandList();
List<String> cmakeCommandListEnd = emamGen.getCMakeConfig().getCMakeListsViewModel().getCmakeCommandListEnd();
List<String> cmakeLibraryLinkageList = emamGen.getCMakeConfig().getCMakeListsViewModel().getCmakeLibraryLinkageList();
LinkedHashSet<CMakeFindModule> moduleDependencies = emamGen.getCMakeConfig().getCMakeListsViewModel().getModuleDependencies();
// merge
emamGen.getCmakeConfig().getCMakeListsViewModel().getCmakeCommandList()
.stream().forEach(s -> cMakeConfig.addCMakeCommand(s));
emamGen.getCmakeConfig().getCMakeListsViewModel().getCmakeCommandListEnd()
.stream().forEach(s -> cMakeConfig.addCMakeCommandEnd(s));
emamGen.getCmakeConfig().getCMakeListsViewModel().getCmakeLibraryLinkageList()
.stream().forEach(s -> cMakeConfig.addCmakeLibraryLinkage(s));
emamGen.getCmakeConfig().getCMakeListsViewModel().getModuleDependencies()
.stream().forEach(s -> cMakeConfig.addModuleDependency(s));
cnnArchGenerator.getCmakeConfig().getCMakeListsViewModel().getCmakeCommandList()
.stream().filter(s -> !cmakeCommandList.contains(s))
.forEach(s -> cmakeCommandList.add(s));
.stream().forEach(s -> cMakeConfig.addCMakeCommand(s));
cnnArchGenerator.getCmakeConfig().getCMakeListsViewModel().getCmakeCommandListEnd()
.stream().filter(s -> !cmakeCommandListEnd.contains(s))
.forEach(s -> cmakeCommandListEnd.add(s));
.stream().forEach(s -> cMakeConfig.addCMakeCommandEnd(s));
cnnArchGenerator.getCmakeConfig().getCMakeListsViewModel().getCmakeLibraryLinkageList()
.stream().filter(s -> !cmakeLibraryLinkageList.contains(s))
.forEach(s -> cmakeLibraryLinkageList.add(s));
.stream().forEach(s -> cMakeConfig.addCmakeLibraryLinkage(s));
cnnArchGenerator.getCmakeConfig().getCMakeListsViewModel().getModuleDependencies()
.stream().filter(s -> !moduleDependencies.contains(s))
.forEach(s -> moduleDependencies.add(s));
cMakeConfig.getCMakeListsViewModel().setCmakeCommandList(cmakeCommandList);
cMakeConfig.getCMakeListsViewModel().setCmakeCommandListEnd(cmakeCommandListEnd);
cMakeConfig.getCMakeListsViewModel().setCmakeLibraryLinkageList(cmakeLibraryLinkageList);
cMakeConfig.getCMakeListsViewModel().setModuleDependencies(moduleDependencies);
.stream().forEach(s -> cMakeConfig.addModuleDependency(s));
}
@Override
......
......@@ -4,11 +4,16 @@ package de.monticore.lang.monticar.emadl.generator;
import de.se_rwth.commons.logging.Log;
import freemarker.template.TemplateException;
import org.apache.commons.cli.*;
import org.apache.commons.lang3.SystemUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import static de.monticore.lang.monticar.generator.cpp.GeneratorCppCli.*;
public class EMADLGeneratorCli {
public static final Option OPTION_MODELS_PATH = Option.builder("m")
......@@ -27,7 +32,8 @@ public class EMADLGeneratorCli {
public static final Option OPTION_OUTPUT_PATH = Option.builder("o")
.longOpt("output-dir")
.desc("full path to output directory for tests e.g. C:\\Users\\vpupkin\\proj\\MyAwesomeAutopilot\\target\\gen-cpp")
.desc("full path to output directory for tests e.g. C:\\Users\\vpupkin\\proj\\MyAwesomeAutopilot\\target\\gen-cpp\n" +
"default is ./target/generated-sources-emadl/")
.hasArg(true)
.required(false)
.build();
......@@ -41,7 +47,7 @@ public class EMADLGeneratorCli {
public static final Option OPTION_TRAINING_PYTHON_PATH = Option.builder("p")
.longOpt("python")
.desc("path to python. Default is /usr/bin/python")
.desc("path to python. Default is /usr/bin/python, or python (PATH) for windows")
.hasArg(true)
.required(false)
.build();
......@@ -55,7 +61,7 @@ public class EMADLGeneratorCli {
public static final Option OPTION_COMPILE = Option.builder("c")
.longOpt("compile")
.desc("Compile the generated c code. Needs to be disabled eg. on Windows. Options: y (compile), n (don't compile). Default is y")
.desc("Compile the generated c code. Options: y (compile), n (don't compile). Default is y")
.hasArg(true)
.required(false)
.build();
......@@ -73,11 +79,21 @@ public class EMADLGeneratorCli {
}
}
private static Options getOptions() {
public static Options getOptions() {
Options options = new Options();
options.addOption(OPTION_MODELS_PATH);
options.addOption(OPTION_ROOT_MODEL);
options.addOption(OPTION_OUTPUT_PATH);
options.addOption(OPTION_FLAG_TESTS);
options.addOption(OPTION_FLAG_ARMADILLO);
options.addOption(OPTION_FLAG_AUTOPILOT_ADAPTER);
options.addOption(OPTION_FLAG_CHECK_MODEL_DIR);
options.addOption(OPTION_FLAG_SERVER_WRAPPER);
options.addOption(OPTION_FLAG_ALGEBRAIC);
options.addOption(OPTION_FLAG_THREADING);
options.addOption(OPTION_FLAG_EXEC_LOGGING);
options.addOption(OPTION_FLAG_CMAKE);
options.addOption(OPTION_BACKEND);
options.addOption(OPTION_RESTRAINED_TRAINING);
options.addOption(OPTION_TRAINING_PYTHON_PATH);
......@@ -85,6 +101,14 @@ public class EMADLGeneratorCli {
return options;
}
// Add EMADL Options
public static void addEMADL2CPPOptions(Options options) {
options.addOption(OPTION_BACKEND);
options.addOption(OPTION_RESTRAINED_TRAINING);
options.addOption(OPTION_TRAINING_PYTHON_PATH);
options.addOption(OPTION_COMPILE);
}
private static CommandLine parseArgs(Options options, CommandLineParser parser, String[] args) {
CommandLine cliArgs;
try {
......@@ -120,14 +144,14 @@ public class EMADLGeneratorCli {
}
if (pythonPath == null) {
pythonPath = "/usr/bin/python";
pythonPath = SystemUtils.IS_OS_WINDOWS ? "python" : "/usr/bin/python";
}
if (forced == null) {
forced = DEFAULT_FORCED;
}
else if (!forced.equals("y") && !forced.equals("n")) {
Log.error("specified setting ("+forced+") for forcing/preventing training not supported. set to default value " + DEFAULT_FORCED);
Log.warn("specified setting ("+forced+") for forcing/preventing training not supported. set to default value " + DEFAULT_FORCED);
forced = DEFAULT_FORCED;
}
......@@ -137,13 +161,38 @@ public class EMADLGeneratorCli {
compile = DEFAULT_COMPILE;
}
else if(!compile.equals("y") && !compile.equals("n")) {
Log.error("specified setting ("+compile+") for skipping the compilation not supported. set to default value " + DEFAULT_COMPILE);
Log.warn("specified setting ("+compile+") for skipping the compilation not supported. set to default value " + DEFAULT_COMPILE);
compile = DEFAULT_COMPILE;
}
if (outputPath != null){
generator.setGenerationTargetPath(outputPath);
}
generator.setGenerateCMake(true);
// EMAM2CPP options
Path modelsDirPath = Paths.get(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()));
generator.getEmamGen().setUseAlgebraicOptimizations(false);
generator.getEmamGen().setUseThreadingOptimization(false);
generator.getEmamGen().setModelsDirPath(modelsDirPath);
// generator.getEmamGen().setGenerationTargetPath(outputPath); // done by EMADLGenerator
generator.getEmamGen().setGenerateTests(cliArgs.hasOption(OPTION_FLAG_TESTS.getOpt()));
if (cliArgs.hasOption(OPTION_FLAG_ARMADILLO.getOpt())) {
generator.getEmamGen().useArmadilloBackend();
}
generator.getEmamGen().setCheckModelDir(cliArgs.hasOption(OPTION_FLAG_CHECK_MODEL_DIR.getLongOpt()));
generator.getEmamGen().setGenerateServerWrapper(cliArgs.hasOption(OPTION_FLAG_SERVER_WRAPPER.getLongOpt()));
generator.getEmamGen().setGenerateAutopilotAdapter(cliArgs.hasOption(OPTION_FLAG_AUTOPILOT_ADAPTER.getLongOpt()));
generator.getEmamGen().setUseAlgebraicOptimizations(cliArgs.hasOption(OPTION_FLAG_ALGEBRAIC.getLongOpt()));
generator.getEmamGen().setUseThreadingOptimization(cliArgs.hasOption(OPTION_FLAG_THREADING.getLongOpt()));
generator.getEmamGen().setExecutionLoggingActive(cliArgs.hasOption(OPTION_FLAG_EXEC_LOGGING.getLongOpt()));
generator.getEmamGen().setGenerateCMake(cliArgs.hasOption(OPTION_FLAG_CMAKE.getLongOpt()));
// end EMAM2CPP options
try{
generator.generate(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()), rootModelName, pythonPath, forced, compile.equals("y"));
}
......
......@@ -11,10 +11,6 @@ find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional library linkage
......
......@@ -11,10 +11,6 @@ find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional library linkage
......
......@@ -11,10 +11,6 @@ find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional library linkage
......
......@@ -11,10 +11,6 @@ find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional library linkage
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment