Add cli option: writeTagFile to write Middleware tags into .tag file when generating

parent 1eaa0622
Pipeline #99070 failed with stages
in 60 minutes
......@@ -91,6 +91,7 @@ Schema of config json:
'rootModel':'<fully qualified name of the root model>',
'generators':['<identifier for first generator>', '<identifier for second generator>',...],
'emadlBackend':'<deep-learning-framework backend. Options: MXNET, CAFFE2>'
'writeTagFile':[ 'true' | 'false'(default) ] Writes a .tag file with all Middleware tags into the generated code
}
```
Generator Options:
......
......@@ -3,25 +3,26 @@ package de.monticore.lang.monticar.generator.middleware;
import java.util.Set;
public class CliParameters {
private static final boolean DEFAULT_WRITE_TAG_FILE = false;
private static final String DEFAULT_EMADL_BACKEND = "MXNET";
private String modelsDir;
private String outputDir;
private String rootModel;
private Set<String> generators;
private String emadlBackend;
private Boolean writeTagFile;
public CliParameters() {
}
public CliParameters(String modelsDir, String outputDir, String rootModel, Set<String> generators) {
this(modelsDir, outputDir, rootModel, generators, "MXNET");
}
public CliParameters(String modelsDir, String outputDir, String rootModel, Set<String> generators, String emadlBackend) {
public CliParameters(String modelsDir, String outputDir, String rootModel, Set<String> generators, String emadlBackend, Boolean writeTagFile) {
this.modelsDir = modelsDir;
this.outputDir = outputDir;
this.rootModel = rootModel;
this.generators = generators;
this.emadlBackend = emadlBackend;
this.emadlBackend = emadlBackend == null ? DEFAULT_EMADL_BACKEND : emadlBackend;
this.writeTagFile = writeTagFile == null ? DEFAULT_WRITE_TAG_FILE : writeTagFile;
}
public String getModelsDir() {
......@@ -43,4 +44,8 @@ public class CliParameters {
public String getEmadlBackend() {
return emadlBackend;
}
public boolean getWriteTagFile() {
return writeTagFile;
}
}
......@@ -5,7 +5,6 @@ import com.google.gson.stream.JsonReader;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema;
import de.monticore.lang.monticar.emadl.generator.EMADLAbstractSymtab;
import de.monticore.lang.monticar.emadl.generator.EMADLGeneratorCli;
import de.monticore.lang.monticar.generator.middleware.impls.CPPGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.EMADLGeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.impls.ODVGenImpl;
......@@ -14,7 +13,6 @@ import de.monticore.lang.monticar.generator.order.simulator.AbstractSymtab;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.cli.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
......@@ -24,7 +22,6 @@ import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
public final class DistributedTargetGeneratorCli {
......@@ -36,6 +33,7 @@ public final class DistributedTargetGeneratorCli {
" 'rootModel':'<fully qualified name of the root model>',\n" +
" 'generators':['<identifier for first generator>', '<identifier for second generator>',...],\n" +
" 'emadlBackend':'<deep-learning-framework backend. Options: MXNET, CAFFE2>'\n" +
" 'writeTagFile':[ 'true' | 'false'(default) ] Writes a .tag file with all Middleware tags into the generated code\n" +
"}\n\n" +
"Generator Options:\n" +
"Behaviour generators:\n" +
......@@ -115,6 +113,7 @@ public final class DistributedTargetGeneratorCli {
DistributedTargetGenerator generator = new DistributedTargetGenerator();
generator.setGenerationTargetPath(cliParameters.getOutputDir());
generator.setGenerateMiddlewareTags(cliParameters.getWriteTagFile());
Set<String> validGenNames = getGeneratorNames();
......
......@@ -14,6 +14,7 @@ import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
......@@ -30,10 +31,10 @@ public class CliTest {
public static final String RESNET_MODELNAME = "tests.emadlTests.resNet34";
private String buildParameterJson(String modelsDir, String rootModel, Collection<String> generators, String outputDir) {
return buildParameterJson(modelsDir, rootModel, generators, outputDir, null);
return buildParameterJson(modelsDir, rootModel, generators, outputDir, null, false);
}
private String buildParameterJson(String modelsDir, String rootModel, Collection<String> generators, String outputDir, String emadlBackend) {
private String buildParameterJson(String modelsDir, String rootModel, Collection<String> generators, String outputDir, String emadlBackend, boolean writeTagFile) {
String result = "{";
result += "'modelsDir': '" + modelsDir + "', ";
result += "'rootModel': '" + rootModel + "', ";
......@@ -41,7 +42,7 @@ public class CliTest {
if (emadlBackend != null) {
result += "'emadlBackend': '" + emadlBackend + "', ";
}
result += "'writeTagFile':'" + writeTagFile + "',";
result += "'outputDir': '" + outputDir + "'";
result += "}";
return result;
......@@ -132,7 +133,8 @@ public class CliTest {
RESNET_MODELNAME,
Arrays.asList("emadlcpp"),
targetDir,
"MXNET");
"MXNET",
false);
DistributedTargetGeneratorCli.main(new String[]{"-r", json});
......@@ -151,7 +153,8 @@ public class CliTest {
RESNET_MODELNAME,
Arrays.asList("emadlcpp","roscpp"),
targetDir,
"MXNET");
"MXNET",
false);
DistributedTargetGeneratorCli.main(new String[]{"-r", json});
String[] positiveFileNames = getEMADLGeneratedFilesList(true);
......@@ -282,6 +285,37 @@ public class CliTest {
assertTrue(logContains("0x6444B"));
}
@Test
public void testWriteTagFile() {
String targetDir="target/cliTest/TagFile/";
String json = buildParameterJson(
VALID_MODELS_DIR_OPTION,
VALID_ROOT_MODEL_OPTION,
VALID_GENERATOR_ALL_OPTION,
targetDir,
null,
true);
DistributedTargetGeneratorCli.main(new String[]{"-r", json});
assertTrue(Files.exists(Paths.get(targetDir, "emam","RosConnections.tag")));
}
@Test
public void testWriteTagFileDisabled() {
String targetDir="target/cliTest/TagFileDisabled/";
String json = buildParameterJson(
VALID_MODELS_DIR_OPTION,
VALID_ROOT_MODEL_OPTION,
VALID_GENERATOR_ALL_OPTION,
targetDir,
null,
false);
DistributedTargetGeneratorCli.main(new String[]{"-r", json});
assertFalse(Files.exists(Paths.get(targetDir, "emam","RosConnections.tag")));
}
private boolean logContains(String errorCode) {
return LogConfig.getFindings().stream().map(Finding::getMsg).anyMatch(msg -> msg.contains(errorCode));
......
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