Don't include flags not present in .gn[i] files

The json files used to generate the Android.bp files have more flags
than those specified in the BUILD.gn and *.gni configuration files. This
change ignores the ones added by the build toolchain and keeps only
those added by the webrtc authors.

Bug: 269761242
Test: run cuttlefish in x64, build for arm64 and riscv64
Change-Id: I55f2bdea229cf11c21b5780b2639abb6dd7c3268
This commit is contained in:
Jorge E. Moreira
2023-02-24 11:28:09 -08:00
parent 4338e01dec
commit 0679981372
2 changed files with 400 additions and 44980 deletions

45339
Android.bp

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,12 @@
#!/usr/bin/env python
import json
import os
import sys
PRINT_ORIGINAL_FULL = False
# This flags are augmented with flags added to the json files but not present in .gn or .gni files
IGNORED_FLAGS = [
'-Wall',
'-Werror',
@ -91,6 +93,7 @@ DEFAULT_CFLAGS_BY_ARCH = {
'arm64': ['-DWEBRTC_HAS_NEON', '-DWEBRTC_ARCH_ARM64', '-DHAVE_ARM64_CRC32C=0'],
'riscv64': ['-DHAVE_ARM64_CRC32C=0'],
}
FLAGS = ['cflags', 'cflags_c', 'cflags_cc', 'asmflags']
ARCH_NAME_MAP = {n: n for n in DEFAULT_CFLAGS_BY_ARCH.keys()}
ARCH_NAME_MAP['x64'] = 'x86_64'
@ -180,12 +183,7 @@ def PrintHeader():
print('}')
def GatherDefaultFlags(targets):
default = {
'cflags' : [],
'cflags_c' : [],
'cflags_cc' : [],
'asmflags' : [],
}
default = { f: [] for f in FLAGS}
arch = {a: {} for a in ARCHS}
first = True
@ -655,6 +653,32 @@ def MergeAll(targets_by_arch):
return targets
def GatherAllFlags(obj):
if type(obj) != type({}):
# not a dictionary
return set()
ret = set()
for f in FLAGS:
ret |= set(obj.get(f, []))
for v in obj.values():
ret |= GatherAllFlags(v)
return ret
def FilterFlagsInUse(flags, directory):
unused = []
for f in flags:
nf = f
if nf.startswith("-D"):
nf = nf[2:]
i = nf.find('=')
if i > 0:
nf = nf[:i]
c = os.system(f"find {directory} -name '*.gn*' | xargs grep -q -s -e '{nf}'")
if c != 0:
# couldn't find the flag in *.gn or *.gni
unused.append(f)
return unused
if len(sys.argv) != 2:
print('wrong number of arguments', file = sys.stderr)
exit(1)
@ -662,10 +686,15 @@ if len(sys.argv) != 2:
dir = sys.argv[1]
targets_by_arch = {}
flags = set()
for arch in ARCHS:
path = "{0}/project_{1}.json".format(dir, arch)
json_file = open(path, 'r')
targets_by_arch[arch] = Preprocess(json.load(json_file))
flags |= GatherAllFlags(targets_by_arch[arch])
unusedFlags = FilterFlagsInUse(flags, f"{dir}/..")
IGNORED_FLAGS = sorted(set(IGNORED_FLAGS) | set(unusedFlags))
targets = MergeAll(targets_by_arch)