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

Commit c164b460 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Replace json_encode with json.encode"

parents 6828e185 8181f4b9
Loading
Loading
Loading
Loading
+0 −33
Original line number Diff line number Diff line
@@ -1000,39 +1000,6 @@ def %s(target, id_string):
	formatString := `
# This file is generated by soong_build. Do not edit.

# a drop-in replacement for json.encode(), not available in cquery environment
# TODO(cparsons): bring json module in and remove this function
def json_encode(input):
  # Avoiding recursion by limiting
  #  - a dict to contain anything except a dict
  #  - a list to contain only primitives
  def encode_primitive(p):
    t = type(p)
    if t == "string" or t == "int":
      return repr(p)
    fail("unsupported value '%s' of type '%s'" % (p, type(p)))

  def encode_list(list):
    items = []
    for item in list:
        if type(item) == "dict":
            # support encoding dict of primitive keys and values. not list currently, because calling encode_list again is recursive.
            kv_pairs = [("%s: %s" % (encode_primitive(k), encode_primitive(v))) for (k, v) in item.items()]
            items.append("{ %s }" % ", ".join(kv_pairs))
        else:
            items.append(encode_primitive(item))
    return "[%s]" % ", ".join(items)

  def encode_list_or_primitive(v):
    return encode_list(v) if type(v) == "list" else encode_primitive(v)

  if type(input) == "dict":
    # TODO(juu): the result is read line by line so can't use '\n' yet
    kv_pairs = [("%s: %s" % (encode_primitive(k), encode_list_or_primitive(v))) for (k, v) in input.items()]
    return "{ %s }" % ", ".join(kv_pairs)
  else:
    return encode_list_or_primitive(input)

{LABEL_REGISTRATION_MAP_SECTION}

{FUNCTION_DEF_SECTION}
+3 −3
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ if androidmk_tag in p:
    local_whole_static_libs = androidmk_info.local_whole_static_libs
    local_shared_libs = androidmk_info.local_shared_libs

return json_encode({
return json.encode({
    "OutputFiles": outputFiles,
    "CcObjectFiles": ccObjectFiles,
    "CcSharedLibraryFiles": sharedLibraries,
@@ -266,7 +266,7 @@ clang_tidy_info = providers(target).get("//build/bazel/rules/cc:clang_tidy.bzl%C
if clang_tidy_info:
    tidy_files = [v.path for v in clang_tidy_info.transitive_tidy_files.to_list()]

return json_encode({
return json.encode({
    "signed_output": info.signed_output.path,
    "signed_compressed_output": signed_compressed_output,
    "unsigned_output": info.unsigned_output.path,
@@ -352,7 +352,7 @@ clang_tidy_info = p.get("//build/bazel/rules/cc:clang_tidy.bzl%ClangTidyInfo")
if clang_tidy_info:
    tidy_files = [v.path for v in clang_tidy_info.transitive_tidy_files.to_list()]

return json_encode({
return json.encode({
    "OutputFile":  output_path,
    "UnstrippedOutput": unstripped,
    "LocalStaticLibs": [l for l in local_static_libs],