Cleanup: move Blender version parsing to make_utils.py
Ref D15957
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import dataclasses
|
import make_utils
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -50,7 +50,7 @@ def main() -> None:
|
|||||||
|
|
||||||
print(f"Output dir: {curdir}")
|
print(f"Output dir: {curdir}")
|
||||||
|
|
||||||
version = parse_blender_version(blender_srcdir)
|
version = make_utils.parse_blender_version()
|
||||||
tarball = tarball_path(curdir, version, cli_args)
|
tarball = tarball_path(curdir, version, cli_args)
|
||||||
manifest = manifest_path(tarball)
|
manifest = manifest_path(tarball)
|
||||||
packages_dir = packages_path(curdir, cli_args)
|
packages_dir = packages_path(curdir, cli_args)
|
||||||
@@ -62,53 +62,7 @@ def main() -> None:
|
|||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
def tarball_path(output_dir: Path, version: make_utils.BlenderVersion, cli_args: Any) -> Path:
|
||||||
class BlenderVersion:
|
|
||||||
version: int # 293 for 2.93.1
|
|
||||||
patch: int # 1 for 2.93.1
|
|
||||||
cycle: str # 'alpha', 'beta', 'release', maybe others.
|
|
||||||
|
|
||||||
@property
|
|
||||||
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(blender_srcdir: Path) -> BlenderVersion:
|
|
||||||
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"],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def tarball_path(output_dir: Path, version: BlenderVersion, cli_args: Any) -> Path:
|
|
||||||
extra = ""
|
extra = ""
|
||||||
if cli_args.include_packages:
|
if cli_args.include_packages:
|
||||||
extra = "-with-libraries"
|
extra = "-with-libraries"
|
||||||
@@ -148,7 +102,7 @@ def packages_path(current_directory: Path, cli_args: Any) -> Optional[Path]:
|
|||||||
|
|
||||||
|
|
||||||
def create_manifest(
|
def create_manifest(
|
||||||
version: BlenderVersion,
|
version: make_utils.BlenderVersion,
|
||||||
outpath: Path,
|
outpath: Path,
|
||||||
blender_srcdir: Path,
|
blender_srcdir: Path,
|
||||||
packages_dir: Optional[Path],
|
packages_dir: Optional[Path],
|
||||||
@@ -170,9 +124,9 @@ def main_files_to_manifest(blender_srcdir: Path, outfile: TextIO) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def submodules_to_manifest(
|
def submodules_to_manifest(
|
||||||
blender_srcdir: Path, version: BlenderVersion, outfile: TextIO
|
blender_srcdir: Path, version: make_utils.BlenderVersion, outfile: TextIO
|
||||||
) -> None:
|
) -> None:
|
||||||
skip_addon_contrib = version.is_release
|
skip_addon_contrib = version.is_release()
|
||||||
assert not blender_srcdir.is_absolute()
|
assert not blender_srcdir.is_absolute()
|
||||||
|
|
||||||
for line in git_command("-C", blender_srcdir, "submodule"):
|
for line in git_command("-C", blender_srcdir, "submodule"):
|
||||||
@@ -200,7 +154,7 @@ def packages_to_manifest(outfile: TextIO, packages_dir: Path) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def create_tarball(
|
def create_tarball(
|
||||||
version: BlenderVersion, tarball: Path, manifest: Path, blender_srcdir: Path, packages_dir: Optional[Path]
|
version: make_utils.BlenderVersion, tarball: Path, manifest: Path, blender_srcdir: Path, packages_dir: Optional[Path]
|
||||||
) -> None:
|
) -> None:
|
||||||
print(f'Creating archive: "{tarball}" ...', end="", flush=True)
|
print(f'Creating archive: "{tarball}" ...', end="", flush=True)
|
||||||
command = ["tar"]
|
command = ["tar"]
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def call(cmd, exit_on_error=True, silent=False):
|
def call(cmd, exit_on_error=True, silent=False):
|
||||||
@@ -101,3 +102,51 @@ def command_missing(command):
|
|||||||
return shutil.which(command) is None
|
return shutil.which(command) is None
|
||||||
else:
|
else:
|
||||||
return False
|
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"],
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user