gn2bp: Add pre_create_action_module

To support //build:chromeos_buildflags
Add pre_create_action_module for target specific modification before the
create_action_module.
There might be a better way to target specific modification but this
makes //build:chromeos_buildflags specific change small for now.

Test: ./update_result.sh, m cronet_aml_base_base_static
Change-Id: I28e0758f84bebf3405298d7b908b6443914b3944
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 74df24a..aa9015a 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -14,6 +14,62 @@
 //
 // This file is automatically generated by gen_android_bp. Do not edit.
 
+// GN: //base:base_static
+cc_library_static {
+    name: "cronet_aml_base_base_static",
+    srcs: [
+        "base/base_switches.cc",
+    ],
+    generated_headers: [
+        "cronet_aml_build_chromeos_buildflags",
+    ],
+    export_generated_headers: [
+        "cronet_aml_build_chromeos_buildflags",
+    ],
+    defaults: [
+        "cronet_aml_defaults",
+    ],
+    cflags: [
+        "-DANDROID",
+        "-DANDROID_NDK_VERSION_ROLL=r23_1",
+        "-DCR_CLANG_REVISION=\"llvmorg-16-init-8697-g60809cd2-1\"",
+        "-DCR_LIBCXX_REVISION=47b31179d10646029c260702650a25d24f555acc",
+        "-DDCHECK_ALWAYS_ON=1",
+        "-DDYNAMIC_ANNOTATIONS_ENABLED=1",
+        "-DHAVE_SYS_UIO_H",
+        "-D_DEBUG",
+        "-D_GNU_SOURCE",
+        "-D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED=1",
+        "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
+        "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
+        "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
+        "-D__STDC_CONSTANT_MACROS",
+        "-D__STDC_FORMAT_MACROS",
+    ],
+    local_include_dirs: [
+        "./",
+        "buildtools/third_party/libc++/",
+        "out/test/gen/",
+    ],
+}
+
+// GN: //build:buildflag_header_h
+filegroup {
+    name: "cronet_aml_build_buildflag_header_h",
+}
+
+// GN: //build:chromeos_buildflags
+genrule {
+    name: "cronet_aml_build_chromeos_buildflags",
+    cmd: "echo '--flags IS_CHROMEOS_DEVICE=false IS_CHROMEOS_LACROS=false IS_CHROMEOS_ASH=false IS_CHROMEOS_WITH_HW_DETAILS=false IS_REVEN=false' | $(location build/write_buildflag_header.py) --output $(out) --rulename //build:chromeos_buildflags --gen-dir . --definitions /dev/stdin",
+    out: [
+        "build/chromeos_buildflags.h",
+    ],
+    tool_files: [
+        "build/write_buildflag_header.py",
+    ],
+}
+
 // GN: //gn:default_deps
 cc_defaults {
     name: "cronet_aml_defaults",
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index d3b43a8..7c7783b 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -664,6 +664,16 @@
 
   blueprint.add_module(module)
 
+# There may be a better way to do target specific modification
+# Target specific modification before create_action_module
+def pre_create_action_module(target):
+  if target.script == "//build/write_buildflag_header.py":
+    # write_buildflag_header.py writes result to args.genDir/args.output
+    # So, override args.genDir by '.' so that args.output=$(out) works
+    for i in range(len(target.args)-1):
+      if target.args[i] == '--gen-dir':
+        target.args[i+1] = '.'
+        break
 
 def create_action_module(blueprint, target):
   bp_module_name = label_to_module_name(target.name)
@@ -770,6 +780,7 @@
         name_without_toolchain == gn_utils.GEN_VERSION_TARGET:
       module = create_gen_version_module(blueprint, target, bp_module_name)
     else:
+      pre_create_action_module(target)
       module = create_action_module(blueprint, target)
   elif target.type == 'copy':
     # TODO: careful now! copy targets are not supported yet, but this will stop
diff --git a/tools/gn2bp/update_results.sh b/tools/gn2bp/update_results.sh
index b7b880f..58f0600 100755
--- a/tools/gn2bp/update_results.sh
+++ b/tools/gn2bp/update_results.sh
@@ -14,6 +14,7 @@
 TARGETS=(
   "//third_party/zlib:zlib"
   "//third_party/libevent:libevent"
+  "//base:base_static"
 )
 
 BASEDIR=$(dirname "$0")