Skip to content

Commit 94084b0

Browse files
Avoid depending on the value of the --stamp flag if possible (#1035)
* Stamp detect * Stamp detect tar.bzl * Stamp detect zip.bzl
1 parent 5399653 commit 94084b0

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

pkg/private/tar/tar.bzl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ load(
2424
"create_mapping_context_from_ctx",
2525
"write_manifest",
2626
)
27-
load("//pkg/private:util.bzl", "setup_output_files", "substitute_package_variables")
27+
load("//pkg/private:util.bzl", "get_stamp_detect", "setup_output_files", "substitute_package_variables")
2828

2929
# TODO(aiuto): Figure out how to get this from the python toolchain.
3030
# See check for lzma in archive.py for a hint at a method.
@@ -38,7 +38,6 @@ SUPPORTED_TAR_COMPRESSIONS = (
3838
["", "gz", "bz2", "xz"] if HAS_XZ_SUPPORT else ["", "gz", "bz2"]
3939
)
4040
_DEFAULT_MTIME = -1
41-
_stamp_condition = Label("//pkg/private:private_stamp_detect")
4241

4342
def _remap(remap_paths, path):
4443
"""If path starts with a key in remap_paths, rewrite it."""
@@ -362,9 +361,6 @@ def pkg_tar(name, **kwargs):
362361
pkg_tar_impl(
363362
name = name,
364363
out = kwargs.pop("out", None) or (name + "." + extension),
365-
private_stamp_detect = select({
366-
_stamp_condition: True,
367-
"//conditions:default": False,
368-
}),
364+
private_stamp_detect = get_stamp_detect(kwargs.get("stamp", 0)),
369365
**kwargs
370366
)

pkg/private/util.bzl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
load("//pkg:providers.bzl", "PackageVariablesInfo")
1717

18+
_stamp_condition = Label("//pkg/private:private_stamp_detect")
19+
1820
def setup_output_files(ctx, package_file_name = None, default_output_file = None):
1921
"""Provide output file metadata for common packaging rules
2022
@@ -126,3 +128,21 @@ def get_repo_mapping_manifest(src):
126128
# https://github.com/bazelbuild/bazel/issues/19937
127129
return getattr(files_to_run_provider, "repo_mapping_manifest")
128130
return None
131+
132+
def get_stamp_detect(stamp_attr):
133+
"""Returns a boolean or select to resolve the stamp setting.
134+
135+
Args:
136+
stamp_attr: Rule-level stamp attribute value.
137+
138+
Returns:
139+
Boolean or select to resolve the stamp setting.
140+
"""
141+
if stamp_attr == 1:
142+
return True
143+
if stamp_attr == -1:
144+
return select({
145+
_stamp_condition: True,
146+
"//conditions:default": False,
147+
})
148+
return False

pkg/private/zip/zip.bzl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ load(
2525
)
2626
load(
2727
"//pkg/private:util.bzl",
28+
"get_stamp_detect",
2829
"setup_output_files",
2930
"substitute_package_variables",
3031
)
3132

32-
_stamp_condition = Label("//pkg/private:private_stamp_detect")
33-
3433
def _pkg_zip_impl(ctx):
3534
outputs, output_file, _ = setup_output_files(ctx)
3635

@@ -186,9 +185,6 @@ def pkg_zip(name, out = None, **kwargs):
186185
pkg_zip_impl(
187186
name = name,
188187
out = out,
189-
private_stamp_detect = select({
190-
_stamp_condition: True,
191-
"//conditions:default": False,
192-
}),
188+
private_stamp_detect = get_stamp_detect(kwargs.get("stamp", 0)),
193189
**kwargs
194190
)

0 commit comments

Comments
 (0)