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

Change @rules_pkg// to @// to allow users to name the repo what they want. #154

Merged
merged 18 commits into from
May 28, 2020
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
4 changes: 2 additions & 2 deletions pkg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ filegroup(
"BUILD",
"//experimental:standard_package",
],
visibility = ["@//distro:__pkg__"],
visibility = ["//distro:__pkg__"],
)

exports_files(["WORKSPACE"], visibility = ["@//distro:__pkg__"])
exports_files(["WORKSPACE"], visibility = ["//distro:__pkg__"])

py_library(
name = "archive",
Expand Down
2 changes: 1 addition & 1 deletion pkg/build_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import tarfile
import tempfile

from rules_pkg import archive
import archive

from helpers import GetFlagValue, SplitNameValuePairAtSeparator

Expand Down
24 changes: 12 additions & 12 deletions pkg/distro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package(
default_visibility = ["//visibility:private"],
)

load("//:pkg.bzl", "pkg_tar")
load("//:version.bzl", "version")
load("//releasing:defs.bzl", "print_rel_notes")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")
load("@rules_pkg//:version.bzl", "version")
load("@rules_python//python:defs.bzl", "py_test")

# Build the artifact to put on the github release page.
Expand Down Expand Up @@ -60,7 +60,7 @@ py_test(
],
deps = [
"@bazel_tools//tools/python/runfiles",
"@rules_pkg//releasing:release_utils",
"//releasing:release_utils",
],
)

Expand All @@ -73,18 +73,18 @@ genrule(
bzl_library(
name = "rules_pkg_lib",
srcs = [
"@//:path.bzl",
"@//:pkg.bzl",
"@//:rpm.bzl",
"@//:version.bzl",
"//:path.bzl",
"//:pkg.bzl",
"//:rpm.bzl",
"//:version.bzl",
],
visibility = ["//visibility:private"],
)

stardoc(
name = "docs_deb",
out = "pkg_deb.md",
input = "@//:pkg.bzl",
input = "//:pkg.bzl",
symbol_names = [
"pkg_deb",
"pkg_deb_impl",
Expand All @@ -95,7 +95,7 @@ stardoc(
stardoc(
name = "docs_tar",
out = "pkg_tar.md",
input = "@//:pkg.bzl",
input = "//:pkg.bzl",
symbol_names = [
"pkg_tar",
"pkg_tar_impl",
Expand All @@ -106,7 +106,7 @@ stardoc(
stardoc(
name = "docs_zip",
out = "pkg_zip.md",
input = "@//:pkg.bzl",
input = "//:pkg.bzl",
symbol_names = [
"pkg_zip",
"pkg_zip_impl",
Expand All @@ -117,6 +117,6 @@ stardoc(
stardoc(
name = "docs_rpm",
out = "pkg_rpm.md",
input = "@//:rpm.bzl",
input = "//:rpm.bzl",
deps = [":rules_pkg_lib"],
)
8 changes: 5 additions & 3 deletions pkg/distro/packaging_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class PackagingTest(unittest.TestCase):

def setUp(self):
self.data_files = runfiles.Create()
self.repo = 'rules_pkg'
self.source_repo = 'rules_pkg'
self.dest_repo = 'not_named_rules_pkg'
self.version = release_version.RELEASE_VERSION

def testBuild(self):
Expand All @@ -39,14 +40,15 @@ def testBuild(self):
if not os.path.exists(tempdir):
os.makedirs(tempdir)
with open(os.path.join(tempdir, 'WORKSPACE'), 'w') as workspace:
file_name = release_tools.package_basename(self.repo, self.version)
file_name = release_tools.package_basename(self.source_repo, self.version)
local_path = runfiles.Create().Rlocation(
os.path.join('rules_pkg', 'distro', file_name))
sha256 = release_tools.get_package_sha256(local_path)
workspace_content = '\n'.join((
'workspace(name = "test_rules_pkg_packaging")',
release_tools.workspace_content(
'file://%s' % local_path, self.repo, sha256,
'file://%s' % local_path, self.source_repo, sha256,
rename_repo=self.dest_repo,
deps_method='rules_pkg_dependencies'
)
))
Expand Down
2 changes: 1 addition & 1 deletion pkg/distro/testdata/BUILD.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@not_named_rules_pkg//:pkg.bzl", "pkg_tar")

pkg_tar(
name = "dummy_tar",
Expand Down
6 changes: 3 additions & 3 deletions pkg/experimental/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ py_binary(
srcs_version = "PY2AND3",
visibility = ["//visibility:public"],
deps = [
"@rules_pkg//:archive",
"@rules_pkg//:make_rpm_lib",
"//:archive",
"//:make_rpm_lib",
],
)

Expand All @@ -42,5 +42,5 @@ filegroup(
"BUILD",
"template.spec.in",
],
visibility = ["@//:__pkg__"],
visibility = ["//:__pkg__"],
)
6 changes: 3 additions & 3 deletions pkg/experimental/rpm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

"""Provides rules for creating RPM packages via pkg_filegroup and friends."""

load("@rules_pkg//experimental:pkg_filegroup.bzl", "PackageDirInfo", "PackageFileInfo")
load("//experimental:pkg_filegroup.bzl", "PackageDirInfo", "PackageFileInfo")

rpm_filetype = [".rpm"]

Expand Down Expand Up @@ -601,12 +601,12 @@ pkg_rpm = rule(
In most cases, you should not need to override this attribute.
""",
allow_single_file = spec_filetype,
default = "@rules_pkg//experimental:template.spec.in",
default = "//experimental:template.spec.in",
),

# Implicit dependencies.
"_make_rpm": attr.label(
default = Label("@rules_pkg//experimental:make_rpm"),
default = Label("//experimental:make_rpm"),
cfg = "exec",
executable = True,
allow_files = True,
Expand Down
2 changes: 1 addition & 1 deletion pkg/experimental/tests/external_repo/pkg/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//experimental:pkg_filegroup.bzl", "make_strip_prefix", "pkg_filegroup")
load("@//experimental:pkg_filegroup.bzl", "make_strip_prefix", "pkg_filegroup")
load("test.bzl", "test_referencing_remote_file")

package(default_visibility = ["//visibility:public"])
Expand Down
4 changes: 2 additions & 2 deletions pkg/experimental/tests/external_repo/pkg/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Test implementation copied from pkg/experimental/tests/pkg_filegroup_test.bzl

load("@bazel_skylib//lib:new_sets.bzl", "sets")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("@rules_pkg//experimental:pkg_filegroup.bzl", "PackageFileInfo", "make_strip_prefix", "pkg_filegroup")
load("@//experimental:pkg_filegroup.bzl", "PackageFileInfo", "make_strip_prefix", "pkg_filegroup")

#### BEGIN copied code

Expand Down Expand Up @@ -54,7 +54,7 @@ def test_referencing_remote_file(name):
pkg_filegroup(
name = "{}_g".format(name),
prefix = "usr/share",
srcs = ["@rules_pkg//tests:loremipsum_txt"],
srcs = ["@//tests:loremipsum_txt"],
# The prefix in rules_pkg. Why yes, this is knotty
strip_prefix = make_strip_prefix(from_root = "tests"),
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/experimental/tests/pkg_filegroup_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
load("@bazel_skylib//lib:new_sets.bzl", "sets")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest")
load(
"@rules_pkg//experimental:pkg_filegroup.bzl",
"@//experimental:pkg_filegroup.bzl",
"PackageDirInfo",
"PackageFileInfo",
"make_strip_prefix",
Expand Down
6 changes: 3 additions & 3 deletions pkg/pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pkg_tar_impl = rule(

# Implicit dependencies.
"build_tar": attr.label(
default = Label("@rules_pkg//:build_tar"),
default = Label("//:build_tar"),
cfg = "exec",
executable = True,
allow_files = True,
Expand Down Expand Up @@ -362,7 +362,7 @@ pkg_deb_impl = rule(

# Implicit dependencies.
"make_deb": attr.label(
default = Label("@rules_pkg//:make_deb"),
default = Label("//:make_deb"),
cfg = "exec",
executable = True,
allow_files = True,
Expand Down Expand Up @@ -429,7 +429,7 @@ pkg_zip_impl = rule(
"out": attr.output(),
# Implicit dependencies.
"build_zip": attr.label(
default = Label("@rules_pkg//:build_zip"),
default = Label("//:build_zip"),
cfg = "exec",
executable = True,
allow_files = True,
Expand Down
2 changes: 1 addition & 1 deletion pkg/releasing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ filegroup(
"*.bzl",
"*.py",
]),
visibility = ["@//distro:__pkg__"],
visibility = ["//distro:__pkg__"],
)

py_library(
Expand Down
4 changes: 2 additions & 2 deletions pkg/releasing/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def print_rel_notes(name, repo, version, outs=None, setup_file="",
deps_method="", toolchains_method=""):
tarball_name = ":%s-%s.tar.gz" % (repo, version)
cmd = [
"$(location @rules_pkg//releasing:print_rel_notes)",
"$(location //releasing:print_rel_notes)",
"--repo=%s" % repo,
"--version=%s" % version,
"--tarball=$(location %s)" % tarball_name,
Expand All @@ -24,6 +24,6 @@ def print_rel_notes(name, repo, version, outs=None, setup_file="",
outs = outs or ["relnotes.txt"],
cmd = " ".join(cmd),
tools = [
"@rules_pkg//releasing:print_rel_notes",
"//releasing:print_rel_notes",
],
)
11 changes: 9 additions & 2 deletions pkg/releasing/release_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ def get_package_sha256(tarball_path):
return tar_sha256


def workspace_content(url, repo, sha256, setup_file=None, deps_method=None,
toolchains_method=None):
def workspace_content(
url,
repo,
sha256,
rename_repo=None,
setup_file=None,
deps_method=None,
toolchains_method=None):
# Create the WORKSPACE stanza needed for this rule set.
if setup_file and not (deps_method or toolchains_method):
print(
Expand All @@ -67,6 +73,7 @@ def workspace_content(url, repo, sha256, setup_file=None, deps_method=None,

# If the github repo has a '-' in the name, that breaks bazel unless we remove
# it or change it to an '_'
repo = rename_repo or repo
repo = repo.replace('-', '_')
# Correct the common mistake of not putting a ':' in your setup file name
if setup_file and ':' not in setup_file:
Expand Down
26 changes: 13 additions & 13 deletions pkg/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
licenses(["notice"]) # Apache 2.0

load("@rules_pkg//:pkg.bzl", "pkg_deb", "pkg_tar", "pkg_zip")
load("@rules_pkg//:rpm.bzl", "pkg_rpm")
load("//:pkg.bzl", "pkg_deb", "pkg_tar", "pkg_zip")
load("//:rpm.bzl", "pkg_rpm")
load("@rules_python//python:defs.bzl", "py_test")

genrule(
Expand Down Expand Up @@ -101,7 +101,7 @@ py_test(
"test_zip_package_dir2.zip",
],
deps = [
"@rules_pkg//:build_zip",
"//:build_zip",
"@bazel_tools//tools/python/runfiles",
],
)
Expand All @@ -128,15 +128,15 @@ py_test(
"no_windows",
],
deps = [
"@rules_pkg//:archive",
"//:archive",
"@bazel_tools//tools/python/runfiles",
],
)

py_test(
name = "path_test",
srcs = ["path_test.py"],
data = ["@rules_pkg//:path.bzl"],
data = ["//:path.bzl"],
srcs_version = "PY2AND3",
)

Expand All @@ -150,8 +150,8 @@ py_test(
"no_windows",
],
deps = [
"@rules_pkg//:make_rpm_lib",
"@rules_pkg//:archive",
"//:make_rpm_lib",
"//:archive",
],
)

Expand All @@ -161,7 +161,7 @@ py_test(
python_version = "PY3",
srcs_version = "PY2AND3",
deps = [
"@rules_pkg//:archive",
"//:archive",
],
)

Expand All @@ -187,7 +187,7 @@ pkg_deb(
description = "toto ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é",
distribution = "trusty",
maintainer = "soméone@somewhere.com",
make_deb = "@rules_pkg//:make_deb",
make_deb = "//:make_deb",
package = "titi",
breaks = ["oldbrokenpkg"],
replaces = ["oldpkg"],
Expand Down Expand Up @@ -222,7 +222,7 @@ pkg_deb(
description = "toto ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é",
distribution = "trusty",
maintainer = "soméone@somewhere.com",
make_deb = "@rules_pkg//:make_deb_py2",
make_deb = "//:make_deb_py2",
package = "titi",
breaks = ["oldbrokenpkg"],
replaces = ["oldpkg"],
Expand All @@ -238,7 +238,7 @@ pkg_deb(
":etc/nsswitch.conf",
":usr/titi",
],
build_tar = "@rules_pkg//:build_tar",
build_tar = "//:build_tar",
extension = "tar%s" % ext,
mode = "0644",
modes = {"usr/titi": "0755"},
Expand All @@ -258,7 +258,7 @@ pkg_deb(

[pkg_tar(
name = "test-tar-inclusion-%s" % ext,
build_tar = "@rules_pkg//:build_tar",
build_tar = "//:build_tar",
deps = [":test-tar-%s" % ext],
) for ext in [
"",
Expand Down Expand Up @@ -389,7 +389,7 @@ sh_test(
"no_windows",
],
deps = [
"@rules_pkg//third_party/test/shell:bashunit",
"//third_party/test/shell:bashunit",
],
)

Expand Down