gn2bp: Support //build/android:build_config_gen

Hardcode BuildConfig.java and generate srcjar

Test: m cronet_aml_build_android_build_config_gen
Change-Id: Ia40c8e4a92dc9662926762e7c568ab15c9603031
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 72674bd..0b5695e 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -2055,20 +2055,28 @@
 // GN: //build/android:build_config_gen
 genrule {
     name: "cronet_aml_build_android_build_config_gen",
-    cmd: "$(location build/android/gyp/gcc_preprocess.py) --include-dirs " +
-         "[\"../../\", \"gen\"] " +
-         "--output " +
-         "gen/build/android/build_config_gen.srcjar " +
-         "--define " +
-         "_ENABLE_ASSERTS " +
-         "../../build/android/java/templates/BuildConfig.template",
+    tools: [
+        "soong_zip",
+    ],
+    cmd: "echo " +
+         "\"package org.chromium.build;\n " +
+         "public class BuildConfig {\n " +
+         "public static boolean IS_MULTIDEX_ENABLED ;\n " +
+         "public static boolean ENABLE_ASSERTS = true;\n " +
+         "public static boolean IS_UBSAN ;\n " +
+         "public static boolean IS_CHROME_BRANDED ;\n " +
+         "public static int R_STRING_PRODUCT_VERSION ;\n " +
+         "public static int MIN_SDK_VERSION = 1;\n " +
+         "public static boolean BUNDLES_SUPPORTED ;\n " +
+         "public static boolean IS_INCREMENTAL_INSTALL ;\n " +
+         "public static boolean ISOLATED_SPLITS_ENABLED ;\n " +
+         "public static boolean IS_FOR_TEST ;\n " +
+         "}\n\" " +
+         "> $(genDir)/BuildConfig.java && " +
+         "$(location soong_zip) -o $(out) -srcjar -f $(genDir)/BuildConfig.java",
     out: [
         "build/android/build_config_gen.srcjar",
     ],
-    tool_files: [
-        "build/android/gyp/gcc_preprocess.py",
-        "build/android/java/templates/BuildConfig.template",
-    ],
 }
 
 // GN: //build/android:build_java__build_config_crbug_908819
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 97eeb4d..5fda3ef 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -667,6 +667,37 @@
 
   blueprint.add_module(module)
 
+# HACK: Need to support build_cofig_gen flexibly instead of hardcoding
+# build_config_gen generates srcjar by executing gcc via gcc_preprocess.py but gcc is not
+# available in genrule sandbox. Also gcc path is not configurable.
+# Under the //net:net, gcc_preprocess.py is only used for build_config_gen.
+# So, for now, hardcoding BuildConfig.java and generates srcjar by soong_zip.
+def override_build_config_gen(module):
+  module.tool_files.clear()
+  module.tools.add("soong_zip")
+  cmd = [
+    "echo",
+    "\\\"package org.chromium.build;\\n",
+    "public class BuildConfig {\\n",
+    "public static boolean IS_MULTIDEX_ENABLED ;\\n",
+    "public static boolean ENABLE_ASSERTS = true;\\n",
+    "public static boolean IS_UBSAN ;\\n",
+    "public static boolean IS_CHROME_BRANDED ;\\n",
+    "public static int R_STRING_PRODUCT_VERSION ;\\n",
+    "public static int MIN_SDK_VERSION = 1;\\n",
+    "public static boolean BUNDLES_SUPPORTED ;\\n",
+    "public static boolean IS_INCREMENTAL_INSTALL ;\\n",
+    "public static boolean ISOLATED_SPLITS_ENABLED ;\\n",
+    "public static boolean IS_FOR_TEST ;\\n",
+    "}\\n\\\"",
+    "> $(genDir)/BuildConfig.java &&",
+    "$(location soong_zip) -o $(out) -srcjar -f $(genDir)/BuildConfig.java"
+  ]
+  NEWLINE = ' " +\n         "'
+  module.cmd = NEWLINE.join(cmd)
+  return module
+
+
 def create_action_module(blueprint, target):
   bp_module_name = label_to_module_name(target.name)
   module = Module('genrule', bp_module_name, target.name)
@@ -822,6 +853,10 @@
     module.srcs.remove(script)
 
   module.out.update(target.outputs)
+
+  if target.name == "//build/android:build_config_gen":
+    module = override_build_config_gen(module)
+
   blueprint.add_module(module)
   return module