Commit dbe8fba1 authored by Jean Meurice's avatar Jean Meurice
Browse files

CLI options merge

parents b820d0b8 1c3a9400
Pipeline #366115 failed with stage
in 67 minutes and 19 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 java.io.*;
import java.nio.charset.Charset;
......@@ -61,7 +61,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;
......@@ -124,14 +124,22 @@ 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) {
//EMAComponentSymbol component = symtab.<EMAComponentSymbol>resolve(qualifiedName, EMAComponentSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol component = symtab.<EMAComponentInstanceSymbol>resolve(qualifiedName, EMAComponentInstanceSymbol.KIND).orElse(null);
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);
String componentName = splitName.get(splitName.size() - 1);
String instanceName = componentName.substring(0, 1).toLowerCase() + componentName.substring(1);
......@@ -150,7 +158,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();
......@@ -168,21 +180,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;
......@@ -398,11 +430,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()));
......@@ -865,28 +906,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
......
......@@ -5,30 +5,21 @@ import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
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;
public class EMADLGeneratorCli {
public static final Option OPTION_MODELS_PATH = Option.builder("m")
.longOpt("models-dir")
.desc("full path to directory with EMADL models e.g. C:\\Users\\vpupkin\\proj\\MyAwesomeAutopilot\\src\\main\\emam")
.hasArg(true)
.required(true)
.build();
import static de.monticore.lang.monticar.generator.cpp.GeneratorCppCli.*;
public static final Option OPTION_ROOT_MODEL = Option.builder("r")
.longOpt("root-model")
.desc("fully qualified name of the root model e.g. de.rwth.vpupkin.modeling.mySuperAwesomeAutopilotComponent")
.hasArg(true)
.required(true)
.build();
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();
......@@ -42,7 +33,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();
......@@ -56,46 +47,12 @@ 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();
public static final Option OPTION_FLAG_DYNAMIC_INTERFACE = Option.builder("di")
.longOpt("dyn-interface")
.desc("Enable autopilot adapter generation")
.hasArg(false)
.required(false)
.build();
public static final Option OPTION_FLAG_GEN_TCP_SERVER = Option.builder("tcp")
.longOpt("tcp-adapter")
.desc("Generate the TCP-Server adapter for the model")
.hasArg(false)
.required(false)
.build();
public static final Option OPTION_FLAG_GEN_DDC_ADAPTER = Option.builder("ddc")
.longOpt("ddc-adapter")
.desc("Generate the DDC adapter for the model")
.hasArg(false)
.required(false)
.build();
public static final Option OPTION_IMPORT_ARMADILLO = Option.builder()
.longOpt("armadillo-import")
.desc("If enabled, the project will include Armadillo for compilation based on the ARMADILLO_PATH environment variable")
.hasArg(false)
.required(false)
.build();
public static final Option OPTION_OUTPUT_NAME = Option.builder("n")
.longOpt("output-name")
.desc("Name for the dynamic-interface or server adapter.")
.hasArg(true)
.required(false)
.build();
private EMADLGeneratorCli() {
}
......@@ -108,21 +65,20 @@ 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);
addBaseOptions(options);
addEMAM2CPPOptions(options);
addEMADL2CPPOptions(options);
return options;
}
// Add EMADL2CPP 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);
options.addOption(OPTION_IMPORT_ARMADILLO);
options.addOption(OPTION_FLAG_GEN_TCP_SERVER);
options.addOption(OPTION_FLAG_GEN_DDC_ADAPTER);
options.addOption(OPTION_FLAG_DYNAMIC_INTERFACE);
options.addOption(OPTION_OUTPUT_NAME);
return options;
}
private static CommandLine parseArgs(Options options, CommandLineParser parser, String[] args) {
......@@ -160,14 +116,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;
}
......@@ -177,7 +133,7 @@ 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;
}
......@@ -185,13 +141,35 @@ public class EMADLGeneratorCli {
generator.setGenerationTargetPath(outputPath);
}
generator.setGenerateCMake(true);
// EMAM2CPP options
GeneratorCPP emamGen = generator.getEmamGen();
Path modelsDirPath = Paths.get(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()));
emamGen.setUseAlgebraicOptimizations(false);
emamGen.setUseThreadingOptimization(false);
emamGen.setModelsDirPath(modelsDirPath);
// emamGen.setGenerationTargetPath(outputPath); // done by EMADLGenerator
emamGen.setGenerateTests(cliArgs.hasOption(OPTION_FLAG_TESTS.getOpt()));
emamGen.setImportArmadillo(cliArgs.hasOption(OPTION_IMPORT_ARMADILLO.getLongOpt()));
emamGen.setGenerateDynamicInterface(cliArgs.hasOption(OPTION_FLAG_DYNAMIC_INTERFACE.getLongOpt()));
emamGen.setGenerateServerAdapter(cliArgs.hasOption(OPTION_FLAG_GEN_TCP_SERVER.getLongOpt()));
emamGen.setGenerateDDCAdapter(cliArgs.hasOption(OPTION_FLAG_GEN_DDC_ADAPTER.getLongOpt()));
emamGen.setOutputName(cliArgs.getOptionValue(OPTION_OUTPUT_NAME.getOpt()));
emamGen.useArmadilloBackend();
if (cliArgs.hasOption(OPTION_FLAG_ARMADILLO.getOpt())) {
emamGen.useArmadilloBackend();
}
emamGen.setCheckModelDir(cliArgs.hasOption(OPTION_FLAG_CHECK_MODEL_DIR.getLongOpt()));
emamGen.setGenerateServerWrapper(cliArgs.hasOption(OPTION_FLAG_SERVER_WRAPPER.getLongOpt()));
emamGen.setUseAlgebraicOptimizations(cliArgs.hasOption(OPTION_FLAG_ALGEBRAIC.getLongOpt()));
emamGen.setUseThreadingOptimization(cliArgs.hasOption(OPTION_FLAG_THREADING.getLongOpt()));
emamGen.setExecutionLoggingActive(cliArgs.hasOption(OPTION_FLAG_EXEC_LOGGING.getLongOpt()));
emamGen.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