Add 'update' and `git-update` targets to update git repos
authorThibault Saunier <thibault.saunier@osg.samsung.com>
Mon, 7 Nov 2016 21:17:39 +0000 (18:17 -0300)
committerThibault Saunier <thibault.saunier@osg.samsung.com>
Tue, 8 Nov 2016 18:16:57 +0000 (15:16 -0300)
README.md
common.py
git-update
meson.build
setup

index 13e67d0..55f508b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -28,18 +28,40 @@ NOTE: on fedora (and maybe other distributions) replace `ninja` with `ninja-buil
 
 # Development environment
 
+## Uninstalled environment
+
 gst-build also contains a special `uninstalled` target that lets you enter an
-uninstalled development environment where you will be able to work on GStreamer easily.
-You can get into that environment running:
+uninstalled development environment where you will be able to work on GStreamer
+easily. You can get into that environment running:
 
 ```
 ninja -C build/ uninstalled
 ```
 
-If your operating system handles symlinks, built modules source code will be available
-at the root of `gst-build/` for example GStreamer core will be in `gstreamer/`. Otherwise
-they will be present in `subprojects/`. You can simply hack in there and to rebuild you
-just need to rerun `ninja -C build/`.
+If your operating system handles symlinks, built modules source code will be
+available at the root of `gst-build/` for example GStreamer core will be in
+`gstreamer/`. Otherwise they will be present in `subprojects/`. You can simply
+hack in there and to rebuild you just need to rerun `ninja -C build/`.
+
+## Update git subprojects
+
+We added a special `update` target to update subprojects (it uses `git pull
+--rebase` meaning you should always make sure the branches you work on are
+following the right upstream branch, you can set it with `git branch
+--set-upstream-to origin/master` if you are working on `gst-build` master
+branch).
+
+Update all GStreamer modules and rebuild:
+
+```
+ninja -C build/ update
+```
+
+Update all GStreamer modules without rebuilding:
+
+```
+ninja -C build/ git-update
+```
 
 
 ## Add information about GStreamer development environment in your prompt line
index 244b30a..40f420e 100644 (file)
--- a/common.py
+++ b/common.py
@@ -1,4 +1,5 @@
 import argparse
+import shutil
 import subprocess
 
 class Colors:
@@ -37,3 +38,12 @@ class Colors:
 def git(*args, repository_path='.'):
     return subprocess.check_output(["git"] + list(args), cwd=repository_path,
                                    stderr=subprocess.STDOUT).decode()
+
+def accept_command(commands):
+    """Search @commands and returns the first found absolute path."""
+    for command in commands:
+        command = shutil.which(command)
+        if command:
+            return command
+
+    return None
index 8ffc2af..d86810e 100755 (executable)
@@ -6,6 +6,7 @@ import xml.etree.ElementTree as ET
 
 from common import git
 from common import Colors
+from common import accept_command
 
 
 SCRIPTDIR = os.path.dirname(__file__)
@@ -51,8 +52,8 @@ def update_repo(repo_name, repo_dir, revision, no_interaction, recurse_i=0):
         out = getattr(e, "output", b"").decode()
         if not no_interaction:
             print("====================================="
-                  "\n%sEntering a shell in %s to fix that"
-                  " just `exit 0` once done` or `exit 255`"
+                  "\n%s\nEntering a shell in %s to fix that"
+                  " just `exit 0` once done, or `exit 255`"
                   " to skip update for that repository"
                   "\n=====================================" % (
                         out, repo_dir))
@@ -95,6 +96,10 @@ if __name__ == "__main__":
                         default=False,
                         action='store_true',
                         help="Do not output ansi colors.")
+    parser.add_argument("--builddir",
+                        default=None,
+                        help="Specifies the build directory where to"
+                        " invoke ninja after updating.")
     parser.add_argument("--no-interaction",
                         default=False,
                         action='store_true',
@@ -109,5 +114,17 @@ if __name__ == "__main__":
 
     if not update_repo('gst-build', SCRIPTDIR, None, options.no_interaction):
         exit(1)
-    exit(not update_subprojects(options.manifest,
-                                options.no_interaction))
+    if not update_subprojects(options.manifest, options.no_interaction):
+        exit(1)
+
+    if options.builddir:
+        ninja = accept_command(["ninja", "ninja-build"])
+        if not ninja:
+            print("Can't find ninja, other backends are not supported for rebuilding")
+            exit(1)
+
+        if not os.path.exists(os.path.join (options.builddir, 'build.ninja')):
+            print("Can't rebuild in %s as no build.ninja file found." % options.builddir)
+
+        print("Rebuilding all GStreamer modules.")
+        exit(subprocess.call([ninja, '-C', options.builddir]))
index 57cfde5..0037b9e 100644 (file)
@@ -84,3 +84,8 @@ endforeach
 setenv = find_program('gst-uninstalled.py')
 run_target('uninstalled', command : [setenv, '--builddir=@0@'.format(meson.current_build_dir()),
            '--gst-version=@0@'.format(gst_branch)])
+
+update = find_program('git-update')
+run_target('git-update', command : [update])
+run_target('update', command : [update,
+    '--builddir=@0@'.format(meson.current_build_dir())])
diff --git a/setup b/setup
index 5cca3c7..2c5d301 100755 (executable)
--- a/setup
+++ b/setup
@@ -9,6 +9,7 @@ import subprocess
 
 from common import git
 from common import Colors
+from common import accept_command
 
 
 PROJECTNAME = "GStreamer build"
@@ -25,16 +26,6 @@ def get_meson():
     return accept_command(["meson.py", "meson"]), accept_command(["mesonconf.py", "mesonconf"])
 
 
-def accept_command(commands):
-    """Search @commands and returns the first found absolute path."""
-    for command in commands:
-        command = shutil.which(command)
-        if command:
-            return command
-
-    return None
-
-
 def get_configs(meson):
      return ['-D', 'werror=true']