Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pkg/private/tar/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ load(
"create_mapping_context_from_ctx",
"write_manifest",
)
load("//pkg/private:util.bzl", "setup_output_files", "substitute_package_variables")
load("//pkg/private:util.bzl", "get_stamp_detect", "setup_output_files", "substitute_package_variables")

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

def _remap(remap_paths, path):
"""If path starts with a key in remap_paths, rewrite it."""
Expand Down Expand Up @@ -362,9 +361,6 @@ def pkg_tar(name, **kwargs):
pkg_tar_impl(
name = name,
out = kwargs.pop("out", None) or (name + "." + extension),
private_stamp_detect = select({
_stamp_condition: True,
"//conditions:default": False,
}),
private_stamp_detect = get_stamp_detect(kwargs.get("stamp", 0)),
**kwargs
)
20 changes: 20 additions & 0 deletions pkg/private/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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

_stamp_condition = Label("//pkg/private:private_stamp_detect")

def setup_output_files(ctx, package_file_name = None, default_output_file = None):
"""Provide output file metadata for common packaging rules

Expand Down Expand Up @@ -126,3 +128,21 @@ def get_repo_mapping_manifest(src):
# https://github.com/bazelbuild/bazel/issues/19937
return getattr(files_to_run_provider, "repo_mapping_manifest")
return None

def get_stamp_detect(stamp_attr):
"""Returns a boolean or select to resolve the stamp setting.

Args:
stamp_attr: Rule-level stamp attribute value.

Returns:
Boolean or select to resolve the stamp setting.
"""
if stamp_attr == 1:
return True
if stamp_attr == -1:
return select({
_stamp_condition: True,
"//conditions:default": False,
})
return False
8 changes: 2 additions & 6 deletions pkg/private/zip/zip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ load(
)
load(
"//pkg/private:util.bzl",
"get_stamp_detect",
"setup_output_files",
"substitute_package_variables",
)

_stamp_condition = Label("//pkg/private:private_stamp_detect")

def _pkg_zip_impl(ctx):
outputs, output_file, _ = setup_output_files(ctx)

Expand Down Expand Up @@ -186,9 +185,6 @@ def pkg_zip(name, out = None, **kwargs):
pkg_zip_impl(
name = name,
out = out,
private_stamp_detect = select({
_stamp_condition: True,
"//conditions:default": False,
}),
private_stamp_detect = get_stamp_detect(kwargs.get("stamp", 0)),
**kwargs
)