Build utils: make_update: Add option to choose SVN branch.

Needed for studio sprite-fright frozen branch.

Also do not overwrite branch for git sub-modules when it is defined, and
fallback to `master` branch in case specified branch is not found in a
specific sub-repository.
This commit is contained in:
Bastien Montagne 2021-09-02 12:11:32 +02:00
parent 799a2b07ad
commit 546314fc96
2 changed files with 21 additions and 11 deletions

@ -31,6 +31,7 @@ def parse_arguments():
parser.add_argument("--no-submodules", action="store_true") parser.add_argument("--no-submodules", action="store_true")
parser.add_argument("--use-tests", action="store_true") parser.add_argument("--use-tests", action="store_true")
parser.add_argument("--svn-command", default="svn") parser.add_argument("--svn-command", default="svn")
parser.add_argument("--svn-branch", default=None)
parser.add_argument("--git-command", default="git") parser.add_argument("--git-command", default="git")
parser.add_argument("--use-centos-libraries", action="store_true") parser.add_argument("--use-centos-libraries", action="store_true")
return parser.parse_args() return parser.parse_args()
@ -46,7 +47,7 @@ def svn_update(args, release_version):
svn_non_interactive = [args.svn_command, '--non-interactive'] svn_non_interactive = [args.svn_command, '--non-interactive']
lib_dirpath = os.path.join(get_blender_git_root(), '..', 'lib') lib_dirpath = os.path.join(get_blender_git_root(), '..', 'lib')
svn_url = make_utils.svn_libraries_base_url(release_version) svn_url = make_utils.svn_libraries_base_url(release_version, args.svn_branch)
# Checkout precompiled libraries # Checkout precompiled libraries
if sys.platform == 'darwin': if sys.platform == 'darwin':
@ -170,26 +171,28 @@ def submodules_update(args, release_version, branch):
sys.stderr.write("git not found, can't update code\n") sys.stderr.write("git not found, can't update code\n")
sys.exit(1) sys.exit(1)
# Update submodules to latest master or appropriate release branch. # Update submodules to appropriate given branch,
if not release_version: # falling back to master if none is given and/or found in a sub-repository.
branch = "master" branch_fallback = "master"
if not branch:
branch = branch_fallback
submodules = [ submodules = [
("release/scripts/addons", branch), ("release/scripts/addons", branch, branch_fallback),
("release/scripts/addons_contrib", branch), ("release/scripts/addons_contrib", branch, branch_fallback),
("release/datafiles/locale", branch), ("release/datafiles/locale", branch, branch_fallback),
("source/tools", branch), ("source/tools", branch, branch_fallback),
] ]
# Initialize submodules only if needed. # Initialize submodules only if needed.
for submodule_path, submodule_branch in submodules: for submodule_path, submodule_branch, submodule_branch_fallback in submodules:
if not os.path.exists(os.path.join(submodule_path, ".git")): if not os.path.exists(os.path.join(submodule_path, ".git")):
call([args.git_command, "submodule", "update", "--init", "--recursive"]) call([args.git_command, "submodule", "update", "--init", "--recursive"])
break break
# Checkout appropriate branch and pull changes. # Checkout appropriate branch and pull changes.
skip_msg = "" skip_msg = ""
for submodule_path, submodule_branch in submodules: for submodule_path, submodule_branch, submodule_branch_fallback in submodules:
cwd = os.getcwd() cwd = os.getcwd()
try: try:
os.chdir(submodule_path) os.chdir(submodule_path)
@ -201,6 +204,11 @@ def submodules_update(args, release_version, branch):
call([args.git_command, "fetch", "origin"]) call([args.git_command, "fetch", "origin"])
call([args.git_command, "checkout", submodule_branch]) call([args.git_command, "checkout", submodule_branch])
call([args.git_command, "pull", "--rebase", "origin", submodule_branch]) call([args.git_command, "pull", "--rebase", "origin", submodule_branch])
# If we cannot find the specified branch for this submodule, fallback to default one (aka master).
if make_utils.git_branch(args.git_command) != submodule_branch:
call([args.git_command, "fetch", "origin"])
call([args.git_command, "checkout", submodule_branch_fallback])
call([args.git_command, "pull", "--rebase", "origin", submodule_branch_fallback])
finally: finally:
os.chdir(cwd) os.chdir(cwd)

@ -70,9 +70,11 @@ def git_branch_release_version(branch, tag):
return release_version return release_version
def svn_libraries_base_url(release_version): def svn_libraries_base_url(release_version, branch):
if release_version: if release_version:
svn_branch = "tags/blender-" + release_version + "-release" svn_branch = "tags/blender-" + release_version + "-release"
elif branch:
svn_branch = "branches/" + branch
else: else:
svn_branch = "trunk" svn_branch = "trunk"
return "https://svn.blender.org/svnroot/bf-blender/" + svn_branch + "/lib/" return "https://svn.blender.org/svnroot/bf-blender/" + svn_branch + "/lib/"