@@ -60,7 +60,9 @@ def _compute_public_headers(
6060 binfiles_dir ,
6161 non_module_map_headers ,
6262 is_sibling_repository_layout ,
63- shorten_virtual_includes ):
63+ shorten_virtual_includes ,
64+ * ,
65+ must_use_strip_prefix = True ):
6466 if include_prefix :
6567 if not paths .is_normalized (include_prefix , False ):
6668 fail ("include prefix should not contain uplevel references: " + include_prefix )
@@ -117,7 +119,7 @@ def _compute_public_headers(
117119 headers = public_headers_artifacts + non_module_map_headers ,
118120 module_map_headers = public_headers_artifacts ,
119121 virtual_include_path = None ,
120- virtual_to_original_headers = depset () ,
122+ virtual_to_original_headers = [] ,
121123 )
122124
123125 module_map_headers = []
@@ -128,8 +130,13 @@ def _compute_public_headers(
128130 else :
129131 virtual_include_dir = paths .join (source_package_path , _VIRTUAL_INCLUDES_DIR , label .name )
130132 for original_header in public_headers_artifacts :
133+ module_map_headers .append (original_header )
134+
131135 repo_relative_path = _repo_relative_path (original_header )
132136 if not repo_relative_path .startswith (strip_prefix ):
137+ if not must_use_strip_prefix :
138+ continue
139+
133140 fail ("header '{}' is not under the specified strip prefix '{}'" .format (repo_relative_path , strip_prefix ))
134141 include_path = paths .relativize (repo_relative_path , strip_prefix )
135142 if include_prefix != None :
@@ -146,14 +153,12 @@ def _compute_public_headers(
146153 if config .coverage_enabled :
147154 virtual_to_original_headers_list .append ((virtual_header .path , original_header .path ))
148155
149- module_map_headers .append (original_header )
150-
151156 virtual_headers = module_map_headers + non_module_map_headers
152157 return struct (
153158 headers = virtual_headers ,
154159 module_map_headers = module_map_headers ,
155160 virtual_include_path = paths .join (binfiles_dir , virtual_include_dir ),
156- virtual_to_original_headers = depset ( virtual_to_original_headers_list ) ,
161+ virtual_to_original_headers = virtual_to_original_headers_list ,
157162 )
158163
159164def _generates_header_module (feature_configuration , public_headers , private_headers , generate_action ):
@@ -195,6 +200,7 @@ _ModuleMapInfo = provider(
195200 fields = [
196201 "module_map" ,
197202 "public_headers" ,
203+ "textual_headers" ,
198204 "private_headers" ,
199205 "dependency_module_maps" ,
200206 "additional_exported_headers" ,
@@ -249,6 +255,12 @@ def _module_map_struct_to_module_map_content(parameters, tree_expander):
249255 add_header (path = header .path , visibility = "" , can_compile = True )
250256 added_paths .add (header .path )
251257
258+ for header in expanded (parameters .textual_headers ):
259+ if header .path in added_paths :
260+ continue
261+ add_header (path = header .path , visibility = "" , can_compile = False )
262+ added_paths .add (header .path )
263+
252264 for header in expanded (parameters .private_headers ):
253265 if header .path in added_paths :
254266 continue
@@ -303,6 +315,7 @@ def _create_module_map_action(
303315 module_map ,
304316 private_headers ,
305317 public_headers ,
318+ textual_headers ,
306319 dependency_module_maps ,
307320 additional_exported_headers ,
308321 separate_module_headers ,
@@ -322,6 +335,7 @@ def _create_module_map_action(
322335 data_struct = _ModuleMapInfo (
323336 module_map = module_map ,
324337 public_headers = public_headers ,
338+ textual_headers = textual_headers ,
325339 private_headers = private_headers ,
326340 dependency_module_maps = dependency_module_maps ,
327341 additional_exported_headers = additional_exported_headers ,
@@ -339,6 +353,7 @@ def _create_module_map_action(
339353 # simple null function.
340354 tree_artifacts = [h for h in private_headers if h .is_directory ]
341355 tree_artifacts += [h for h in public_headers if h .is_directory ]
356+ tree_artifacts += [h for h in textual_headers if h .is_directory ]
342357 content .add_all (tree_artifacts , map_each = lambda x : None , allow_closure = True )
343358
344359 actions .write (module_map .file , content = content , is_executable = True , mnemonic = "CppModuleMap" )
@@ -433,15 +448,34 @@ def _init_cc_compilation_context(
433448 else :
434449 include_dirs_for_context .append (public_headers .virtual_include_path )
435450
451+ textual_headers = _compute_public_headers (
452+ actions ,
453+ config ,
454+ public_textual_headers ,
455+ include_prefix ,
456+ strip_include_prefix ,
457+ label ,
458+ binfiles_dir ,
459+ non_module_map_headers ,
460+ sibling_repo_layout ,
461+ shorten_virtual_includes ,
462+ must_use_strip_prefix = False ,
463+ )
464+ if textual_headers .virtual_include_path :
465+ if external or feature_configuration .is_requested ("system_include_paths" ):
466+ external_include_dirs .append (textual_headers .virtual_include_path )
467+ else :
468+ include_dirs_for_context .append (textual_headers .virtual_include_path )
469+
436470 if config .coverage_enabled :
437471 # Populate the map only when code coverage collection is enabled, to report the actual
438472 # source file name in the coverage output file.
439- virtual_to_original_headers = public_headers .virtual_to_original_headers
473+ virtual_to_original_headers = public_headers .virtual_to_original_headers + textual_headers . virtual_to_original_headers
440474 else :
441- virtual_to_original_headers = depset ()
475+ virtual_to_original_headers = []
442476
443477 declared_include_srcs .extend (public_headers .headers )
444- declared_include_srcs .extend (public_textual_headers )
478+ declared_include_srcs .extend (textual_headers . headers )
445479 declared_include_srcs .extend (private_headers_artifacts )
446480 declared_include_srcs .extend (additional_inputs )
447481
@@ -488,8 +522,10 @@ def _init_cc_compilation_context(
488522
489523 if _enabled (feature_configuration , "only_doth_headers_in_module_maps" ):
490524 public_headers_for_module_map_action = [header for header in public_headers .module_map_headers if (header .is_directory or header .extension == "h" )]
525+ textual_headers_for_module_map_action = [header for header in textual_headers .module_map_headers if (header .is_directory or header .extension == "h" )]
491526 else :
492527 public_headers_for_module_map_action = public_headers .module_map_headers
528+ textual_headers_for_module_map_action = textual_headers .module_map_headers
493529
494530 private_headers_for_module_map_action = private_headers_artifacts
495531 if _enabled (feature_configuration , "exclude_private_headers_in_module_maps" ):
@@ -499,6 +535,7 @@ def _init_cc_compilation_context(
499535 actions = actions ,
500536 module_map = module_map ,
501537 public_headers = public_headers_for_module_map_action ,
538+ textual_headers = textual_headers_for_module_map_action ,
502539 separate_module_headers = separate_public_headers .module_map_headers ,
503540 dependency_module_maps = dependency_module_maps ,
504541 private_headers = private_headers_for_module_map_action ,
@@ -559,15 +596,15 @@ def _init_cc_compilation_context(
559596 external_includes = depset (external_include_dirs ),
560597 system_includes = depset (system_include_dirs_for_context ),
561598 includes = depset (include_dirs_for_context ),
562- virtual_to_original_headers = virtual_to_original_headers ,
599+ virtual_to_original_headers = depset ( virtual_to_original_headers ) ,
563600 dependent_cc_compilation_contexts = dependent_cc_compilation_contexts ,
564601 non_code_inputs = additional_inputs ,
565602 defines = depset (defines ),
566603 local_defines = depset (local_defines ),
567604 headers = depset (declared_include_srcs ),
568605 direct_public_headers = public_headers .headers ,
569606 direct_private_headers = private_headers_artifacts ,
570- direct_textual_headers = public_textual_headers ,
607+ direct_textual_headers = textual_headers . headers ,
571608 module_map = module_map ,
572609 pic_header_module = pic_header_module ,
573610 header_module = header_module ,
@@ -585,15 +622,15 @@ def _init_cc_compilation_context(
585622 external_includes = depset (external_include_dirs ),
586623 system_includes = depset (system_include_dirs_for_context ),
587624 includes = depset (include_dirs_for_context ),
588- virtual_to_original_headers = virtual_to_original_headers ,
625+ virtual_to_original_headers = depset ( virtual_to_original_headers ) ,
589626 dependent_cc_compilation_contexts = dependent_cc_compilation_contexts + implementation_deps ,
590627 non_code_inputs = additional_inputs ,
591628 defines = depset (defines ),
592629 local_defines = depset (local_defines ),
593630 headers = depset (declared_include_srcs ),
594631 direct_public_headers = public_headers .headers ,
595632 direct_private_headers = private_headers_artifacts ,
596- direct_textual_headers = public_textual_headers ,
633+ direct_textual_headers = textual_headers . headers ,
597634 module_map = module_map ,
598635 pic_header_module = pic_header_module ,
599636 header_module = header_module ,
0 commit comments