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

Make the default behavior of pkg_files#strip_prefix more intuitive; rename it to srcs_strip_prefix #656

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,15 @@ http_archive(
load("@bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "rules_pkg_migration_deps",
requirements_lock = "//migration:migration_deps_lock.txt",
)

load("@rules_pkg_migration_deps//:requirements.bzl", migration_install_deps = "install_deps")

migration_install_deps()

1 change: 1 addition & 0 deletions distro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pkg_tar(
srcs = [
":small_workspace",
"//:standard_package",
"//migration:standard_package",
"//pkg:standard_package",
"//pkg/private:standard_package",
"//pkg/private/deb:standard_package",
Expand Down
2 changes: 0 additions & 2 deletions examples/rich_structure/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pkg_files(
],
# Where it should be in the final package
prefix = "usr/share/doc/foo",
# Required, but why?: see #354
strip_prefix = strip_prefix.from_pkg(),
)

pkg_filegroup(
Expand Down
4 changes: 1 addition & 3 deletions examples/rich_structure/resources/l10n/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pkg_files(
# We know they should be read only. We don't know who should own them.
mode = "0444",
),
strip_prefix = strip_prefix.from_pkg(),
)

# Use the English catalog again under a different name.
Expand All @@ -44,7 +43,6 @@ pkg_files(
mode = "0444",
),
prefix = "foo/en_GB",
strip_prefix = strip_prefix.from_pkg(),
)

# This gathers together all our message catalogs, and adds a prefix based
Expand All @@ -65,7 +63,7 @@ pkg_files(
attributes = pkg_attributes(
mode = "0444",
),
strip_prefix = strip_prefix.from_root("resources"),
srcs_strip_prefix = strip_prefix.from_root("resources"),
)

pkg_tar(
Expand Down
6 changes: 5 additions & 1 deletion examples/rich_structure/src/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mklink")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mklink", "strip_prefix")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//:foo_defs.bzl", "shared_object_path_selector")

Expand Down Expand Up @@ -56,6 +56,8 @@ pkg_files(
":fooctl",
],
# Where it should be in the final package
srcs_strip_prefix = strip_prefix.flatten(),
# Where it should be in the final package
prefix = select(shared_object_path_selector) + "/bin",
# Should this work?
# runfiles_prefix = select(shared_object_path_selector) + "/bin/runfiles",
Expand All @@ -66,6 +68,7 @@ pkg_files(
srcs = [
":foolib",
],
srcs_strip_prefix = strip_prefix.flatten(),
prefix = "usr/lib/foo",
)

Expand All @@ -83,6 +86,7 @@ pkg_files(
srcs = [
":man",
],
srcs_strip_prefix = strip_prefix.flatten(),
attributes = pkg_attributes(
group = "man",
mode = "0444",
Expand Down
4 changes: 3 additions & 1 deletion examples/rich_structure/src/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mkdirs")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mkdirs", "strip_prefix")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//:foo_defs.bzl", "shared_object_path_selector")

Expand Down Expand Up @@ -41,6 +41,7 @@ pkg_files(
srcs = [
":food",
],
srcs_strip_prefix = strip_prefix.flatten(),
attributes = pkg_attributes(
group = "root",
mode = "0551",
Expand All @@ -63,6 +64,7 @@ pkg_files(
srcs = [
":mansrc",
],
srcs_strip_prefix = strip_prefix.flatten(),
attributes = pkg_attributes(
group = "man",
mode = "0444",
Expand Down
42 changes: 42 additions & 0 deletions migration/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2023 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.

load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load("@rules_pkg_migration_deps//:requirements.bzl", "requirement")

filegroup(
name = "standard_package",
srcs = glob([
"*.py"
] + [
"BUILD",
"migration_deps.txt",
"migration_deps_lock.txt",
]),
visibility = ["//distro:__pkg__"],
)

py_binary(
name = "strip_prefix",
srcs = ["migrate_strip_prefix.py"],
main = "migrate_strip_prefix.py",
deps = [requirement("libcst")],
)

compile_pip_requirements(
name = "requirements",
requirements_in = "migration_deps.txt",
requirements_txt = "migration_deps_lock.txt",
)
Loading