-
Notifications
You must be signed in to change notification settings - Fork 221
Add stamp attribute to pkg_tar (in the style of cc_binary(stamp=-1,0,1) #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
77306e4
b324296
e0e8190
681aa3d
d125268
19ed27d
d957ebe
1eb1c6d
ac66b05
1c2ac89
85fb173
4e280a0
5f525db
7c46ee7
3d7dc39
0ddce67
6afe619
86bbeea
e205d27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright 2021 The Bazel Authors. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| licenses(["notice"]) | ||
|
|
||
| load("@rules_pkg//:pkg.bzl", "pkg_tar") | ||
|
|
||
| pkg_tar( | ||
| name = "never_stamped", | ||
| srcs = [ | ||
| ":BUILD", | ||
| ], | ||
| ) | ||
|
|
||
| pkg_tar( | ||
| name = "always_stamped", | ||
| srcs = [ | ||
| ":BUILD", | ||
| ], | ||
| stamp = 1, | ||
| ) | ||
|
|
||
| pkg_tar( | ||
| name = "controlled_by_stamp_option", | ||
| srcs = [ | ||
| ":BUILD", | ||
| ], | ||
| stamp = -1, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Copyright 2021 The Bazel Authors. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| workspace(name = "rules_pkg_examples") | ||
|
|
||
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
|
||
| local_repository( | ||
| name = "rules_pkg", | ||
| path = "../../pkg", | ||
| ) | ||
|
|
||
| load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") | ||
|
|
||
| rules_pkg_dependencies() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Examples of how time stamping works. | ||
|
aiuto marked this conversation as resolved.
|
||
|
|
||
| ## How it works | ||
|
|
||
| Target declarations may use the `stamp` attribute to control | ||
| the time stamping of files in an archive. The behavior follows | ||
| the pattern of the cc_binary rule: | ||
|
|
||
| https://docs.bazel.build/versions/main/be/c-cpp.html#cc_binary | ||
|
|
||
| Read the BUILD file for more details. | ||
|
|
||
| ## Try this | ||
|
|
||
| ``` | ||
| bazel build :* | ||
| for tarball in bazel-bin/*.tar ; do | ||
| echo ==== $tarball | ||
| tar tvf $tarball | ||
| done | ||
|
|
||
| bazel build :* --stamp=1 | ||
| for tarball in bazel-bin/*.tar ; do | ||
| echo ==== $tarball | ||
| tar tvf $tarball | ||
| done | ||
|
aiuto marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| You should see something like: | ||
| ``` | ||
| INFO: Build completed successfully, 3 total actions | ||
| ==== bazel-bin/always_stamped.tar | ||
| drwxr-xr-x 0 0 0 0 May 3 17:34 ./ | ||
| -r-xr-xr-x 0 0 0 968 May 3 17:34 ./BUILD | ||
| ==== bazel-bin/controlled_by_stamp_option.tar | ||
| drwxr-xr-x 0 0 0 0 Dec 31 1999 ./ | ||
| -r-xr-xr-x 0 0 0 968 Dec 31 1999 ./BUILD | ||
| ==== bazel-bin/never_stamped.tar | ||
| drwxr-xr-x 0 0 0 0 Dec 31 1999 ./ | ||
| -r-xr-xr-x 0 0 0 968 Dec 31 1999 ./BUILD | ||
| INFO: Build option --stamp has changed, discarding analysis cache. | ||
| INFO: Build completed successfully, 3 total actions | ||
| ==== bazel-bin/always_stamped.tar | ||
| drwxr-xr-x 0 0 0 0 May 3 17:34 ./ | ||
| -r-xr-xr-x 0 0 0 968 May 3 17:34 ./BUILD | ||
| ==== bazel-bin/controlled_by_stamp_option.tar | ||
| drwxr-xr-x 0 0 0 0 May 6 17:42 ./ | ||
| -r-xr-xr-x 0 0 0 968 May 6 17:42 ./BUILD | ||
| ==== bazel-bin/never_stamped.tar | ||
| drwxr-xr-x 0 0 0 0 Dec 31 1999 ./ | ||
| -r-xr-xr-x 0 0 0 968 Dec 31 1999 ./BUILD | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ pkg_tar( | |
| srcs = [ | ||
| ":small_workspace", | ||
| "//:standard_package", | ||
| "//private:standard_package", | ||
| "//releasing:standard_package", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bah, this is missing |
||
| "//toolchains:standard_package", | ||
| ], | ||
|
|
@@ -97,7 +98,7 @@ genrule( | |
| bzl_library( | ||
| name = "rules_pkg_lib", | ||
| srcs = [ | ||
| "//:private/util.bzl", | ||
| "//private:util.bzl", | ||
| "//:package_variables.bzl", | ||
| "//:path.bzl", | ||
| "//:pkg.bzl", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
|
|
||
| load(":path.bzl", "compute_data_path", "dest_path") | ||
| load(":providers.bzl", "PackageArtifactInfo", "PackageVariablesInfo") | ||
| load("private/util.bzl", "setup_output_files", "substitute_package_variables") | ||
| load("//private:util.bzl", "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. | ||
|
|
@@ -30,6 +30,7 @@ SUPPORTED_TAR_COMPRESSIONS = ( | |
| ) | ||
| deb_filetype = [".deb", ".udeb"] | ||
| _DEFAULT_MTIME = -1 | ||
| _stamp_condition = str(Label("//private:private_stamp_detect")) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does stringifying the Also, should this be |
||
|
|
||
| def _remap(remap_paths, path): | ||
| """If path starts with a key in remap_paths, rewrite it.""" | ||
|
|
@@ -151,6 +152,10 @@ def _pkg_tar_impl(ctx): | |
| "--link=%s:%s" % (_quote(k, protect = ":"), ctx.attr.symlinks[k]) | ||
| for k in ctx.attr.symlinks | ||
| ] | ||
| if ctx.attr.stamp == 1 or (ctx.attr.stamp == -1 and | ||
| ctx.attr.private_stamp_detect): | ||
| args.append("--stamp_from=%s" % ctx.version_file.path) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any plans on having |
||
| files.append(ctx.version_file) | ||
| arg_file = ctx.actions.declare_file(ctx.label.name + ".args") | ||
| files.append(arg_file) | ||
| ctx.actions.write(arg_file, "\n".join(args)) | ||
|
|
@@ -337,6 +342,7 @@ def _pkg_deb_impl(ctx): | |
| ), | ||
| ] | ||
|
|
||
|
|
||
| # A rule for creating a tar file, see README.md | ||
| pkg_tar_impl = rule( | ||
| implementation = _pkg_tar_impl, | ||
|
|
@@ -372,6 +378,10 @@ pkg_tar_impl = rule( | |
| doc = "See Common Attributes", | ||
| providers = [PackageVariablesInfo], | ||
| ), | ||
| "stamp": attr.int(default = 0), | ||
| # Is --stamp set on the command line? | ||
| # TODO(https://github.com/bazelbuild/rules_pkg/issues/340): Remove this. | ||
| "private_stamp_detect": attr.bool(default = False), | ||
|
|
||
| # Implicit dependencies. | ||
| "build_tar": attr.label( | ||
|
|
@@ -413,6 +423,10 @@ 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, | ||
| }), | ||
|
aiuto marked this conversation as resolved.
|
||
| **kwargs | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright 2021 The Bazel Authors. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """rules_pkg internal code. | ||
|
|
||
| This is subject to change at any time. | ||
| """ | ||
|
|
||
| load("@rules_python//python:defs.bzl", "py_library") | ||
|
|
||
| licenses(["notice"]) | ||
|
|
||
| filegroup( | ||
| name = "standard_package", | ||
| srcs = glob([ | ||
| "BUILD", | ||
| "*.bzl", | ||
| "*.py", | ||
| ]), | ||
| visibility = ["//distro:__pkg__"], | ||
| ) | ||
|
|
||
| exports_files( | ||
| glob([ | ||
| "*.bzl", | ||
| ]), | ||
| visibility = ["//distro:__pkg__"], | ||
| ) | ||
|
|
||
| config_setting( | ||
| name = "private_stamp_detect", | ||
| values = {"stamp": "1"}, | ||
| ) | ||
|
|
||
| py_library( | ||
| name = "build_info", | ||
| srcs = [ | ||
| "build_info.py", | ||
| ], | ||
| srcs_version = "PY3", | ||
| visibility = [ | ||
| "//:__pkg__", | ||
| "//tests:__pkg__", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright 2021 The Bazel Authors. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Get BUILD_TIMESTAMP.""" | ||
|
|
||
|
|
||
| def get_timestamp(volatile_status_file): | ||
| """Get BUILD_TIMESTAMP as an integer. | ||
|
|
||
| Reads a file of "name<space>value" pairs and returns the value | ||
| of the BUILD_TIMESTAMP. The file should be in the workspace status | ||
| format: https://docs.bazel.build/versions/master/user-manual.html#workspace_status | ||
|
|
||
| Args: | ||
| volatile_status_file: path to input file. Typically ctx.version_file.path. | ||
| Returns: | ||
| int: value of BUILD_TIMESTAMP | ||
| Exceptions: | ||
| Exception: Raised if there is no BUILD_TIMESTAMP or if it is not a number. | ||
| """ | ||
| with open(volatile_status_file, 'r') as status_f: | ||
| for line in status_f: | ||
| parts = line.strip().split(' ') | ||
| if len(parts) > 1 and parts[0] == 'BUILD_TIMESTAMP': | ||
| return int(parts[1]) | ||
| raise Exception( | ||
| "Invalid status file <%s>. Expected to find BUILD_TIMESTAMP" % volatile_status_file) |
Uh oh!
There was an error while loading. Please reload this page.