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/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