diff options
author | Wei Li <weiwli@google.com> | 2022-07-08 19:09:06 -0700 |
---|---|---|
committer | Cherrypicker Worker <android-build-cherrypicker-worker@google.com> | 2022-07-13 13:39:12 +0000 |
commit | e26ebc8675a5f8962ce69c75e6d73991dbdb4ae3 (patch) | |
tree | 32e2c06c64c3125aaef21760db715f35528e8f97 | |
parent | 8396d07202f89b254aca657553f81cb3c88666cc (diff) | |
download | soong-e26ebc8675a5f8962ce69c75e6d73991dbdb4ae3.tar.gz |
JSON format doesn't support comments, so a JSONWithCommentsDecoder is added to support line comments start with // that used in apex_manifest.json files. This fixes the CI errors reported in b/238399517.
Bug: 238399517
Test: build/bazel/ci/bp2build.sh
Change-Id: Iaa3c2ab319eb7a52cbedaddd057646fc089d745a
(cherry picked from commit 18b7a2e8a242a7b8fab59fb3ac3b57902d9e6e4f)
Merged-In: Iaa3c2ab319eb7a52cbedaddd057646fc089d745a
-rwxr-xr-x | scripts/jsonmodify.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/scripts/jsonmodify.py b/scripts/jsonmodify.py index 96ff8cacd..8bd8d4556 100755 --- a/scripts/jsonmodify.py +++ b/scripts/jsonmodify.py @@ -82,6 +82,14 @@ class AppendList(str): raise ValueError(self + " should be a array.") cur[key].extend(args) +# A JSONDecoder that supports line comments start with // +class JSONWithCommentsDecoder(json.JSONDecoder): + def __init__(self, **kw): + super().__init__(**kw) + + def decode(self, s: str): + s = '\n'.join(l for l in s.split('\n') if not l.lstrip(' ').startswith('//')) + return super().decode(s) def main(): parser = argparse.ArgumentParser() @@ -115,9 +123,9 @@ def main(): if args.input: with open(args.input) as f: - obj = json.load(f, object_pairs_hook=collections.OrderedDict) + obj = json.load(f, object_pairs_hook=collections.OrderedDict, cls=JSONWithCommentsDecoder) else: - obj = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict) + obj = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict, cls=JSONWithCommentsDecoder) for p in args.patch: p[0].apply(obj, *p[1:]) |