Implemented: struct_msgs are now generated and correctly linked

parent cec7af95
......@@ -5,12 +5,16 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Expanded
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.MiddlewareSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.RosConnectionSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.TemplateHelper;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.impls.RosMsgImpl;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
import de.monticore.lang.monticar.generator.rosmsg.RosMsg;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
......@@ -18,9 +22,11 @@ import java.util.*;
public class DistributedTargetGenerator extends CMakeGenerator {
private RosMsgImpl rosMsgImpl;
private Set<String> subDirs = new HashSet<>();
public DistributedTargetGenerator() {
rosMsgImpl = new RosMsgImpl("rosmsg");
rosMsgImpl = new RosMsgImpl("struct_msgs");
//this.add(rosMsgImpl,"rosmsg/");
}
......@@ -55,20 +61,26 @@ public class DistributedTargetGenerator extends CMakeGenerator {
List<File> files = new ArrayList<>();
CMakeGenerator cmakeListsGenerator = new CMakeGenerator();
cmakeListsGenerator.setGenerationTargetPath(generationTargetPath);
subDirs.add("rosMsg");
for (ExpandedComponentInstanceSymbol comp : generatorMap.keySet()) {
files.addAll(generatorMap.get(comp).generate(comp, taggingResolver));
//add empty generator to cmakeListsGenerator so that CMakeLists.txt will be generated
cmakeListsGenerator.add(new GeneratorImpl() {
}, comp.getFullName().replace(".", "_"));
//add empty generator to subDirs so that CMakeLists.txt will be generated correctly
subDirs.add(comp.getFullName().replace(".", "_"));
}
files.addAll(cmakeListsGenerator.generate(componentInstanceSymbol, taggingResolver));
files.addAll(rosMsgImpl.generate(componentInstanceSymbol, taggingResolver));
files.add(generateCMake());
files.add(generateRosMsgGen());
return files;
}
//TODO:refactor, dont always generate
private File generateRosMsgGen() throws IOException {
File file = new File(generationTargetPath + "rosMsg/CMakeLists.txt");
FileUtils.write(file, TemplateHelper.struct_msgsCmakeTemplate);
return file;
}
private GeneratorImpl createFullGenerator(String subdir) {
MiddlewareGenerator res = new MiddlewareGenerator();
res.setGenerationTargetPath(generationTargetPath + (subdir.endsWith("/") ? subdir : subdir + "/"));
......@@ -165,5 +177,27 @@ public class DistributedTargetGenerator extends CMakeGenerator {
return componentInstanceSymbol.getSubComponents();
}
//TODO: refactor
private File generateCMake() throws IOException {
FileContent fileContent = new FileContent();
fileContent.setFileName("CMakeLists.txt");
StringBuilder content = new StringBuilder();
content.append("cmake_minimum_required(VERSION 3.5)\n");
//TODO setProjectName?
content.append("project (default)\n");
content.append("set (CMAKE_CXX_STANDARD 11)\n");
subDirs.stream().filter(dir -> dir.equals("rosMsg")).forEach(
dir -> content.append("add_subdirectory(" + dir + ")\n")
);
subDirs.stream().filter(dir -> !dir.equals("rosMsg")).forEach(
dir -> content.append("add_subdirectory(" + dir + ")\n")
);
fileContent.setFileContent(content.toString());
return FileHelper.generateFile(generationTargetPath, fileContent);
}
}
......@@ -132,4 +132,31 @@ public class TemplateHelper {
"target_link_libraries(DummyAdapter_${compName} ${compName})\n" +
"target_include_directories(DummyAdapter_${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\n" +
"export(TARGETS DummyAdapter_${compName} FILE DummyAdapter_${compName}.cmake)";
public static String struct_msgsCmakeTemplate =
"cmake_minimum_required(VERSION 3.5)\n" +
"project (struct_msgs)\n" +
"\n" +
"find_package(genmsg REQUIRED)\n" +
"\n" +
"FILE(GLOB MSG_FILES_RAW RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ../*/roscpp/struct_msgs/*.msg)\n" +
"\n" +
"#generate struct_msgs iff .msg files where found\n" +
"if(MSG_FILES_RAW)\n" +
" #filter: add each struct msg only once (distinct by filename without path)\n" +
" foreach(CUR_MSG_FILE ${MSG_FILES_RAW})\n" +
" get_filename_component(TMP_MSG_NAME ${CUR_MSG_FILE} NAME)\n" +
" IF(NOT MSG_DEFINED_${TMP_MSG})\n" +
" LIST(APPEND MSG_FILES ${CUR_MSG_FILE})\n" +
" SET(MSG_DEFINED_${TMP_MSG} TRUE)\n" +
" ENDIF()\n" +
" endforeach(CUR_MSG_FILE)\n" +
"\n" +
" #generate messages\n" +
" add_message_files(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} FILES ${MSG_FILES})\n" +
" generate_messages()\n" +
"\n" +
" #export the include_dirs, so that other subprojects can use it\n" +
" set(struct_msgs_INCLUDE_DIRS ${struct_msgs_INCLUDE_DIRS} PARENT_SCOPE)\n" +
"endif()\n";
}
......@@ -10,7 +10,6 @@ import de.monticore.lang.monticar.generator.middleware.impls.DummyMiddlewareSymb
import de.monticore.lang.monticar.generator.middleware.impls.RosCppGenImpl;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
......@@ -99,8 +98,6 @@ public class GenerationTest extends AbstractSymtabTest {
distributedTargetGenerator.generate(componentInstanceSymbol, taggingResolver);
}
//TODO: implement feature
@Ignore
@Test
public void testDistributedStructTargetGenerator() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
......
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