aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgeorgev93 <georgeavogt93@gmail.com>2020-06-28 21:59:17 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2020-06-30 23:50:10 +0300
commit5acd8acd51859ab3189f43d6ba2fcd3e4b27518d (patch)
tree10c73d0a7390697ba263f9257f78a3225e6603ee
parent4a371c97f422d0dc68fece2fe56d544ccd6558e9 (diff)
downloadmeson-5acd8acd51859ab3189f43d6ba2fcd3e4b27518d.zip
meson-5acd8acd51859ab3189f43d6ba2fcd3e4b27518d.tar.gz
meson-5acd8acd51859ab3189f43d6ba2fcd3e4b27518d.tar.bz2
Move mesonbuild/cmake/data/run_ctgt.py to mesonbuild/scripts/cmake_run_ctgt.py, as well as enclose everything in a run() function so it can be called by `meson --internal cmake_run_ctgt ...`. Also, include mesonbuild/cmake/data/ in the msi package.
-rwxr-xr-xmesonbuild/cmake/data/run_ctgt.py96
-rw-r--r--mesonbuild/cmake/interpreter.py8
-rwxr-xr-xmesonbuild/scripts/cmake_run_ctgt.py100
-rw-r--r--msi/createmsi.py2
4 files changed, 105 insertions, 101 deletions
diff --git a/mesonbuild/cmake/data/run_ctgt.py b/mesonbuild/cmake/data/run_ctgt.py
deleted file mode 100755
index 9d5d437..0000000
--- a/mesonbuild/cmake/data/run_ctgt.py
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/env python3
-
-import argparse
-import subprocess
-import shutil
-import os
-import sys
-from pathlib import Path
-
-commands = [[]]
-SEPARATOR = ';;;'
-
-# Generate CMD parameters
-parser = argparse.ArgumentParser(description='Wrapper for add_custom_command')
-parser.add_argument('-d', '--directory', type=str, metavar='D', required=True, help='Working directory to cwd to')
-parser.add_argument('-o', '--outputs', nargs='+', metavar='O', required=True, help='Expected output files')
-parser.add_argument('-O', '--original-outputs', nargs='*', metavar='O', default=[], help='Output files expected by CMake')
-parser.add_argument('commands', nargs=argparse.REMAINDER, help='A "{}" seperated list of commands'.format(SEPARATOR))
-
-# Parse
-args = parser.parse_args()
-
-dummy_target = None
-if len(args.outputs) == 1 and len(args.original_outputs) == 0:
- dummy_target = args.outputs[0]
-elif len(args.outputs) != len(args.original_outputs):
- print('Length of output list and original output list differ')
- sys.exit(1)
-
-for i in args.commands:
- if i == SEPARATOR:
- commands += [[]]
- continue
-
- i = i.replace('"', '') # Remove lefover quotes
- commands[-1] += [i]
-
-# Execute
-for i in commands:
- # Skip empty lists
- 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)
-
- 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)
-
-if dummy_target:
- with open(dummy_target, 'a'):
- os.utime(dummy_target, None)
- exit(0)
-
-# Copy outputs
-zipped_outputs = zip(args.outputs, args.original_outputs)
-for expected, generated in zipped_outputs:
- do_copy = False
- if not os.path.exists(expected):
- if not os.path.exists(generated):
- print('Unable to find generated file. This can cause the build to fail:')
- print(generated)
- do_copy = False
- else:
- do_copy = True
- elif os.path.exists(generated):
- if os.path.getmtime(generated) > os.path.getmtime(expected):
- do_copy = True
-
- if do_copy:
- if os.path.exists(expected):
- os.remove(expected)
- shutil.copyfile(generated, expected)
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
index d5ec0a7..2857527 100644
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -22,7 +22,7 @@ from .client import CMakeClient, RequestCMakeInputs, RequestConfigure, RequestCo
from .fileapi import CMakeFileAPI
from .executor import CMakeExecutor
from .traceparser import CMakeTraceParser, CMakeGeneratorTarget
-from .. import mlog
+from .. import mlog, mesonlib
from ..environment import Environment
from ..mesonlib import MachineChoice, OrderedSet, version_compare
from ..compilers.compilers import lang_suffixes, header_suffixes, obj_suffixes, lib_suffixes, is_header
@@ -1059,9 +1059,6 @@ class CMakeInterpreter:
root_cb.lines += [function('project', [self.project_name] + self.languages)]
# Add the run script for custom commands
- run_script = pkg_resources.resource_filename('mesonbuild', 'cmake/data/run_ctgt.py')
- run_script_var = 'ctgt_run_script'
- root_cb.lines += [assign(run_script_var, function('find_program', [[run_script]], {'required': True}))]
# Add the targets
processing = []
@@ -1243,7 +1240,8 @@ class CMakeInterpreter:
# Generate the command list
command = []
- command += [id_node(run_script_var)]
+ command += mesonlib.meson_command
+ command += ['--internal', 'cmake_run_ctgt']
command += ['-o', '@OUTPUT@']
if tgt.original_outputs:
command += ['-O'] + tgt.original_outputs
diff --git a/mesonbuild/scripts/cmake_run_ctgt.py b/mesonbuild/scripts/cmake_run_ctgt.py
new file mode 100755
index 0000000..5c0b31f
--- /dev/null
+++ b/mesonbuild/scripts/cmake_run_ctgt.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python3
+
+import argparse
+import subprocess
+import shutil
+import os
+import sys
+from pathlib import Path
+
+def run(argsv):
+ commands = [[]]
+ SEPARATOR = ';;;'
+
+ # Generate CMD parameters
+ parser = argparse.ArgumentParser(description='Wrapper for add_custom_command')
+ parser.add_argument('-d', '--directory', type=str, metavar='D', required=True, help='Working directory to cwd to')
+ parser.add_argument('-o', '--outputs', nargs='+', metavar='O', required=True, help='Expected output files')
+ parser.add_argument('-O', '--original-outputs', nargs='*', metavar='O', default=[], help='Output files expected by CMake')
+ parser.add_argument('commands', nargs=argparse.REMAINDER, help='A "{}" seperated list of commands'.format(SEPARATOR))
+
+ # Parse
+ args = parser.parse_args(argsv)
+
+ dummy_target = None
+ if len(args.outputs) == 1 and len(args.original_outputs) == 0:
+ dummy_target = args.outputs[0]
+ elif len(args.outputs) != len(args.original_outputs):
+ print('Length of output list and original output list differ')
+ sys.exit(1)
+
+ for i in args.commands:
+ if i == SEPARATOR:
+ commands += [[]]
+ continue
+
+ i = i.replace('"', '') # Remove lefover quotes
+ commands[-1] += [i]
+
+ # Execute
+ for i in commands:
+ # Skip empty lists
+ 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)
+
+ 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:
+ sys.exit(1)
+
+ if dummy_target:
+ with open(dummy_target, 'a'):
+ os.utime(dummy_target, None)
+ sys.exit(0)
+
+ # Copy outputs
+ zipped_outputs = zip(args.outputs, args.original_outputs)
+ for expected, generated in zipped_outputs:
+ do_copy = False
+ if not os.path.exists(expected):
+ if not os.path.exists(generated):
+ print('Unable to find generated file. This can cause the build to fail:')
+ print(generated)
+ do_copy = False
+ else:
+ do_copy = True
+ elif os.path.exists(generated):
+ if os.path.getmtime(generated) > os.path.getmtime(expected):
+ do_copy = True
+
+ if do_copy:
+ if os.path.exists(expected):
+ os.remove(expected)
+ shutil.copyfile(generated, expected)
+
+if __name__ == '__main__':
+ sys.run(sys.argv[1:])
diff --git a/msi/createmsi.py b/msi/createmsi.py
index 4d03593..76cb520 100644
--- a/msi/createmsi.py
+++ b/msi/createmsi.py
@@ -154,6 +154,7 @@ class PackageGenerator:
shutil.rmtree(sdir)
main_stage, ninja_stage = self.staging_dirs
dep_data_dir = 'mesonbuild/dependencies/data'
+ cmake_data_dir = 'mesonbuild/cmake/data'
modules = self.get_all_modules_from_dir('mesonbuild/modules')
modules += self.get_all_modules_from_dir('mesonbuild/scripts')
modules += self.get_more_modules()
@@ -176,6 +177,7 @@ class PackageGenerator:
subprocess.check_call(pyinst_cmd)
shutil.move(pyinstaller_tmpdir + '/meson', main_stage)
shutil.copytree(dep_data_dir, main_stage + '/mesonbuild/dependencies/data')
+ shutil.copytree(cmake_data_dir, main_stage + '/mesonbuild/cmake/data')
if not os.path.exists(os.path.join(main_stage, 'meson.exe')):
sys.exit('Meson exe missing from staging dir.')
os.mkdir(ninja_stage)