diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-06-28 13:13:57 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-06-28 13:22:37 +0200 |
commit | 98813c1d22244430f95c386890b81abd3c915ccf (patch) | |
tree | cf7478fbb7c447338b0f4824b40ca7d3c65d0581 | |
parent | 35b4ae5d61c1fed573282299b36cf2544c282382 (diff) | |
download | meson-98813c1d22244430f95c386890b81abd3c915ccf.zip meson-98813c1d22244430f95c386890b81abd3c915ccf.tar.gz meson-98813c1d22244430f95c386890b81abd3c915ccf.tar.bz2 |
cmake: Added custom target wrapper script
-rwxr-xr-x | mesonbuild/cmake/data/run_ctgt.py | 59 | ||||
-rw-r--r-- | setup.py | 5 |
2 files changed, 63 insertions, 1 deletions
diff --git a/mesonbuild/cmake/data/run_ctgt.py b/mesonbuild/cmake/data/run_ctgt.py new file mode 100755 index 0000000..0a9b80d --- /dev/null +++ b/mesonbuild/cmake/data/run_ctgt.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess +import shutil +import os +import sys + +commands = [[]] +SEPERATOR = ';;;' + +# 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', required=True, help='Output files expected by CMake') +parser.add_argument('commands', nargs=argparse.REMAINDER, help='A "{}" seperated list of commands'.format(SEPERATOR)) + +# Parse +args = parser.parse_args() + +if 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 == SEPERATOR: + commands += [[]] + continue + + commands[-1] += [i] + +# Execute +for i in commands: + # Skip empty lists + if not i: + continue + + subprocess.run(i, cwd=args.directory) + +# 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) @@ -36,7 +36,10 @@ packages = ['mesonbuild', 'mesonbuild.modules', 'mesonbuild.scripts', 'mesonbuild.wrap'] -package_data = {'mesonbuild.dependencies': ['data/CMakeLists.txt', 'data/CMakeListsLLVM.txt', 'data/CMakePathInfo.txt']} +package_data = { + 'mesonbuild.dependencies': ['data/CMakeLists.txt', 'data/CMakeListsLLVM.txt', 'data/CMakePathInfo.txt'], + 'mesonbuild.cmake': ['data/run_ctgt.py'], +} data_files = [] if sys.platform != 'win32': # Only useful on UNIX-like systems |