Fix errors from validate_target_files

We should skip lines that don't contain '=', e.g. empty lines.
Also, pop a warning instead of an error if a prop is defined
multiple times with the same value

Bug: 177240467
Test: unittest, run validate_target_files
Change-Id: Ifc9eadb91e5dda7170a19d875016e5a47e8fc592
This commit is contained in:
Tianjie 2021-01-12 14:04:58 -08:00
parent 4a632325a4
commit 2e0b835d28
2 changed files with 20 additions and 10 deletions

View File

@ -357,9 +357,6 @@ class ValidateTargetFilesTest(test_utils.ReleaseToolsTestCase):
'google/coral/coral:10/RP1A.200325.001/6337676:user/dev-keys',
'ro.product.odm.device=coral',
]
input_tmp = ValidateTargetFilesTest.make_build_prop({
'ODM/etc/build.prop': '\n'.join(build_prop),
})
input_tmp = ValidateTargetFilesTest.make_build_prop(build_prop)
self.assertRaises(ValueError, CheckBuildPropDuplicity,
input_tmp)
self.assertRaises(ValueError, CheckBuildPropDuplicity, input_tmp)

View File

@ -236,6 +236,7 @@ def ValidateInstallRecoveryScript(input_tmp, info_dict):
logging.info('Done checking %s', script_path)
# Symlink files in `src` to `dst`, if the files do not
# already exists in `dst` directory.
def symlinkIfNotExists(src, dst):
@ -246,6 +247,7 @@ def symlinkIfNotExists(src, dst):
continue
os.symlink(os.path.join(src, filename), os.path.join(dst, filename))
def ValidateVerifiedBootImages(input_tmp, info_dict, options):
"""Validates the Verified Boot related images.
@ -423,16 +425,25 @@ def ValidateVerifiedBootImages(input_tmp, info_dict, options):
'Verified %s with avbtool (key: %s):\n%s', image, key,
stdoutdata.rstrip())
def CheckDataDuplicity(lines):
def CheckDataInconsistency(lines):
build_prop = {}
for line in lines:
if line.startswith("import") or line.startswith("#"):
continue
key, value = line.split("=", 1)
if "=" not in line:
continue
key, value = line.rstrip().split("=", 1)
if key in build_prop:
return key
logging.info("Duplicated key found for {}".format(key))
if value != build_prop[key]:
logging.error("Key {} is defined twice with different values {} vs {}"
.format(key, value, build_prop[key]))
return key
build_prop[key] = value
def CheckBuildPropDuplicity(input_tmp):
"""Check all buld.prop files inside directory input_tmp, raise error
if they contain duplicates"""
@ -448,9 +459,11 @@ def CheckBuildPropDuplicity(input_tmp):
continue
logging.info("Checking {}".format(path))
with open(path, 'r') as fp:
dupKey = CheckDataDuplicity(fp.readlines())
dupKey = CheckDataInconsistency(fp.readlines())
if dupKey:
raise ValueError("{} contains duplicate keys for {}", path, dupKey)
raise ValueError("{} contains duplicate keys for {}".format(
path, dupKey))
def main():
parser = argparse.ArgumentParser(