[pitivi] Port configure script to python



commit 3a1d93b657161e1e0ce64e4da4d128b2d13bb3e7
Author: Thibault Saunier <tsaunier gnome org>
Date:   Mon Aug 1 17:48:49 2016 -0400

    Port configure script to python
    
    And update gst-transcoder submodule
    
    Differential Revision: https://phabricator.freedesktop.org/D1234

 configure                  |  149 ++++++++++++++++++++++++--------------------
 subprojects/gst-transcoder |    2 +-
 2 files changed, 83 insertions(+), 68 deletions(-)
---
diff --git a/configure b/configure
index 750625c..01beb3f 100755
--- a/configure
+++ b/configure
@@ -1,77 +1,92 @@
-#!/bin/sh
-
-DIR=$(cd "$(dirname "$0")" && pwd)
-
-MESON=meson
-command -v $MESON > /dev/null 2>&1
-if [ $? != 0 ]
-then
-    MESON=meson.py
-    command -v $MESON > /dev/null 2>&1
-    if [ $? != 0 ]
-    then
-        echo "You should install mesonbuild to build Pitivi: http://mesonbuild.com/";
-        echo "You can simply install it with:"
-        echo "    $ sudo pip3 install meson"
-
-        exit 1
-    fi
-fi
-
-NINJA=ninja
-command -v $NINJA > /dev/null 2>&1
-if [ $? != 0 ]
-then
-    NINJA=ninja-build
-    command -v $NINJA > /dev/null 2>&1
-    if [ $? != 0 ]
-    then
-      echo "You should install ninja-build to build Pitivi: https://ninja-build.org/";
-      exit 1
-    fi
-fi
-
-# Make sure we have subprojects/gst-transcoder
-if test ! -f subprojects/gst-transcoder/meson.build;
-then
-  echo "+ Setting up subprojects/gst-transcoder/ submodule"
-  git submodule init
-fi
-git submodule update
-
-# Install the pre-commit hook for doing clean commits
-rm -f .git/hooks/pre-commit
-ln -s ../../pre-commit.hook .git/hooks/pre-commit
-echo ""
-which pre-commit > /dev/null
-if [ $? -eq 0 ];
-then
-  pre-commit install
-else
-  echo "Please install pre-commit from http://pre-commit.com/ before proposing patches"
-  echo ""
-fi
-
-BUILDDIR=mesonbuild
-rm -Rf $BUILDDIR > /dev/null 2>&1
-mkdir $BUILDDIR/ && cd $BUILDDIR && $MESON ../ "$@"
-
-cat <<EOF > $DIR/Makefile
-all:
-       cd $BUILDDIR && $NINJA
+#!/usr/bin/env python3
+"""Script for generating the Makefiles."""
+
+import os
+import sys
+import shutil
+import subprocess
+
+PROJECTNAME = "Pitivi"
+
+ROOTDIR = os.path.abspath(os.path.dirname(__file__))
+MAKEFILE_TMPL = """all:
+%(tab)scd %(build_dir)s && %(ninja)s
 
 install:
-       cd $BUILDDIR && DESTDIR="\${DESTDIR}" $NINJA install
+%(tab)scd %(build_dir)s && DESTDIR="${DESTDIR}" %(ninja)s install
 
 check:
-       cd $BUILDDIR && $NINJA test
+%(tab)scd %(build_dir)s && %(ninja)s test
 
 dist:
-       cd $BUILDDIR && $NINJA dist
+%(tab)scd %(build_dir)s && %(ninja)s dist
 
 clean:
-       rm -Rf $BUILDDIR
-       rm Makefile
+%(tab)srm -Rf %(build_dir)s
+%(tab)srm Makefile
+"""
+
+
+def accept_command(commands):
+    """Checks if @command --version works."""
+    for command in commands:
+        try:
+            subprocess.check_output([command, "--version"])
+            return command
+        except FileNotFoundError:
+            pass
+
+    return None
+
+
+def install_pre_commit_hook():
+    """Installs the pre commit hook."""
+    os.chdir(ROOTDIR)
+    try:
+        os.remove(os.path.join(ROOTDIR, ".git", "pre-commit"))
+    except FileNotFoundError:
+        pass
+
+    os.symlink(os.path.join(os.path.pardir, os.path.pardir, "pre-commit.hook"),
+               os.path.join(ROOTDIR, ".git", "pre-commit"))
+    try:
+        subprocess.check_call(["pre-commit", "install"])
+    except FileNotFoundError:
+        print("Please install pre-commit from http://pre-commit.com/ before"
+              " proposing patches")
+
+
+def configure_meson():
+    """Configures meson and generate the Makefile."""
+    meson = accept_command(["meson", "meson.py"])
+    if not meson:
+        print("Install mesonbuild to build %s: http://mesonbuild.com/\n";
+              "You can simply install it with:\n"
+              "    $ sudo pip3 install meson" % PROJECTNAME)
+        exit(1)
+
+    ninja = accept_command(["ninja", "ninja-build"])
+    if not ninja:
+        print("Install ninja-build to build %s: https://ninja-build.org/";
+              % PROJECTNAME)
+        exit(1)
+
+    build_dir = os.path.join(ROOTDIR, "mesonbuild")
+    shutil.rmtree(build_dir, True)
+    os.mkdir(build_dir)
+    os.chdir(build_dir)
+
+    try:
+        subprocess.check_call([meson, "../"] + sys.argv[1:])
+    except subprocess.CalledProcessError:
+        exit(1)
 
-EOF
+    with open(os.path.join(ROOTDIR, "Makefile"), "w") as makefile:
+        makefile.write(MAKEFILE_TMPL %
+                       {"build_dir": build_dir,
+                        "ninja": ninja,
+                        "tab": "       "})
 
+if __name__ == "__main__":
+    configure_meson()
+    install_pre_commit_hook()
diff --git a/subprojects/gst-transcoder b/subprojects/gst-transcoder
index db82989..6ff7f83 160000
--- a/subprojects/gst-transcoder
+++ b/subprojects/gst-transcoder
@@ -1 +1 @@
-Subproject commit db82989f7d9532406d24a4dfba1456819edba505
+Subproject commit 6ff7f832f29e8a8c89673c6bac4e3a1b27a28041


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]