gn build: Make sync script group output by revision

Differential Revision: https://reviews.llvm.org/D66090

llvm-svn: 368665
This commit is contained in:
Nico Weber 2019-08-13 11:24:20 +00:00
parent 86dd28a547
commit 01dab0ed97
1 changed files with 38 additions and 11 deletions

View File

@ -12,6 +12,7 @@ binaries have corresponding BUILD.gn files.
from __future__ import print_function from __future__ import print_function
from collections import defaultdict
import os import os
import re import re
import subprocess import subprocess
@ -29,10 +30,23 @@ def sync_source_lists():
cmake_cpp_re = re.compile(r'^\s*([A-Za-z_0-9./-]+\.(?:cpp|c|h|S))$', cmake_cpp_re = re.compile(r'^\s*([A-Za-z_0-9./-]+\.(?:cpp|c|h|S))$',
re.MULTILINE) re.MULTILINE)
changed = False 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=os.name == 'nt').rstrip()
def svnrev_from_gitrev(gitrev):
git_llvm = os.path.join(
os.path.dirname(__file__), '..', '..', 'git-svn', 'git-llvm')
return int(subprocess.check_output(
[sys.executable, git_llvm, 'svn-lookup', gitrev],
shell=os.name == 'nt').rstrip().lstrip('r'))
# Collect changes to gn files, grouped by revision.
for gn_file in gn_files: for gn_file in gn_files:
# The CMakeLists.txt for llvm/utils/gn/secondary/foo/BUILD.gn is # The CMakeLists.txt for llvm/utils/gn/secondary/foo/BUILD.gn is
# directly at foo/CMakeLists.txt. # at foo/CMakeLists.txt.
strip_prefix = 'llvm/utils/gn/secondary/' strip_prefix = 'llvm/utils/gn/secondary/'
if not gn_file.startswith(strip_prefix): if not gn_file.startswith(strip_prefix):
continue continue
@ -49,16 +63,29 @@ def sync_source_lists():
if gn_cpp == cmake_cpp: if gn_cpp == cmake_cpp:
continue continue
changed = True def by_rev(files, key):
print(gn_file) for f in files:
add = sorted(cmake_cpp - gn_cpp) svnrev = svnrev_from_gitrev(find_gitrev(f, cmake_file))
if add: changes_by_rev[svnrev][gn_file][key].append(f)
print('add:\n' + '\n'.join(' "%s",' % a for a in add)) by_rev(sorted(cmake_cpp - gn_cpp), 'add')
remove = sorted(gn_cpp - cmake_cpp) by_rev(sorted(gn_cpp - cmake_cpp), 'remove')
if remove:
print('remove:\n' + '\n'.join(remove)) # Output necessary changes grouped by revision.
for svnrev in sorted(changes_by_rev.keys()):
print('gn build: Merge r{0} -- https://reviews.llvm.org/rL{0}'
.format(svnrev))
for gn_file, data in sorted(changes_by_rev[svnrev].items()):
print(' ' + gn_file)
add = data.get('add')
if add:
print(' add:\n' + '\n'.join(' "%s",' % a for a in add))
remove = data.get('remove')
if remove:
print(' remove:\n ' + '\n '.join(remove))
print()
print() print()
return changed
return bool(changes_by_rev)
def sync_unittests(): def sync_unittests():