From 7b86fca5886ac0621d93d55556b52fd2fa5da7d4 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 17 Feb 2023 10:04:37 +0100 Subject: [PATCH] Make update: Use BKE_blender_version to detect release branches On a user level there are no expected changes, other than being able to update submodules and libraries from a main repository at a detached HEAD situation (which did not work before). On the infrastructure level of things this moves us closer to ability to use the main make_update.py for the buildbot update-code stage, and to remove the update-code section from the pipeline_config.yaml. The initial idea of switching make_update to the pipeline config did not really work, causing duplicated work done on blender side and the buildbot side. Additionally, it is not easy to switch make_update.py to use pipeline_config.yaml because the YAML parser is not included into default package of Python. There will be few more steps of updates to this script before we can actually clean-up the pipeline_config: the changes needs to be also applied on the buildbot side to switch it to the actual make_update. Switching buildbot to the official make_update.py allows to much more easily apply the submodules change as per #104573. --- build_files/utils/make_update.py | 17 ++++++----- build_files/utils/make_utils.py | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/build_files/utils/make_update.py b/build_files/utils/make_update.py index 5ba85c43b8e..835e07d80b1 100755 --- a/build_files/utils/make_update.py +++ b/build_files/utils/make_update.py @@ -230,14 +230,15 @@ if __name__ == "__main__": blender_skip_msg = "" submodules_skip_msg = "" - # Test if we are building a specific release version. - branch = make_utils.git_branch(args.git_command) - if branch == 'HEAD': - sys.stderr.write('Blender git repository is in detached HEAD state, must be in a branch\n') - sys.exit(1) - - tag = make_utils.git_tag(args.git_command) - release_version = make_utils.git_branch_release_version(branch, tag) + blender_version = make_utils. parse_blender_version() + if blender_version.cycle != 'alpha': + major = blender_version.version // 100 + minor = blender_version.version % 100 + branch = f"blender-v{major}.{minor}-release" + release_version = f"{major}.{minor}" + else: + branch = 'main' + release_version = None if not args.no_libraries: svn_update(args, release_version) diff --git a/build_files/utils/make_utils.py b/build_files/utils/make_utils.py index e4c676474b5..c91720aeb48 100755 --- a/build_files/utils/make_utils.py +++ b/build_files/utils/make_utils.py @@ -9,6 +9,7 @@ import re import shutil import subprocess import sys +from pathlib import Path def call(cmd, exit_on_error=True, silent=False): @@ -101,3 +102,52 @@ def command_missing(command): return shutil.which(command) is None else: return False + + +class BlenderVersion: + def __init__(self, version, patch, cycle): + # 293 for 2.93.1 + self.version = version + # 1 for 2.93.1 + self.patch = patch + # 'alpha', 'beta', 'release', maybe others. + self.cycle = cycle + + def is_release(self) -> bool: + return self.cycle == "release" + + def __str__(self) -> str: + """Convert to version string. + + >>> str(BlenderVersion(293, 1, "alpha")) + '2.93.1-alpha' + >>> str(BlenderVersion(327, 0, "release")) + '3.27.0' + """ + version_major = self.version // 100 + version_minor = self.version % 100 + as_string = f"{version_major}.{version_minor}.{self.patch}" + if self.is_release(): + return as_string + return f"{as_string}-{self.cycle}" + + +def parse_blender_version() -> BlenderVersion: + blender_srcdir = Path(__file__).absolute().parent.parent.parent + version_path = blender_srcdir / "source/blender/blenkernel/BKE_blender_version.h" + + version_info = {} + line_re = re.compile(r"^#define (BLENDER_VERSION[A-Z_]*)\s+([0-9a-z]+)$") + + with version_path.open(encoding="utf-8") as version_file: + for line in version_file: + match = line_re.match(line.strip()) + if not match: + continue + version_info[match.group(1)] = match.group(2) + + return BlenderVersion( + int(version_info["BLENDER_VERSION"]), + int(version_info["BLENDER_VERSION_PATCH"]), + version_info["BLENDER_VERSION_CYCLE"], + ) -- 2.30.2