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:
@@ -357,9 +357,6 @@ class ValidateTargetFilesTest(test_utils.ReleaseToolsTestCase):
|
|||||||
'google/coral/coral:10/RP1A.200325.001/6337676:user/dev-keys',
|
'google/coral/coral:10/RP1A.200325.001/6337676:user/dev-keys',
|
||||||
'ro.product.odm.device=coral',
|
'ro.product.odm.device=coral',
|
||||||
]
|
]
|
||||||
input_tmp = ValidateTargetFilesTest.make_build_prop({
|
input_tmp = ValidateTargetFilesTest.make_build_prop(build_prop)
|
||||||
'ODM/etc/build.prop': '\n'.join(build_prop),
|
|
||||||
})
|
|
||||||
|
|
||||||
self.assertRaises(ValueError, CheckBuildPropDuplicity,
|
self.assertRaises(ValueError, CheckBuildPropDuplicity, input_tmp)
|
||||||
input_tmp)
|
|
||||||
|
@@ -236,6 +236,7 @@ def ValidateInstallRecoveryScript(input_tmp, info_dict):
|
|||||||
|
|
||||||
logging.info('Done checking %s', script_path)
|
logging.info('Done checking %s', script_path)
|
||||||
|
|
||||||
|
|
||||||
# Symlink files in `src` to `dst`, if the files do not
|
# Symlink files in `src` to `dst`, if the files do not
|
||||||
# already exists in `dst` directory.
|
# already exists in `dst` directory.
|
||||||
def symlinkIfNotExists(src, dst):
|
def symlinkIfNotExists(src, dst):
|
||||||
@@ -246,6 +247,7 @@ def symlinkIfNotExists(src, dst):
|
|||||||
continue
|
continue
|
||||||
os.symlink(os.path.join(src, filename), os.path.join(dst, filename))
|
os.symlink(os.path.join(src, filename), os.path.join(dst, filename))
|
||||||
|
|
||||||
|
|
||||||
def ValidateVerifiedBootImages(input_tmp, info_dict, options):
|
def ValidateVerifiedBootImages(input_tmp, info_dict, options):
|
||||||
"""Validates the Verified Boot related images.
|
"""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,
|
'Verified %s with avbtool (key: %s):\n%s', image, key,
|
||||||
stdoutdata.rstrip())
|
stdoutdata.rstrip())
|
||||||
|
|
||||||
def CheckDataDuplicity(lines):
|
|
||||||
|
def CheckDataInconsistency(lines):
|
||||||
build_prop = {}
|
build_prop = {}
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("import") or line.startswith("#"):
|
if line.startswith("import") or line.startswith("#"):
|
||||||
continue
|
continue
|
||||||
key, value = line.split("=", 1)
|
if "=" not in line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
key, value = line.rstrip().split("=", 1)
|
||||||
if key in build_prop:
|
if key in build_prop:
|
||||||
|
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
|
return key
|
||||||
build_prop[key] = value
|
build_prop[key] = value
|
||||||
|
|
||||||
|
|
||||||
def CheckBuildPropDuplicity(input_tmp):
|
def CheckBuildPropDuplicity(input_tmp):
|
||||||
"""Check all buld.prop files inside directory input_tmp, raise error
|
"""Check all buld.prop files inside directory input_tmp, raise error
|
||||||
if they contain duplicates"""
|
if they contain duplicates"""
|
||||||
@@ -448,9 +459,11 @@ def CheckBuildPropDuplicity(input_tmp):
|
|||||||
continue
|
continue
|
||||||
logging.info("Checking {}".format(path))
|
logging.info("Checking {}".format(path))
|
||||||
with open(path, 'r') as fp:
|
with open(path, 'r') as fp:
|
||||||
dupKey = CheckDataDuplicity(fp.readlines())
|
dupKey = CheckDataInconsistency(fp.readlines())
|
||||||
if dupKey:
|
if dupKey:
|
||||||
raise ValueError("{} contains duplicate keys for {}", path, dupKey)
|
raise ValueError("{} contains duplicate keys for {}".format(
|
||||||
|
path, dupKey))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
Reference in New Issue
Block a user