From 66c01401deb186e6daa20cf4bf6a098076dda236 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 15 Jan 2016 23:37:22 +0200 Subject: [PATCH] Moved scripts in the module and started work to run them via the main meson command. --- meson.py | 22 ++++++- meson/environment.py | 2 +- meson/mesonmain.py | 60 +++++++++++++++---- meson/modules/gnome.py | 2 +- meson/ninjabackend.py | 11 ++-- {scripts => meson/scripts}/commandrunner.py | 12 ++-- {scripts => meson/scripts}/delwithsuffix.py | 33 +++++----- {scripts => meson/scripts}/depfixer.py | 15 +++-- {scripts => meson/scripts}/dirchanger.py | 12 ++-- {scripts => meson/scripts}/gtkdochelper.py | 10 +++- {scripts => meson/scripts}/meson_benchmark.py | 0 {scripts => meson/scripts}/meson_install.py | 11 ++-- {scripts => meson/scripts}/meson_test.py | 2 +- {scripts => meson/scripts}/regen_checker.py | 9 ++- {scripts => meson/scripts}/symbolextractor.py | 12 ++-- {scripts => meson/scripts}/vcstagger.py | 11 ++-- scripts/mesonconf.py => mesonconf.py | 0 scripts/mesongui.py => mesongui.py | 0 .../mesonintrospect.py => mesonintrospect.py | 0 scripts/wraptool.py => wraptool.py | 0 20 files changed, 156 insertions(+), 68 deletions(-) rename {scripts => meson/scripts}/commandrunner.py (90%) mode change 100755 => 100644 rename {scripts => meson/scripts}/delwithsuffix.py (55%) mode change 100755 => 100644 rename {scripts => meson/scripts}/depfixer.py (98%) mode change 100755 => 100644 rename {scripts => meson/scripts}/dirchanger.py (80%) mode change 100755 => 100644 rename {scripts => meson/scripts}/gtkdochelper.py (96%) mode change 100755 => 100644 rename {scripts => meson/scripts}/meson_benchmark.py (100%) mode change 100755 => 100644 rename {scripts => meson/scripts}/meson_install.py (98%) mode change 100755 => 100644 rename {scripts => meson/scripts}/meson_test.py (99%) mode change 100755 => 100644 rename {scripts => meson/scripts}/regen_checker.py (88%) mode change 100755 => 100644 rename {scripts => meson/scripts}/symbolextractor.py (94%) mode change 100755 => 100644 rename {scripts => meson/scripts}/vcstagger.py (90%) mode change 100755 => 100644 rename scripts/mesonconf.py => mesonconf.py (100%) mode change 100755 => 100644 rename scripts/mesongui.py => mesongui.py (100%) mode change 100755 => 100644 rename scripts/mesonintrospect.py => mesonintrospect.py (100%) mode change 100755 => 100644 rename scripts/wraptool.py => wraptool.py (100%) diff --git a/meson.py b/meson.py index 94d6e2201..ab8db7250 100755 --- a/meson.py +++ b/meson.py @@ -1,6 +1,24 @@ #!/usr/bin/env python3 +# Copyright 2016 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from meson import mesonmain -import sys +import sys, os + +thisfile = __file__ +if not os.path.isabs(thisfile): + thisfile = os.path.join(os.getcwd(), thisfile) -sys.exit(mesonmain.run(sys.argv[:])) +sys.exit(mesonmain.run(thisfile, sys.argv[1:])) diff --git a/meson/environment.py b/meson/environment.py index a99cb305f..8df856ca7 100644 --- a/meson/environment.py +++ b/meson/environment.py @@ -1,4 +1,4 @@ -# Copyright 2012-2014 The Meson development team +# Copyright 2012-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/meson/mesonmain.py b/meson/mesonmain.py index 0bf123caa..58ba06b2f 100644 --- a/meson/mesonmain.py +++ b/meson/mesonmain.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2012-2015 The Meson development team +# Copyright 2012-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ import sys, stat, traceback, pickle, argparse import datetime import os.path from . import environment, interpreter, mesonlib -from .import build +from . import build import platform from . import mlog, coredata @@ -163,21 +163,58 @@ itself as required.''' dumpfile = os.path.join(env.get_scratch_dir(), 'build.dat') pickle.dump(b, open(dumpfile, 'wb')) -def run(args): +def run_script_command(args): + cmdname = args[0] + cmdargs = args[1:] + if cmdname == 'test': + import meson.scripts.meson_test as abc + cmdfunc = abc.run + elif cmdname == 'benchmark': + import meson.scripts.meson_benchmark as abc + cmdfunc = abc.run + elif cmdname == 'commandrunner': + import meson.scripts.commandrunner as abc + cmdfunc = abc.run + elif cmdname == 'delsuffix': + import meson.scripts.delwithsuffix as abc + cmdfunc = abc.run + elif cmdname == 'dirchanger': + import meson.scripts.dirchanger as abc + cmdfunc = abc.run + elif cmdname == 'gtkdoc': + import meson.scripts.gtkdochelper as abc + cmdfunc = abc.run + elif cmdname == 'regencheck': + import meson.scripts.regen_checker as abc + cmdfunc = abc.run + elif cmdname == 'symbolextractor': + import meson.scripts.symbolextractor as abc + cmdfunc = abc.run + elif cmdname == 'vcstagger': + import meson.scripts.vcstagger as abc + cmdfunc = abc.run + else: + raise MesonException('Unknown internal command {}.'.format(cmdname)) + return cmdfunc(cmdargs) + +def run(mainfile, args): if sys.version_info < (3, 3): print('Meson works correctly only with python 3.3+.') print('You have python %s.' % sys.version) print('Please update your environment') return 1 - if args[-1] == 'secret-handshake': - args = args[:-1] + if args[0] == '--internal': + if args[1] != 'regenerate': + sys.exit(run_script_command(args[1:])) + args = args[2:] handshake = True else: handshake = False + print(args) args = mesonlib.expand_arguments(args) if not args: return 1 - options = parser.parse_args(args[1:]) + options = parser.parse_args(args) if options.print_version: print(coredata.version) return 0 @@ -191,16 +228,15 @@ def run(args): dir2 = args[1] else: dir2 = '.' - this_file = os.path.abspath(__file__) - while os.path.islink(this_file): - resolved = os.readlink(this_file) + while os.path.islink(mainfile): + resolved = os.readlink(mainfile) if resolved[0] != '/': - this_file = os.path.join(os.path.dirname(this_file), resolved) + mainfile = os.path.join(os.path.dirname(mainfile), resolved) else: - this_file = resolved + mainfile = resolved try: - app = MesonApp(dir1, dir2, this_file, handshake, options) + app = MesonApp(dir1, dir2, mainfile, handshake, options) except Exception as e: # Log directory does not exist, so just print # to stdout. diff --git a/meson/modules/gnome.py b/meson/modules/gnome.py index 70ac81b34..e552b8488 100644 --- a/meson/modules/gnome.py +++ b/meson/modules/gnome.py @@ -1,4 +1,4 @@ -# Copyright 2015 The Meson development team +# Copyright 2015-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/meson/ninjabackend.py b/meson/ninjabackend.py index d21cea011..80c94f9e9 100644 --- a/meson/ninjabackend.py +++ b/meson/ninjabackend.py @@ -1,4 +1,4 @@ -# Copyright 2012-2014 The Meson development team +# Copyright 2012-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -582,9 +582,8 @@ int dummy; self.serialise_tests() valgrind = environment.find_valgrind() script_root = self.environment.get_script_dir() - test_script = os.path.join(script_root, 'meson_test.py') test_data = os.path.join(self.environment.get_scratch_dir(), 'meson_test_setup.dat') - cmd = [sys.executable, test_script, test_data] + cmd = [sys.executable, self.environment.get_build_command(), '--internal', 'test', test_data] elem = NinjaBuildElement('test', 'CUSTOM_COMMAND', ['all', 'PHONY']) elem.add_item('COMMAND', cmd) elem.add_item('DESC', 'Running all tests.') @@ -604,7 +603,7 @@ int dummy; # And then benchmarks. benchmark_script = os.path.join(script_root, 'meson_benchmark.py') benchmark_data = os.path.join(self.environment.get_scratch_dir(), 'meson_benchmark_setup.dat') - cmd = [sys.executable, benchmark_script, benchmark_data] + cmd = [sys.executable, self.environment.get_build_command(), '--internal', 'benchmark', benchmark_data] elem = NinjaBuildElement('benchmark', 'CUSTOM_COMMAND', ['all', 'PHONY']) elem.add_item('COMMAND', cmd) elem.add_item('DESC', 'Running benchmark suite.') @@ -628,9 +627,11 @@ int dummy; outfile.write('rule REGENERATE_BUILD\n') c = (quote_char + ninja_quote(sys.executable) + quote_char, quote_char + ninja_quote(self.environment.get_build_command()) + quote_char, + '--internal', + 'regenerate', quote_char + ninja_quote(self.environment.get_source_dir()) + quote_char, quote_char + ninja_quote(self.environment.get_build_dir()) + quote_char) - outfile.write(" command = %s %s %s %s --backend ninja secret-handshake\n" % c) + outfile.write(" command = %s %s %s %s %s %s --backend ninja\n" % c) outfile.write(' description = Regenerating build files\n') outfile.write(' generator = 1\n\n') if len(self.build.pot) > 0: diff --git a/scripts/commandrunner.py b/meson/scripts/commandrunner.py old mode 100755 new mode 100644 similarity index 90% rename from scripts/commandrunner.py rename to meson/scripts/commandrunner.py index 0dad58516..f5a2fffdf --- a/scripts/commandrunner.py +++ b/meson/scripts/commandrunner.py @@ -42,9 +42,10 @@ def run_command(source_dir, build_dir, subdir, command, arguments): print('Could not execute command "%s".' % command) sys.exit(1) -if __name__ == '__main__': - if len(sys.argv) < 5: - print(sys.argv[0], ' [arguments]') +def run(args): + if len(sys.argv) < 4: + print('commandrunner.py [arguments]') + sys.exit(1) src_dir = sys.argv[1] build_dir = sys.argv[2] subdir = sys.argv[3] @@ -52,4 +53,7 @@ if __name__ == '__main__': arguments = sys.argv[5:] pc = run_command(src_dir, build_dir, subdir, command, arguments) pc.wait() - sys.exit(pc.returncode) + return pc.returncode + +if __name__ == '__main__': + sys.exit(run(sys.argv[1:])) diff --git a/scripts/delwithsuffix.py b/meson/scripts/delwithsuffix.py old mode 100755 new mode 100644 similarity index 55% rename from scripts/delwithsuffix.py rename to meson/scripts/delwithsuffix.py index 4b8a60de8..38ab406fc --- a/scripts/delwithsuffix.py +++ b/meson/scripts/delwithsuffix.py @@ -16,17 +16,22 @@ import os, sys -if len(sys.argv) != 3: - print('%s ' % sys.argv[0]) - sys.exit(1) - -topdir = sys.argv[1] -suffix = sys.argv[2] -if suffix[0] != '.': - suffix = '.' + suffix - -for (root, dirs, files) in os.walk(topdir): - for f in files: - if f.endswith(suffix): - fullname = os.path.join(root, f) - os.unlink(fullname) +def run(args): + if len(sys.argv) != 2: + print('delwithsuffix.py ') + sys.exit(1) + + topdir = sys.argv[1] + suffix = sys.argv[2] + if suffix[0] != '.': + suffix = '.' + suffix + + for (root, _, files) in os.walk(topdir): + for f in files: + if f.endswith(suffix): + fullname = os.path.join(root, f) + os.unlink(fullname) + return 0 + +if __name__ == '__main__': + run(sys.argv[1:]) diff --git a/scripts/depfixer.py b/meson/scripts/depfixer.py old mode 100755 new mode 100644 similarity index 98% rename from scripts/depfixer.py rename to meson/scripts/depfixer.py index 4f7ce3d87..1ab83b6d4 --- a/scripts/depfixer.py +++ b/meson/scripts/depfixer.py @@ -284,16 +284,19 @@ class Elf(DataSizes): entry.write(self.bf) return None -if __name__ == '__main__': - if len(sys.argv) < 2 or len(sys.argv) > 3: +def run(args): + if len(args) < 1 or len(args) > 2: print('This application resets target rpath.') print('Don\'t run this unless you know what you are doing.') print('%s: ' % sys.argv[0]) exit(1) - e = Elf(sys.argv[1]) - if len(sys.argv) == 2: + e = Elf(args[0]) + if len(args) == 1: e.print_rpath() else: - new_rpath = sys.argv[2] + new_rpath = args[1] e.fix_rpath(new_rpath.encode('utf8')) - #e.fix_deps(prefix.encode()) + return 0 + +if __name__ == '__main__': + run(sys.argv[1:]) diff --git a/scripts/dirchanger.py b/meson/scripts/dirchanger.py old mode 100755 new mode 100644 similarity index 80% rename from scripts/dirchanger.py rename to meson/scripts/dirchanger.py index fd3dc2350..93a901d54 --- a/scripts/dirchanger.py +++ b/meson/scripts/dirchanger.py @@ -19,8 +19,12 @@ the command given in the rest of the arguments.''' import os, subprocess, sys -dirname = sys.argv[1] -command = sys.argv[2:] +def run(args): + dirname = args[0] + command = args[1:] -os.chdir(dirname) -sys.exit(subprocess.call(command)) + os.chdir(dirname) + return subprocess.call(command) + +if __name__ == '__main__': + sys.exit(run(sys.argv[1:])) diff --git a/scripts/gtkdochelper.py b/meson/scripts/gtkdochelper.py old mode 100755 new mode 100644 similarity index 96% rename from scripts/gtkdochelper.py rename to meson/scripts/gtkdochelper.py index 7e476b8de..68be8f2af --- a/scripts/gtkdochelper.py +++ b/meson/scripts/gtkdochelper.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright 2015 The Meson development team +# Copyright 2015-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -87,8 +87,8 @@ def install_gtkdoc(build_root, doc_subdir, install_prefix, datadir, module): shutil.rmtree(final_destination, ignore_errors=True) shutil.copytree(source, final_destination) -if __name__ == '__main__': - options = parser.parse_args(sys.argv[1:]) +def run(args): + options = parser.parse_args(args) if len(options.htmlargs) > 0: htmlargs = options.htmlargs.split('@@') else: @@ -116,3 +116,7 @@ if __name__ == '__main__': installdir, 'share/gtk-doc/html', options.modulename) + return 0 + +if __name__ == '__main__': + sys.exit(run(sys.argv[1:])) diff --git a/scripts/meson_benchmark.py b/meson/scripts/meson_benchmark.py old mode 100755 new mode 100644 similarity index 100% rename from scripts/meson_benchmark.py rename to meson/scripts/meson_benchmark.py diff --git a/scripts/meson_install.py b/meson/scripts/meson_install.py old mode 100755 new mode 100644 similarity index 98% rename from scripts/meson_install.py rename to meson/scripts/meson_install.py index e0a5eb24b..a2868643e --- a/scripts/meson_install.py +++ b/meson/scripts/meson_install.py @@ -203,10 +203,13 @@ def install_targets(d): print('Stderr:\n%s\n' % stde.decode()) sys.exit(1) -if __name__ == '__main__': - if len(sys.argv) != 2: +def run(args): + if len(args) != 1: print('Installer script for Meson. Do not run on your own, mmm\'kay?') - print('%s [install info file]' % sys.argv[0]) - datafilename = sys.argv[1] + print('meson_install.py [install info file]') + datafilename = args[0] do_install(datafilename) + return 0 +if __name__ == '__main__': + sys.exit(run(sys.argv[1:])) diff --git a/scripts/meson_test.py b/meson/scripts/meson_test.py old mode 100755 new mode 100644 similarity index 99% rename from scripts/meson_test.py rename to meson/scripts/meson_test.py index 43b1cdb30..c5814ef32 --- a/scripts/meson_test.py +++ b/meson/scripts/meson_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2013-2015 The Meson development team +# Copyright 2013-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/regen_checker.py b/meson/scripts/regen_checker.py old mode 100755 new mode 100644 similarity index 88% rename from scripts/regen_checker.py rename to meson/scripts/regen_checker.py index a0fe028cb..f360a7ce3 --- a/scripts/regen_checker.py +++ b/meson/scripts/regen_checker.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2015 The Meson development team +# Copyright 2015-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -35,8 +35,11 @@ def regen(regeninfo): '--backend=vs2010', 'secret-handshake'] subprocess.check_call(cmd) -if __name__ == '__main__': - regeninfo = pickle.load(open(os.path.join(sys.argv[1], 'regeninfo.dump'), 'rb')) +def run(args): + regeninfo = pickle.load(open(os.path.join(args[0], 'regeninfo.dump'), 'rb')) if need_regen(regeninfo): regen(regeninfo) sys.exit(0) + +if __name__ == '__main__': + run(sys.argv[1:]) diff --git a/scripts/symbolextractor.py b/meson/scripts/symbolextractor.py old mode 100755 new mode 100644 similarity index 94% rename from scripts/symbolextractor.py rename to meson/scripts/symbolextractor.py index fe86d355a..9607466d0 --- a/scripts/symbolextractor.py +++ b/meson/scripts/symbolextractor.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2013-2015 The Meson development team +# Copyright 2013-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -92,11 +92,15 @@ def gen_symbols(libfilename, outfilename, cross_host): else: dummy_syms(outfilename) -if __name__ == '__main__': - options = parser.parse_args() +def run(args): + options = parser.parse_args(args) if len(options.args) != 2: - print(sys.argv[0], ' ') + print('symbolextractor.py ') sys.exit(1) libfile = options.args[0] outfile = options.args[1] gen_symbols(libfile, outfile, options.cross_host) + return 0 + +if __name__ == '__main__': + sys.exit(run(sys.argv[1:])) diff --git a/scripts/vcstagger.py b/meson/scripts/vcstagger.py old mode 100755 new mode 100644 similarity index 90% rename from scripts/vcstagger.py rename to meson/scripts/vcstagger.py index ccc584e92..390e37a8d --- a/scripts/vcstagger.py +++ b/meson/scripts/vcstagger.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2015 The Meson development team +# Copyright 2015-2016 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,7 +27,10 @@ def config_vcs_tag(infile, outfile, fallback, source_dir, replace_string, regex_ if (not os.path.exists(outfile)) or (open(outfile).read() != new_data): open(outfile, 'w').write(new_data) -if __name__ == '__main__': - infile, outfile, fallback, source_dir, replace_string, regex_selector = sys.argv[1:7] - command = sys.argv[7:] +def run(args): + infile, outfile, fallback, source_dir, replace_string, regex_selector = args[0:6] + command = args[6:] config_vcs_tag(infile, outfile, fallback, source_dir, replace_string, regex_selector, command) + +if __name__ == '__main__': + sys.exit(run(sys.argv[1:])) diff --git a/scripts/mesonconf.py b/mesonconf.py old mode 100755 new mode 100644 similarity index 100% rename from scripts/mesonconf.py rename to mesonconf.py diff --git a/scripts/mesongui.py b/mesongui.py old mode 100755 new mode 100644 similarity index 100% rename from scripts/mesongui.py rename to mesongui.py diff --git a/scripts/mesonintrospect.py b/mesonintrospect.py old mode 100755 new mode 100644 similarity index 100% rename from scripts/mesonintrospect.py rename to mesonintrospect.py diff --git a/scripts/wraptool.py b/wraptool.py similarity index 100% rename from scripts/wraptool.py rename to wraptool.py