gn2bp: Split function to set local_include_dirs

Test: ./update_results.sh
Change-Id: I341043b46348cac2af949e121b4bb4cd8b266827
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 7320434..8a42011 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -968,6 +968,32 @@
     if '-fexceptions' in flag:
       module.cppflags.add('-fexceptions')
 
+def set_module_include_dirs(module, cflags, include_dirs):
+  local_include_dirs_set = set()
+  for flag in cflags:
+    if '-isystem' in flag:
+      local_include_dirs_set.add(flag[len('-isystem../../'):])
+
+  # Adding local_include_dirs is necessary due to source_sets / filegroups
+  # which do not properly propagate include directories.
+  # Filter any directory inside //out as a) this directory does not exist for
+  # aosp / soong builds and b) the include directory should already be
+  # configured via library dependency.
+  local_include_dirs_set.update([gn_utils.label_to_path(d)
+                                 for d in include_dirs
+                                 if not re.match('^//out/.*', d)])
+  module.local_include_dirs = sorted(list(local_include_dirs_set))
+
+  # Order matters for some targets. For example, base/time/time_exploded_icu.cc
+  # in //base:base needs to have sysroot include after icu/source/common
+  # include. So adding sysroot include at the end.
+  for flag in sorted(cflags):
+    if '--sysroot' in flag:
+      sysroot = flag[len('--sysroot=../../'):]
+      if sysroot == "build/linux/debian_bullseye_amd64-sysroot":
+        module.local_include_dirs.append(sysroot + "/usr/include/x86_64-linux-gnu")
+      module.local_include_dirs.append(sysroot + "/usr/include")
+
 def create_modules_from_target(blueprint, gn, gn_target_name):
   """Generate module(s) for a given GN target.
 
@@ -1044,32 +1070,9 @@
       for src in arch.sources
       if is_supported_source_file(src) and not src.startswith("//out/test"))
 
-  local_include_dirs_set = set()
   if target.type in gn_utils.LINKER_UNIT_TYPES:
     set_module_flags(module, target.cflags, target.defines)
-    for flag in target.cflags:
-      if '-isystem' in flag:
-        local_include_dirs_set.add(flag[len('-isystem../../'):])
-
-    # Adding local_include_dirs is necessary due to source_sets / filegroups
-    # which do not properly propagate include directories.
-    # Filter any directory inside //out as a) this directory does not exist for
-    # aosp / soong builds and b) the include directory should already be
-    # configured via library dependency.
-    local_include_dirs_set.update([gn_utils.label_to_path(d)
-                                      for d in target.include_dirs
-                                      if not re.match('^//out/.*', d)])
-    module.local_include_dirs = sorted(list(local_include_dirs_set))
-
-    # Order matters for some targets. For example, base/time/time_exploded_icu.cc
-    # in //base:base needs to have sysroot include after icu/source/common
-    # include. So adding sysroot include at the end.
-    for flag in sorted(target.cflags):
-      if '--sysroot' in flag:
-        sysroot = flag[len('--sysroot=../../'):]
-        if sysroot == "build/linux/debian_bullseye_amd64-sysroot":
-          module.local_include_dirs.append(sysroot + "/usr/include/x86_64-linux-gnu")
-        module.local_include_dirs.append(sysroot + "/usr/include")
+    set_module_include_dirs(module, target.cflags, target.include_dirs)
 
   if module.is_compiled():
     module.host_supported = target.host_supported()