From 2e0b835d282e515da4953ce82c3c24f58ec6b12b Mon Sep 17 00:00:00 2001 From: Tianjie Date: Tue, 12 Jan 2021 14:04:58 -0800 Subject: [PATCH] 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 --- .../test_validate_target_files.py | 7 ++---- tools/releasetools/validate_target_files.py | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tools/releasetools/test_validate_target_files.py b/tools/releasetools/test_validate_target_files.py index e9896ae0c..48b563d7b 100644 --- a/tools/releasetools/test_validate_target_files.py +++ b/tools/releasetools/test_validate_target_files.py @@ -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) diff --git a/tools/releasetools/validate_target_files.py b/tools/releasetools/validate_target_files.py index d2178b214..401857f4c 100755 --- a/tools/releasetools/validate_target_files.py +++ b/tools/releasetools/validate_target_files.py @@ -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(