2121 "get_relative_path" ,
2222 "is_versioned_shared_library_extension_valid" ,
2323 "path_contains_up_level_references" ,
24+ "should_create_per_object_debug_info" ,
2425 _artifact_category = "artifact_category" ,
2526 _extensions = "extensions" ,
2627 _package_source_root = "package_source_root" ,
@@ -40,9 +41,47 @@ linker_mode = struct(
4041
4142# LINT.IfChange(forked_exports)
4243
44+ cpp_file_types = struct (
45+ LINKER_SCRIPT = ["ld" , "lds" , "ldscript" ],
46+ )
47+
4348artifact_category = _artifact_category
4449extensions = _extensions
4550
51+ def _replace_name (name , new_name ):
52+ last_slash = name .rfind ("/" )
53+ if last_slash == - 1 :
54+ return new_name
55+ return name [:last_slash ] + "/" + new_name
56+
57+ def _get_base_name (name ):
58+ last_slash = name .rfind ("/" )
59+ if last_slash == - 1 :
60+ return name
61+ return name [last_slash + 1 :]
62+
63+ def _get_artifact_name_for_category (cc_toolchain , is_dynamic_link_type , output_name ):
64+ linked_artifact_category = None
65+ if is_dynamic_link_type :
66+ linked_artifact_category = artifact_category .DYNAMIC_LIBRARY
67+ else :
68+ linked_artifact_category = artifact_category .EXECUTABLE
69+
70+ return cc_common .get_artifact_name_for_category (cc_toolchain = cc_toolchain , category = linked_artifact_category , output_name = output_name )
71+
72+ def _get_linked_artifact (ctx , cc_toolchain , is_dynamic_link_type ):
73+ name = ctx .label .name
74+ new_name = _get_artifact_name_for_category (cc_toolchain , is_dynamic_link_type , _get_base_name (name ))
75+ name = _replace_name (name , new_name )
76+
77+ return ctx .actions .declare_file (name )
78+
79+ def _is_test_target (ctx ):
80+ if hasattr (ctx .attr , "testonly" ):
81+ return ctx .attr .testonly
82+
83+ return False
84+
4685def _create_save_feature_state_artifacts (
4786 output_groups_builder ,
4887 cpp_configuration ,
@@ -979,6 +1018,22 @@ def _get_local_defines_for_runfiles_lookup(ctx, all_deps):
9791018 return ["BAZEL_CURRENT_REPOSITORY=\" {}\" " .format (ctx .label .workspace_name )]
9801019 return []
9811020
1021+ def _linker_scripts (ctx ):
1022+ result = []
1023+ for dep in ctx .attr .deps :
1024+ for f in dep [DefaultInfo ].files .to_list ():
1025+ if f .extension in cpp_file_types .LINKER_SCRIPT :
1026+ result .append (f )
1027+ return result
1028+
1029+ def _is_stamping_enabled (ctx ):
1030+ if ctx .configuration .is_tool_configuration ():
1031+ return 0
1032+ stamp = 0
1033+ if hasattr (ctx .attr , "stamp" ):
1034+ stamp = ctx .attr .stamp
1035+ return stamp
1036+
9821037cc_helper = struct (
9831038 create_strip_action = _create_strip_action ,
9841039 get_expanded_env = _get_expanded_env ,
@@ -1021,5 +1076,10 @@ cc_helper = struct(
10211076 merge_output_groups = _merge_output_groups ,
10221077 extensions = extensions ,
10231078 get_local_defines_for_runfiles_lookup = _get_local_defines_for_runfiles_lookup ,
1079+ linker_scripts = _linker_scripts ,
1080+ is_stamping_enabled = _is_stamping_enabled ,
1081+ is_test_target = _is_test_target ,
1082+ get_linked_artifact = _get_linked_artifact ,
1083+ should_create_per_object_debug_info = should_create_per_object_debug_info ,
10241084)
10251085# LINT.ThenChange(https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl:forked_exports)
0 commit comments