Replace json_encode with json.encode

Now that the json module is available in the cquery starlark execution
enviornment.

Bug: 245315355
Test: m nothing
Change-Id: Ie7c314e2f4e2ef4257bd84abc1add01ddb668f0b
This commit is contained in:
Cole Faust 2023-03-19 14:24:23 -07:00
parent 9ba1ddd355
commit 8181f4b916
2 changed files with 3 additions and 36 deletions

View file

@ -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}

View file

@ -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],