Add a way to prefix Android targets names

Both Conscrypt (more correctly, //external/boringssl) and Cronet in AOSP
rely on generate_build_files.py to create their Android.bp. This results
in build target name clashes. Cronet currently solves this by
namespacing its own build target names, but this is not
common/recommended practice in AOSP.

By introducing a way to prefix the build target name, Cronet will be
able to generate build targets that differ from Conscrypt's.

Bug: b:396593141
Change-Id: I34971e8973d5215eb9bb18601c7940910033ce36
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/76447
Commit-Queue: Stefano Duo <stefanoduo@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/util/generate_build_files.py b/util/generate_build_files.py
index 3a9f2ca..5d86f5c 100644
--- a/util/generate_build_files.py
+++ b/util/generate_build_files.py
@@ -30,6 +30,9 @@
   return x if not PREFIX else os.path.join(PREFIX, x)
 
 
+TARGET_PREFIX = ''
+
+
 LICENSE_TEMPLATE = """Copyright 2015 The BoringSSL Authors
 
 Licensed under the Apache License, Version 2.0 (the "License");
@@ -63,6 +66,7 @@
 """
 
   def PrintVariableSection(self, out, name, files):
+    name = f'{TARGET_PREFIX}{name}'
     out.write('%s := \\\n' % name)
     for f in sorted(files):
       out.write('  %s\\\n' % f)
@@ -98,6 +102,7 @@
 
   def PrintDefaults(self, blueprint, name, files, asm_files=[], data=[]):
     """Print a cc_defaults section from a list of C files and optionally assembly outputs"""
+    name = f'{TARGET_PREFIX}{name}'
     if asm_files:
       blueprint.write('\n')
       blueprint.write('%s_asm = [\n' % name)
@@ -668,12 +673,15 @@
 
 if __name__ == '__main__':
   parser = optparse.OptionParser(
-      usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
+      usage='Usage: %%prog [--prefix=<path>] [--target-prefix=<prefix>] [all|%s]' %
       '|'.join(sorted(ALL_PLATFORMS.keys())))
   parser.add_option('--prefix', dest='prefix',
       help='For Bazel, prepend argument to all source files')
+  parser.add_option('--target-prefix', dest='target_prefix',
+      help='For Android, prepend argument to all target names')
   options, args = parser.parse_args(sys.argv[1:])
   PREFIX = options.prefix
+  TARGET_PREFIX = options.target_prefix
 
   if not args:
     parser.print_help()