Merge changes I84a02511,Ieae4ffb3 into main am: 7b1a78b429

Original change: https://android-review.googlesource.com/c/platform/external/mesa3d/+/3171240

Change-Id: I262a9048c39cb5ce40e6f1e04397bbb776e74291
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/python-build/meson_fuchsia.py b/python-build/meson_fuchsia.py
index 0f3c31d..c28ed83 100644
--- a/python-build/meson_fuchsia.py
+++ b/python-build/meson_fuchsia.py
@@ -89,6 +89,13 @@
   impl.load_config_file('python-build/generate_fuchsia_build.config')
 
 
+def add_subdirs_to_set(dir, dir_set):
+  subdirs = os.listdir(dir)
+  for subdir in subdirs:
+    subdir = os.path.join(dir, subdir)
+    if os.path.isdir(subdir):
+      dir_set.add(subdir)
+
 def include_directories(*paths, is_system=False):
   dirs = impl.get_include_dirs(paths)
   name = dirs[0].replace('/', '_')
@@ -99,17 +106,19 @@
   if name not in _gIncludeDirectories:
     # Mesa likes to include files at a level down from the include path,
     # so ensure Bazel allows this by including all of the possibilities.
-    # Hopefully we don't need to go two or more levels down.
     # Can't repeat entries so use a set.
     dir_set = set()
     for dir in dirs:
       dir = os.path.normpath(dir)
       dir_set.add(dir)
-      subdirs = os.listdir(dir)
-      for subdir in subdirs:
-        subdir = os.path.join(dir, subdir)
-        if os.path.isdir(subdir):
-          dir_set.add(subdir)
+      add_subdirs_to_set(dir, dir_set)
+
+    # HACK: For special cases we go down two levels:
+    # - Mesa vulkan runtime does #include "vulkan/wsi/..."
+    paths_needing_two_levels = [ 'src/vulkan' ]
+    for dir in list(dir_set):
+      if dir in paths_needing_two_levels:
+        add_subdirs_to_set(dir, dir_set)
 
     impl.fprint('# header library')
     impl.fprint('cc_library(')
@@ -375,6 +384,7 @@
   srcs = set()
   generated_sources = set()
   generated_headers = set()
+  generated_header_files = []
   for source_arg in source:
     assert type(source_arg) is list
     _get_sources(source_arg, srcs, generated_sources, generated_headers)
@@ -389,8 +399,10 @@
     for src in impl.get_linear_list([dep.sources]):
       if type(src) == impl.CustomTargetItem:
         generated_headers.add(src.target.target_name_h())
+        generated_header_files.extend(src.target.header_outputs())
       elif type(src) == impl.CustomTarget:
         generated_headers.add(src.target_name_h())
+        generated_header_files.extend(src.header_outputs())
       else:
         exit('Unhandled source dependency: ' + str(type(src)))
     include_directories.extend(
@@ -459,7 +471,10 @@
       '  # hdrs are our files that might be included; listed here so Bazel will'
       ' allow them to be included'
   )
-  impl.fprint('  hdrs = []')
+  impl.fprint('  hdrs = [')
+  for hdr in set(generated_header_files):
+    impl.fprint('    "%s",' % hdr)
+  impl.fprint('   ]')
   for hdr in local_include_dirs:
     impl.fprint(
         '    + glob(["%s"])' % os.path.normpath(os.path.join(hdr, '*.h'))
diff --git a/python-build/meson_impl.py b/python-build/meson_impl.py
index ae7a4f32..01aefa3 100644
--- a/python-build/meson_impl.py
+++ b/python-build/meson_impl.py
@@ -322,6 +322,13 @@
       return self._name + '.c'
     return self._name
 
+  def header_outputs(self):
+    hdrs = []
+    for out in self._outputs:
+      if out.endswith('.h'):
+        hdrs.append(out)
+    return hdrs
+
   def __iter__(self):
     return iter([self])