forked from blender/blender
Sergey Sharybin
3f3067c70c
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. Pull Request #104875
154 lines
4.4 KiB
Python
Executable File
154 lines
4.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
"""
|
|
Utility functions for make update and make tests.
|
|
"""
|
|
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def call(cmd, exit_on_error=True, silent=False):
|
|
if not silent:
|
|
print(" ".join(cmd))
|
|
|
|
# Flush to ensure correct order output on Windows.
|
|
sys.stdout.flush()
|
|
sys.stderr.flush()
|
|
|
|
if silent:
|
|
retcode = subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
else:
|
|
retcode = subprocess.call(cmd)
|
|
|
|
if exit_on_error and retcode != 0:
|
|
sys.exit(retcode)
|
|
return retcode
|
|
|
|
|
|
def check_output(cmd, exit_on_error=True):
|
|
# Flush to ensure correct order output on Windows.
|
|
sys.stdout.flush()
|
|
sys.stderr.flush()
|
|
|
|
try:
|
|
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, universal_newlines=True)
|
|
except subprocess.CalledProcessError as e:
|
|
if exit_on_error:
|
|
sys.stderr.write(" ".join(cmd))
|
|
sys.stderr.write(e.output + "\n")
|
|
sys.exit(e.returncode)
|
|
output = ""
|
|
|
|
return output.strip()
|
|
|
|
|
|
def git_branch_exists(git_command, branch):
|
|
return (
|
|
call([git_command, "rev-parse", "--verify", branch], exit_on_error=False, silent=True) == 0 or
|
|
call([git_command, "rev-parse", "--verify", "remotes/origin/" + branch], exit_on_error=False, silent=True) == 0
|
|
)
|
|
|
|
|
|
def git_branch(git_command):
|
|
# Get current branch name.
|
|
try:
|
|
branch = subprocess.check_output([git_command, "rev-parse", "--abbrev-ref", "HEAD"])
|
|
except subprocess.CalledProcessError as e:
|
|
sys.stderr.write("Failed to get Blender git branch\n")
|
|
sys.exit(1)
|
|
|
|
return branch.strip().decode('utf8')
|
|
|
|
|
|
def git_tag(git_command):
|
|
# Get current tag name.
|
|
try:
|
|
tag = subprocess.check_output([git_command, "describe", "--exact-match"], stderr=subprocess.STDOUT)
|
|
except subprocess.CalledProcessError as e:
|
|
return None
|
|
|
|
return tag.strip().decode('utf8')
|
|
|
|
|
|
def git_branch_release_version(branch, tag):
|
|
release_version = re.search("^blender-v(.*)-release$", branch)
|
|
if release_version:
|
|
release_version = release_version.group(1)
|
|
elif tag:
|
|
release_version = re.search(r"^v([0-9]*\.[0-9]*).*", tag)
|
|
if release_version:
|
|
release_version = release_version.group(1)
|
|
return release_version
|
|
|
|
|
|
def svn_libraries_base_url(release_version, branch=None):
|
|
if release_version:
|
|
svn_branch = "tags/blender-" + release_version + "-release"
|
|
elif branch:
|
|
svn_branch = "branches/" + branch
|
|
else:
|
|
svn_branch = "trunk"
|
|
return "https://svn.blender.org/svnroot/bf-blender/" + svn_branch + "/lib/"
|
|
|
|
|
|
def command_missing(command):
|
|
# Support running with Python 2 for macOS
|
|
if sys.version_info >= (3, 0):
|
|
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"],
|
|
)
|