gn2bp: Set the output name for libcronet.so

.so file name needs to match with CronetLibraryLoader.java
(e.g. libcronet.109.0.5386.0.so)

Test: m, atest CtsCronetTestCases
Change-Id: I82285c32e82fc27ba5233e1bef7195ec57c35bea
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 4626ef6..0ec99bd 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -6618,6 +6618,7 @@
     linker_scripts: [
         "base/android/library_loader/anchor_functions.lds",
     ],
+    stem: "libcronet.109.0.5386.0",
     target: {
         android_arm: {
             generated_headers: [
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index b357b58..4c60bfa 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -308,6 +308,8 @@
     self.stubs = {}
     self.cppflags = set()
     self.rtti = False
+    # Name of the output. Used for setting .so file name for libcronet
+    self.stem = None
 
   def to_string(self, output):
     if self.comment:
@@ -354,6 +356,7 @@
     self._output_field(output, 'proto')
     self._output_field(output, 'linker_scripts')
     self._output_field(output, 'cppflags')
+    self._output_field(output, 'stem')
     if self.rtti:
       self._output_field(output, 'rtti')
 
@@ -963,6 +966,13 @@
   if module.type == 'cc_library_static':
     module.export_generated_headers = module.generated_headers
 
+  if module.name == 'cronet_aml_components_cronet_android_cronet':
+    if target.output_name is None:
+      raise Error('Failed to get output_name for libcronet name')
+    # .so file name needs to match with CronetLibraryLoader.java (e.g. libcronet.109.0.5386.0.so)
+    # So setting the output name based on the output_name from the desc.json
+    module.stem = 'lib' + target.output_name
+
   # dep_name is an unmangled GN target name (e.g. //foo:bar(toolchain)).
   # Currently, only one module is generated from target even target has multiple toolchains.
   # And module is generated based on the first visited target.
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index 71d0d23..80c90f6 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -155,6 +155,9 @@
       self.is_finalized = False
       self.arch = dict()
 
+      # This is used to get the name/version of libcronet
+      self.output_name = None
+
     def host_supported(self):
       return 'host' in self.arch
 
@@ -347,6 +350,7 @@
     target.ldflags.update(desc.get('ldflags', []))
     target.arch[arch].defines.update(desc.get('defines', []))
     target.arch[arch].include_dirs.update(desc.get('include_dirs', []))
+    target.output_name = desc.get('output_name', None)
     if "-frtti" in target.arch[arch].cflags:
       target.rtti = True