Add post source path check(e.g. check for msbuild after calling vcvars64.bat)

parent 870c9b91
Pipeline #106131 passed with stages
in 9 minutes and 31 seconds
......@@ -115,7 +115,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
.filter(CompilationGenerator::isValid)
.forEach(g -> {
try {
res.add(FileHelper.generateFile(generationTargetPath ,g.getCompilationScript()));
res.addAll(FileHelper.generateFiles(generationTargetPath ,g.getCompilationScripts()));
} catch (IOException e) {
Log.error("0xD4BAA: Error generating compile scripts!", e);
}
......
......@@ -69,6 +69,18 @@ public class BashCompilationGenerator extends CompilationGenerator {
return "\n";
}
@Override
protected List<String> getPostSourceExecutables() {
ArrayList<String> res = new ArrayList<>();
if(useRos()){
res.add("roscore");
}
if(useRos2()){
res.add("ros2");
}
return res;
}
@Override
protected List<String> getEnvironmentFiles() {
List<String> res = new ArrayList<>();
......
......@@ -3,6 +3,7 @@ package de.monticore.lang.monticar.generator.middleware.compile;
import de.monticore.lang.monticar.generator.FileContent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -12,9 +13,10 @@ public abstract class CompilationGenerator {
private boolean useRos2 = false;
public abstract boolean supportsRos();
public abstract boolean supportsRos2();
public boolean isValid(){
public boolean isValid() {
return (supportsRos() || !useRos()) && (supportsRos2() || !useRos2());
}
......@@ -48,26 +50,27 @@ public abstract class CompilationGenerator {
this.useRos2 = useRos2;
}
protected String fillPathTemplate(String newExe){
return getPathTemplate().replace("<new_exe>",newExe);
protected String fillPathTemplate(String newExe) {
return getPathTemplate().replace("<new_exe>", newExe);
}
protected String fillCheckExeTemplate(String exe){
return getCheckExeTemplate().replace("<exe>",exe);
protected String fillCheckExeTemplate(String exe) {
return getCheckExeTemplate().replace("<exe>", exe);
}
protected String fillSourceEnvVarsTemplate(String envFile){
return getSourceEnvVarsTemplate().replace("<env_file>",envFile);
protected String fillSourceEnvVarsTemplate(String envFile) {
return getSourceEnvVarsTemplate().replace("<env_file>", envFile);
}
protected String fillScriptTemplate(String additional_executables, String executable_checks, String additional_env){
protected String fillScriptTemplate(String additional_executables, String executable_checks, String additional_env, String post_executable_checks) {
return getScriptTemplate()
.replace("<additional_executables>",additional_executables)
.replace("<executable_checks>",executable_checks)
.replace("<additional_env>",additional_env);
.replace("<additional_executables>", additional_executables)
.replace("<executable_checks>", executable_checks)
.replace("<additional_env>", additional_env)
.replace("<post_executable_checks>", post_executable_checks);
}
public FileContent getCompilationScript(){
public List<FileContent> getCompilationScripts() {
FileContent res = new FileContent();
String additional_executables = getAdditionalPathDirs().stream()
.map(this::fillPathTemplate)
......@@ -81,17 +84,23 @@ public abstract class CompilationGenerator {
.map(this::fillSourceEnvVarsTemplate)
.collect(Collectors.joining(getNewlineDelimiter()));
String post_executable_checks = getPostSourceExecutables().stream()
.map(this::fillCheckExeTemplate)
.collect(Collectors.joining(getNewlineDelimiter()));
res.setFileName(getFileName());
res.setFileContent(fillScriptTemplate(additional_executables,executable_checks,additional_env));
res.setFileContent(fillScriptTemplate(additional_executables, executable_checks, additional_env, post_executable_checks));
return res;
return Arrays.asList(res);
}
protected abstract List<String> getPostSourceExecutables();
protected abstract List<String> getEnvironmentFiles();
protected abstract List<String> getExecutables();
public static List<CompilationGenerator> getInstanceOfAllGenerators(){
public static List<CompilationGenerator> getInstanceOfAllGenerators() {
List<CompilationGenerator> res = new ArrayList<>();
res.add(new BashCompilationGenerator());
res.add(new MingwCompilationGenerator());
......
......@@ -28,6 +28,11 @@ public class MingwCompilationGenerator extends WindowsCompilationGenerator {
return "compileMingw.bat";
}
@Override
protected List<String> getPostSourceExecutables() {
return new ArrayList<>();
}
@Override
protected List<String> getEnvironmentFiles() {
return new ArrayList<>();
......
......@@ -28,18 +28,28 @@ public class MsbuildCompilationGenerator extends WindowsCompilationGenerator {
return "compileMsbuild.bat";
}
@Override
protected List<String> getPostSourceExecutables() {
List<String> res = new ArrayList<>();
res.add("msbuild");
if(useRos2()){
res.add("ros2");
}
return res;
}
@Override
protected List<String> getEnvironmentFiles() {
List<String> res = new ArrayList<>();
res.add("vcvars64.bat");
if(useRos2()){
res.add("%ROS_HOME%\\local_setup.bat");
res.add("%ROS2_HOME%\\local_setup.bat");
}
return res;
}
@Override
protected List<String> getExecutables() {
return Arrays.asList("cmake","vcvars64.bat","msbuild");
return Arrays.asList("cmake","vcvars64.bat");
}
}
package de.monticore.lang.monticar.generator.middleware.compile;
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.roscpp.helper.NameHelper;
import java.util.ArrayList;
import java.util.List;
public abstract class WindowsCompilationGenerator extends CompilationGenerator {
private String PATH_TEMPLATE = "IF NOT [%<new_exe>_HOME%] == [] (\n" +
" set PATH=\"%<new_exe>_HOME%;%PATH%\"\n" +
......@@ -35,4 +43,22 @@ public abstract class WindowsCompilationGenerator extends CompilationGenerator {
public boolean supportsRos() {
return false;
}
private String fillSubstTemplate(String compileScript) {
return TemplateHelper.getSubstTemplate()
.replace("<compile_script>", compileScript);
}
@Override
public List<FileContent> getCompilationScripts() {
ArrayList<FileContent> fileContents = new ArrayList<>();
fileContents.addAll(super.getCompilationScripts());
FileContent substScript = new FileContent();
substScript.setFileName("subst" + getFileName().substring(0,1).toUpperCase() + getFileName().substring(1));
substScript.setFileContent(fillSubstTemplate(getFileName()));
fileContents.add(substScript);
return fileContents;
}
}
......@@ -7,6 +7,8 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class FileHelper {
......@@ -24,4 +26,12 @@ public class FileHelper {
bufferedWriter.close();
return f;
}
public static List<File> generateFiles(String targetPath, List<FileContent> fileContents) throws IOException {
ArrayList<File> files = new ArrayList<>();
for (FileContent fc : fileContents) {
files.add(generateFile(targetPath, fc));
}
return files;
}
}
......@@ -60,5 +60,9 @@ public class TemplateHelper {
return getTemplate("compileMsbuild.bat.template");
}
public static String getSubstTemplate(){
return getTemplate("subst.bat.template");
}
}
......@@ -4,16 +4,18 @@ set -e
# add *_HOME to PATH temporarily
<additional_executables>
# source additional environment variables
<additional_env>
# check if needed programs are in PATH
<executable_checks>
# source additional environment variables
<additional_env>
# Post source check if needed programs are in PATH
<post_executable_checks>
# cmake
curDir=`dirname "$0"`
cmake -B"$curDir"/build/ -H"$curDir/src" "$@"
# make
make -C "$curDir"
\ No newline at end of file
make -j4 -C "$curDir"
\ No newline at end of file
......@@ -2,16 +2,19 @@
:: add *_HOME to PATH temporarily
<additional_executables>
:: check if needed programs are in PATH
<executable_checks>
:: source additional environment variables
<additional_env>
:: check if needed programs are in PATH
<executable_checks>
:: Post source check if needed programs are in PATH
<post_executable_checks>
:: cmake
cmake -B./build/ -G "MinGW Makefiles" %* ./src
:: make
cd .\build
make
make -j4
cd ..
\ No newline at end of file
......@@ -2,16 +2,19 @@
:: add *_HOME to PATH temporarily
<additional_executables>
:: check if needed programs are in PATH
<executable_checks>
:: source additional environment variables
<additional_env>
:: check if needed programs are in PATH
<executable_checks>
:: Post source check if needed programs are in PATH
<post_executable_checks>
:: cmake
cmake -B./build/ -G "Visual Studio 15 2017 Win64" %* ./src
:: msbuild
cd .\build
msbuild /t:build /p:Configuration=Release ALL_BUILD.vcxproj
msbuild /m /t:build /p:Configuration=Release ALL_BUILD.vcxproj
cd ..
\ No newline at end of file
cmake_minimum_required(VERSION 3.5)
project (Coordinator_${compName} CXX)
project (Coordinator_${compName} LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 14)
set (THREADS_PREFER_PTHREAD_FLAG ON)
......
:: Substituting the current dir with a drive letter to bypass windows path length limit
:: Set environment variable EMA_SUBST_LETTER to change letter is used
:: Default is N
IF NOT [%EMA_SUBST_LETTER%] == [] (
set usedLetter=%EMA_SUBST_LETTER%
) else (
set usedLetter=N
)
set curDir=%~dp0
set curDir=%curDir:~0,-1%
subst /d %usedLetter%:
subst %usedLetter%: "%curDir%"
pushd .
cd /d %usedLetter%:
call <compile_script>
popd
subst /d %usedLetter%:
\ No newline at end of file
......@@ -16,10 +16,10 @@ public class CompilationGeneratorTest extends AbstractSymtabTest {
private static String OUT_BASE = "target/compileScripts/";
@Test
public void testBashWithRos() throws IOException {
public void testRos() throws IOException {
BashCompilationGenerator bashCompilationGenerator = new BashCompilationGenerator();
bashCompilationGenerator.setUseRos(true);
FileContent script = bashCompilationGenerator.getCompilationScript();
FileContent script = bashCompilationGenerator.getCompilationScripts().get(0);
assertEquals("compile.sh", script.getFileName());
File f1 = FileHelper.generateFile(OUT_BASE + "Ros/", script);
testFilesAreEqual(Arrays.asList(f1), "compileScripts/Ros/");
......@@ -28,17 +28,17 @@ public class CompilationGeneratorTest extends AbstractSymtabTest {
@Test
public void testNoRos() throws IOException {
BashCompilationGenerator bashCompilationGenerator = new BashCompilationGenerator();
FileContent script1 = bashCompilationGenerator.getCompilationScript();
FileContent script1 = bashCompilationGenerator.getCompilationScripts().get(0);
assertEquals("compile.sh", script1.getFileName());
File f1 = FileHelper.generateFile(OUT_BASE + "NoRos/", script1);
MingwCompilationGenerator mingwCompilationGenerator = new MingwCompilationGenerator();
FileContent script2 = mingwCompilationGenerator.getCompilationScript();
FileContent script2 = mingwCompilationGenerator.getCompilationScripts().get(0);
assertEquals("compileMingw.bat", script2.getFileName());
File f2 = FileHelper.generateFile(OUT_BASE + "NoRos/", script2);
MsbuildCompilationGenerator msbuildCompilationGenerator = new MsbuildCompilationGenerator();
FileContent script3 = msbuildCompilationGenerator.getCompilationScript();
FileContent script3 = msbuildCompilationGenerator.getCompilationScripts().get(0);
assertEquals("compileMsbuild.bat", script3.getFileName());
File f3 = FileHelper.generateFile(OUT_BASE + "NoRos/", script3);
......@@ -49,13 +49,13 @@ public class CompilationGeneratorTest extends AbstractSymtabTest {
public void testRos2() throws IOException {
BashCompilationGenerator bashCompilationGenerator = new BashCompilationGenerator();
bashCompilationGenerator.setUseRos2(true);
FileContent script1 = bashCompilationGenerator.getCompilationScript();
FileContent script1 = bashCompilationGenerator.getCompilationScripts().get(0);
assertEquals("compile.sh", script1.getFileName());
File f1 = FileHelper.generateFile(OUT_BASE + "Ros2/", script1);
MsbuildCompilationGenerator msbuildCompilationGenerator = new MsbuildCompilationGenerator();
msbuildCompilationGenerator.setUseRos2(true);
FileContent script3 = msbuildCompilationGenerator.getCompilationScript();
FileContent script3 = msbuildCompilationGenerator.getCompilationScripts().get(0);
assertEquals("compileMsbuild.bat", script3.getFileName());
File f2 = FileHelper.generateFile(OUT_BASE + "Ros2/", script3);
......
......@@ -11,9 +11,6 @@ then
export PATH="$make_HOME:$PATH"
fi
# source additional environment variables
# check if needed programs are in PATH
if [[ `command -v cmake` ]]
then
......@@ -30,10 +27,15 @@ else
exit 1
fi
# source additional environment variables
# Post source check if needed programs are in PATH
# cmake
curDir=`dirname "$0"`
cmake -B"$curDir"/build/ -H"$curDir/src" "$@"
# make
make -C "$curDir"
\ No newline at end of file
make -j4 -C "$curDir"
\ No newline at end of file
......@@ -10,9 +10,6 @@ IF NOT [%g++_HOME%] == [] (
set PATH="%g++_HOME%;%PATH%"
)
:: source additional environment variables
:: check if needed programs are in PATH
where cmake
IF NOT %ERRORLEVEL% EQU 0 (
......@@ -30,10 +27,16 @@ IF NOT %ERRORLEVEL% EQU 0 (
exit /B 1
)
:: source additional environment variables
:: Post source check if needed programs are in PATH
:: cmake
cmake -B./build/ -G "MinGW Makefiles" %* ./src
:: make
cd .\build
make
make -j4
cd ..
\ No newline at end of file
......@@ -7,9 +7,6 @@ IF NOT [%msbuild_HOME%] == [] (
set PATH="%msbuild_HOME%;%PATH%"
)
:: source additional environment variables
call vcvars64.bat
:: check if needed programs are in PATH
where cmake
IF NOT %ERRORLEVEL% EQU 0 (
......@@ -21,6 +18,11 @@ IF NOT %ERRORLEVEL% EQU 0 (
echo "Can not find vcvars64.bat in PATH! Aborting."
exit /B 1
)
:: source additional environment variables
call vcvars64.bat
:: Post source check if needed programs are in PATH
where msbuild
IF NOT %ERRORLEVEL% EQU 0 (
echo "Can not find msbuild in PATH! Aborting."
......@@ -32,5 +34,5 @@ cmake -B./build/ -G "Visual Studio 15 2017 Win64" %* ./src
:: msbuild
cd .\build
msbuild /t:build /p:Configuration=Release ALL_BUILD.vcxproj
msbuild /m /t:build /p:Configuration=Release ALL_BUILD.vcxproj
cd ..
\ No newline at end of file
......@@ -11,9 +11,6 @@ then
export PATH="$make_HOME:$PATH"
fi
# source additional environment variables
source "$ROS_HOME"/setup.bash
# check if needed programs are in PATH
if [[ `command -v cmake` ]]
then
......@@ -30,10 +27,21 @@ else
exit 1
fi
# source additional environment variables
source "$ROS_HOME"/setup.bash
# Post source check if needed programs are in PATH
if [[ `command -v roscore` ]]
then
echo "Found roscore"
else
echo "Can not find roscore in PATH! Aborting."
exit 1
fi
# cmake
curDir=`dirname "$0"`
cmake -B"$curDir"/build/ -H"$curDir/src" "$@"
# make
make -C "$curDir"
\ No newline at end of file
make -j4 -C "$curDir"
\ No newline at end of file
......@@ -11,9 +11,6 @@ then
export PATH="$make_HOME:$PATH"
fi
# source additional environment variables
source "$ROS2_HOME"/setup.bash
# check if needed programs are in PATH
if [[ `command -v cmake` ]]
then
......@@ -30,10 +27,21 @@ else
exit 1
fi
# source additional environment variables
source "$ROS2_HOME"/setup.bash
# Post source check if needed programs are in PATH
if [[ `command -v ros2` ]]
then
echo "Found ros2"
else
echo "Can not find ros2 in PATH! Aborting."
exit 1
fi
# cmake
curDir=`dirname "$0"`
cmake -B"$curDir"/build/ -H"$curDir/src" "$@"
# make
make -C "$curDir"
\ No newline at end of file
make -j4 -C "$curDir"
\ No newline at end of file
......@@ -7,10 +7,6 @@ IF NOT [%msbuild_HOME%] == [] (
set PATH="%msbuild_HOME%;%PATH%"
)
:: source additional environment variables
call vcvars64.bat
call %ROS_HOME%\local_setup.bat
:: check if needed programs are in PATH
where cmake
IF NOT %ERRORLEVEL% EQU 0 (
......@@ -22,16 +18,27 @@ IF NOT %ERRORLEVEL% EQU 0 (
echo "Can not find vcvars64.bat in PATH! Aborting."
exit /B 1
)
:: source additional environment variables
call vcvars64.bat
call %ROS2_HOME%\local_setup.bat
:: Post source check if needed programs are in PATH
where msbuild
IF NOT %ERRORLEVEL% EQU 0 (
echo "Can not find msbuild in PATH! Aborting."
exit /B 1
)
where ros2
IF NOT %ERRORLEVEL% EQU 0 (
echo "Can not find ros2 in PATH! Aborting."
exit /B 1
)
:: cmake
cmake -B./build/ -G "Visual Studio 15 2017 Win64" %* ./src
:: msbuild
cd .\build
msbuild /t:build /p:Configuration=Release ALL_BUILD.vcxproj
msbuild /m /t:build /p:Configuration=Release ALL_BUILD.vcxproj
cd ..
\ No newline at end of file
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