aboutsummaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-09-15 16:09:24 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-09-16 16:13:03 +0000
commit450ff3b4ebae80de192f24afb5cd1993faf226b4 (patch)
tree4ab5c27592775466a5eb0837e56a7317c09a54fb /setup.py
parent82d3f8435bc8819b39ece35cd062962b52b5a148 (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>
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py49
1 files changed, 35 insertions, 14 deletions
diff --git a/setup.py b/setup.py
index 965b4cb1e..637d9ca4b 100644
--- a/setup.py
+++ b/setup.py
@@ -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():