Skip to content

Commit e0bcd3c

Browse files
bigelephant29copybara-github
authored andcommitted
PostMark: Respect stamp = -1.
PiperOrigin-RevId: 855716841 Change-Id: I7e94b85443bf262e85f1765493bb1f006bdc5316
1 parent b9d7117 commit e0bcd3c

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

cc/common/cc_helper.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ load(
2828
_is_stamping_enabled = "is_stamping_enabled",
2929
_package_source_root = "package_source_root",
3030
_repository_exec_path = "repository_exec_path",
31+
_should_stamp = "should_stamp",
3132
)
3233
load(":cc_info.bzl", "CcInfo")
3334
load(":visibility.bzl", "INTERNAL_VISIBILITY")
@@ -1132,6 +1133,7 @@ cc_helper = struct(
11321133
get_local_defines_for_runfiles_lookup = _get_local_defines_for_runfiles_lookup,
11331134
linker_scripts = _linker_scripts,
11341135
is_stamping_enabled = _is_stamping_enabled,
1136+
should_stamp = _should_stamp,
11351137
is_test_target = _is_test_target,
11361138
get_linked_artifact = _get_linked_artifact,
11371139
should_create_per_object_debug_info = should_create_per_object_debug_info,

cc/common/cc_helper_internal.bzl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def repository_exec_path(repository, sibling_repository_layout):
283283
return get_relative_path(prefix, repository)
284284

285285
def is_stamping_enabled(ctx):
286-
"""Returns whether to encode build information into the binary.
286+
"""Returns the tri-state of whether to encode build information into the binary.
287287
288288
Args:
289289
ctx: The rule context.
@@ -303,6 +303,22 @@ def is_stamping_enabled(ctx):
303303
stamp = ctx.attr.stamp
304304
return stamp
305305

306+
def should_stamp(ctx):
307+
"""Returns whether stamping should actually be performed based on stamp attribute and config.
308+
309+
Unlike is_stamping_enabled, this takes into account the --[no]stamp Blaze flag, so the return value is a boolean, not a tri-state.
310+
311+
Args:
312+
ctx: The rule context.
313+
314+
Returns:
315+
true if stamping should be performed, false otherwise.
316+
"""
317+
stamping_tri_state = is_stamping_enabled(ctx)
318+
return False if ctx.configuration.is_tool_configuration() else (
319+
stamping_tri_state == 1 or (stamping_tri_state == -1 and ctx.configuration.stamp_binaries())
320+
)
321+
306322
def is_shared_library(file):
307323
return file.extension in ["so", "dylib", "dll", "pyd", "wasm", "tgt", "vpi"]
308324

cc/private/compile/linkstamp_compile.bzl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Used for C++ linkstamp compiling.
2020
load("//cc:action_names.bzl", "LINKSTAMP_COMPILE_ACTION_NAME")
2121
load(
2222
"//cc/common:cc_helper_internal.bzl",
23-
"is_stamping_enabled",
23+
"should_stamp",
2424
)
2525
load("//cc/common:semantics.bzl", cc_semantics = "semantics")
2626
load("//cc/private:cc_info.bzl", "EMPTY_COMPILATION_CONTEXT")
@@ -63,10 +63,7 @@ def register_linkstamp_compile_action(
6363
ctx = _cc_internal.actions2ctx_cheat(actions)
6464

6565
if stamping == None:
66-
stamping_tri_state = is_stamping_enabled(ctx)
67-
stamping = False if ctx.configuration.is_tool_configuration() else (
68-
stamping_tri_state == 1 or (stamping_tri_state == -1 and ctx.configuration.stamp_binaries())
69-
)
66+
stamping = should_stamp(ctx)
7067

7168
output_group_info = cc_toolchain._build_info_files
7269
if stamping:

0 commit comments

Comments
 (0)