scripts: Fix fetching of meson command to run
authorNirbheek Chauhan <nirbheek@centricular.com>
Fri, 10 Aug 2018 21:20:14 +0000 (02:50 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Fri, 10 Aug 2018 21:22:51 +0000 (02:52 +0530)
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
common.py
gst-uninstalled.py
setup.py

index 1a71241..9c4d3b4 100755 (executable)
@@ -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"):
index b3ee7c5..dee8b1f 100644 (file)
--- 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
-
-    meson = accept_command(["meson.py", "meson"])
-
-    return meson
+                return [comp]
+
+    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')
index 43e81c9..0ddeea1 100755 (executable)
@@ -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))
index b42a247..5f286b9 100755 (executable)
--- 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: