Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18b7a2e8 authored by Wei Li's avatar Wei Li
Browse files

JSON format doesn't support comments, so a JSONWithCommentsDecoder is added to...

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
parent 01365d58
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -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:])