[Bf-blender-cvs] [b6114c38496] master: Build: skip Blender repository pull in "make update" when not possible

Brecht Van Lommel noreply at git.blender.org
Sun Sep 8 14:53:11 CEST 2019


Commit: b6114c38496a87ea7eb6b46f975f8de68ed67d27
Author: Brecht Van Lommel
Date:   Sun Sep 8 14:17:58 2019 +0200
Branches: master
https://developer.blender.org/rBb6114c38496a87ea7eb6b46f975f8de68ed67d27

Build: skip Blender repository pull in "make update" when not possible

This prints a more informative message, and is convenient when working with
local changes or in a branch where you only need to update submodules or tests.

===================================================================

M	build_files/utils/make_update.py
M	build_files/utils/make_utils.py

===================================================================

diff --git a/build_files/utils/make_update.py b/build_files/utils/make_update.py
index 8184674e37e..2cbbd1ffd72 100755
--- a/build_files/utils/make_update.py
+++ b/build_files/utils/make_update.py
@@ -12,10 +12,14 @@ import shutil
 import sys
 
 import make_utils
-from make_utils import call
+from make_utils import call, check_output
 
-# Parse arguments
+def print_stage(text):
+    print("")
+    print(text)
+    print("")
 
+# Parse arguments
 def parse_arguments():
     parser = argparse.ArgumentParser()
     parser.add_argument("--no-libraries", action="store_true")
@@ -26,25 +30,11 @@ def parse_arguments():
     parser.add_argument("--git-command", default="git")
     return parser.parse_args()
 
-args = parse_arguments()
-no_libraries = args.no_libraries
-no_blender = args.no_blender
-no_submodules = args.no_submodules
-use_tests = args.use_tests
-git_command = args.git_command
-svn_command = args.svn_command
-svn_non_interactive = [args.svn_command, '--non-interactive']
-
-def print_stage(text):
-    print("")
-    print(text)
-    print("")
-
-# Test if we are building a specific release version.
-release_version = make_utils.git_branch_release_version(git_command)
 
 # Setup for precompiled libraries and tests from svn.
-if not no_libraries:
+def svn_update(args, release_version):
+    svn_non_interactive = [args.svn_command, '--non-interactive']
+
     lib_dirpath = os.path.join('..', 'lib')
     svn_url = make_utils.svn_libraries_base_url(release_version)
 
@@ -66,21 +56,21 @@ if not no_libraries:
         if not os.path.exists(lib_platform_dirpath):
             print_stage("Checking out Precompiled Libraries")
 
-            if shutil.which(svn_command) is None:
+            if shutil.which(args.svn_command) is None:
                 sys.stderr.write("svn not found, can't checkout libraries\n")
                 sys.exit(1)
 
             svn_url_platform = svn_url + lib_platform
             call(svn_non_interactive + ["checkout", svn_url_platform, lib_platform_dirpath])
 
-    if use_tests:
+    if args.use_tests:
         lib_tests = "tests"
         lib_tests_dirpath = os.path.join(lib_dirpath, lib_tests)
 
         if not os.path.exists(lib_tests_dirpath):
             print_stage("Checking out Tests")
 
-            if shutil.which(svn_command) is None:
+            if shutil.which(args.svn_command) is None:
                 sys.stderr.write("svn not found, can't checkout tests\n")
                 sys.exit(1)
 
@@ -101,7 +91,7 @@ if not no_libraries:
 
         if os.path.isdir(dirpath) and \
            (os.path.exists(svn_dirpath) or os.path.exists(svn_root_dirpath)):
-            if shutil.which(svn_command) is None:
+            if shutil.which(args.svn_command) is None:
                 sys.stderr.write("svn not found, can't update libraries\n")
                 sys.exit(1)
 
@@ -109,25 +99,71 @@ if not no_libraries:
             call(svn_non_interactive + ["switch", svn_url + dirname, dirpath])
             call(svn_non_interactive + ["update", dirpath])
 
-# Update blender repository and submodules.
-if not no_blender:
-    print_stage("Updating Blender Git Repository")
-    if shutil.which(git_command) is None:
+
+# Update blender repository.
+def blender_update_skip(args):
+    if shutil.which(args.git_command) is None:
         sys.stderr.write("git not found, can't update code\n")
         sys.exit(1)
 
-    call([git_command, "pull", "--rebase"])
+    # Abort if a rebase is still progress.
+    rebase_merge = check_output([args.git_command, 'rev-parse', '--git-path', 'rebase-merge'])
+    rebase_apply = check_output([args.git_command, 'rev-parse', '--git-path', 'rebase-apply'])
+    merge_head = check_output([args.git_command, 'rev-parse', '--git-path', 'MERGE_HEAD'])
+    if os.path.exists(rebase_merge) or \
+       os.path.exists(rebase_apply) or \
+       os.path.exists(merge_head):
+        return "rebase or merge in progress, complete it first"
+
+    # Abort if uncommitted changes.
+    changes = check_output([args.git_command, 'status', '--porcelain', '--untracked-files=no'])
+    if len(changes) != 0:
+        return "you have unstaged changes"
+
+    # Test if there is an upstream branch configured
+    branch = check_output([args.git_command, "rev-parse", "--abbrev-ref", "HEAD"])
+    remote = check_output([args.git_command, "config", "branch." + branch + ".remote"], exit_on_error=False)
+    if len(remote) == 0:
+        return "no remote branch to pull from"
+
+    return None
+
+def blender_update(args):
+    print_stage("Updating Blender Git Repository")
+    call([args.git_command, "pull", "--rebase"])
+
 
-if not no_submodules:
+# Update submodules.
+def submodules_update(args, release_version):
     print_stage("Updating Submodules")
-    if shutil.which(git_command) is None:
+    if shutil.which(args.git_command) is None:
         sys.stderr.write("git not found, can't update code\n")
         sys.exit(1)
 
-    call([git_command, "submodule", "update", "--init", "--recursive"])
+    call([args.git_command, "submodule", "update", "--init", "--recursive"])
     if not release_version:
         # Update submodules to latest master if not building a specific release.
         # In that case submodules are set to a specific revision, which is checked
         # out by running "git submodule update".
-        call([git_command, "submodule", "foreach", "git", "checkout", "master"])
-        call([git_command, "submodule", "foreach", "git", "pull", "--rebase", "origin", "master"])
+        call([args.git_command, "submodule", "foreach", "git", "checkout", "master"])
+        call([args.git_command, "submodule", "foreach", "git", "pull", "--rebase", "origin", "master"])
+
+
+if __name__ == "__main__":
+    args = parse_arguments()
+    blender_skipped = None
+
+    # Test if we are building a specific release version.
+    release_version = make_utils.git_branch_release_version(args.git_command)
+
+    if not args.no_libraries:
+        svn_update(args, release_version)
+    if not args.no_blender:
+        blender_skipped = blender_update_skip(args)
+        if not blender_skipped:
+            blender_update(args)
+    if not args.no_submodules:
+        submodules_update(args, release_version)
+
+    if blender_skipped:
+        print_stage("Blender repository skipped: " + blender_skipped)
diff --git a/build_files/utils/make_utils.py b/build_files/utils/make_utils.py
index d05c1e6f838..9a1f740a393 100755
--- a/build_files/utils/make_utils.py
+++ b/build_files/utils/make_utils.py
@@ -6,7 +6,7 @@ import re
 import subprocess
 import sys
 
-def call(cmd):
+def call(cmd, exit_on_error=True):
     print(" ".join(cmd))
 
     # Flush to ensure correct order output on Windows.
@@ -14,8 +14,25 @@ def call(cmd):
     sys.stderr.flush()
 
     retcode = subprocess.call(cmd)
-    if retcode != 0:
-      sys.exit(retcode)
+    if exit_on_error and retcode != 0:
+        sys.exit(retcode)
+    return retcode
+
+def check_output(cmd, exit_on_error=True):
+    # Flush to ensure correct order output on Windows.
+    sys.stdout.flush()
+    sys.stderr.flush()
+
+    try:
+        output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
+    except subprocess.CalledProcessError as e:
+        if exit_on_error:
+            sys.stderr.write(" ".join(cmd))
+            sys.stderr.write(e.output + "\n")
+            sys.exit(e.returncode)
+        output = ""
+
+    return output.strip()
 
 def git_branch_release_version(git_command):
     # Test if we are building a specific release version.



More information about the Bf-blender-cvs mailing list