From 783e6a226d55bab1e3c4eb8bd29a898a2784686e Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sat, 11 Aug 2018 02:50:14 +0530 Subject: [PATCH] scripts: Fix fetching of meson command to run Don't assume that meson is always a python script, on Windows it can be (and soon will almost always be) an executable. See: Meson MSI installer and https://github.com/mesonbuild/meson/pull/4004 --- checkout-branch-worktree | 3 +-- common.py | 24 ++++++++++++------------ gst-uninstalled.py | 7 +++---- setup.py | 9 +++++---- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/checkout-branch-worktree b/checkout-branch-worktree index 1a7124150c..9c4d3b4d84 100755 --- a/checkout-branch-worktree +++ b/checkout-branch-worktree @@ -21,8 +21,7 @@ def checkout_subprojects(worktree_dir, branch): worktree_subdir = os.path.join(worktree_dir, "subprojects") meson = get_meson() - installed_s = subprocess.check_output([sys.executable, meson, 'introspect', - options.builddir, '--projectinfo']) + installed_s = subprocess.check_output(meson + ['introspect', options.builddir, '--projectinfo']) for subproj in json.loads(installed_s.decode())["subprojects"]: repo_name = subproj["name"] if not repo_name.startswith("gst"): diff --git a/common.py b/common.py index b3ee7c5547..dee8b1f7da 100644 --- a/common.py +++ b/common.py @@ -51,13 +51,12 @@ def accept_command(commands): command = shutil.which(command) if command: return command - return None def get_meson(): meson = os.path.join(ROOTDIR, 'meson', 'meson.py') if os.path.exists(meson): - return meson + return [sys.executable, meson] mesonintrospect = os.environ.get('MESONINTROSPECT', '') for comp in shlex.split (mesonintrospect): @@ -65,15 +64,16 @@ def get_meson(): # let's not get tricked if 'python' in os.path.basename (comp): continue - if os.path.exists (comp): - mesondir = os.path.dirname(comp) - if mesonintrospect.endswith('.py') or mesonintrospect.endswith('.py introspect'): - meson = os.path.join(mesondir, 'meson.py') + if os.path.exists(comp): + if comp.endswith('.py'): + return [sys.executable, comp] else: - meson = os.path.join(mesondir, 'meson') - if os.path.exists (meson): - return meson + return [comp] - meson = accept_command(["meson.py", "meson"]) - - return meson + meson = accept_command(['meson.py']) + if meson: + return [sys.executable, meson] + meson = accept_command(['meson']) + if meson: + return [meson] + raise RuntimeError('Could not find Meson') diff --git a/gst-uninstalled.py b/gst-uninstalled.py index 43e81c922f..0ddeea15e9 100755 --- a/gst-uninstalled.py +++ b/gst-uninstalled.py @@ -76,7 +76,7 @@ def get_subprocess_env(options): setup_python_env(options, env) meson = get_meson() - targets_s = subprocess.check_output([sys.executable, meson, 'introspect', options.builddir, '--targets']) + targets_s = subprocess.check_output(meson + ['introspect', options.builddir, '--targets']) targets = json.loads(targets_s.decode()) paths = set() mono_paths = set() @@ -111,9 +111,8 @@ def get_subprocess_env(options): presets = set() encoding_targets = set() pkg_dirs = set() - if '--installed' in subprocess.check_output([sys.executable, meson, 'introspect', '-h']).decode(): - installed_s = subprocess.check_output([sys.executable, meson, 'introspect', - options.builddir, '--installed']) + if '--installed' in subprocess.check_output(meson + ['introspect', '-h']).decode(): + installed_s = subprocess.check_output(meson + ['introspect', options.builddir, '--installed']) for path, installpath in json.loads(installed_s.decode()).items(): if path.endswith('.prs'): presets.add(os.path.dirname(path)) diff --git a/setup.py b/setup.py index b42a247b0f..5f286b9c5e 100755 --- a/setup.py +++ b/setup.py @@ -33,8 +33,9 @@ class GstBuildConfigurer: print("Not reconfiguring") return True - meson = get_meson() - if not meson: + try: + meson = get_meson() + except RuntimeError: print("Install mesonbuild to build %s: http://mesonbuild.com/\n" "You can simply install it with:\n" " $ sudo pip3 install meson" % PROJECTNAME) @@ -51,8 +52,8 @@ class GstBuildConfigurer: os.mkdir(build_dir) try: - subprocess.check_call( - [sys.executable, meson, "../"] + self.args + self.get_configs(), cwd=build_dir) + subprocess.check_call(meson + ["../"] + self.args + self.get_configs(), + cwd=build_dir) print("\nYou can now build GStreamer and its various subprojects running:\n" " $ {} -C {!r}".format(os.path.basename(ninja), build_dir)) except subprocess.CalledProcessError: