From 9ca54d8f2fa51639432b7f4c7ff5ca191bdaf7f2 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 13 Aug 2019 11:48:15 +0000 Subject: [PATCH] gn build: Extract git() and git_out() functions in sync script git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368671 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../gn/build/sync_source_lists_from_cmake.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/utils/gn/build/sync_source_lists_from_cmake.py b/utils/gn/build/sync_source_lists_from_cmake.py index d695e48d2cf..bd321d15c7f 100755 --- a/utils/gn/build/sync_source_lists_from_cmake.py +++ b/utils/gn/build/sync_source_lists_from_cmake.py @@ -52,9 +52,10 @@ def patch_gn_file(gn_file, add, remove): def sync_source_lists(write): # Use shell=True on Windows in case git is a bat file. - git_want_shell = os.name == 'nt' - gn_files = subprocess.check_output(['git', 'ls-files', '*BUILD.gn'], - shell=git_want_shell).splitlines() + def git(args): subprocess.check_call(['git'] + args, shell=os.name == 'nt') + def git_out(args): + return subprocess.check_output(['git'] + args, shell=os.name == 'nt') + gn_files = git_out(['ls-files', '*BUILD.gn']).splitlines() # Matches e.g. | "foo.cpp",|, captures |foo| in group 1. gn_cpp_re = re.compile(r'^\s*"([^"]+\.(?:cpp|c|h|S))",$', re.MULTILINE) @@ -65,9 +66,8 @@ def sync_source_lists(write): changes_by_rev = defaultdict(lambda: defaultdict(lambda: defaultdict(list))) def find_gitrev(touched_line, in_file): - return subprocess.check_output( - ['git', 'log', '--format=%h', '-1', '-S' + touched_line, in_file], - shell=git_want_shell).rstrip() + return git_out( + ['log', '--format=%h', '-1', '-S' + touched_line, in_file]).rstrip() def svnrev_from_gitrev(gitrev): git_llvm = os.path.join( os.path.dirname(__file__), '..', '..', 'git-svn', 'git-llvm') @@ -111,8 +111,7 @@ def sync_source_lists(write): remove = data.get('remove', []) if write: patch_gn_file(gn_file, add, remove) - subprocess.check_call(['git', 'add', gn_file], - shell=git_want_shell) + git(['add', gn_file]) else: print(' ' + gn_file) if add: @@ -121,9 +120,7 @@ def sync_source_lists(write): print(' remove:\n ' + '\n '.join(remove)) print() if write: - subprocess.check_call( - ['git', 'commit', '-m', 'gn build: Merge r%d' % svnrev], - shell=git_want_shell) + git(['commit', '-m', 'gn build: Merge r%d' % svnrev]) else: print() -- 2.40.0