Cleanup: use main functions to allow importing scripts
Support importing scripts without running their logic to allow basic validation (see #130746). Parts of !131037 were used. Co-authored-by: Bastien Montagne <bastien@blender.org>
This commit is contained in:
@@ -11,65 +11,73 @@ import sys
|
||||
# todo:
|
||||
# strip executables
|
||||
|
||||
# get parameters
|
||||
if len(sys.argv) < 5:
|
||||
sys.stderr.write('Excepted arguments: ./build_archive.py name extension install_dir output_dir')
|
||||
sys.exit(1)
|
||||
|
||||
package_name = sys.argv[1]
|
||||
extension = sys.argv[2]
|
||||
install_dir = sys.argv[3]
|
||||
output_dir = sys.argv[4]
|
||||
def main() -> int:
|
||||
# get parameters
|
||||
if len(sys.argv) < 5:
|
||||
sys.stderr.write('Excepted arguments: ./build_archive.py name extension install_dir output_dir')
|
||||
return 1
|
||||
|
||||
package_archive = os.path.join(output_dir, package_name + '.' + extension)
|
||||
package_dir = package_name
|
||||
package_name = sys.argv[1]
|
||||
extension = sys.argv[2]
|
||||
install_dir = sys.argv[3]
|
||||
output_dir = sys.argv[4]
|
||||
|
||||
# remove existing package with the same name
|
||||
try:
|
||||
if os.path.exists(package_archive):
|
||||
os.remove(package_archive)
|
||||
if os.path.exists(package_dir):
|
||||
package_archive = os.path.join(output_dir, package_name + '.' + extension)
|
||||
package_dir = package_name
|
||||
|
||||
# remove existing package with the same name
|
||||
try:
|
||||
if os.path.exists(package_archive):
|
||||
os.remove(package_archive)
|
||||
if os.path.exists(package_dir):
|
||||
shutil.rmtree(package_dir)
|
||||
except Exception as ex:
|
||||
sys.stderr.write('Failed to clean up old package files: ' + str(ex) + '\n')
|
||||
return 1
|
||||
|
||||
# create temporary package dir
|
||||
try:
|
||||
shutil.copytree(install_dir, package_dir)
|
||||
|
||||
for f in os.listdir(package_dir):
|
||||
if f.startswith('makes'):
|
||||
os.remove(os.path.join(package_dir, f))
|
||||
except Exception as ex:
|
||||
sys.stderr.write('Failed to copy install directory: ' + str(ex) + '\n')
|
||||
return 1
|
||||
|
||||
# create archive
|
||||
try:
|
||||
if not os.path.exists(output_dir):
|
||||
os.mkdir(output_dir)
|
||||
|
||||
archive_env = os.environ.copy()
|
||||
|
||||
if extension == 'zip':
|
||||
archive_cmd = ['zip', '-9', '-r', package_archive, package_dir]
|
||||
elif extension == 'tar.xz':
|
||||
archive_cmd = ['tar', '-cf', package_archive, '--owner=0', '--group=0',
|
||||
'--use-compress-program=xz', package_dir]
|
||||
archive_env['XZ_OPT'] = '-9'
|
||||
else:
|
||||
sys.stderr.write('Unknown archive extension: ' + extension)
|
||||
return 1
|
||||
|
||||
subprocess.check_call(archive_cmd, env=archive_env)
|
||||
except Exception as ex:
|
||||
sys.stderr.write('Failed to create package archive: ' + str(ex) + '\n')
|
||||
return 1
|
||||
|
||||
# empty temporary package dir
|
||||
try:
|
||||
shutil.rmtree(package_dir)
|
||||
except Exception as ex:
|
||||
sys.stderr.write('Failed to clean up old package files: ' + str(ex) + '\n')
|
||||
sys.exit(1)
|
||||
except Exception as ex:
|
||||
sys.stderr.write('Failed to clean up package directory: ' + str(ex) + '\n')
|
||||
return 1
|
||||
|
||||
# create temporary package dir
|
||||
try:
|
||||
shutil.copytree(install_dir, package_dir)
|
||||
return 0
|
||||
|
||||
for f in os.listdir(package_dir):
|
||||
if f.startswith('makes'):
|
||||
os.remove(os.path.join(package_dir, f))
|
||||
except Exception as ex:
|
||||
sys.stderr.write('Failed to copy install directory: ' + str(ex) + '\n')
|
||||
sys.exit(1)
|
||||
|
||||
# create archive
|
||||
try:
|
||||
if not os.path.exists(output_dir):
|
||||
os.mkdir(output_dir)
|
||||
|
||||
archive_env = os.environ.copy()
|
||||
|
||||
if extension == 'zip':
|
||||
archive_cmd = ['zip', '-9', '-r', package_archive, package_dir]
|
||||
elif extension == 'tar.xz':
|
||||
archive_cmd = ['tar', '-cf', package_archive, '--owner=0', '--group=0',
|
||||
'--use-compress-program=xz', package_dir]
|
||||
archive_env['XZ_OPT'] = '-9'
|
||||
else:
|
||||
sys.stderr.write('Unknown archive extension: ' + extension)
|
||||
sys.exit(-1)
|
||||
|
||||
subprocess.check_call(archive_cmd, env=archive_env)
|
||||
except Exception as ex:
|
||||
sys.stderr.write('Failed to create package archive: ' + str(ex) + '\n')
|
||||
sys.exit(1)
|
||||
|
||||
# empty temporary package dir
|
||||
try:
|
||||
shutil.rmtree(package_dir)
|
||||
except Exception as ex:
|
||||
sys.stderr.write('Failed to clean up package directory: ' + str(ex) + '\n')
|
||||
sys.exit(1)
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -15,9 +15,8 @@ import make_utils
|
||||
from make_utils import call
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
# Parse arguments.
|
||||
|
||||
|
||||
def parse_arguments() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--ctest-command", default="ctest")
|
||||
@@ -28,49 +27,55 @@ def parse_arguments() -> argparse.Namespace:
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
args = parse_arguments()
|
||||
git_command = args.git_command
|
||||
ctest_command = args.ctest_command
|
||||
cmake_command = args.cmake_command
|
||||
config = args.config
|
||||
build_dir = args.build_directory
|
||||
def main() -> int:
|
||||
args = parse_arguments()
|
||||
git_command = args.git_command
|
||||
ctest_command = args.ctest_command
|
||||
cmake_command = args.cmake_command
|
||||
config = args.config
|
||||
build_dir = args.build_directory
|
||||
|
||||
if make_utils.command_missing(ctest_command):
|
||||
sys.stderr.write("ctest not found, can't run tests\n")
|
||||
sys.exit(1)
|
||||
if make_utils.command_missing(ctest_command):
|
||||
sys.stderr.write("ctest not found, can't run tests\n")
|
||||
return 1
|
||||
|
||||
if make_utils.command_missing(git_command):
|
||||
sys.stderr.write("git not found, can't run tests\n")
|
||||
sys.exit(1)
|
||||
if make_utils.command_missing(git_command):
|
||||
sys.stderr.write("git not found, can't run tests\n")
|
||||
return 1
|
||||
|
||||
# Test if we are building a specific release version.
|
||||
lib_tests_dirpath = Path("tests") / "data"
|
||||
# Test if we are building a specific release version.
|
||||
lib_tests_dirpath = Path("tests") / "data"
|
||||
|
||||
if not (lib_tests_dirpath / ".git").exists():
|
||||
print("Tests files not found, downloading...")
|
||||
if not (lib_tests_dirpath / ".git").exists():
|
||||
print("Tests files not found, downloading...")
|
||||
|
||||
if make_utils.command_missing(cmake_command):
|
||||
sys.stderr.write("cmake not found, can't checkout test files\n")
|
||||
sys.exit(1)
|
||||
if make_utils.command_missing(cmake_command):
|
||||
sys.stderr.write("cmake not found, can't checkout test files\n")
|
||||
return 1
|
||||
|
||||
# Ensure the test data files sub-module is configured and present.
|
||||
make_utils.git_enable_submodule(git_command, Path("tests") / "data")
|
||||
make_utils.git_update_submodule(args.git_command, lib_tests_dirpath)
|
||||
# Ensure the test data files sub-module is configured and present.
|
||||
make_utils.git_enable_submodule(git_command, Path("tests") / "data")
|
||||
make_utils.git_update_submodule(args.git_command, lib_tests_dirpath)
|
||||
|
||||
# Run cmake again to detect tests files.
|
||||
os.chdir(build_dir)
|
||||
call([cmake_command, "."])
|
||||
|
||||
# Run tests
|
||||
tests_dir = os.path.join(build_dir, "tests")
|
||||
os.makedirs(tests_dir, exist_ok=True)
|
||||
|
||||
# Run cmake again to detect tests files.
|
||||
os.chdir(build_dir)
|
||||
call([cmake_command, "."])
|
||||
command = [ctest_command, ".", "--output-on-failure"]
|
||||
if len(config):
|
||||
command += ["-C", config]
|
||||
tests_log = "log_" + config + ".txt"
|
||||
else:
|
||||
tests_log = "log.txt"
|
||||
command += ["-O", os.path.join(tests_dir, tests_log)]
|
||||
call(command)
|
||||
return 0
|
||||
|
||||
# Run tests
|
||||
tests_dir = os.path.join(build_dir, "tests")
|
||||
os.makedirs(tests_dir, exist_ok=True)
|
||||
|
||||
os.chdir(build_dir)
|
||||
command = [ctest_command, ".", "--output-on-failure"]
|
||||
if len(config):
|
||||
command += ["-C", config]
|
||||
tests_log = "log_" + config + ".txt"
|
||||
else:
|
||||
tests_log = "log.txt"
|
||||
command += ["-O", os.path.join(tests_dir, tests_log)]
|
||||
call(command)
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -63,7 +63,7 @@ def parse_arguments() -> argparse.Namespace:
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def get_blender_git_root() -> Path:
|
||||
def get_blender_git_root(args: argparse.Namespace) -> Path:
|
||||
"""
|
||||
Get root directory of the current Git directory.
|
||||
"""
|
||||
@@ -126,7 +126,7 @@ def get_submodule_directories(args: argparse.Namespace) -> "tuple[Path, ...]":
|
||||
Get list of all configured submodule directories.
|
||||
"""
|
||||
|
||||
blender_git_root = get_blender_git_root()
|
||||
blender_git_root = get_blender_git_root(args)
|
||||
dot_modules = blender_git_root / ".gitmodules"
|
||||
|
||||
if not dot_modules.exists():
|
||||
@@ -143,13 +143,13 @@ def ensure_git_lfs(args: argparse.Namespace) -> None:
|
||||
call((args.git_command, "lfs", "install", "--skip-repo"), exit_on_error=True)
|
||||
|
||||
|
||||
def prune_stale_files() -> None:
|
||||
def prune_stale_files(args: argparse.Namespace) -> None:
|
||||
"""
|
||||
Ensure files from previous Git configurations do not exist anymore
|
||||
"""
|
||||
print_stage("Removing stale files")
|
||||
|
||||
blender_git_root = get_blender_git_root()
|
||||
blender_git_root = get_blender_git_root(args)
|
||||
found_stale_files = False
|
||||
|
||||
for relative_dir_to_remove in (
|
||||
@@ -322,7 +322,7 @@ def external_script_copy_old_submodule_over(
|
||||
directory: Path,
|
||||
old_submodules_dir: Path,
|
||||
) -> None:
|
||||
blender_git_root = get_blender_git_root()
|
||||
blender_git_root = get_blender_git_root(args)
|
||||
external_dir = blender_git_root / directory
|
||||
|
||||
print(f"Moving {old_submodules_dir} to {directory} ...")
|
||||
@@ -349,7 +349,7 @@ def floating_checkout_initialize_if_needed(
|
||||
) -> None:
|
||||
"""Initialize checkout of an external repository"""
|
||||
|
||||
blender_git_root = get_blender_git_root()
|
||||
blender_git_root = get_blender_git_root(args)
|
||||
blender_dot_git = blender_git_root / ".git"
|
||||
external_dir = blender_git_root / directory
|
||||
|
||||
@@ -392,7 +392,7 @@ def floating_checkout_add_origin_if_needed(
|
||||
|
||||
cwd = os.getcwd()
|
||||
|
||||
blender_git_root = get_blender_git_root()
|
||||
blender_git_root = get_blender_git_root(args)
|
||||
external_dir = blender_git_root / directory
|
||||
|
||||
origin_blender_url = make_utils.git_get_remote_url(args.git_command, "origin")
|
||||
@@ -447,7 +447,7 @@ def floating_checkout_update(
|
||||
) -> str:
|
||||
"""Update a single external checkout with the given name in the scripts folder"""
|
||||
|
||||
blender_git_root = get_blender_git_root()
|
||||
blender_git_root = get_blender_git_root(args)
|
||||
external_dir = blender_git_root / directory
|
||||
|
||||
if only_update and not external_dir.exists():
|
||||
@@ -456,7 +456,7 @@ def floating_checkout_update(
|
||||
floating_checkout_initialize_if_needed(args, repo_name, directory, old_submodules_dir)
|
||||
floating_checkout_add_origin_if_needed(args, repo_name, directory)
|
||||
|
||||
blender_git_root = get_blender_git_root()
|
||||
blender_git_root = get_blender_git_root(args)
|
||||
external_dir = blender_git_root / directory
|
||||
|
||||
print(f"* Updating {directory} ...")
|
||||
@@ -556,7 +556,7 @@ def add_submodule_push_url(args: argparse.Namespace) -> None:
|
||||
Add pushURL configuration for all locally activated submodules, pointing to SSH protocol.
|
||||
"""
|
||||
|
||||
blender_git_root = get_blender_git_root()
|
||||
blender_git_root = get_blender_git_root(args)
|
||||
modules = blender_git_root / ".git" / "modules"
|
||||
|
||||
submodule_directories = get_submodule_directories(args)
|
||||
@@ -611,7 +611,7 @@ def submodules_lib_update(args: argparse.Namespace, branch: "str | None") -> str
|
||||
return msg
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main() -> int:
|
||||
args = parse_arguments()
|
||||
blender_skip_msg = ""
|
||||
libraries_skip_msg = ""
|
||||
@@ -629,7 +629,7 @@ if __name__ == "__main__":
|
||||
ensure_git_lfs(args)
|
||||
|
||||
if args.prune_destructive:
|
||||
prune_stale_files()
|
||||
prune_stale_files(args)
|
||||
|
||||
if not args.no_blender:
|
||||
blender_skip_msg = git_update_skip(args)
|
||||
@@ -655,4 +655,10 @@ if __name__ == "__main__":
|
||||
# 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)
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -29,9 +29,9 @@ SOURCE_EXT = (
|
||||
".glsl",
|
||||
)
|
||||
|
||||
words = set()
|
||||
words_multi = set()
|
||||
defines = {}
|
||||
words: set[str] = set()
|
||||
words_multi: set[str] = set()
|
||||
defines: dict[str, str] = {}
|
||||
|
||||
import re
|
||||
re_words = re.compile("[A-Za-z_][A-Za-z_0-9]*")
|
||||
@@ -41,23 +41,23 @@ re_defines = re.compile("^\\s*#define\\s+([A-Za-z_][A-Za-z_0-9]*)", re.MULTILINE
|
||||
# https://stackoverflow.com/a/18381470/432509
|
||||
|
||||
|
||||
def remove_comments(string):
|
||||
def remove_comments(string: str) -> str:
|
||||
pattern = r"(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)"
|
||||
# first group captures quoted strings (double or single)
|
||||
# second group captures comments (//single-line or /* multi-line */)
|
||||
regex = re.compile(pattern, re.MULTILINE | re.DOTALL)
|
||||
|
||||
def _replacer(match):
|
||||
def _replacer(m: re.Match[str]) -> str:
|
||||
# if the 2nd group (capturing comments) is not None,
|
||||
# it means we have captured a non-quoted (real) comment string.
|
||||
if match.group(2) is not None:
|
||||
if m.group(2) is not None:
|
||||
return "" # so we will return empty to remove the comment
|
||||
else: # otherwise, we will return the 1st group
|
||||
return match.group(1) # capture
|
||||
return m.group(1) # capture
|
||||
return regex.sub(_replacer, string)
|
||||
|
||||
|
||||
def extract_terms(fn, data_src):
|
||||
def extract_terms(fn: str, data_src: str) -> None:
|
||||
data_src_nocomments = remove_comments(data_src)
|
||||
for m in re_words.finditer(data_src_nocomments):
|
||||
words_len = len(words)
|
||||
@@ -73,15 +73,22 @@ def extract_terms(fn, data_src):
|
||||
return None
|
||||
|
||||
|
||||
run(
|
||||
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
|
||||
is_text=lambda fn: fn.endswith(SOURCE_EXT),
|
||||
text_operation=extract_terms,
|
||||
# Can't be used if we want to accumulate in a global variable.
|
||||
use_multiprocess=False,
|
||||
)
|
||||
def main() -> int:
|
||||
run(
|
||||
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
|
||||
is_text=lambda fn: fn.endswith(SOURCE_EXT),
|
||||
text_operation=extract_terms,
|
||||
# Can't be used if we want to accumulate in a global variable.
|
||||
use_multiprocess=False,
|
||||
)
|
||||
|
||||
print("Found", len(defines), "defines, searching", len(words_multi), "terms...")
|
||||
for fn, define in sorted([(fn, define) for define, fn in defines.items()]):
|
||||
if define not in words_multi:
|
||||
print(define, "->", fn)
|
||||
print("Found", len(defines), "defines, searching", len(words_multi), "terms...")
|
||||
for fn, define in sorted([(fn, define) for define, fn in defines.items()]):
|
||||
if define not in words_multi:
|
||||
print(define, "->", fn)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -6,50 +6,59 @@
|
||||
# generate svn rev-sha1 mapping
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.normpath(os.path.join(CURRENT_DIR, "..", ".."))))
|
||||
|
||||
print("creating git-log of %r" % SOURCE_DIR)
|
||||
os.chdir(SOURCE_DIR)
|
||||
os.system('git log --all --format="%H %cd" --date=iso > "' + CURRENT_DIR + '/git_log.txt"')
|
||||
|
||||
print("creating mapping...")
|
||||
os.chdir(CURRENT_DIR)
|
||||
time_to_sha1 = {}
|
||||
f = "git_log.txt"
|
||||
with open(f, "r", encoding="utf-8") as fh:
|
||||
for l in fh:
|
||||
sha1 = l[:40]
|
||||
time = l[41:60]
|
||||
time_to_sha1[time] = sha1
|
||||
os.remove("git_log.txt")
|
||||
def main() -> int:
|
||||
print("creating git-log of %r" % SOURCE_DIR)
|
||||
os.chdir(SOURCE_DIR)
|
||||
os.system('git log --all --format="%H %cd" --date=iso > "' + CURRENT_DIR + '/git_log.txt"')
|
||||
|
||||
# for reverse mapping
|
||||
rev_sha1_ls = []
|
||||
|
||||
with open("rev_to_sha1.py", "w", encoding="utf-8") as fh_dst:
|
||||
fh_dst.write("data = {\n")
|
||||
|
||||
f = "git_sh1_to_svn_rev.fossils"
|
||||
print("creating mapping...")
|
||||
os.chdir(CURRENT_DIR)
|
||||
time_to_sha1 = {}
|
||||
f = "git_log.txt"
|
||||
with open(f, "r", encoding="utf-8") as fh:
|
||||
for l in fh:
|
||||
# skip 'SVN:'
|
||||
rev, time = l[4:].split("\t", 1)
|
||||
time = time.split("Z", 1)[0].replace("T", " ", 1)
|
||||
sha1 = time_to_sha1.get(time)
|
||||
if sha1 is not None:
|
||||
fh_dst.write('%s: "%s",\n' % (rev, sha1))
|
||||
sha1 = l[:40]
|
||||
time = l[41:60]
|
||||
time_to_sha1[time] = sha1
|
||||
os.remove("git_log.txt")
|
||||
|
||||
rev_sha1_ls.append((rev, sha1))
|
||||
# for reverse mapping
|
||||
rev_sha1_ls = []
|
||||
|
||||
fh_dst.write('}\n')
|
||||
with open("rev_to_sha1.py", "w", encoding="utf-8") as fh_dst:
|
||||
fh_dst.write("data = {\n")
|
||||
|
||||
print("written: rev_to_sha1.py")
|
||||
f = "git_sh1_to_svn_rev.fossils"
|
||||
with open(f, "r", encoding="utf-8") as fh:
|
||||
for l in fh:
|
||||
# skip 'SVN:'
|
||||
rev, time = l[4:].split("\t", 1)
|
||||
time = time.split("Z", 1)[0].replace("T", " ", 1)
|
||||
sha1 = time_to_sha1.get(time)
|
||||
if sha1 is not None:
|
||||
fh_dst.write('%s: "%s",\n' % (rev, sha1))
|
||||
|
||||
with open("sha1_to_rev.py", "w", encoding="utf-8") as fh_dst:
|
||||
fh_dst.write("data = {\n")
|
||||
for rev, sha1 in rev_sha1_ls:
|
||||
fh_dst.write('"%s": %s,\n' % (sha1, rev))
|
||||
fh_dst.write('}\n')
|
||||
rev_sha1_ls.append((rev, sha1))
|
||||
|
||||
print("written: sha1_to_rev.py")
|
||||
fh_dst.write('}\n')
|
||||
|
||||
print("written: rev_to_sha1.py")
|
||||
|
||||
with open("sha1_to_rev.py", "w", encoding="utf-8") as fh_dst:
|
||||
fh_dst.write("data = {\n")
|
||||
for rev, sha1 in rev_sha1_ls:
|
||||
fh_dst.write('"%s": %s,\n' % (sha1, rev))
|
||||
fh_dst.write('}\n')
|
||||
|
||||
print("written: sha1_to_rev.py")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -21,95 +21,101 @@ def get_string(cmd):
|
||||
return subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('utf8').strip()
|
||||
|
||||
|
||||
# Parse arguments.
|
||||
mode = None
|
||||
base_branch = 'main'
|
||||
if len(sys.argv) >= 2:
|
||||
# Note that recursive conflict resolution strategy has to reversed in rebase compared to merge.
|
||||
# See https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt--m
|
||||
if sys.argv[1] == '--rebase':
|
||||
mode = 'rebase'
|
||||
recursive_format_commit_merge_options = '-Xignore-all-space -Xtheirs'
|
||||
elif sys.argv[1] == '--merge':
|
||||
mode = 'merge'
|
||||
recursive_format_commit_merge_options = '-Xignore-all-space -Xours'
|
||||
if len(sys.argv) == 4:
|
||||
if sys.argv[2] == '--base_branch':
|
||||
base_branch = sys.argv[3]
|
||||
def main() -> int:
|
||||
# Parse arguments.
|
||||
mode = None
|
||||
base_branch = 'main'
|
||||
if len(sys.argv) >= 2:
|
||||
# Note that recursive conflict resolution strategy has to reversed in rebase compared to merge.
|
||||
# See https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt--m
|
||||
if sys.argv[1] == '--rebase':
|
||||
mode = 'rebase'
|
||||
recursive_format_commit_merge_options = '-Xignore-all-space -Xtheirs'
|
||||
elif sys.argv[1] == '--merge':
|
||||
mode = 'merge'
|
||||
recursive_format_commit_merge_options = '-Xignore-all-space -Xours'
|
||||
if len(sys.argv) == 4:
|
||||
if sys.argv[2] == '--base_branch':
|
||||
base_branch = sys.argv[3]
|
||||
|
||||
if mode is None:
|
||||
print("Merge or rebase Blender main (or another base branch) into a branch in 3 steps,")
|
||||
print("to automatically merge clang-format changes.")
|
||||
print("")
|
||||
print(" --rebase Perform equivalent of 'git rebase main'")
|
||||
print(" --merge Perform equivalent of 'git merge main'")
|
||||
print("")
|
||||
print("Optional arguments:")
|
||||
print(" --base_branch <branch name> Use given branch instead of main")
|
||||
print(" (assuming that base branch has already been updated")
|
||||
print(" and has the initial clang-format commit).")
|
||||
sys.exit(0)
|
||||
if mode is None:
|
||||
print("Merge or rebase Blender main (or another base branch) into a branch in 3 steps,")
|
||||
print("to automatically merge clang-format changes.")
|
||||
print("")
|
||||
print(" --rebase Perform equivalent of 'git rebase main'")
|
||||
print(" --merge Perform equivalent of 'git merge main'")
|
||||
print("")
|
||||
print("Optional arguments:")
|
||||
print(" --base_branch <branch name> Use given branch instead of main")
|
||||
print(" (assuming that base branch has already been updated")
|
||||
print(" and has the initial clang-format commit).")
|
||||
return 0
|
||||
|
||||
# Verify we are in the right directory.
|
||||
root_path = get_string(['git', 'rev-parse', '--show-superproject-working-tree'])
|
||||
if os.path.realpath(root_path) != os.path.realpath(os.getcwd()):
|
||||
print("BLENDER MERGE: must run from blender repository root directory")
|
||||
sys.exit(1)
|
||||
# Verify we are in the right directory.
|
||||
root_path = get_string(['git', 'rev-parse', '--show-superproject-working-tree'])
|
||||
if os.path.realpath(root_path) != os.path.realpath(os.getcwd()):
|
||||
print("BLENDER MERGE: must run from blender repository root directory")
|
||||
return 1
|
||||
|
||||
# Abort if a rebase is still progress.
|
||||
rebase_merge = get_string(['git', 'rev-parse', '--git-path', 'rebase-merge'])
|
||||
rebase_apply = get_string(['git', 'rev-parse', '--git-path', 'rebase-apply'])
|
||||
merge_head = get_string(['git', 'rev-parse', '--git-path', 'MERGE_HEAD'])
|
||||
if os.path.exists(rebase_merge) or \
|
||||
os.path.exists(rebase_apply) or \
|
||||
os.path.exists(merge_head):
|
||||
print("BLENDER MERGE: rebase or merge in progress, complete it first")
|
||||
sys.exit(1)
|
||||
# Abort if a rebase is still progress.
|
||||
rebase_merge = get_string(['git', 'rev-parse', '--git-path', 'rebase-merge'])
|
||||
rebase_apply = get_string(['git', 'rev-parse', '--git-path', 'rebase-apply'])
|
||||
merge_head = get_string(['git', 'rev-parse', '--git-path', 'MERGE_HEAD'])
|
||||
if os.path.exists(rebase_merge) or \
|
||||
os.path.exists(rebase_apply) or \
|
||||
os.path.exists(merge_head):
|
||||
print("BLENDER MERGE: rebase or merge in progress, complete it first")
|
||||
return 1
|
||||
|
||||
# Abort if uncommitted changes.
|
||||
changes = get_string(['git', 'status', '--porcelain', '--untracked-files=no'])
|
||||
if len(changes) != 0:
|
||||
print("BLENDER MERGE: detected uncommitted changes, can't run")
|
||||
sys.exit(1)
|
||||
# Abort if uncommitted changes.
|
||||
changes = get_string(['git', 'status', '--porcelain', '--untracked-files=no'])
|
||||
if len(changes) != 0:
|
||||
print("BLENDER MERGE: detected uncommitted changes, can't run")
|
||||
return 1
|
||||
|
||||
# Setup command, with commit message for merge commits.
|
||||
if mode == 'rebase':
|
||||
mode_cmd = 'rebase'
|
||||
else:
|
||||
branch = get_string(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
|
||||
mode_cmd = 'merge --no-edit -m "Merge \'' + base_branch + '\' into \'' + branch + '\'"'
|
||||
# Setup command, with commit message for merge commits.
|
||||
if mode == 'rebase':
|
||||
mode_cmd = 'rebase'
|
||||
else:
|
||||
branch = get_string(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
|
||||
mode_cmd = 'merge --no-edit -m "Merge \'' + base_branch + '\' into \'' + branch + '\'"'
|
||||
|
||||
# Rebase up to the clang-format commit.
|
||||
code = os.system('git merge-base --is-ancestor ' + pre_format_commit + ' HEAD')
|
||||
if code != 0:
|
||||
code = os.system('git ' + mode_cmd + ' ' + pre_format_commit)
|
||||
# Rebase up to the clang-format commit.
|
||||
code = os.system('git merge-base --is-ancestor ' + pre_format_commit + ' HEAD')
|
||||
if code != 0:
|
||||
print("BLENDER MERGE: resolve conflicts, complete " + mode + " and run again")
|
||||
sys.exit(code)
|
||||
code = os.system('git ' + mode_cmd + ' ' + pre_format_commit)
|
||||
if code != 0:
|
||||
print("BLENDER MERGE: resolve conflicts, complete " + mode + " and run again")
|
||||
return code
|
||||
|
||||
# Rebase clang-format commit.
|
||||
code = os.system('git merge-base --is-ancestor ' + format_commits[-1] + ' HEAD')
|
||||
if code != 0:
|
||||
os.system('git ' + mode_cmd + ' ' + recursive_format_commit_merge_options + ' ' + format_commits[-1])
|
||||
paths = get_string(('git', '--no-pager', 'diff', '--name-only', format_commits[-1])).replace('\n', ' ')
|
||||
if sys.platform == 'win32' and len(paths) > 8000:
|
||||
# Windows command-line does not accept more than 8191 chars.
|
||||
os.system('make format')
|
||||
else:
|
||||
os.system('make format PATHS="' + paths + '"')
|
||||
os.system('git add -u')
|
||||
count = int(get_string(['git', 'rev-list', '--count', '' + format_commits[-1] + '..HEAD']))
|
||||
if count == 1 or mode == 'merge':
|
||||
# Amend if we just have a single commit or are merging.
|
||||
os.system('git commit --amend --no-edit')
|
||||
else:
|
||||
# Otherwise create a commit for formatting.
|
||||
os.system('git commit -m "Cleanup: apply clang format"')
|
||||
# Rebase clang-format commit.
|
||||
code = os.system('git merge-base --is-ancestor ' + format_commits[-1] + ' HEAD')
|
||||
if code != 0:
|
||||
os.system('git ' + mode_cmd + ' ' + recursive_format_commit_merge_options + ' ' + format_commits[-1])
|
||||
paths = get_string(('git', '--no-pager', 'diff', '--name-only', format_commits[-1])).replace('\n', ' ')
|
||||
if sys.platform == 'win32' and len(paths) > 8000:
|
||||
# Windows command-line does not accept more than 8191 chars.
|
||||
os.system('make format')
|
||||
else:
|
||||
os.system('make format PATHS="' + paths + '"')
|
||||
os.system('git add -u')
|
||||
count = int(get_string(['git', 'rev-list', '--count', '' + format_commits[-1] + '..HEAD']))
|
||||
if count == 1 or mode == 'merge':
|
||||
# Amend if we just have a single commit or are merging.
|
||||
os.system('git commit --amend --no-edit')
|
||||
else:
|
||||
# Otherwise create a commit for formatting.
|
||||
os.system('git commit -m "Cleanup: apply clang format"')
|
||||
|
||||
# Rebase remaining commits
|
||||
code = os.system('git ' + mode_cmd + ' ' + base_branch)
|
||||
if code != 0:
|
||||
print("BLENDER MERGE: resolve conflicts, complete " + mode + " and you're done")
|
||||
else:
|
||||
print("BLENDER MERGE: done")
|
||||
sys.exit(code)
|
||||
# Rebase remaining commits
|
||||
code = os.system('git ' + mode_cmd + ' ' + base_branch)
|
||||
if code != 0:
|
||||
print("BLENDER MERGE: resolve conflicts, complete " + mode + " and you're done")
|
||||
else:
|
||||
print("BLENDER MERGE: done")
|
||||
|
||||
return code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
# Created by Robert Wenzlaff (Det. Thorn).
|
||||
# Oct. 30, 2003
|
||||
|
||||
import sys
|
||||
from tkinter import (
|
||||
Button,
|
||||
Canvas,
|
||||
@@ -288,9 +289,15 @@ class App:
|
||||
|
||||
|
||||
################## Main App #######################
|
||||
root = Tk()
|
||||
def main() -> int:
|
||||
root = Tk()
|
||||
|
||||
app = App(root)
|
||||
root.title("Cursor Maker")
|
||||
app = App(root)
|
||||
root.title("Cursor Maker")
|
||||
|
||||
root.mainloop()
|
||||
root.mainloop()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -83,9 +83,15 @@ def sort_struct_lists(fn: str, data_src: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
run(
|
||||
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
|
||||
is_text=lambda fn: fn.endswith(SOURCE_EXT),
|
||||
text_operation=sort_struct_lists,
|
||||
use_multiprocess=True,
|
||||
)
|
||||
def main() -> int:
|
||||
run(
|
||||
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
|
||||
is_text=lambda fn: fn.endswith(SOURCE_EXT),
|
||||
text_operation=sort_struct_lists,
|
||||
use_multiprocess=True,
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -84,9 +84,15 @@ def clean_structs(fn: str, data_src: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
run(
|
||||
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
|
||||
is_text=lambda fn: fn.endswith(SOURCE_EXT),
|
||||
text_operation=clean_structs,
|
||||
use_multiprocess=False,
|
||||
)
|
||||
def main() -> int:
|
||||
run(
|
||||
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
|
||||
is_text=lambda fn: fn.endswith(SOURCE_EXT),
|
||||
text_operation=clean_structs,
|
||||
use_multiprocess=False,
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
@@ -93,9 +93,15 @@ def sort_cmake_file_lists(fn: str, data_src: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
run(
|
||||
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
|
||||
is_text=lambda fn: fn.endswith("CMakeLists.txt"),
|
||||
text_operation=sort_cmake_file_lists,
|
||||
use_multiprocess=True,
|
||||
)
|
||||
def main() -> int:
|
||||
run(
|
||||
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
|
||||
is_text=lambda fn: fn.endswith("CMakeLists.txt"),
|
||||
text_operation=sort_cmake_file_lists,
|
||||
use_multiprocess=True,
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user