@@ -52,6 +52,9 @@ load("//cc/private/compile:lto_compilation_context.bzl", "create_lto_compilation
5252
5353_VALID_CPP_SOURCE_TYPES = set ([CPP_SOURCE_TYPE_SOURCE , CPP_SOURCE_TYPE_HEADER , CPP_SOURCE_TYPE_CLIF_INPUT_PROTO ])
5454
55+ def _clang_trace_enabled (feature_configuration ):
56+ return feature_configuration .is_enabled ("clang_trace" )
57+
5558def _cpp_source_init (* , label , source , type ):
5659 if type not in _VALID_CPP_SOURCE_TYPES :
5760 fail ("invalid type of cpp source, got:" , type , "expected one of:" , _VALID_CPP_SOURCE_TYPES )
@@ -347,6 +350,8 @@ def compile(
347350 "lto_compilation_context" : {},
348351 "gcno_files" : [],
349352 "pic_gcno_files" : [],
353+ "trace_files" : [],
354+ "pic_trace_files" : [],
350355 "dwo_files" : [],
351356 "pic_dwo_files" : [],
352357 "cpp_module_files" : [],
@@ -837,6 +842,7 @@ def _create_cc_compile_actions_with_cpp20_module_helper(
837842 cpp_module_map = cc_compilation_context ._module_map ,
838843 add_object = True ,
839844 enable_coverage = is_code_coverage_enabled ,
845+ enable_trace = _clang_trace_enabled (feature_configuration ),
840846 generate_dwo = should_create_per_object_debug_info (feature_configuration , cpp_configuration ),
841847 bitcode_output = bitcode_output ,
842848 fdo_context = fdo_context ,
@@ -985,6 +991,7 @@ def _create_cc_compile_actions_with_cpp20_module_helper(
985991 cpp_module_map = cc_compilation_context ._module_map ,
986992 add_object = True ,
987993 enable_coverage = is_code_coverage_enabled ,
994+ enable_trace = _clang_trace_enabled (feature_configuration ),
988995 generate_dwo = should_create_per_object_debug_info (feature_configuration , cpp_configuration ),
989996 bitcode_output = bitcode_output ,
990997 fdo_context = fdo_context ,
@@ -1268,6 +1275,7 @@ def _create_cc_compile_actions(
12681275 cpp_module_map = cc_compilation_context ._module_map ,
12691276 add_object = True ,
12701277 enable_coverage = is_code_coverage_enabled ,
1278+ enable_trace = _clang_trace_enabled (feature_configuration ),
12711279 generate_dwo = should_create_per_object_debug_info (feature_configuration , cpp_configuration ),
12721280 bitcode_output = bitcode_output ,
12731281 fdo_context = fdo_context ,
@@ -1420,6 +1428,7 @@ def _create_pic_nopic_compile_source_actions(
14201428 cpp_module_map ,
14211429 add_object ,
14221430 enable_coverage ,
1431+ enable_trace ,
14231432 generate_dwo ,
14241433 bitcode_output ,
14251434 fdo_context ,
@@ -1454,6 +1463,7 @@ def _create_pic_nopic_compile_source_actions(
14541463 cpp_module_map = cpp_module_map ,
14551464 add_object = add_object ,
14561465 enable_coverage = enable_coverage ,
1466+ enable_trace = enable_trace ,
14571467 generate_dwo = generate_dwo ,
14581468 bitcode_output = bitcode_output ,
14591469 fdo_context = fdo_context ,
@@ -1491,6 +1501,7 @@ def _create_pic_nopic_compile_source_actions(
14911501 cpp_module_map = cpp_module_map ,
14921502 add_object = add_object ,
14931503 enable_coverage = enable_coverage ,
1504+ enable_trace = enable_trace ,
14941505 generate_dwo = generate_dwo ,
14951506 bitcode_output = bitcode_output ,
14961507 fdo_context = fdo_context ,
@@ -1529,6 +1540,7 @@ def _create_compile_source_action(
15291540 cpp_module_map ,
15301541 add_object ,
15311542 enable_coverage ,
1543+ enable_trace ,
15321544 generate_dwo ,
15331545 bitcode_output ,
15341546 fdo_context ,
@@ -1592,6 +1604,11 @@ def _create_compile_source_action(
15921604 configuration = configuration ,
15931605 enable_coverage = enable_coverage ,
15941606 )
1607+ trace_file = _maybe_declare_trace_file (
1608+ ctx = action_construction_context ,
1609+ enable_trace = enable_trace ,
1610+ object_file = object_file ,
1611+ )
15951612
15961613 dwo_file = None
15971614 if generate_dwo and not bitcode_output :
@@ -1680,14 +1697,20 @@ def _create_compile_source_action(
16801697 if add_object and fdo_context_has_artifacts :
16811698 additional_inputs = additional_compilation_inputs + auxiliary_fdo_inputs .to_list ()
16821699
1700+ all_additional_outputs = list (additional_outputs )
1701+ if trace_file :
1702+ all_additional_outputs .append (trace_file )
1703+
16831704 # Provide these args conditionally as they require a recent version of Bazel.
16841705 if modmap_file :
16851706 module_args = {
1686- "additional_outputs" : additional_outputs ,
1707+ "additional_outputs" : all_additional_outputs ,
16871708 "module_files" : module_files ,
16881709 "modmap_file" : modmap_file ,
16891710 "modmap_input_file" : modmap_input_file ,
16901711 }
1712+ elif all_additional_outputs :
1713+ module_args = {"additional_outputs" : all_additional_outputs }
16911714 else :
16921715 module_args = {}
16931716
@@ -1736,6 +1759,11 @@ def _create_compile_source_action(
17361759 outputs ["pic_gcno_files" ].append (gcno_file )
17371760 else :
17381761 outputs ["gcno_files" ].append (gcno_file )
1762+ if trace_file :
1763+ if use_pic :
1764+ outputs ["pic_trace_files" ].append (trace_file )
1765+ else :
1766+ outputs ["trace_files" ].append (trace_file )
17391767 return object_file
17401768
17411769def _create_temps_action (
@@ -2136,6 +2164,7 @@ def _create_module_action(
21362164 cpp_module_map = cpp_module_map ,
21372165 add_object = False ,
21382166 enable_coverage = False ,
2167+ enable_trace = False ,
21392168 generate_dwo = False ,
21402169 bitcode_output = False ,
21412170 additional_compilation_inputs = additional_compilation_inputs ,
@@ -2297,12 +2326,25 @@ def _maybe_declare_gcno_file(
22972326 )
22982327 return gcno_file
22992328
2329+ def _maybe_declare_trace_file (
2330+ ctx ,
2331+ enable_trace ,
2332+ object_file ):
2333+ if not enable_trace :
2334+ return None
2335+ return _cc_internal .declare_other_output_file (
2336+ ctx = ctx ,
2337+ output_name = paths .replace_extension (paths .basename (object_file .path ), ".json" ),
2338+ object_file = object_file ,
2339+ )
2340+
23002341def _create_compile_action (
23012342 * ,
23022343 action_construction_context = None ,
23032344 action_name = None ,
23042345 additional_compilation_inputs = None ,
23052346 additional_include_scanning_roots = [],
2347+ additional_outputs = [],
23062348 cc_compilation_context = None ,
23072349 cc_toolchain = None ,
23082350 compile_build_variables = None ,
@@ -2329,6 +2371,7 @@ def _create_compile_action(
23292371 action_name = action_name ,
23302372 additional_compilation_inputs = additional_compilation_inputs ,
23312373 additional_include_scanning_roots = additional_include_scanning_roots ,
2374+ additional_outputs = additional_outputs ,
23322375 cc_compilation_context = cc_compilation_context ,
23332376 cc_toolchain = cc_toolchain ,
23342377 compile_build_variables = compile_build_variables ,
0 commit comments