Skip to content
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

Remove PackageArtifactsInfo. #752

Merged
merged 3 commits into from
Sep 12, 2023
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
20 changes: 13 additions & 7 deletions pkg/private/deb/deb.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"""Rule for creating Debian packages."""

load("//pkg:providers.bzl", "PackageArtifactInfo", "PackageVariablesInfo")
load("//pkg:providers.bzl", "PackageVariablesInfo")
load("//pkg/private:util.bzl", "setup_output_files")

_tar_filetype = [".tar", ".tar.gz", ".tgz", ".tar.bz2", "tar.xz"]
Expand Down Expand Up @@ -172,16 +172,23 @@ def _pkg_deb_impl(ctx):
files = depset([output_file]),
runfiles = ctx.runfiles(files = outputs),
),
PackageArtifactInfo(
label = ctx.label.name,
file = output_file,
file_name = output_name,
),
]

# A rule for creating a deb file, see README.md
pkg_deb_impl = rule(
implementation = _pkg_deb_impl,
doc = """
Create a Debian package.

This rule produces 2 artifacts: a .deb and a .changes file. The DefaultInfo will
include both. If you need downstream rule to specificially depend on only the .deb or
.changes file then you can use `filegroup` to select distinct output groups.

**OutputGroupInfo**
- `out` the Debian package or a symlink to the actual package.
- `deb` the package with any precise file name created with `package_file_name`.
- `changes` the .changes file.
""",
attrs = {
# @unsorted-dict-items
"data": attr.label(
Expand Down Expand Up @@ -361,7 +368,6 @@ See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files.""",
allow_files = True,
),
},
provides = [PackageArtifactInfo],
)

def pkg_deb(name, out = None, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion pkg/private/pkg_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Concepts and terms:
load("//pkg:path.bzl", "compute_data_path", "dest_path")
load(
"//pkg:providers.bzl",
"PackageArtifactInfo",
"PackageDirsInfo",
"PackageFilegroupInfo",
"PackageFilesInfo",
Expand Down
8 changes: 1 addition & 7 deletions pkg/private/tar/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Rules for making .tar files."""

load("//pkg:path.bzl", "compute_data_path", "dest_path")
load("//pkg:providers.bzl", "PackageArtifactInfo", "PackageVariablesInfo")
load("//pkg:providers.bzl", "PackageVariablesInfo")
load(
"//pkg/private:pkg_files.bzl",
"add_directory",
Expand Down Expand Up @@ -238,11 +238,6 @@ def _pkg_tar_impl(ctx):
OutputGroupInfo(
manifest = [manifest_file],
),
PackageArtifactInfo(
label = ctx.label.name,
file = output_file,
file_name = output_name,
),
]

# A rule for creating a tar file, see README.md
Expand Down Expand Up @@ -305,7 +300,6 @@ The name may contain variables, same as [package_file_name](#package_file_name)"
allow_files = True,
),
},
provides = [PackageArtifactInfo],
)

def pkg_tar(name, **kwargs):
Expand Down
5 changes: 1 addition & 4 deletions pkg/private/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ def setup_output_files(ctx, package_file_name = None, default_output_file = None
Callers should:
- write to `output_file`
- add `outputs` to their returned `DefaultInfo(files)` provider
- return a `PackageArtifactInfo` provider of the form:
label: `ctx.label.name`
file: `output_file`
file_name: `output_name`
- Possibly add a distinguishing element to OutputGroups

Args:
ctx: rule context
Expand Down
7 changes: 0 additions & 7 deletions pkg/private/zip/zip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
load("//pkg:path.bzl", "compute_data_path", "dest_path")
load(
"//pkg:providers.bzl",
"PackageArtifactInfo",
"PackageVariablesInfo",
)
load(
Expand Down Expand Up @@ -83,11 +82,6 @@ def _pkg_zip_impl(ctx):
files = depset([output_file]),
runfiles = ctx.runfiles(files = outputs),
),
PackageArtifactInfo(
label = ctx.label.name,
file = output_file,
file_name = output_name,
),
]

pkg_zip_impl = rule(
Expand Down Expand Up @@ -160,7 +154,6 @@ The list of compressions is the same as Python's ZipFile: https://docs.python.or
allow_files = True,
),
},
provides = [PackageArtifactInfo],
)

def pkg_zip(name, out = None, **kwargs):
Expand Down
15 changes: 8 additions & 7 deletions pkg/rpm_pfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ find_system_rpmbuild(name="rules_pkg_rpmbuild")

load(
"//pkg:providers.bzl",
"PackageArtifactInfo",
"PackageDirsInfo",
"PackageFilegroupInfo",
"PackageFilesInfo",
Expand Down Expand Up @@ -678,11 +677,6 @@ def _pkg_rpm_impl(ctx):
DefaultInfo(
files = depset(outputs),
),
PackageArtifactInfo(
file = output_file,
file_name = output_name,
label = ctx.label.name,
),
]

# Define the rule.
Expand Down Expand Up @@ -715,6 +709,14 @@ pkg_rpm = rule(

Is the equivalent to `%config(missingok, noreplace)` in the `%files` list.

This rule produces 2 artifacts: an .rpm and a .changes file. The DefaultInfo will
include both. If you need downstream rule to specificially depend on only the .rpm or
.changes file then you can use `filegroup` to select distinct output groups.

**OutputGroupInfo**
- `out` the RPM or a symlink to the actual package.
- `rpm` the package with any precise file name created with `package_file_name`.
- `changes` the .changes file.
""",
# @unsorted-dict-items
attrs = {
Expand Down Expand Up @@ -1022,6 +1024,5 @@ pkg_rpm = rule(
},
executable = False,
implementation = _pkg_rpm_impl,
provides = [PackageArtifactInfo],
toolchains = ["@rules_pkg//toolchains/rpm:rpmbuild_toolchain_type"],
)
48 changes: 27 additions & 21 deletions tests/rpm/analysis_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ load(
"pkg_mklink",
)
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("//pkg:providers.bzl", "PackageArtifactInfo", "PackageVariablesInfo")
load("//pkg:providers.bzl", "PackageVariablesInfo")
load("//pkg:rpm.bzl", "pkg_rpm")
load("//tests/util:defs.bzl", "directory", "generic_base_case_test", "generic_negative_test")

Expand Down Expand Up @@ -167,42 +167,48 @@ def _package_naming_test_impl(ctx):
env = analysistest.begin(ctx)
target_under_test = analysistest.target_under_test(env)

pai = target_under_test[PackageArtifactInfo]
ogi = target_under_test[OutputGroupInfo]

pai_file = pai.file
pai_name = pai.file_name
out_file = ogi.out.to_list()[0]
rpm_file = ogi.rpm.to_list()[0]
changes_file = ogi.changes.to_list()[0] if ogi.changes else None
asserts.equals(
env,
pai_name,
rpm_file.basename,
ctx.attr.expected_name,
"PackageArtifactInfo file name does not match expected value.",
"OutputGroupInfo rpm name does not match expected value.",
)

# Try to find the expected files in the DefaultInfo. We have to look for
# them; PackageArtifactInfo only gives a file name, not a File structure.
packaged_file = None
packaged_file_found = False
# Try to find the expected files in the DefaultInfo.
out_file_found = False
rpm_file_found = False
changes_file_found = False if changes_file else True
default_name_found = False
for f in target_under_test[DefaultInfo].files.to_list():
if f == pai.file:
packaged_file_found = True
if f.basename == pai_name:
packaged_file = f
if f == out_file:
out_file_found = True
if f == rpm_file:
rpm_file_found = True
if f == changes_file:
changes_file_found = True
elif f.basename == ctx.attr.expected_default_name and not default_name_found:
default_name_found = True

asserts.true(
env,
packaged_file != None,
"File name mentioned in PackageArtifactInfo '{}' is not in DefaultInfo".format(pai_name),
out_file_found,
"out component of OutputGroupInfo '{}' is not in DefaultInfo".format(out_file),
)

asserts.true(
env,
packaged_file_found,
"File object mentioned in PackageArtifactInfo '{}' missing from DefaultInfo".format(pai_name),
rpm_file_found,
"rpm component of OutputGroupInfo '{}' is not in DefaultInfo".format(rpm_file),
)
asserts.true(
env,
changes_file_found,
"changes component of OutputGroupInfo '{}' is not in DefaultInfo".format(changes_file),
)

asserts.true(
env,
default_name_found,
Expand Down Expand Up @@ -239,7 +245,7 @@ dummy_pkg_variables = rule(

def _test_naming(name):
# Test whether name templating via PackageVariablesInfo functions as expected, and ensure that
# outputs are passed through to PackageArtifactsInfo.
# outputs are passed through to OutputGroupInfo.
pkg_files(
name = "{}_file_base".format(name),
srcs = ["foo"],
Expand Down