diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-09-15 16:09:24 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-09-16 16:13:03 +0000 |
commit | 450ff3b4ebae80de192f24afb5cd1993faf226b4 (patch) | |
tree | 4ab5c27592775466a5eb0837e56a7317c09a54fb | |
parent | 82d3f8435bc8819b39ece35cd062962b52b5a148 (diff) |
setup.py: Make prepareSubModules() a bit smarter
Avoid unnecessarily re-initializing the submodules and checking
out branches.
In a first loop, collect the subdirectories and check whether any
are missing. Initialize submodules only in that case.
In the second loop, check out the correct branch if it differs.
Change-Id: I3c16fd9b7bd6feb77b7b921d61f7e622cfab797f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | setup.py | 49 | ||||
-rw-r--r-- | utils.py | 10 |
2 files changed, 45 insertions, 14 deletions
@@ -122,7 +122,7 @@ from utils import rmtree from utils import makefile from utils import copyfile from utils import copydir -from utils import run_process +from utils import run_process_output, run_process from utils import has_option from utils import option_value from utils import update_env_path @@ -284,25 +284,46 @@ if OPTION_NOEXAMPLES: # Initialize, pull and checkout submodules def prepareSubModules(): print("Initializing submodules for PySide2 version %s" % __version__) - git_update_cmd = ["git", "submodule", "update", "--init"] - if run_process(git_update_cmd) != 0: - raise DistutilsSetupError("Failed to initialize the git submodules") - git_pull_cmd = ["git", "submodule", "foreach", "git", "fetch", "--all"] - if run_process(git_pull_cmd) != 0: - raise DistutilsSetupError("Failed to initialize the git submodules") submodules_dir = os.path.join(script_dir, "sources") + # Create list of [name, desired branch, absolute path, desired branch] + # and determine whether all submodules are present + needInitSubModules = False + modulesList = [] for m in submodules[__version__]: module_name = m[0] module_version = m[1] - print("Checking out submodule %s to branch %s" % (module_name, module_version)) - module_dir = '' - if len(m) > 2: - module_dir = m[2] + module_dir = m[2] if len(m) > 2 else '' module_dir = os.path.join(submodules_dir, module_dir, module_name) + if not os.path.exists(module_dir): + needInitSubModules = True + modulesList.append([module_name, module_version, module_dir]) + if needInitSubModules: + git_update_cmd = ["git", "submodule", "update", "--init"] + if run_process(git_update_cmd) != 0: + raise DistutilsSetupError("Failed to initialize the git submodules") + git_pull_cmd = ["git", "submodule", "foreach", "git", "fetch", "--all"] + if run_process(git_pull_cmd) != 0: + raise DistutilsSetupError("Failed to initialize the git submodules") + else: + print("All submodules present...") + # Ensure all submodules have the correct branch checked out + for m in modulesList: + module_name = m[0] + module_version = m[1] + module_dir = m[2] os.chdir(module_dir) - git_checkout_cmd = ["git", "checkout", module_version] - if run_process(git_checkout_cmd) != 0: - raise DistutilsSetupError("Failed to initialize the git submodule %s" % module_name) + currentBranch = '' + for line in run_process_output(['git', 'branch']): + if line.startswith('* '): + currentBranch = line[2:len(line)] + break + if currentBranch != module_version: + print("Checking out submodule %s to branch %s (from %s)" % (module_name, module_version, currentBranch)) + git_checkout_cmd = ["git", "checkout", module_version] + if run_process(git_checkout_cmd) != 0: + raise DistutilsSetupError("Failed to initialize the git submodule %s" % module_name) + else: + print("Submodule %s has branch %s checked out" % (module_name, module_version)) os.chdir(script_dir) def prepareBuild(): @@ -325,6 +325,16 @@ def rmtree(dirname): raise shutil.rmtree(dirname, ignore_errors=False, onerror=handleRemoveReadonly) +def run_process_output(args, initial_env=None): + if initial_env is None: + initial_env = os.environ + stdOut = subprocess.Popen(args, env = initial_env, universal_newlines = 1, + stdout=subprocess.PIPE).stdout + result = [] + for rawLine in stdOut.readlines(): + line = rawLine.decode('utf-8') + result.append(line.rstrip()) + return result def run_process(args, initial_env=None): def _log(buffer, checkNewLine=False): |