From 23b98cd6e66c6ae0f070e28e0f8b1566c0b5e585 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 16 Jan 2016 17:35:29 +0200 Subject: Renamed meson package to mesonbuild so that we can have a script named meson in the same toplevel dir. --- mesonbuild/scripts/commandrunner.py | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 mesonbuild/scripts/commandrunner.py (limited to 'mesonbuild/scripts/commandrunner.py') diff --git a/mesonbuild/scripts/commandrunner.py b/mesonbuild/scripts/commandrunner.py new file mode 100644 index 000000000..f5a2fffdf --- /dev/null +++ b/mesonbuild/scripts/commandrunner.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +# Copyright 2014 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. + +"""This program is a wrapper to run external commands. It determines +what to run, sets up the environment and executes the command.""" + +import sys, os, subprocess, shutil + +def run_command(source_dir, build_dir, subdir, command, arguments): + env = {'MESON_SOURCE_ROOT' : source_dir, + 'MESON_BUILD_ROOT' : build_dir, + 'MESON_SUBDIR' : subdir + } + cwd = os.path.join(source_dir, subdir) + child_env = os.environ.copy() + child_env.update(env) + + # Is the command an executable in path? + exe = shutil.which(command) + if exe is not None: + command_array = [exe] + arguments + return subprocess.Popen(command_array, env=child_env, cwd=cwd) + # No? Maybe it is a script in the source tree. + fullpath = os.path.join(source_dir, subdir, command) + command_array = [fullpath] + arguments + try: + return subprocess.Popen(command_array,env=child_env, cwd=cwd) + except FileNotFoundError: + print('Could not execute command "%s".' % command) + sys.exit(1) + +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] + command = sys.argv[4] + arguments = sys.argv[5:] + pc = run_command(src_dir, build_dir, subdir, command, arguments) + pc.wait() + return pc.returncode + +if __name__ == '__main__': + sys.exit(run(sys.argv[1:])) -- cgit v1.2.3 From d6e176f45589485786fe87ba7ef15fe7fd8302d1 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 16 Jan 2016 18:04:59 +0200 Subject: Made gtkdoc and run targets work. --- mesonbuild/mesonmain.py | 2 +- mesonbuild/modules/gnome.py | 8 ++++---- mesonbuild/ninjabackend.py | 4 ++-- mesonbuild/scripts/commandrunner.py | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'mesonbuild/scripts/commandrunner.py') diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 82f30fe03..7b0834ce8 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -188,7 +188,7 @@ def run_script_command(args): import mesonbuild.scripts.dirchanger as abc cmdfunc = abc.run elif cmdname == 'gtkdoc': - import meson.scripts.gtkdochelper as abc + import mesonbuild.scripts.gtkdochelper as abc cmdfunc = abc.run elif cmdname == 'regencheck': import mesonbuild.scripts.regen_checker as abc diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index e552b8488..a3516949c 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -260,11 +260,11 @@ class GnomeModule: main_file = main_xml src_dir = kwargs['src_dir'] targetname = modulename + '-doc' - command = os.path.normpath(os.path.join(os.path.split(__file__)[0], "../gtkdochelper.py")) + command = [state.environment.get_build_command(), '--internal', 'gtkdoc'] if hasattr(src_dir, 'held_object'): src_dir= src_dir.held_object if not isinstance(src_dir, build.IncludeDirs): - raise MesonException('Invalidt keyword argument for src_dir.') + raise MesonException('Invalid keyword argument for src_dir.') incdirs = src_dir.get_incdirs() if len(incdirs) != 1: raise MesonException('Argument src_dir has more than one directory specified.') @@ -279,9 +279,9 @@ class GnomeModule: '--modulename=' + modulename] args += self.unpack_args('--htmlargs=', 'html_args', kwargs) args += self.unpack_args('--scanargs=', 'scan_args', kwargs) - res = [build.RunTarget(targetname, command, args, state.subdir)] + res = [build.RunTarget(targetname, command[0], command[1:] + args, state.subdir)] if kwargs.get('install', True): - res.append(build.InstallScript([command] + args)) + res.append(build.InstallScript(command + args)) return res def unpack_args(self, arg, kwarg_name, kwargs): diff --git a/mesonbuild/ninjabackend.py b/mesonbuild/ninjabackend.py index 36c5ce961..89aa57381 100644 --- a/mesonbuild/ninjabackend.py +++ b/mesonbuild/ninjabackend.py @@ -362,7 +362,7 @@ int dummy; self.processed_targets[target.name + target.type_suffix()] = True def generate_run_target(self, target, outfile): - runnerscript = os.path.join(self.environment.get_script_dir(), 'commandrunner.py') + runnerscript = [sys.executable, self.environment.get_build_command(), '--internal', 'commandrunner'] deps = [] arg_strings = [] for i in target.args: @@ -376,7 +376,7 @@ int dummy; mlog.debug(str(i)) raise MesonException('Unreachable code in generate_run_target.') elem = NinjaBuildElement(target.name, 'CUSTOM_COMMAND', deps) - cmd = [sys.executable, runnerscript, self.environment.get_source_dir(), self.environment.get_build_dir(), target.subdir] + cmd = runnerscript + [self.environment.get_source_dir(), self.environment.get_build_dir(), target.subdir] texe = target.command try: texe = texe.held_object diff --git a/mesonbuild/scripts/commandrunner.py b/mesonbuild/scripts/commandrunner.py index f5a2fffdf..1c37f5c54 100644 --- a/mesonbuild/scripts/commandrunner.py +++ b/mesonbuild/scripts/commandrunner.py @@ -43,14 +43,14 @@ def run_command(source_dir, build_dir, subdir, command, arguments): sys.exit(1) def run(args): - if len(sys.argv) < 4: + if len(args) < 4: print('commandrunner.py [arguments]') - sys.exit(1) - src_dir = sys.argv[1] - build_dir = sys.argv[2] - subdir = sys.argv[3] - command = sys.argv[4] - arguments = sys.argv[5:] + return 1 + src_dir = args[0] + build_dir = args[1] + subdir = args[2] + command = args[3] + arguments = args[4:] pc = run_command(src_dir, build_dir, subdir, command, arguments) pc.wait() return pc.returncode -- cgit v1.2.3