aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmesonbuild/cmake/data/run_ctgt.py26
-rw-r--r--mesonbuild/cmake/traceparser.py15
-rw-r--r--test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt9
-rw-r--r--test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp (renamed from test cases/cmake/8 custom command/subprojects/cmMod/main.cpp)10
4 files changed, 55 insertions, 5 deletions
diff --git a/mesonbuild/cmake/data/run_ctgt.py b/mesonbuild/cmake/data/run_ctgt.py
index 1897a1b..9d5d437 100755
--- a/mesonbuild/cmake/data/run_ctgt.py
+++ b/mesonbuild/cmake/data/run_ctgt.py
@@ -5,6 +5,7 @@ import subprocess
import shutil
import os
import sys
+from pathlib import Path
commands = [[]]
SEPARATOR = ';;;'
@@ -40,9 +41,32 @@ for i in commands:
if not i:
continue
+ cmd = []
+ stdout = None
+ stderr = None
+ capture_file = ''
+
+ for j in i:
+ if j in ['>', '>>']:
+ stdout = subprocess.PIPE
+ continue
+ elif j in ['&>', '&>>']:
+ stdout = subprocess.PIPE
+ stderr = subprocess.STDOUT
+ continue
+
+ if stdout is not None or stderr is not None:
+ capture_file += j
+ else:
+ cmd += [j]
+
try:
os.makedirs(args.directory, exist_ok=True)
- subprocess.run(i, cwd=args.directory, check=True)
+
+ res = subprocess.run(cmd, stdout=stdout, stderr=stderr, cwd=args.directory, check=True)
+ if capture_file:
+ out_file = Path(args.directory) / capture_file
+ out_file.write_bytes(res.stdout)
except subprocess.CalledProcessError:
exit(1)
diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py
index 8eb8605..d6970f2 100644
--- a/mesonbuild/cmake/traceparser.py
+++ b/mesonbuild/cmake/traceparser.py
@@ -309,7 +309,7 @@ class CMakeTraceParser:
def _cmake_add_custom_command(self, tline: CMakeTraceLine, name=None):
# DOC: https://cmake.org/cmake/help/latest/command/add_custom_command.html
- args = list(tline.args) # Make a working copy
+ args = self._flatten_args(list(tline.args)) # Commands can be passed as ';' seperated lists
if not args:
return self._gen_exception('add_custom_command', 'requires at least 1 argument', tline)
@@ -325,15 +325,15 @@ class CMakeTraceParser:
target = CMakeGeneratorTarget(name)
def handle_output(key: str, target: CMakeGeneratorTarget) -> None:
- target.outputs += key.split(';')
+ target.outputs += [key]
def handle_command(key: str, target: CMakeGeneratorTarget) -> None:
if key == 'ARGS':
return
- target.command[-1] += key.split(';')
+ target.command[-1] += [key]
def handle_depends(key: str, target: CMakeGeneratorTarget) -> None:
- target.depends += key.split(';')
+ target.depends += [key]
def handle_working_dir(key: str, target: CMakeGeneratorTarget) -> None:
if target.working_dir is None:
@@ -608,6 +608,13 @@ class CMakeTraceParser:
args = [parse_generator_expressions(x) for x in args]
yield CMakeTraceLine(data['file'], data['line'], data['cmd'], args)
+ def _flatten_args(self, args: T.List[str]) -> T.List[str]:
+ # Split lists in arguments
+ res = [] # type: T.List[str]
+ for i in args:
+ res += i.split(';')
+ return res
+
def _guess_files(self, broken_list: T.List[str]) -> T.List[str]:
# Nothing has to be done for newer formats
if self.trace_format != 'human':
diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt
index 39b19d7..1498c36 100644
--- a/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt
+++ b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt
@@ -7,6 +7,9 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_definitions("-DDO_NOTHING_JUST_A_FLAG=1")
+add_executable(genMain genMain.cpp)
+add_custom_command(OUTPUT main.cpp COMMAND genMain > main.cpp)
+
add_executable(gen main.cpp)
add_executable(mycpy cp.cpp)
@@ -16,9 +19,15 @@ add_custom_command(
COMMAND gen ARGS genTest
)
+set(CMD_PART)
+list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.in cpyBase.cpp.in.gen)
+list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.in.gen cpyBase.cpp.out)
+list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.out cpyBase.cpp.something)
+
add_custom_command(
OUTPUT cpyBase.cpp
COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyBase.cpp.am" cpyBase.cpp.in
+ ${CMD_PART}
COMMAND mycpy cpyBase.cpp.in cpyBase.cpp.something
COMMAND mycpy cpyBase.cpp.something cpyBase.cpp.IAmRunningOutOfIdeas
COMMAND mycpy cpyBase.cpp.IAmRunningOutOfIdeas cpyBase.cpp
diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/main.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp
index 9fade21..33f0201 100644
--- a/test cases/cmake/8 custom command/subprojects/cmMod/main.cpp
+++ b/test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp
@@ -1,4 +1,10 @@
#include <iostream>
+
+using namespace std;
+
+int main() {
+ cout << R"asd(
+#include <iostream>
#include <fstream>
using namespace std;
@@ -28,3 +34,7 @@ std::string getStr() {
return 0;
}
+)asd";
+
+ return 0;
+}