From 2977b089a6cd45038d39a5498f0a6cabb11774bf Mon Sep 17 00:00:00 2001 From: aiuto Date: Wed, 27 May 2020 21:22:25 -0400 Subject: [PATCH] Change @rules_pkg// to @// to allow users to name the repo what they want. (#154) * Change @rules_pkg// to @// when approriate. This allows users to include the rules and remap the repo to a new name I used the @// to give a visual reminder that this is interpreted w.r.t. to the repo, and not your workspace root. * do the experimental branch * sync.to.master * @// -> // --- pkg/BUILD | 4 +-- pkg/build_tar.py | 2 +- pkg/distro/BUILD | 24 ++++++++--------- pkg/distro/packaging_test.py | 8 +++--- pkg/distro/testdata/BUILD.tmpl | 2 +- pkg/experimental/BUILD | 6 ++--- pkg/experimental/rpm.bzl | 6 ++--- .../tests/external_repo/pkg/BUILD | 2 +- .../tests/external_repo/pkg/test.bzl | 4 +-- pkg/experimental/tests/pkg_filegroup_test.bzl | 2 +- pkg/pkg.bzl | 6 ++--- pkg/releasing/BUILD | 2 +- pkg/releasing/defs.bzl | 4 +-- pkg/releasing/release_tools.py | 11 ++++++-- pkg/tests/BUILD | 26 +++++++++---------- 15 files changed, 59 insertions(+), 50 deletions(-) diff --git a/pkg/BUILD b/pkg/BUILD index b9518e34..2f30872c 100644 --- a/pkg/BUILD +++ b/pkg/BUILD @@ -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", diff --git a/pkg/build_tar.py b/pkg/build_tar.py index 1719099c..feb7daba 100644 --- a/pkg/build_tar.py +++ b/pkg/build_tar.py @@ -21,7 +21,7 @@ import tarfile import tempfile -from rules_pkg import archive +import archive from helpers import GetFlagValue, SplitNameValuePairAtSeparator diff --git a/pkg/distro/BUILD b/pkg/distro/BUILD index 6d4a7995..816dfbaa 100644 --- a/pkg/distro/BUILD +++ b/pkg/distro/BUILD @@ -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. @@ -60,7 +60,7 @@ py_test( ], deps = [ "@bazel_tools//tools/python/runfiles", - "@rules_pkg//releasing:release_utils", + "//releasing:release_utils", ], ) @@ -73,10 +73,10 @@ 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"], ) @@ -84,7 +84,7 @@ bzl_library( stardoc( name = "docs_deb", out = "pkg_deb.md", - input = "@//:pkg.bzl", + input = "//:pkg.bzl", symbol_names = [ "pkg_deb", "pkg_deb_impl", @@ -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", @@ -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", @@ -117,6 +117,6 @@ stardoc( stardoc( name = "docs_rpm", out = "pkg_rpm.md", - input = "@//:rpm.bzl", + input = "//:rpm.bzl", deps = [":rules_pkg_lib"], ) diff --git a/pkg/distro/packaging_test.py b/pkg/distro/packaging_test.py index f71b90fd..2d6a57da 100644 --- a/pkg/distro/packaging_test.py +++ b/pkg/distro/packaging_test.py @@ -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): @@ -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' ) )) diff --git a/pkg/distro/testdata/BUILD.tmpl b/pkg/distro/testdata/BUILD.tmpl index 8e51370b..9b5d925a 100644 --- a/pkg/distro/testdata/BUILD.tmpl +++ b/pkg/distro/testdata/BUILD.tmpl @@ -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", diff --git a/pkg/experimental/BUILD b/pkg/experimental/BUILD index 727e94c4..3d28f460 100644 --- a/pkg/experimental/BUILD +++ b/pkg/experimental/BUILD @@ -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", ], ) @@ -42,5 +42,5 @@ filegroup( "BUILD", "template.spec.in", ], - visibility = ["@//:__pkg__"], + visibility = ["//:__pkg__"], ) diff --git a/pkg/experimental/rpm.bzl b/pkg/experimental/rpm.bzl index ea649775..9713bb70 100644 --- a/pkg/experimental/rpm.bzl +++ b/pkg/experimental/rpm.bzl @@ -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"] @@ -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, diff --git a/pkg/experimental/tests/external_repo/pkg/BUILD b/pkg/experimental/tests/external_repo/pkg/BUILD index 755d9535..1a7842b3 100644 --- a/pkg/experimental/tests/external_repo/pkg/BUILD +++ b/pkg/experimental/tests/external_repo/pkg/BUILD @@ -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"]) diff --git a/pkg/experimental/tests/external_repo/pkg/test.bzl b/pkg/experimental/tests/external_repo/pkg/test.bzl index 0c86a35a..74476c54 100644 --- a/pkg/experimental/tests/external_repo/pkg/test.bzl +++ b/pkg/experimental/tests/external_repo/pkg/test.bzl @@ -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 @@ -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"), ) diff --git a/pkg/experimental/tests/pkg_filegroup_test.bzl b/pkg/experimental/tests/pkg_filegroup_test.bzl index e36e9217..5129c644 100644 --- a/pkg/experimental/tests/pkg_filegroup_test.bzl +++ b/pkg/experimental/tests/pkg_filegroup_test.bzl @@ -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", diff --git a/pkg/pkg.bzl b/pkg/pkg.bzl index ed7c48df..679f3d83 100644 --- a/pkg/pkg.bzl +++ b/pkg/pkg.bzl @@ -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, @@ -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, @@ -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, diff --git a/pkg/releasing/BUILD b/pkg/releasing/BUILD index bb6b0ae7..9ac1e8ff 100644 --- a/pkg/releasing/BUILD +++ b/pkg/releasing/BUILD @@ -24,7 +24,7 @@ filegroup( "*.bzl", "*.py", ]), - visibility = ["@//distro:__pkg__"], + visibility = ["//distro:__pkg__"], ) py_library( diff --git a/pkg/releasing/defs.bzl b/pkg/releasing/defs.bzl index 80e2c23a..90fb34d2 100644 --- a/pkg/releasing/defs.bzl +++ b/pkg/releasing/defs.bzl @@ -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, @@ -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", ], ) diff --git a/pkg/releasing/release_tools.py b/pkg/releasing/release_tools.py index 3acaece0..d0d0b459 100644 --- a/pkg/releasing/release_tools.py +++ b/pkg/releasing/release_tools.py @@ -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( @@ -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: diff --git a/pkg/tests/BUILD b/pkg/tests/BUILD index 8b80c1a2..a86ead7e 100644 --- a/pkg/tests/BUILD +++ b/pkg/tests/BUILD @@ -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( @@ -101,7 +101,7 @@ py_test( "test_zip_package_dir2.zip", ], deps = [ - "@rules_pkg//:build_zip", + "//:build_zip", "@bazel_tools//tools/python/runfiles", ], ) @@ -128,7 +128,7 @@ py_test( "no_windows", ], deps = [ - "@rules_pkg//:archive", + "//:archive", "@bazel_tools//tools/python/runfiles", ], ) @@ -136,7 +136,7 @@ py_test( py_test( name = "path_test", srcs = ["path_test.py"], - data = ["@rules_pkg//:path.bzl"], + data = ["//:path.bzl"], srcs_version = "PY2AND3", ) @@ -150,8 +150,8 @@ py_test( "no_windows", ], deps = [ - "@rules_pkg//:make_rpm_lib", - "@rules_pkg//:archive", + "//:make_rpm_lib", + "//:archive", ], ) @@ -161,7 +161,7 @@ py_test( python_version = "PY3", srcs_version = "PY2AND3", deps = [ - "@rules_pkg//:archive", + "//:archive", ], ) @@ -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"], @@ -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"], @@ -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"}, @@ -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 [ "", @@ -389,7 +389,7 @@ sh_test( "no_windows", ], deps = [ - "@rules_pkg//third_party/test/shell:bashunit", + "//third_party/test/shell:bashunit", ], )