2019-08-20 12:05:03 +02:00
|
|
|
#!/usr/bin/env python3
|
2022-02-11 14:30:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
"""
|
|
|
|
"make update" for all platforms, updating svn libraries and tests and Blender
|
|
|
|
git repository and sub-modules.
|
|
|
|
|
|
|
|
For release branches, this will check out the appropriate branches of
|
|
|
|
sub-modules and libraries.
|
|
|
|
"""
|
2019-08-23 19:35:02 +02:00
|
|
|
|
|
|
|
import argparse
|
2019-08-20 12:05:03 +02:00
|
|
|
import os
|
2021-02-01 22:34:16 +01:00
|
|
|
import platform
|
2019-08-23 19:35:02 +02:00
|
|
|
import shutil
|
2019-08-20 12:05:03 +02:00
|
|
|
import sys
|
|
|
|
|
2019-08-29 11:13:41 +02:00
|
|
|
import make_utils
|
2019-09-08 14:17:58 +02:00
|
|
|
from make_utils import call, check_output
|
2019-08-30 14:20:29 +02:00
|
|
|
|
2022-10-31 12:54:36 +11:00
|
|
|
from typing import (
|
|
|
|
List,
|
|
|
|
Optional,
|
|
|
|
)
|
2020-10-02 10:10:01 +10:00
|
|
|
|
2022-10-31 12:54:36 +11:00
|
|
|
|
|
|
|
def print_stage(text: str) -> None:
|
2019-09-08 14:17:58 +02:00
|
|
|
print("")
|
|
|
|
print(text)
|
|
|
|
print("")
|
2019-08-23 19:35:02 +02:00
|
|
|
|
2019-09-08 14:17:58 +02:00
|
|
|
# Parse arguments
|
2020-10-02 10:10:01 +10:00
|
|
|
|
|
|
|
|
2022-10-31 12:54:36 +11:00
|
|
|
def parse_arguments() -> argparse.Namespace:
|
2019-08-23 19:35:02 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
2019-09-03 17:38:40 +02:00
|
|
|
parser.add_argument("--no-libraries", action="store_true")
|
|
|
|
parser.add_argument("--no-blender", action="store_true")
|
|
|
|
parser.add_argument("--no-submodules", action="store_true")
|
2019-09-05 12:34:17 +02:00
|
|
|
parser.add_argument("--use-tests", action="store_true")
|
2019-08-23 19:35:02 +02:00
|
|
|
parser.add_argument("--svn-command", default="svn")
|
2021-09-02 12:11:32 +02:00
|
|
|
parser.add_argument("--svn-branch", default=None)
|
2019-08-23 19:35:02 +02:00
|
|
|
parser.add_argument("--git-command", default="git")
|
2019-10-09 09:42:42 +02:00
|
|
|
parser.add_argument("--use-centos-libraries", action="store_true")
|
2019-08-23 19:35:02 +02:00
|
|
|
return parser.parse_args()
|
|
|
|
|
2020-10-02 10:10:01 +10:00
|
|
|
|
2022-10-31 12:54:36 +11:00
|
|
|
def get_blender_git_root() -> str:
|
2019-10-09 09:42:42 +02:00
|
|
|
return check_output([args.git_command, "rev-parse", "--show-toplevel"])
|
|
|
|
|
2019-08-23 19:35:02 +02:00
|
|
|
# Setup for precompiled libraries and tests from svn.
|
2020-10-02 10:10:01 +10:00
|
|
|
|
|
|
|
|
2022-10-31 12:54:36 +11:00
|
|
|
def svn_update(args: argparse.Namespace, release_version: Optional[str]) -> None:
|
2019-09-08 14:17:58 +02:00
|
|
|
svn_non_interactive = [args.svn_command, '--non-interactive']
|
|
|
|
|
2019-10-09 09:42:42 +02:00
|
|
|
lib_dirpath = os.path.join(get_blender_git_root(), '..', 'lib')
|
2021-09-02 12:11:32 +02:00
|
|
|
svn_url = make_utils.svn_libraries_base_url(release_version, args.svn_branch)
|
2019-08-23 19:35:02 +02:00
|
|
|
|
|
|
|
# Checkout precompiled libraries
|
|
|
|
if sys.platform == 'darwin':
|
2022-11-17 14:00:31 +01:00
|
|
|
# Check platform.version to detect arm64 with x86_64 python binary.
|
|
|
|
if platform.machine() == 'arm64' or ('ARM64' in platform.version()):
|
2021-02-01 22:34:16 +01:00
|
|
|
lib_platform = "darwin_arm64"
|
2022-11-17 14:00:31 +01:00
|
|
|
elif platform.machine() == 'x86_64':
|
|
|
|
lib_platform = "darwin"
|
2021-02-01 22:34:16 +01:00
|
|
|
else:
|
|
|
|
lib_platform = None
|
2019-08-23 19:35:02 +02:00
|
|
|
elif sys.platform == 'win32':
|
|
|
|
# Windows checkout is usually handled by bat scripts since python3 to run
|
|
|
|
# this script is bundled as part of the precompiled libraries. However it
|
|
|
|
# is used by the buildbot.
|
2019-11-08 19:09:59 -07:00
|
|
|
lib_platform = "win64_vc15"
|
2019-10-09 09:42:42 +02:00
|
|
|
elif args.use_centos_libraries:
|
|
|
|
lib_platform = "linux_centos7_x86_64"
|
2019-08-23 19:35:02 +02:00
|
|
|
else:
|
|
|
|
# No precompiled libraries for Linux.
|
|
|
|
lib_platform = None
|
|
|
|
|
|
|
|
if lib_platform:
|
|
|
|
lib_platform_dirpath = os.path.join(lib_dirpath, lib_platform)
|
|
|
|
|
|
|
|
if not os.path.exists(lib_platform_dirpath):
|
|
|
|
print_stage("Checking out Precompiled Libraries")
|
|
|
|
|
2019-09-30 10:19:55 +02:00
|
|
|
if make_utils.command_missing(args.svn_command):
|
2019-08-31 18:43:31 +02:00
|
|
|
sys.stderr.write("svn not found, can't checkout libraries\n")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2019-08-23 19:35:02 +02:00
|
|
|
svn_url_platform = svn_url + lib_platform
|
2019-08-31 14:55:38 +02:00
|
|
|
call(svn_non_interactive + ["checkout", svn_url_platform, lib_platform_dirpath])
|
2019-08-23 19:35:02 +02:00
|
|
|
|
2019-09-08 14:17:58 +02:00
|
|
|
if args.use_tests:
|
2019-09-05 12:34:17 +02:00
|
|
|
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")
|
|
|
|
|
2019-09-30 10:19:55 +02:00
|
|
|
if make_utils.command_missing(args.svn_command):
|
2019-09-05 12:34:17 +02:00
|
|
|
sys.stderr.write("svn not found, can't checkout tests\n")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
svn_url_tests = svn_url + lib_tests
|
|
|
|
call(svn_non_interactive + ["checkout", svn_url_tests, lib_tests_dirpath])
|
|
|
|
|
2019-08-23 19:35:02 +02:00
|
|
|
# Update precompiled libraries and tests
|
2022-10-31 12:54:38 +11:00
|
|
|
|
|
|
|
if not os.path.isdir(lib_dirpath):
|
|
|
|
print("Library path: %r, not found, skipping" % lib_dirpath)
|
|
|
|
else:
|
|
|
|
paths_local_and_remote = []
|
|
|
|
if os.path.exists(os.path.join(lib_dirpath, ".svn")):
|
|
|
|
print_stage("Updating Precompiled Libraries and Tests (one repository)")
|
|
|
|
paths_local_and_remote.append((lib_dirpath, svn_url))
|
|
|
|
else:
|
|
|
|
print_stage("Updating Precompiled Libraries and Tests (multiple repositories)")
|
|
|
|
# Separate paths checked out.
|
|
|
|
for dirname in os.listdir(lib_dirpath):
|
|
|
|
if dirname.startswith("."):
|
|
|
|
# Temporary paths such as ".mypy_cache" will report a warning, skip hidden directories.
|
|
|
|
continue
|
|
|
|
|
|
|
|
dirpath = os.path.join(lib_dirpath, dirname)
|
|
|
|
if not (os.path.isdir(dirpath) and os.path.exists(os.path.join(dirpath, ".svn"))):
|
|
|
|
continue
|
|
|
|
|
|
|
|
paths_local_and_remote.append((dirpath, svn_url + dirname))
|
|
|
|
|
|
|
|
if paths_local_and_remote:
|
|
|
|
if make_utils.command_missing(args.svn_command):
|
|
|
|
sys.stderr.write("svn not found, can't update libraries\n")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
for dirpath, svn_url_full in paths_local_and_remote:
|
|
|
|
call(svn_non_interactive + ["cleanup", dirpath])
|
2019-10-09 21:35:57 +02:00
|
|
|
# Switch to appropriate branch and update.
|
2022-10-31 12:54:38 +11:00
|
|
|
call(svn_non_interactive + ["switch", svn_url_full, dirpath], exit_on_error=False)
|
2019-08-31 14:55:38 +02:00
|
|
|
call(svn_non_interactive + ["update", dirpath])
|
2019-08-23 19:35:02 +02:00
|
|
|
|
2022-04-20 15:08:46 +10:00
|
|
|
|
2019-10-09 14:41:34 +02:00
|
|
|
# Test if git repo can be updated.
|
2022-10-31 12:54:36 +11:00
|
|
|
def git_update_skip(args: argparse.Namespace, check_remote_exists: bool = True) -> str:
|
2019-09-30 10:19:55 +02:00
|
|
|
if make_utils.command_missing(args.git_command):
|
2019-09-03 17:38:40 +02:00
|
|
|
sys.stderr.write("git not found, can't update code\n")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2019-09-08 14:17:58 +02:00
|
|
|
# Abort if a rebase is still progress.
|
2019-10-08 15:11:55 +02:00
|
|
|
rebase_merge = check_output([args.git_command, 'rev-parse', '--git-path', 'rebase-merge'], exit_on_error=False)
|
|
|
|
rebase_apply = check_output([args.git_command, 'rev-parse', '--git-path', 'rebase-apply'], exit_on_error=False)
|
|
|
|
merge_head = check_output([args.git_command, 'rev-parse', '--git-path', 'MERGE_HEAD'], exit_on_error=False)
|
2019-09-08 14:17:58 +02:00
|
|
|
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
|
2019-10-09 21:35:57 +02:00
|
|
|
if check_remote_exists:
|
|
|
|
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"
|
2019-09-08 14:17:58 +02:00
|
|
|
|
2019-10-09 14:41:34 +02:00
|
|
|
return ""
|
2019-09-08 14:17:58 +02:00
|
|
|
|
2020-10-02 10:15:51 +10:00
|
|
|
|
2019-10-09 14:41:34 +02:00
|
|
|
# Update blender repository.
|
2022-10-31 12:54:36 +11:00
|
|
|
def blender_update(args: argparse.Namespace) -> None:
|
2019-09-08 14:17:58 +02:00
|
|
|
print_stage("Updating Blender Git Repository")
|
|
|
|
call([args.git_command, "pull", "--rebase"])
|
|
|
|
|
2019-09-03 17:38:40 +02:00
|
|
|
|
2019-09-08 14:17:58 +02:00
|
|
|
# Update submodules.
|
2022-10-31 12:54:36 +11:00
|
|
|
def submodules_update(
|
|
|
|
args: argparse.Namespace,
|
|
|
|
release_version: Optional[str],
|
|
|
|
branch: Optional[str],
|
|
|
|
) -> str:
|
2019-09-03 17:38:40 +02:00
|
|
|
print_stage("Updating Submodules")
|
2019-09-30 10:19:55 +02:00
|
|
|
if make_utils.command_missing(args.git_command):
|
2019-09-03 17:38:40 +02:00
|
|
|
sys.stderr.write("git not found, can't update code\n")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-09-02 12:11:32 +02:00
|
|
|
# Update submodules to appropriate given branch,
|
|
|
|
# falling back to master if none is given and/or found in a sub-repository.
|
|
|
|
branch_fallback = "master"
|
|
|
|
if not branch:
|
|
|
|
branch = branch_fallback
|
2019-10-09 14:41:34 +02:00
|
|
|
|
|
|
|
submodules = [
|
2021-09-02 12:11:32 +02:00
|
|
|
("release/scripts/addons", branch, branch_fallback),
|
|
|
|
("release/scripts/addons_contrib", branch, branch_fallback),
|
|
|
|
("release/datafiles/locale", branch, branch_fallback),
|
|
|
|
("source/tools", branch, branch_fallback),
|
2019-10-09 14:41:34 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
# Initialize submodules only if needed.
|
2021-09-02 12:11:32 +02:00
|
|
|
for submodule_path, submodule_branch, submodule_branch_fallback in submodules:
|
2019-10-09 14:41:34 +02:00
|
|
|
if not os.path.exists(os.path.join(submodule_path, ".git")):
|
|
|
|
call([args.git_command, "submodule", "update", "--init", "--recursive"])
|
|
|
|
break
|
|
|
|
|
|
|
|
# Checkout appropriate branch and pull changes.
|
|
|
|
skip_msg = ""
|
2021-09-02 12:11:32 +02:00
|
|
|
for submodule_path, submodule_branch, submodule_branch_fallback in submodules:
|
2019-10-09 14:41:34 +02:00
|
|
|
cwd = os.getcwd()
|
|
|
|
try:
|
|
|
|
os.chdir(submodule_path)
|
2019-10-09 21:35:57 +02:00
|
|
|
msg = git_update_skip(args, check_remote_exists=False)
|
2019-10-09 14:41:34 +02:00
|
|
|
if msg:
|
|
|
|
skip_msg += submodule_path + " skipped: " + msg + "\n"
|
|
|
|
else:
|
2021-09-20 13:17:01 +02:00
|
|
|
# Find a matching branch that exists.
|
|
|
|
call([args.git_command, "fetch", "origin"])
|
|
|
|
if make_utils.git_branch_exists(args.git_command, submodule_branch):
|
|
|
|
pass
|
|
|
|
elif make_utils.git_branch_exists(args.git_command, submodule_branch_fallback):
|
|
|
|
submodule_branch = submodule_branch_fallback
|
|
|
|
else:
|
2022-10-31 12:54:36 +11:00
|
|
|
# Skip.
|
|
|
|
submodule_branch = ""
|
2021-09-20 13:17:01 +02:00
|
|
|
|
|
|
|
# Switch to branch and pull.
|
|
|
|
if submodule_branch:
|
|
|
|
if make_utils.git_branch(args.git_command) != submodule_branch:
|
|
|
|
call([args.git_command, "checkout", submodule_branch])
|
|
|
|
call([args.git_command, "pull", "--rebase", "origin", submodule_branch])
|
2019-10-09 14:41:34 +02:00
|
|
|
finally:
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
|
|
return skip_msg
|
2019-09-08 14:17:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
args = parse_arguments()
|
2019-10-09 14:41:34 +02:00
|
|
|
blender_skip_msg = ""
|
|
|
|
submodules_skip_msg = ""
|
2019-09-08 14:17:58 +02:00
|
|
|
|
|
|
|
# Test if we are building a specific release version.
|
2019-10-09 14:41:34 +02:00
|
|
|
branch = make_utils.git_branch(args.git_command)
|
2021-09-13 13:13:03 +02:00
|
|
|
if branch == 'HEAD':
|
|
|
|
sys.stderr.write('Blender git repository is in detached HEAD state, must be in a branch\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-07-13 15:42:47 +02:00
|
|
|
tag = make_utils.git_tag(args.git_command)
|
|
|
|
release_version = make_utils.git_branch_release_version(branch, tag)
|
2019-09-08 14:17:58 +02:00
|
|
|
|
|
|
|
if not args.no_libraries:
|
|
|
|
svn_update(args, release_version)
|
|
|
|
if not args.no_blender:
|
2019-10-09 14:41:34 +02:00
|
|
|
blender_skip_msg = git_update_skip(args)
|
|
|
|
if blender_skip_msg:
|
|
|
|
blender_skip_msg = "Blender repository skipped: " + blender_skip_msg + "\n"
|
|
|
|
else:
|
2019-09-08 14:17:58 +02:00
|
|
|
blender_update(args)
|
|
|
|
if not args.no_submodules:
|
2019-10-09 14:41:34 +02:00
|
|
|
submodules_skip_msg = submodules_update(args, release_version, branch)
|
|
|
|
|
|
|
|
# Report any skipped repositories at the end, so it's not as easy to miss.
|
|
|
|
skip_msg = blender_skip_msg + submodules_skip_msg
|
|
|
|
if skip_msg:
|
|
|
|
print_stage(skip_msg.strip())
|
|
|
|
|
|
|
|
# For failed submodule update we throw an error, since not having correct
|
|
|
|
# submodules can make Blender throw errors.
|
|
|
|
# For Blender itself we don't and consider "make update" to be a command
|
|
|
|
# you can use while working on uncommitted code.
|
|
|
|
if submodules_skip_msg:
|
|
|
|
sys.exit(1)
|