summaryrefslogtreecommitdiff
path: root/scripts/jsonmodify.py
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2022-07-11 17:45:18 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2022-07-11 17:45:18 +0000
commit83222003728c9dc19da91b4b58a92269c7f44570 (patch)
tree27333e8fb4aea662b29bffc899e03d54d4018379 /scripts/jsonmodify.py
parent2971a94e4c6128bb147f38c25f82b3e6159a516f (diff)
parent18b7a2e8a242a7b8fab59fb3ac3b57902d9e6e4f (diff)
Merge "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."
Diffstat (limited to 'scripts/jsonmodify.py')
-rwxr-xr-xscripts/jsonmodify.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/scripts/jsonmodify.py b/scripts/jsonmodify.py
index ba1109e7a..5132aa8f6 100755
--- a/scripts/jsonmodify.py
+++ b/scripts/jsonmodify.py
@@ -75,6 +75,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()
@@ -103,9 +111,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:])