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
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 902ac60..44dc055 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -1000,39 +1000,6 @@
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}
diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go
index cf649a4..f74c519 100644
--- a/bazel/cquery/request_type.go
+++ b/bazel/cquery/request_type.go
@@ -197,7 +197,7 @@
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 @@
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 @@
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],