summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/BUILD35
-rw-r--r--tests/a.cc1
-rw-r--r--tests/archive_test.py2
-rw-r--r--tests/b.cc1
-rw-r--r--tests/deb/BUILD14
-rw-r--r--tests/deb/control_field_test.py16
-rw-r--r--tests/deb/pkg_deb_test.py30
-rw-r--r--tests/foo.cc21
-rw-r--r--tests/install/BUILD1
-rw-r--r--tests/install/test.py2
-rw-r--r--tests/mappings/BUILD30
-rw-r--r--tests/mappings/all.manifest.golden8
-rw-r--r--tests/mappings/executable.manifest.golden10
-rw-r--r--tests/mappings/executable.manifest.windows.golden8
-rw-r--r--tests/mappings/external_repo/pkg/BUILD19
-rw-r--r--tests/mappings/external_repo/pkg/test.bzl4
-rw-r--r--tests/mappings/filter_directory/BUILD8
-rw-r--r--tests/mappings/filter_directory/inspect_directory.py.tpl2
-rw-r--r--tests/mappings/filter_directory/test_filter_directory.py18
-rw-r--r--tests/mappings/glob_for_texts_manifest.golden8
-rw-r--r--tests/mappings/manifest_test_lib.py56
-rw-r--r--tests/mappings/mappings_external_repo_test.bzl11
-rw-r--r--tests/mappings/mappings_test.bzl20
-rwxr-xr-xtests/mappings/node_modules_manifest.golden14
-rw-r--r--tests/mappings/utf8_manifest.golden12
-rw-r--r--tests/path_test.bzl5
-rw-r--r--tests/rpm/BUILD137
-rw-r--r--tests/rpm/analysis_tests.bzl68
-rw-r--r--tests/rpm/pkg_rpm_basic_test.py50
-rw-r--r--tests/rpm/source_date_epoch/BUILD4
-rw-r--r--tests/rpm/source_date_epoch/rpm_contents_vs_manifest_test.py2
-rw-r--r--tests/rpm/template-test.spec.tpl2
-rw-r--r--tests/rpm/toolchain_tests.bzl1
-rw-r--r--tests/rpm/tree_artifacts/BUILD6
-rw-r--r--tests/rpm/tree_artifacts/rpm_contents_vs_manifest_test.py2
-rw-r--r--tests/rpm/tree_artifacts/rpm_treeartifact_ops_test.py2
-rw-r--r--tests/stamp_test.py2
-rw-r--r--tests/tar/BUILD298
-rw-r--r--tests/tar/is_compressed_test.py2
-rw-r--r--tests/tar/pkg_tar_test.py48
-rw-r--r--tests/tar/tar_writer_test.py2
-rw-r--r--tests/util/defs.bzl28
-rw-r--r--tests/zip/BUILD49
-rw-r--r--tests/zip/zip_test.py30
-rw-r--r--tests/zip/zip_test_lib.py10
45 files changed, 822 insertions, 277 deletions
diff --git a/tests/BUILD b/tests/BUILD
index 21b6396..f6ab2b0 100644
--- a/tests/BUILD
+++ b/tests/BUILD
@@ -13,13 +13,14 @@
# limitations under the License.
# -*- coding: utf-8 -*-
+load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_python//python:defs.bzl", "py_test")
-load(":my_package_name.bzl", "my_package_naming")
-load(":path_test.bzl", "path_tests")
load("//pkg:deb.bzl", "pkg_deb")
load("//pkg:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
load("//pkg:tar.bzl", "pkg_tar")
load("//pkg:zip.bzl", "pkg_zip")
+load(":my_package_name.bzl", "my_package_naming")
+load(":path_test.bzl", "path_tests")
package(
default_applicable_licenses = ["//:license"],
@@ -75,19 +76,20 @@ py_test(
"archive_test.py",
],
data = [
- "//tests:testdata/empty.ar",
- "//tests:testdata/a_ab.ar",
"//tests:testdata/a.ar",
- "//tests:testdata/a_b_ab.ar",
+ "//tests:testdata/a_ab.ar",
"//tests:testdata/a_b.ar",
+ "//tests:testdata/a_b_ab.ar",
"//tests:testdata/ab.ar",
"//tests:testdata/b.ar",
+ "//tests:testdata/empty.ar",
],
+ imports = [".."],
python_version = "PY3",
srcs_version = "PY3",
deps = [
"//pkg/private:archive",
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
)
@@ -99,15 +101,32 @@ py_test(
srcs_version = "PY3",
)
+cc_library(
+ name = "liba",
+ srcs = ["a.cc"],
+ data = ["testdata/hello.txt"],
+)
+
+cc_library(
+ name = "libb",
+ srcs = ["b.cc"],
+ data = ["testdata/hello.txt"],
+)
+
cc_binary(
name = "an_executable",
srcs = ["foo.cc"],
- data = ["BUILD"],
+ data = ["foo.cc"],
+ deps = [
+ ":liba",
+ ":libb",
+ ],
)
py_test(
name = "helpers_test",
srcs = ["helpers_test.py"],
+ imports = [".."],
python_version = "PY3",
srcs_version = "PY3",
deps = [
@@ -189,7 +208,7 @@ py_test(
],
python_version = "PY3",
deps = [
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
)
diff --git a/tests/a.cc b/tests/a.cc
new file mode 100644
index 0000000..d46545e
--- /dev/null
+++ b/tests/a.cc
@@ -0,0 +1 @@
+int a = 1;
diff --git a/tests/archive_test.py b/tests/archive_test.py
index 21ddd5e..4c604c6 100644
--- a/tests/archive_test.py
+++ b/tests/archive_test.py
@@ -15,7 +15,7 @@
import unittest
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
from pkg.private import archive
diff --git a/tests/b.cc b/tests/b.cc
new file mode 100644
index 0000000..b20302a
--- /dev/null
+++ b/tests/b.cc
@@ -0,0 +1 @@
+int b = 2;
diff --git a/tests/deb/BUILD b/tests/deb/BUILD
index cfdbbf3..5df0ab2 100644
--- a/tests/deb/BUILD
+++ b/tests/deb/BUILD
@@ -16,11 +16,11 @@
# Tests for pkg_deb specific behavior
load("@rules_python//python:defs.bzl", "py_test")
-load(":deb_tests.bzl", "package_naming_test")
-load("//pkg:mappings.bzl", "pkg_mklink")
load("//pkg:deb.bzl", "pkg_deb")
+load("//pkg:mappings.bzl", "pkg_mklink")
load("//pkg:tar.bzl", "pkg_tar")
load("//tests:my_package_name.bzl", "my_package_naming")
+load(":deb_tests.bzl", "package_naming_test")
package(default_applicable_licenses = ["//:license"])
@@ -100,10 +100,11 @@ py_test(
# The target includes both the .deb and .changes files in DefaultInfo
":test_deb",
],
+ imports = ["../.."],
python_version = "PY3",
deps = [
"//pkg/private:archive",
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
)
@@ -119,6 +120,7 @@ py_test(
srcs = [
"control_field_test.py",
],
+ imports = ["../.."],
python_version = "PY3",
deps = [
"//pkg/private/deb:make_deb_lib",
@@ -128,6 +130,9 @@ py_test(
# Test case for expanding $(var) constructions and for using ctx.var directly
pkg_deb(
name = "deb_using_ctxvar",
+ # This does not make sense for architecture, but for testing, compilation
+ # mode is more stable than cpu.
+ architecture = "$(COMPILATION_MODE)",
config = "config",
data = ":tar_input",
description = "Compiled with $(COMPILATION_MODE)",
@@ -135,9 +140,6 @@ pkg_deb(
maintainer = "soméone@somewhere.com",
package = "fizzbuzz",
version = "7",
- # This does not make sense for architecture, but for testing, compilation
- # mode is more stable thatn cpu.
- architecture = "$(COMPILATION_MODE)",
)
package_naming_test(
diff --git a/tests/deb/control_field_test.py b/tests/deb/control_field_test.py
index a469141..5f4f5e9 100644
--- a/tests/deb/control_field_test.py
+++ b/tests/deb/control_field_test.py
@@ -52,23 +52,31 @@ class MakeControlFieldTest(unittest.TestCase):
self.assertEqual(
'Description: fizzbuzz\n',
make_deb.MakeDebianControlField(
- 'Description', 'fizzbuzz', is_multiline=True))
+ 'Description', 'fizzbuzz', multiline=make_deb.Multiline.YES))
self.assertEqual(
'Description: fizz\n buzz\n',
make_deb.MakeDebianControlField(
- 'Description', 'fizz\n buzz\n', is_multiline=True))
+ 'Description', 'fizz\n buzz\n', multiline=make_deb.Multiline.YES))
+ self.assertEqual(
+ 'Description:\n fizz\n buzz\n',
+ make_deb.MakeDebianControlField(
+ 'Description', ' fizz\n buzz\n', multiline=make_deb.Multiline.YES_ADD_NEWLINE))
def test_multiline_add_required_space(self):
self.assertEqual(
'Description: fizz\n buzz\n',
make_deb.MakeDebianControlField(
- 'Description', 'fizz\nbuzz', is_multiline=True))
+ 'Description', 'fizz\nbuzz', multiline=make_deb.Multiline.YES))
+ self.assertEqual(
+ 'Description:\n fizz\n buzz\n',
+ make_deb.MakeDebianControlField(
+ 'Description', 'fizz\nbuzz\n', multiline=make_deb.Multiline.YES_ADD_NEWLINE))
def test_multiline_add_trailing_newline(self):
self.assertEqual(
'Description: fizz\n buzz\n baz\n',
make_deb.MakeDebianControlField(
- 'Description', 'fizz\n buzz\n baz', is_multiline=True))
+ 'Description', 'fizz\n buzz\n baz', multiline=make_deb.Multiline.YES))
if __name__ == '__main__':
diff --git a/tests/deb/pkg_deb_test.py b/tests/deb/pkg_deb_test.py
index 3334413..8a2e653 100644
--- a/tests/deb/pkg_deb_test.py
+++ b/tests/deb/pkg_deb_test.py
@@ -22,7 +22,7 @@ import sys
import tarfile
import unittest
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
from pkg.private import archive
@@ -111,7 +111,7 @@ class PkgDebTest(unittest.TestCase):
if k == 'data':
value = f.extractfile(info).read()
elif k == 'name':
- # The test data uses / as path sep, but the tarbal is in OS native
+ # The test data uses / as path sep, but the tarball is in OS native
# format. This aligns the tarball name back to what we expect.
value = name_in_tar_file.replace(os.path.sep, '/')
elif k == 'isdir':
@@ -249,6 +249,32 @@ class PkgDebTest(unittest.TestCase):
content[d_start + len(d_expect)].isupper(),
'Description has unexpected characters at end (%s)' % content)
+ self.maxDiff = None
+ expect = '''Format: 1\.8
+Date: Thu Jan 1 \d{2}:00:00 1970
+Source: fizzbuzz
+Binary: fizzbuzz
+Architecture: all
+Version: 4\.5\.6
+Distribution: trusty
+Urgency: low
+Maintainer: soméone@somewhere.com
+Changed-By: soméone@somewhere.com
+Description:
+ fizzbuzz - toto ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é
+Changes:
+ fizzbuzz \(4\.5\.6\) trusty; urgency=low
+ Changes are tracked in revision control\.
+Files:
+ [a-f0-9]{32} \d{4} contrib/devel optional fizzbuzz_4\.5\.6_all\.deb
+Checksums-Sha1:
+ [a-f0-9]{40} \d{4} fizzbuzz_4\.5\.6_all\.deb
+Checksums-Sha256:
+ [a-f0-9]{64} \d{4} fizzbuzz_4\.5\.6_all\.deb
+'''
+
+ self.assertRegex(content, expect)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/foo.cc b/tests/foo.cc
index 4359267..3274cf8 100644
--- a/tests/foo.cc
+++ b/tests/foo.cc
@@ -1 +1,20 @@
-int main(int argc, char* argv[]) { return 0; }
+#include <fstream>
+#include <iostream>
+#include <string>
+
+extern int a, b;
+
+// A very roundabout hello world.
+int main(int argc, char* argv[]) {
+ std::string runfiles(argv[0]);
+ runfiles.append(".runfiles");
+ std::string hello(runfiles + "/rules_pkg/tests/testdata/hello.txt");
+ std::fstream fs;
+ fs.open(hello, std::iostream::in);
+ char tmp[1000];
+ fs.read(tmp, sizeof(tmp));
+ fs.close();
+ std::cout << tmp;
+
+ return (a + b > 0) ? 0 : 1;
+}
diff --git a/tests/install/BUILD b/tests/install/BUILD
index f083b3f..5a2c127 100644
--- a/tests/install/BUILD
+++ b/tests/install/BUILD
@@ -26,6 +26,7 @@ py_test(
data = [
":test_installer",
],
+ imports = ["../.."],
main = "test.py",
tags = [
# TODO(nacl): investigate this. See also
diff --git a/tests/install/test.py b/tests/install/test.py
index 996ae09..bbb02ab 100644
--- a/tests/install/test.py
+++ b/tests/install/test.py
@@ -20,7 +20,7 @@ import unittest
import stat
import subprocess
-from rules_python.python.runfiles import runfiles
+from python.runfiles import runfiles
from pkg.private import manifest
diff --git a/tests/mappings/BUILD b/tests/mappings/BUILD
index 44752cb..fd3469b 100644
--- a/tests/mappings/BUILD
+++ b/tests/mappings/BUILD
@@ -13,31 +13,30 @@
# limitations under the License.
load(
- ":mappings_test.bzl",
- "manifest_golden_test",
- "mappings_analysis_tests",
- "mappings_unit_tests",
-)
-load(":mappings_external_repo_test.bzl", "mappings_external_repo_analysis_tests")
-load(
"//pkg:mappings.bzl",
"pkg_attributes",
- "pkg_filegroup",
"pkg_files",
"pkg_mkdirs",
"strip_prefix",
)
load("//tests/util:defs.bzl", "directory", "link_tree", "write_content_manifest")
-load("@rules_python//python:defs.bzl", "py_test")
+load(":mappings_external_repo_test.bzl", "mappings_external_repo_analysis_tests")
+load(
+ ":mappings_test.bzl",
+ "manifest_golden_test",
+ "mappings_analysis_tests",
+ "mappings_unit_tests",
+)
package(default_applicable_licenses = ["//:license"])
py_library(
name = "manifest_test_lib",
srcs = ["manifest_test_lib.py"],
+ imports = ["../.."],
srcs_version = "PY3",
deps = [
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
)
@@ -129,17 +128,18 @@ manifest_golden_test(
write_content_manifest(
name = "executable_manifest",
srcs = [
+ "mappings_test.bzl",
"//tests:an_executable",
],
include_runfiles = True,
)
alias(
- name = "executable_test_expected",
- actual = select({
- "@platforms//os:windows": "executable.manifest.windows.golden",
- "//conditions:default": "executable.manifest.golden",
- }),
+ name = "executable_test_expected",
+ actual = select({
+ "@platforms//os:windows": "executable.manifest.windows.golden",
+ "//conditions:default": "executable.manifest.golden",
+ }),
)
manifest_golden_test(
diff --git a/tests/mappings/all.manifest.golden b/tests/mappings/all.manifest.golden
index 475ec96..6a5f107 100644
--- a/tests/mappings/all.manifest.golden
+++ b/tests/mappings/all.manifest.golden
@@ -1,7 +1,7 @@
[
- {"type": "file", "dest": "BUILD", "src": "tests/mappings/BUILD", "mode": "", "user": null, "group": null, "origin": "@//tests/mappings:BUILD"},
- {"type": "dir", "dest": "foodir", "src": null, "mode": "711", "user": "foo", "group": "bar", "origin": "@//tests/mappings:dirs"},
+ {"type": "file", "dest": "BUILD", "src": "tests/mappings/BUILD", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:BUILD"},
+ {"type": "dir", "dest": "foodir", "src": null, "mode": "711", "user": "foo", "group": "bar", "uid": null, "gid": null, "origin": "@//tests/mappings:dirs"},
- {"type": "file", "dest": "mappings_test.bzl", "src": "tests/mappings/mappings_test.bzl", "mode": "0644", "user": null, "group": null, "origin": "@//tests/mappings:files"},
- {"type": "tree", "dest": "treeartifact", "src": "tests/mappings/treeartifact", "mode": "0644", "user": null, "group": null, "origin": "@//tests/mappings:directory-with-contents"}
+ {"type": "file", "dest": "mappings_test.bzl", "src": "tests/mappings/mappings_test.bzl", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:files"},
+ {"type": "tree", "dest": "treeartifact", "src": "tests/mappings/treeartifact", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:directory-with-contents"}
]
diff --git a/tests/mappings/executable.manifest.golden b/tests/mappings/executable.manifest.golden
index 7f85aab..9219554 100644
--- a/tests/mappings/executable.manifest.golden
+++ b/tests/mappings/executable.manifest.golden
@@ -1,5 +1,7 @@
[
- {"type": "file", "dest": "an_executable.runfiles/tests/BUILD", "src": "tests/BUILD", "mode": "", "user": null, "group": null, "origin": "@//tests:an_executable"},
- {"type": "file", "dest": "an_executable.runfiles/tests/an_executable", "src": "tests/an_executable", "mode": "0755", "user": null, "group": null, "origin": "@//tests:an_executable"},
- {"type": "file", "dest": "an_executable", "src": "tests/an_executable", "mode": "0755", "user": null, "group": null, "origin": "@//tests:an_executable"}
-] \ No newline at end of file
+{"dest":"an_executable.runfiles/tests/foo.cc","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/foo.cc","type":"file","uid":null,"user":null},
+{"dest":"an_executable.runfiles/tests/an_executable","gid":null,"group":null,"mode":"0755","origin":"@//tests:an_executable","src":"tests/an_executable","type":"file","uid":null,"user":null},
+{"dest":"an_executable.runfiles/tests/testdata/hello.txt","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/testdata/hello.txt","type":"file","uid":null,"user":null},
+{"dest":"an_executable","gid":null,"group":null,"mode":"0755","origin":"@//tests:an_executable","src":"tests/an_executable","type":"file","uid":null,"user":null},
+{"dest":"mappings_test.bzl","gid":null,"group":null,"mode":"","origin":"@//tests/mappings:mappings_test.bzl","src":"tests/mappings/mappings_test.bzl","type":"file","uid":null,"user":null}
+]
diff --git a/tests/mappings/executable.manifest.windows.golden b/tests/mappings/executable.manifest.windows.golden
index 55b0804..150f477 100644
--- a/tests/mappings/executable.manifest.windows.golden
+++ b/tests/mappings/executable.manifest.windows.golden
@@ -1,5 +1,7 @@
[
- {"type": "file", "dest": "an_executable.exe.runfiles/tests/BUILD", "src": "tests/BUILD", "mode": "", "user": null, "group": null, "origin": "@//tests:an_executable"},
- {"type": "file", "dest": "an_executable.exe.runfiles/tests/an_executable.exe", "src": "tests/an_executable.exe", "mode": "0755", "user": null, "group": null, "origin": "@//tests:an_executable"},
- {"type": "file", "dest": "an_executable.exe", "src": "tests/an_executable.exe", "mode": "0755", "user": null, "group": null, "origin": "@//tests:an_executable"}
+{"dest":"an_executable.exe.runfiles/tests/foo.cc","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/foo.cc","type":"file","uid":null,"user":null},
+{"dest":"an_executable.exe.runfiles/tests/an_executable.exe","gid":null,"group":null,"mode":"0755","origin":"@//tests:an_executable","src":"tests/an_executable.exe","type":"file","uid":null,"user":null},
+{"dest":"an_executable.exe.runfiles/tests/testdata/hello.txt","gid":null,"group":null,"mode":"","origin":"@//tests:an_executable","src":"tests/testdata/hello.txt","type":"file","uid":null,"user":null},
+{"dest":"an_executable.exe","gid":null,"group":null,"mode":"0755","origin":"@//tests:an_executable","src":"tests/an_executable.exe","type":"file","uid":null,"user":null},
+{"dest":"mappings_test.bzl","gid":null,"group":null,"mode":"","origin":"@//tests/mappings:mappings_test.bzl","src":"tests/mappings/mappings_test.bzl","type":"file","uid":null,"user":null}
]
diff --git a/tests/mappings/external_repo/pkg/BUILD b/tests/mappings/external_repo/pkg/BUILD
index 8800ce3..33db6a8 100644
--- a/tests/mappings/external_repo/pkg/BUILD
+++ b/tests/mappings/external_repo/pkg/BUILD
@@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("@//:mappings.bzl", "pkg_files", "strip_prefix")
+load("@//pkg:mappings.bzl", "pkg_files", "strip_prefix")
+load("@//pkg:tar.bzl", "pkg_tar")
+load("@//pkg:verify_archive.bzl", "verify_archive_test")
load("@//tests/util:defs.bzl", "fake_artifact")
load("test.bzl", "test_referencing_remote_file")
@@ -39,3 +41,18 @@ pkg_files(
test_referencing_remote_file(
name = "pf_local_file_in_extrepo",
)
+
+# Add a target to ensure verify_archive_test can be
+# called from another workspace
+pkg_tar(
+ name = "external_archive",
+ srcs = ["dir/extproj.sh"],
+)
+
+verify_archive_test(
+ name = "external_archive_test",
+ max_size = 1,
+ min_size = 1,
+ must_contain = ["extproj.sh"],
+ target = ":external_archive",
+)
diff --git a/tests/mappings/external_repo/pkg/test.bzl b/tests/mappings/external_repo/pkg/test.bzl
index 4951cd7..c0a7713 100644
--- a/tests/mappings/external_repo/pkg/test.bzl
+++ b/tests/mappings/external_repo/pkg/test.bzl
@@ -18,8 +18,8 @@ Test implementation copied from pkg/mappings.bzl
"""
-load("@//:mappings.bzl", "pkg_files", "strip_prefix")
-load("@//:providers.bzl", "PackageFilesInfo")
+load("@//pkg:mappings.bzl", "pkg_files", "strip_prefix")
+load("@//pkg:providers.bzl", "PackageFilesInfo")
load("@bazel_skylib//lib:new_sets.bzl", "sets")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
diff --git a/tests/mappings/filter_directory/BUILD b/tests/mappings/filter_directory/BUILD
index 4b0399b..a1ff831 100644
--- a/tests/mappings/filter_directory/BUILD
+++ b/tests/mappings/filter_directory/BUILD
@@ -13,9 +13,9 @@
# limitations under the License.
load("@rules_python//python:defs.bzl", "py_test")
-load(":defs.bzl", "inspect_directory_test")
load("//pkg:mappings.bzl", "filter_directory")
load("//tests/util:defs.bzl", "directory")
+load(":defs.bzl", "inspect_directory_test")
# TODO: the below tests only check for rule success and confirmation that
# directory structure matches expectations. A more thorough test implementation
@@ -227,7 +227,9 @@ directory(
py_test(
name = "negative_tests",
srcs = ["test_filter_directory.py"],
- data = ["//pkg:filter_directory"],
main = "test_filter_directory.py",
- deps = ["@rules_python//python/runfiles"],
+ deps = [
+ "//pkg:filter_directory_lib",
+ "@rules_python//python/runfiles",
+ ],
)
diff --git a/tests/mappings/filter_directory/inspect_directory.py.tpl b/tests/mappings/filter_directory/inspect_directory.py.tpl
index 938ddd7..cc935cf 100644
--- a/tests/mappings/filter_directory/inspect_directory.py.tpl
+++ b/tests/mappings/filter_directory/inspect_directory.py.tpl
@@ -17,7 +17,7 @@
import json
import os
import unittest
-from rules_python.python.runfiles import runfiles
+from python.runfiles import runfiles
DIRECTORY_ROOT = "%DIRECTORY_ROOT%"
# This is JSON, which shouldn't have any triple quotes in it.
diff --git a/tests/mappings/filter_directory/test_filter_directory.py b/tests/mappings/filter_directory/test_filter_directory.py
index 96b1220..8426905 100644
--- a/tests/mappings/filter_directory/test_filter_directory.py
+++ b/tests/mappings/filter_directory/test_filter_directory.py
@@ -24,20 +24,8 @@ import sys
import tempfile
import unittest
-from rules_python.python.runfiles import runfiles
-
-# Get the filter_directory script into the import path. There might be a
-# better way to do this, but it works.
-
-rf = runfiles.Create()
-filter_directory_script = rf.Rlocation('/'.join([
- os.environ["TEST_WORKSPACE"],
- "pkg",
- "filter_directory"
-]))
-
-sys.path.append(os.path.dirname(filter_directory_script))
-import filter_directory # noqa: E402
+from pkg import filter_directory
+from python.runfiles import runfiles
# TODO: These tests are largely to ensure that filter_directory fails, but it
@@ -109,7 +97,7 @@ class FilterDirectoryInternalTest(unittest.TestCase):
def test_invalid_prefixes(self):
self.assertFilterDirectoryFails(
prefix="/absolute/path",
- message="--prefix with aboslute paths should be rejected",
+ message="--prefix with absolute paths should be rejected",
)
self.assertFilterDirectoryFails(
diff --git a/tests/mappings/glob_for_texts_manifest.golden b/tests/mappings/glob_for_texts_manifest.golden
index c144b83..9ff7e21 100644
--- a/tests/mappings/glob_for_texts_manifest.golden
+++ b/tests/mappings/glob_for_texts_manifest.golden
@@ -1,6 +1,6 @@
[
- {"type": "file", "dest": "file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt", "src": "tests/testdata/file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt", "mode": "", "user": null, "group": null, "origin": "@//tests:glob_for_texts"},
- {"type": "file", "dest": "hello.txt", "src": "tests/testdata/hello.txt", "mode": "", "user": null, "group": null, "origin": "@//tests:glob_for_texts"},
- {"type": "file", "dest": "loremipsum.txt", "src": "tests/testdata/loremipsum.txt", "mode": "", "user": null, "group": null, "origin": "@//tests:glob_for_texts"},
- {"type": "file", "dest": "test_tar_package_dir_file.txt", "src": "tests/testdata/test_tar_package_dir_file.txt", "mode": "", "user": null, "group": null, "origin": "@//tests:glob_for_texts"}
+ {"type": "file", "dest": "file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt", "src": "tests/testdata/file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests:glob_for_texts"},
+ {"type": "file", "dest": "hello.txt", "src": "tests/testdata/hello.txt", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests:glob_for_texts"},
+ {"type": "file", "dest": "loremipsum.txt", "src": "tests/testdata/loremipsum.txt", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests:glob_for_texts"},
+ {"type": "file", "dest": "test_tar_package_dir_file.txt", "src": "tests/testdata/test_tar_package_dir_file.txt", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests:glob_for_texts"}
]
diff --git a/tests/mappings/manifest_test_lib.py b/tests/mappings/manifest_test_lib.py
index 0534ebe..b668439 100644
--- a/tests/mappings/manifest_test_lib.py
+++ b/tests/mappings/manifest_test_lib.py
@@ -16,26 +16,56 @@
import json
import unittest
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
class ContentManifestTest(unittest.TestCase):
"""Test harness to see if we wrote the content manifest correctly."""
run_files = runfiles.Create()
- def assertManifestsMatch(self, expected, got):
+ def assertManifestsMatch(self, expected_path, got_path):
"""Check two manifest files for equality.
Args:
- expected: The path to the content we expect.
- got: The path to the content we got.
+ expected_path: The path to the content we expect.
+ got_path: The path to the content we got.
"""
- e_file = ContentManifestTest.run_files.Rlocation('rules_pkg/' + expected)
- with open(e_file, mode='rb') as e_fp:
- expected = json.load(e_fp)
- expected_dict = {x["dest"]: x for x in expected}
- g_file = ContentManifestTest.run_files.Rlocation('rules_pkg/' + got)
- with open(g_file, mode='rb') as g_fp:
- got = json.load(g_fp)
- got_dict = {x["dest"]: x for x in got}
- self.assertEqual(expected_dict, got_dict)
+ e_file = ContentManifestTest.run_files.Rlocation('rules_pkg/' + expected_path)
+ with open(e_file, mode='rt', encoding='utf-8') as e_fp:
+ expected = json.loads(e_fp.read())
+ expected_dict = {x['dest']: x for x in expected}
+ g_file = ContentManifestTest.run_files.Rlocation('rules_pkg/' + got_path)
+ with open(g_file, mode='rt', encoding='utf-8') as g_fp:
+ got = json.loads(g_fp.read())
+ got_dict = {x['dest']: x for x in got}
+
+ ok = True
+ expected_dests = set(expected_dict.keys())
+ got_dests = set(got_dict.keys())
+ for dest, what in expected_dict.items():
+ got = got_dict.get(dest)
+ if got:
+ # bzlmod mode changes root to @@//, but older version give @//
+ origin = got.get('origin')
+ if origin and origin.startswith('@@//'):
+ got['origin'] = origin[1:]
+ self.assertDictEqual(what, got)
+ else:
+ print('Missing expected path "%s" in manifest' % dest)
+ ok = False
+ for dest, what in got_dict.items():
+ expected = expected_dict.get(dest)
+ if expected:
+ self.assertDictEqual(expected, what)
+ else:
+ print('Got unexpected path "%s" in manifest:' % dest, what)
+ ok = False
+
+ if not ok:
+ print('To update the golden file:')
+ print(' cp bazel-bin/%s %s' % (got_path, expected_path))
+ print('or')
+ print('============= snip ==========')
+ print(got_dict.values())
+ print('============= snip ==========')
+ self.assertTrue(ok)
diff --git a/tests/mappings/mappings_external_repo_test.bzl b/tests/mappings/mappings_external_repo_test.bzl
index aeb3223..7b9b0ac 100644
--- a/tests/mappings/mappings_external_repo_test.bzl
+++ b/tests/mappings/mappings_external_repo_test.bzl
@@ -14,11 +14,8 @@
"""Tests for file mapping routines in pkg/mappings.bzl"""
-load("@bazel_skylib//lib:new_sets.bzl", "sets")
-load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest")
-load(":mappings_test.bzl", "pkg_files_contents_test")
-load("//pkg:providers.bzl", "PackageFilegroupInfo", "PackageFilesInfo")
load("//pkg:mappings.bzl", "pkg_files", "strip_prefix")
+load(":mappings_test.bzl", "pkg_files_contents_test")
##########
# pkg_files tests involving external repositories
@@ -109,6 +106,7 @@ def _test_pkg_files_extrepo():
expected_dests = ["usr/bin/dir/extproj.sh"],
)
+# buildifier: disable=unnamed-macro
def mappings_external_repo_analysis_tests():
"""Declare mappings.bzl analysis tests"""
_test_pkg_files_extrepo()
@@ -133,5 +131,10 @@ def mappings_external_repo_analysis_tests():
# The main purpose behind it is to verify cases wherein we build a
# file, but then have it consumed by some remote package.
"@mappings_test_external_repo//pkg:pf_local_file_in_extrepo",
+ # This test is more focused around the verify_archive_test repo but is still
+ # based on using someting from another repo. In particular, ensuring the
+ # verify_archive_test macro can be called properly from a workspace outside
+ # of the main one.
+ "@mappings_test_external_repo//pkg:external_archive_test",
],
)
diff --git a/tests/mappings/mappings_test.bzl b/tests/mappings/mappings_test.bzl
index fcb4639..d5dc0c2 100644
--- a/tests/mappings/mappings_test.bzl
+++ b/tests/mappings/mappings_test.bzl
@@ -14,14 +14,9 @@
"""Tests for file mapping routines in pkg/mappings.bzl"""
+load("@bazel_skylib//lib:new_sets.bzl", "sets")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest")
-load(
- "//pkg:providers.bzl",
- "PackageDirsInfo",
- "PackageFilegroupInfo",
- "PackageFilesInfo",
- "PackageSymlinkInfo",
-)
+load("@rules_python//python:defs.bzl", "py_test")
load(
"//pkg:mappings.bzl",
"REMOVE_BASE_DIRECTORY",
@@ -33,14 +28,19 @@ load(
"strip_prefix",
)
load(
+ "//pkg:providers.bzl",
+ "PackageDirsInfo",
+ "PackageFilegroupInfo",
+ "PackageFilesInfo",
+ "PackageSymlinkInfo",
+)
+load(
"//tests/util:defs.bzl",
"directory",
"fake_artifact",
"generic_base_case_test",
"generic_negative_test",
)
-load("@bazel_skylib//lib:new_sets.bzl", "sets")
-load("@rules_python//python:defs.bzl", "py_test")
##########
# Helpers
@@ -883,6 +883,7 @@ def _strip_prefix_test_impl(ctx):
strip_prefix_test = unittest.make(_strip_prefix_test_impl)
+# buildifier: disable=unnamed-macro
def mappings_analysis_tests():
"""Declare mappings.bzl analysis tests"""
_test_pkg_files_contents()
@@ -969,6 +970,7 @@ _gen_manifest_test_main = rule(
},
)
+# buildifier: disable=function-docstring-args
def manifest_golden_test(name, target, expected):
"""Tests that a content manifest file matches a golden copy.
diff --git a/tests/mappings/node_modules_manifest.golden b/tests/mappings/node_modules_manifest.golden
index 436128b..b234629 100755
--- a/tests/mappings/node_modules_manifest.golden
+++ b/tests/mappings/node_modules_manifest.golden
@@ -1,9 +1,9 @@
[
- {"type": "symlink", "dest": "node_modules/.pnpm/bar@1.0.0/node_modules/bar", "src": "STORE/bar", "mode": "", "user": null, "group": null, "origin": "@//tests/mappings:node_modules"},
- {"type": "symlink", "dest": "node_modules/.pnpm/bar@1.0.0/node_modules/qar", "src": "../../qar@2.0.0/node_modules/qar", "mode": "", "user": null, "group": null, "origin": "@//tests/mappings:node_modules"},
- {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/bar", "src": "../../bar@1.0.0/node_modules/bar", "mode": "", "user": null, "group": null, "origin": "@//tests/mappings:node_modules"},
- {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/foo", "src": "STORE/foo", "mode": "", "user": null, "group": null, "origin": "@//tests/mappings:node_modules"},
- {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/qar", "src": "../../qar@2.0.0/node_modules/qar", "mode": "", "user": null, "group": null, "origin": "@//tests/mappings:node_modules"},
- {"type": "symlink", "dest": "node_modules/.pnpm/qar@2.0.0/node_modules/qar", "src": "STORE/qar", "mode": "", "user": null, "group": null, "origin": "@//tests/mappings:node_modules"},
- {"type": "symlink", "dest": "node_modules/foo", "src": ".pnpm/foo@1.0.0/node_modules/foo", "mode": "", "user": null, "group": null, "origin": "@//tests/mappings:node_modules"}
+ {"type": "symlink", "dest": "node_modules/.pnpm/bar@1.0.0/node_modules/bar", "src": "STORE/bar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"},
+ {"type": "symlink", "dest": "node_modules/.pnpm/bar@1.0.0/node_modules/qar", "src": "../../qar@2.0.0/node_modules/qar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"},
+ {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/bar", "src": "../../bar@1.0.0/node_modules/bar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"},
+ {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/foo", "src": "STORE/foo", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"},
+ {"type": "symlink", "dest": "node_modules/.pnpm/foo@1.0.0/node_modules/qar", "src": "../../qar@2.0.0/node_modules/qar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"},
+ {"type": "symlink", "dest": "node_modules/.pnpm/qar@2.0.0/node_modules/qar", "src": "STORE/qar", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"},
+ {"type": "symlink", "dest": "node_modules/foo", "src": ".pnpm/foo@1.0.0/node_modules/foo", "mode": "", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:node_modules"}
]
diff --git a/tests/mappings/utf8_manifest.golden b/tests/mappings/utf8_manifest.golden
index a875085..11352ca 100644
--- a/tests/mappings/utf8_manifest.golden
+++ b/tests/mappings/utf8_manifest.golden
@@ -1,8 +1,8 @@
[
- {"type": "file", "dest": "1-a", "src": "tests/testdata/utf8/1-a", "mode": "0644", "user": null, "group": null, "origin": "@//tests/mappings:utf8_files"},
- {"type": "file", "dest": "2-λ", "src": "tests/testdata/utf8/2-λ", "mode": "0644", "user": null, "group": null, "origin": "@//tests/mappings:utf8_files"},
- {"type": "file", "dest": "3-世", "src": "tests/testdata/utf8/3-世", "mode": "0644", "user": null, "group": null, "origin": "@//tests/mappings:utf8_files"},
- {"type": "file", "dest": "BUILD", "src": "tests/testdata/utf8/BUILD", "mode": "0644", "user": null, "group": null, "origin": "@//tests/mappings:utf8_files"},
- {"type": "file", "dest": "sübdir/2-λ", "src": "tests/testdata/utf8/sübdir/2-λ", "mode": "0644", "user": null, "group": null, "origin": "@//tests/mappings:utf8_files"},
- {"type": "file", "dest": "sübdir/hello", "src": "tests/testdata/utf8/sübdir/hello", "mode": "0644", "user": null, "group": null, "origin": "@//tests/mappings:utf8_files"}
+ {"type": "file", "dest": "1-a", "src": "tests/testdata/utf8/1-a", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"},
+ {"type": "file", "dest": "2-λ", "src": "tests/testdata/utf8/2-λ", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"},
+ {"type": "file", "dest": "3-世", "src": "tests/testdata/utf8/3-世", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"},
+ {"type": "file", "dest": "BUILD", "src": "tests/testdata/utf8/BUILD", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"},
+ {"type": "file", "dest": "sübdir/2-λ", "src": "tests/testdata/utf8/sübdir/2-λ", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"},
+ {"type": "file", "dest": "sübdir/hello", "src": "tests/testdata/utf8/sübdir/hello", "mode": "0644", "user": null, "group": null, "uid": null, "gid": null, "origin": "@//tests/mappings:utf8_files"}
]
diff --git a/tests/path_test.bzl b/tests/path_test.bzl
index a2a46d2..2a01383 100644
--- a/tests/path_test.bzl
+++ b/tests/path_test.bzl
@@ -14,16 +14,15 @@
"""Tests for path.bzl"""
+load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("//pkg:mappings.bzl", "pkg_mkdirs")
load("//pkg:path.bzl", "compute_data_path")
-load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest")
##########
# Test compute_data_path
##########
def _compute_data_path_test_impl(ctx):
env = analysistest.begin(ctx)
- target_under_test = analysistest.target_under_test(env)
# Subtle: This allows you to vendor the library into your own repo at some
# arbitrary path.
@@ -33,7 +32,7 @@ def _compute_data_path_test_impl(ctx):
asserts.equals(
env,
expect,
- compute_data_path(ctx, ctx.attr.in_path),
+ compute_data_path(ctx.label, ctx.attr.in_path),
)
return analysistest.end(env)
diff --git a/tests/rpm/BUILD b/tests/rpm/BUILD
index 5f91da8..f51d75b 100644
--- a/tests/rpm/BUILD
+++ b/tests/rpm/BUILD
@@ -124,6 +124,50 @@ pkg_filegroup(
)
############################################################################
+# scriptlets for testing
+############################################################################
+
+_POST_SCRIPTLET = "echo post"
+_POSTUN_SCRIPTLET = "echo postun"
+_PRE_SCRIPTLET = "echo pre"
+_PREUN_SCRIPTLET = "echo preun"
+_POSTTRANS_SCRIPTLET = "echo posttrans"
+
+[
+ genrule(
+ name = name,
+ outs = ["{}.sh".format(name)],
+ cmd = "echo '{}' > $@".format(content),
+ )
+ for name, content in [
+ ("post", _POST_SCRIPTLET),
+ ("postun", _POSTUN_SCRIPTLET),
+ ("pre", _PRE_SCRIPTLET),
+ ("preun", _PREUN_SCRIPTLET),
+ ("posttrans", _POSTTRANS_SCRIPTLET),
+ ]
+]
+
+############################################################################
+# versionfile for testing
+############################################################################
+
+_VERSION = "1.1.1"
+_RELEASE = "2222"
+
+genrule(
+ name = "version_file",
+ outs = ["version"],
+ cmd = "echo '{}' > $@".format(_VERSION),
+)
+
+genrule(
+ name = "release_file",
+ outs = ["release"],
+ cmd = "echo '{}' > $@".format(_RELEASE),
+)
+
+############################################################################
# Test RPMs
############################################################################
@@ -136,22 +180,23 @@ pkg_rpm(
conflicts = ["not-a-test"],
description = """pkg_rpm test rpm description""",
license = "Apache 2.0",
- post_scriptlet = """echo post""",
- postun_scriptlet = """echo postun""",
- pre_scriptlet = """echo pre""",
- preun_scriptlet = """echo preun""",
+ post_scriptlet = _POST_SCRIPTLET,
+ postun_scriptlet = _POSTUN_SCRIPTLET,
+ pre_scriptlet = _PRE_SCRIPTLET,
+ preun_scriptlet = _PREUN_SCRIPTLET,
+ posttrans_scriptlet = _POSTTRANS_SCRIPTLET,
provides = ["test"],
- release = "2222",
+ release = _RELEASE,
requires = ["test-lib > 1.0"],
requires_contextual = {"preun": ["bash"]},
spec_template = "template-test.spec.tpl",
summary = "pkg_rpm test rpm summary",
- version = "1.1.1",
+ version = _VERSION,
)
# Just like the above one, except the compression is changed.
pkg_rpm(
- name = "test_rpm-bzip2",
+ name = "test_rpm_bzip2",
srcs = [
":test_pfg",
],
@@ -160,17 +205,18 @@ pkg_rpm(
conflicts = ["not-a-test"],
description = """pkg_rpm test rpm description""",
license = "Apache 2.0",
- post_scriptlet = """echo post""",
- postun_scriptlet = """echo postun""",
- pre_scriptlet = """echo pre""",
- preun_scriptlet = """echo preun""",
+ post_scriptlet = _POST_SCRIPTLET,
+ postun_scriptlet = _POSTUN_SCRIPTLET,
+ pre_scriptlet = _PRE_SCRIPTLET,
+ preun_scriptlet = _PREUN_SCRIPTLET,
+ posttrans_scriptlet = _POSTTRANS_SCRIPTLET,
provides = ["test"],
- release = "2222",
+ release = _RELEASE,
requires = ["test-lib > 1.0"],
requires_contextual = {"preun": ["bash"]},
spec_template = "template-test.spec.tpl",
summary = "pkg_rpm test rpm summary",
- version = "1.1.1",
+ version = _VERSION,
)
# Like the first one, except `srcs` is now passed in without using a
@@ -187,17 +233,66 @@ pkg_rpm(
conflicts = ["not-a-test"],
description = """pkg_rpm test rpm description""",
license = "Apache 2.0",
- post_scriptlet = """echo post""",
- postun_scriptlet = """echo postun""",
- pre_scriptlet = """echo pre""",
- preun_scriptlet = """echo preun""",
+ post_scriptlet = _POST_SCRIPTLET,
+ postun_scriptlet = _POSTUN_SCRIPTLET,
+ pre_scriptlet = _PRE_SCRIPTLET,
+ preun_scriptlet = _PREUN_SCRIPTLET,
+ posttrans_scriptlet = _POSTTRANS_SCRIPTLET,
+ provides = ["test"],
+ release = _RELEASE,
+ requires = ["test-lib > 1.0"],
+ requires_contextual = {"preun": ["bash"]},
+ spec_template = "template-test.spec.tpl",
+ summary = "pkg_rpm test rpm summary",
+ version = _VERSION,
+)
+
+# Like the first one, except we use files for scriptlets
+pkg_rpm(
+ name = "test_rpm_scriptlets_files",
+ srcs = [
+ ":test_pfg",
+ ],
+ architecture = "noarch",
+ conflicts = ["not-a-test"],
+ description = """pkg_rpm test rpm description""",
+ license = "Apache 2.0",
+ post_scriptlet_file = ":post",
+ postun_scriptlet_file = ":postun",
+ pre_scriptlet_file = ":pre",
+ preun_scriptlet_file = ":preun",
+ posttrans_scriptlet_file = ":posttrans",
provides = ["test"],
release = "2222",
requires = ["test-lib > 1.0"],
requires_contextual = {"preun": ["bash"]},
spec_template = "template-test.spec.tpl",
summary = "pkg_rpm test rpm summary",
- version = "1.1.1",
+ version = _VERSION,
+)
+
+# Like the first one, except we use release and version files
+pkg_rpm(
+ name = "test_rpm_release_version_files",
+ srcs = [
+ ":test_pfg",
+ ],
+ architecture = "noarch",
+ conflicts = ["not-a-test"],
+ description = """pkg_rpm test rpm description""",
+ license = "Apache 2.0",
+ post_scriptlet_file = ":post",
+ postun_scriptlet_file = ":postun",
+ pre_scriptlet_file = ":pre",
+ preun_scriptlet_file = ":preun",
+ posttrans_scriptlet_file = ":posttrans",
+ provides = ["test"],
+ release_file = ":release_file",
+ requires = ["test-lib > 1.0"],
+ requires_contextual = {"preun": ["bash"]},
+ spec_template = "template-test.spec.tpl",
+ summary = "pkg_rpm test rpm summary",
+ version_file = ":version_file",
)
############################################################################
@@ -285,6 +380,7 @@ genrule(
# NOTE: excludes 'rpmlib' requires that may be version-dependent
echo 'capability:sense'
# Common, automatically generated
+ echo '/bin/sh:interp,posttrans'
echo '/bin/sh:pre,interp'
echo '/bin/sh:post,interp'
echo '/bin/sh:preun,interp'
@@ -305,10 +401,12 @@ sh_library(
testonly = True,
srcs = [
":test_rpm",
- ":test_rpm-bzip2",
+ ":test_rpm_bzip2",
":test_rpm_direct",
":test_rpm_manifest",
":test_rpm_metadata",
+ ":test_rpm_scriptlets_files",
+ ":test_rpm_release_version_files",
],
)
@@ -373,6 +471,7 @@ diff_test(
py_library(
name = "rpm_util",
srcs = ["rpm_util.py"],
+ imports = ["../.."],
visibility = [":__subpackages__"],
)
diff --git a/tests/rpm/analysis_tests.bzl b/tests/rpm/analysis_tests.bzl
index 52f4c5e..fd3317f 100644
--- a/tests/rpm/analysis_tests.bzl
+++ b/tests/rpm/analysis_tests.bzl
@@ -14,6 +14,7 @@
"""Tests for RPM generation analysis"""
+load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load(
"//pkg:mappings.bzl",
"pkg_filegroup",
@@ -21,10 +22,9 @@ load(
"pkg_mkdirs",
"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")
+load("//tests/util:defs.bzl", "generic_base_case_test", "generic_negative_test")
def _declare_pkg_rpm(name, srcs_ungrouped, tags = None, **kwargs):
pfg_name = "{}_pfg".format(name)
@@ -49,7 +49,7 @@ def _declare_pkg_rpm(name, srcs_ungrouped, tags = None, **kwargs):
**kwargs
)
-def _declare_conflicts_test(name, srcs, **kwargs):
+def _declare_conflicts_test(name, srcs):
rpm_name = name + "_rpm"
_declare_pkg_rpm(
name = rpm_name,
@@ -167,46 +167,53 @@ 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
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
- elif f.basename == ctx.attr.expected_default_name and not default_name_found:
+ if f == out_file:
+ out_file_found = True
+ if f == rpm_file:
+ rpm_file_found = True
+ if f == changes_file:
+ changes_file_found = True
+ if f.basename == ctx.attr.expected_name:
default_name_found = True
asserts.true(
env,
- packaged_file != None,
- "File name mentioned in PackageArtifactInfo '{}' is not in DefaultInfo".format(pai_name),
+ rpm_file_found,
+ "rpm component of OutputGroupInfo '{}' is not in DefaultInfo".format(rpm_file),
)
-
- asserts.true(
+ asserts.false(
env,
- packaged_file_found,
- "File object mentioned in PackageArtifactInfo '{}' missing from DefaultInfo".format(pai_name),
+ out_file_found,
+ "out component of OutputGroupInfo '{}' is not in DefaultInfo".format(out_file),
+ )
+ asserts.false(
+ env,
+ changes_file_found,
+ "changes component of OutputGroupInfo '{}' is not in DefaultInfo".format(changes_file),
)
-
asserts.true(
env,
default_name_found,
- "Expected package file with default name '{}' is not in DefaultInfo".format(ctx.attr.expected_default_name),
+ "Expected package file with default name '{}' is not in DefaultInfo".format(ctx.attr.expected_name),
)
return analysistest.end(env)
@@ -215,12 +222,11 @@ package_naming_test = analysistest.make(
_package_naming_test_impl,
attrs = {
"expected_name": attr.string(),
- "expected_default_name": attr.string(),
},
)
# Dummy substitution set, used in below test cases
-def _dummy_pkg_variables_impl(ctx):
+def _dummy_pkg_variables_impl(_):
return [
PackageVariablesInfo(
values = {
@@ -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"],
@@ -256,7 +262,6 @@ def _test_naming(name):
name = name + "_no_extra",
target_under_test = ":" + name + "_no_extra_rpm",
expected_name = name + "_no_extra_rpm-1.0-1.noarch.rpm",
- expected_default_name = name + "_no_extra_rpm" + ".rpm",
)
##################################################
@@ -280,7 +285,6 @@ def _test_naming(name):
name = name + "_with_different_name",
target_under_test = ":" + name + "_with_different_name_rpm",
expected_name = name + "-foo-bar.rpm",
- expected_default_name = name + "_with_different_name_rpm" + ".rpm",
)
##################################################
@@ -298,7 +302,7 @@ def _test_naming(name):
],
)
-def analysis_tests(name, **kwargs):
+def analysis_tests(name):
# Need to test:
#
# - Mutual exclusivity of certain options (low priority)
diff --git a/tests/rpm/pkg_rpm_basic_test.py b/tests/rpm/pkg_rpm_basic_test.py
index a152f06..8b29934 100644
--- a/tests/rpm/pkg_rpm_basic_test.py
+++ b/tests/rpm/pkg_rpm_basic_test.py
@@ -19,8 +19,9 @@ import subprocess
import csv
import io
import os
-import rpm_util
-from rules_python.python.runfiles import runfiles
+
+from python.runfiles import runfiles
+from tests.rpm import rpm_util
# This provides some tests for built RPMs, mostly by taking the built RPM and
# running rpm queries on it.
@@ -42,11 +43,15 @@ class PkgRpmBasicTest(unittest.TestCase):
def setUp(self):
self.runfiles = runfiles.Create()
self.test_rpm_path = self.runfiles.Rlocation(
- "rules_pkg/tests/rpm/test_rpm.rpm")
+ "rules_pkg/tests/rpm/test_rpm-1.1.1-2222.noarch.rpm")
self.test_rpm_direct_path = self.runfiles.Rlocation(
- "rules_pkg/tests/rpm/test_rpm_direct.rpm")
+ "rules_pkg/tests/rpm/test_rpm_direct-1.1.1-2222.noarch.rpm")
self.test_rpm_bzip2_path = self.runfiles.Rlocation(
- "rules_pkg/tests/rpm/test_rpm-bzip2.rpm")
+ "rules_pkg/tests/rpm/test_rpm_bzip2-1.1.1-2222.noarch.rpm")
+ self.test_rpm_scriptlets_files_path = self.runfiles.Rlocation(
+ "rules_pkg/tests/rpm/test_rpm_scriptlets_files-1.1.1-2222.noarch.rpm")
+ self.test_rpm_release_version_files = self.runfiles.Rlocation(
+ "rules_pkg/tests/rpm/test_rpm_release_version_files--.noarch.rpm")
self.maxDiff = None
def test_scriptlet_content(self):
@@ -59,31 +64,36 @@ preuninstall scriptlet (using /bin/sh):
echo preun
postuninstall scriptlet (using /bin/sh):
echo postun
+posttrans scriptlet (using /bin/sh):
+echo posttrans
"""
- output = subprocess.check_output(
- ["rpm", "-qp", "--scripts", self.test_rpm_path])
-
- self.assertEqual(output, expected)
+ for path in (self.test_rpm_path, self.test_rpm_scriptlets_files_path):
+ output = subprocess.check_output(["rpm", "-qp", "--scripts", path])
+ self.assertEqual(output, expected)
def test_basic_headers(self):
- fields = {
- "NAME": b"test_rpm",
+ common_fields = {
"VERSION": b"1.1.1",
"RELEASE": b"2222",
"ARCH": b"noarch",
"GROUP": b"Unspecified",
"SUMMARY": b"pkg_rpm test rpm summary",
}
- for fieldname, expected in fields.items():
- output = subprocess.check_output([
- "rpm", "-qp", "--queryformat", "%{" + fieldname + "}",
- self.test_rpm_path
- ])
-
- self.assertEqual(
- output, expected,
- "RPM Tag {} does not match expected value".format(fieldname))
+ for rpm, fields in [
+ (self.test_rpm_path, {"NAME": b"test_rpm"}),
+ (self.test_rpm_release_version_files, {"NAME": b"test_rpm_release_version_files"}),
+ ]:
+ fields.update(common_fields)
+ for fieldname, expected in fields.items():
+ output = subprocess.check_output([
+ "rpm", "-qp", "--queryformat", "%{" + fieldname + "}",
+ rpm,
+ ])
+
+ self.assertEqual(
+ output, expected,
+ "RPM Tag {} does not match expected value".format(fieldname))
def test_contents(self):
manifest_file = self.runfiles.Rlocation(
diff --git a/tests/rpm/source_date_epoch/BUILD b/tests/rpm/source_date_epoch/BUILD
index c6baced..156f844 100644
--- a/tests/rpm/source_date_epoch/BUILD
+++ b/tests/rpm/source_date_epoch/BUILD
@@ -28,7 +28,7 @@ py_test(
name = "source_date_epoch_insource",
srcs = ["rpm_contents_vs_manifest_test.py"],
data = [":rpm_sde_insource_data"],
- env = {"TEST_RPM": "rpm_sde_insource.rpm"},
+ env = {"TEST_RPM": "rpm_sde_insource-1.1.1-2222.noarch.rpm"},
main = "rpm_contents_vs_manifest_test.py",
tags = [
"no_windows", # Windows doesn't have rpm(8) or rpmbuild(8)
@@ -94,7 +94,7 @@ py_test(
name = "source_date_epoch_from_file",
srcs = ["rpm_contents_vs_manifest_test.py"],
data = [":rpm_sde_fromfile_data"],
- env = {"TEST_RPM": "rpm_sde_fromfile.rpm"},
+ env = {"TEST_RPM": "rpm_sde_fromfile-1.1.1-2222.noarch.rpm"},
main = "rpm_contents_vs_manifest_test.py",
tags = [
"no_windows", # Windows doesn't have rpm(8) or rpmbuild(8)
diff --git a/tests/rpm/source_date_epoch/rpm_contents_vs_manifest_test.py b/tests/rpm/source_date_epoch/rpm_contents_vs_manifest_test.py
index ca249c7..22db9b0 100644
--- a/tests/rpm/source_date_epoch/rpm_contents_vs_manifest_test.py
+++ b/tests/rpm/source_date_epoch/rpm_contents_vs_manifest_test.py
@@ -19,7 +19,7 @@ import io
import os
import unittest
-from rules_python.python.runfiles import runfiles
+from python.runfiles import runfiles
from tests.rpm import rpm_util
# Tue Mar 23 00:00:00 EDT 2021
diff --git a/tests/rpm/template-test.spec.tpl b/tests/rpm/template-test.spec.tpl
index f771f37..3f975f9 100644
--- a/tests/rpm/template-test.spec.tpl
+++ b/tests/rpm/template-test.spec.tpl
@@ -43,3 +43,5 @@ ${POST_SCRIPTLET}
${PREUN_SCRIPTLET}
${POSTUN_SCRIPTLET}
+
+${POSTTRANS_SCRIPTLET}
diff --git a/tests/rpm/toolchain_tests.bzl b/tests/rpm/toolchain_tests.bzl
index 0f6a499..9fffa8e 100644
--- a/tests/rpm/toolchain_tests.bzl
+++ b/tests/rpm/toolchain_tests.bzl
@@ -119,5 +119,6 @@ def _create_toolchain_creation_tests():
expect_path = "/usr/bin/foo",
)
+# buildifier: disable=unnamed-macro
def create_toolchain_analysis_tests():
_create_toolchain_creation_tests()
diff --git a/tests/rpm/tree_artifacts/BUILD b/tests/rpm/tree_artifacts/BUILD
index 04d7d8e..d295a1a 100644
--- a/tests/rpm/tree_artifacts/BUILD
+++ b/tests/rpm/tree_artifacts/BUILD
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+load("@rules_python//python:defs.bzl", "py_test")
load(
"//pkg:mappings.bzl",
"REMOVE_BASE_DIRECTORY",
@@ -22,7 +23,6 @@ load(
)
load("//pkg:rpm.bzl", "pkg_rpm")
load("//tests/util:defs.bzl", "directory")
-load("@rules_python//python:defs.bzl", "py_test")
############################################################################
# Test handling of directory outputs
@@ -44,6 +44,7 @@ py_test(
name = "layer_with_files",
srcs = ["rpm_contents_vs_manifest_test.py"],
data = [":layer_with_files_test_data"],
+ env = {"TEST_RPM": "test_dirs_rpm-1.1.1-2222.noarch.rpm"},
main = "rpm_contents_vs_manifest_test.py",
tags = [
"no_windows", # Windows doesn't have rpm(8) or rpmbuild(8)
@@ -152,7 +153,7 @@ py_test(
name = "layer_with_files_reversed",
srcs = ["rpm_contents_vs_manifest_test.py"],
data = [":layer_with_files_reversed_test_data"],
- env = {"TEST_RPM": "test_dirs_rpm_reversed.rpm"},
+ env = {"TEST_RPM": "test_dirs_rpm_reversed-1.1.1-2222.noarch.rpm"},
main = "rpm_contents_vs_manifest_test.py",
tags = [
"no_windows", # Windows doesn't have rpm(8) or rpmbuild(8)
@@ -204,6 +205,7 @@ py_test(
name = "treeartifact_ops",
srcs = ["rpm_treeartifact_ops_test.py"],
data = [":treeartifact_ops_rpm_test_data"],
+ env = {"TEST_RPM": "treeartifact_ops_rpm-1.1.1-2222.noarch.rpm"},
main = "rpm_treeartifact_ops_test.py",
tags = [
"no_windows", # Windows doesn't have rpm(8) or rpmbuild(8)
diff --git a/tests/rpm/tree_artifacts/rpm_contents_vs_manifest_test.py b/tests/rpm/tree_artifacts/rpm_contents_vs_manifest_test.py
index f0f8b3a..2b1dabc 100644
--- a/tests/rpm/tree_artifacts/rpm_contents_vs_manifest_test.py
+++ b/tests/rpm/tree_artifacts/rpm_contents_vs_manifest_test.py
@@ -19,7 +19,7 @@ import csv
import io
import os
-from rules_python.python.runfiles import runfiles
+from python.runfiles import runfiles
from tests.rpm import rpm_util
EXPECTED_RPM_MANIFEST_CSV = """
diff --git a/tests/rpm/tree_artifacts/rpm_treeartifact_ops_test.py b/tests/rpm/tree_artifacts/rpm_treeartifact_ops_test.py
index 2f74bc9..6810368 100644
--- a/tests/rpm/tree_artifacts/rpm_treeartifact_ops_test.py
+++ b/tests/rpm/tree_artifacts/rpm_treeartifact_ops_test.py
@@ -19,7 +19,7 @@ import io
import os
import unittest
-from rules_python.python.runfiles import runfiles
+from python.runfiles import runfiles
from tests.rpm import rpm_util
EXPECTED_RPM_MANIFEST_CSV = """
diff --git a/tests/stamp_test.py b/tests/stamp_test.py
index 7ba722b..3709a1b 100644
--- a/tests/stamp_test.py
+++ b/tests/stamp_test.py
@@ -19,7 +19,7 @@ import time
import unittest
import zipfile
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
# keep in sync with archive.py
PORTABLE_MTIME = 946684800 # 2000-01-01 00:00:00.000 UTC
diff --git a/tests/tar/BUILD b/tests/tar/BUILD
index bd3712b..d0fc200 100644
--- a/tests/tar/BUILD
+++ b/tests/tar/BUILD
@@ -14,14 +14,16 @@
# -*- coding: utf-8 -*-
"""Tests for pkg_tar."""
+load("@rules_python//python:defs.bzl", "py_binary", "py_test")
+
# buildifier: disable=bzl-visibility
-load("//pkg:mappings.bzl", "pkg_files", "pkg_mklink", "strip_prefix")
+load("//pkg:mappings.bzl", "pkg_attributes", "pkg_files", "pkg_mkdirs", "pkg_mklink")
load("//pkg:verify_archive.bzl", "verify_archive_test")
+
+# buildifier: disable=bzl-visibility
load("//pkg/private/tar:tar.bzl", "SUPPORTED_TAR_COMPRESSIONS", "pkg_tar")
load("//tests:my_package_name.bzl", "my_package_naming")
load("//tests/util:defs.bzl", "directory", "fake_artifact", "link_tree")
-load("@rules_python//python:defs.bzl", "py_test")
-load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
package(
default_applicable_licenses = ["//:license"],
@@ -44,11 +46,12 @@ py_test(
"//tests:testdata/tar_test.tar.xz",
"//tests:testdata/test_tar_package_dir_file.txt",
],
+ imports = ["../.."],
python_version = "PY3",
srcs_version = "PY3",
deps = [
"//pkg/private/tar:tar_writer",
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
)
@@ -105,10 +108,18 @@ pkg_tar(
package_variables = ":my_package_variables",
)
+pkg_mkdirs(
+ name = "mydir",
+ dirs = [
+ "mydir",
+ ],
+)
+
pkg_tar(
name = "test_tar_package_dir_substitution",
srcs = [
":BUILD",
+ ":mydir",
],
package_dir = "level1/{label}/level3",
package_variables = ":my_package_variables",
@@ -123,8 +134,8 @@ pkg_mklink(
pkg_tar(
name = "test_tar_package_dir",
srcs = [
- ":mylink",
":etc/nsswitch.conf",
+ ":mylink",
],
package_dir = "/my/package",
)
@@ -165,7 +176,6 @@ pkg_tar(
[pkg_tar(
name = "test-tar-inclusion-%s" % ext,
- build_tar = "//pkg/private/tar:build_tar",
deps = [
":test-tar-basic-%s" % ext,
":test_tar_naming",
@@ -199,7 +209,7 @@ pkg_tar(
name = "test-tar-strip_prefix-dot",
srcs = [
":etc/nsswitch.conf",
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
strip_prefix = ".",
)
@@ -268,21 +278,21 @@ pkg_tar(
verify_archive_test(
name = "repackaging_long_filename_test",
- target = ":test-tar-repackaging-long-filename",
+ max_size = 2,
must_contain = [
"can_i_repackage_a_file_with_a_long_name/file_with_a_ridiculously_long_name_consectetur_adipiscing_elit_fusce_laoreet_lorem_neque_sed_pharetra_erat.txt",
],
+ must_contain_regex = [
+ ".*can_i_repackage_a_file_with_a_long_name/$",
+ ],
# there is really no need for these cases. I just want to use all the test capabilities.
must_not_contain = [
"i_am_not here",
],
- must_contain_regex = [
- ".*can_i_repackage_a_file_with_a_long_name/$",
- ],
must_not_contain_regex = [
"^five.is.right.out",
],
- max_size = 2,
+ target = ":test-tar-repackaging-long-filename",
)
pkg_tar(
@@ -315,14 +325,117 @@ fake_artifact(
name = "a_program",
files = ["//tests:testdata/executable.sh"],
runfiles = ["BUILD"],
+ executable = True,
)
pkg_tar(
name = "test-tar-with-runfiles",
srcs = [
":a_program",
+ "//tests:an_executable",
+ ],
+ include_runfiles = True,
+)
+
+verify_archive_test(
+ name = "runfiles_test",
+ target = ":test-tar-with-runfiles",
+ must_contain = [
+ "a_program",
+ "a_program.runfiles/tests/tar/BUILD",
+ "executable.sh",
+ ] + select({
+ "@platforms//os:windows": [
+ "an_executable.exe",
+ "an_executable.exe.runfiles/tests/foo.cc",
+ "an_executable.exe.runfiles/tests/an_executable.exe",
+ "an_executable.exe.runfiles/tests/testdata/hello.txt",
+ ],
+ "//conditions:default": [
+ "an_executable",
+ "an_executable.runfiles/tests/foo.cc",
+ "an_executable.runfiles/tests/an_executable",
+ "an_executable.runfiles/tests/testdata/hello.txt",
+ ]
+ }),
+)
+
+pkg_tar(
+ name = "test-tar-remap-runfiles-base-path",
+ srcs = [
+ ":a_program",
+ "//tests:an_executable",
+ ],
+ include_runfiles = True,
+ remap_paths = {
+ "/a_program": "/new_name",
+ "/an_executable": "/other/different_name",
+ },
+)
+
+verify_archive_test(
+ name = "runfiles_remap_base_path_test",
+ must_contain = [
+ "new_name",
+ "new_name.runfiles/tests/tar/BUILD",
+ "executable.sh",
+ ] + select({
+ "@platforms//os:windows": [
+ "other/different_name.exe",
+ "other/different_name.exe.runfiles/tests/foo.cc",
+ "other/different_name.exe.runfiles/tests/an_executable.exe",
+ "other/different_name.exe.runfiles/tests/testdata/hello.txt",
+ ],
+ "//conditions:default": [
+ "other/different_name",
+ "other/different_name.runfiles/tests/foo.cc",
+ "other/different_name.runfiles/tests/an_executable",
+ "other/different_name.runfiles/tests/testdata/hello.txt",
+ ],
+ }),
+ target = ":test-tar-remap-runfiles-base-path",
+)
+
+pkg_tar(
+ name = "test-tar-remap-runfiles-full-paths",
+ srcs = [
+ ":a_program",
+ "//tests:an_executable",
],
include_runfiles = True,
+ remap_paths = {
+ # rename the entire runfiles directory
+ "/a_program.runfiles/": "/a/program/runfiles/",
+ # rename a specific file
+ "/an_executable.runfiles/tests/testdata/hello.txt": "/myfiles/hello.txt",
+ "/an_executable.exe.runfiles/tests/testdata/hello.txt": "/myfiles/hello.txt",
+ # rename a specific subdirectory
+ "/an_executable.runfiles/tests/": "/mytests/",
+ "/an_executable.exe.runfiles/tests/": "/mytests/",
+ },
+)
+
+verify_archive_test(
+ name = "runfiles_remap_full_paths_test",
+ must_contain = [
+ "a_program",
+ "a/program/runfiles/tests/tar/BUILD",
+ "executable.sh",
+ ] + select({
+ "@platforms//os:windows": [
+ "an_executable.exe",
+ "mytests/foo.cc",
+ "mytests/an_executable.exe",
+ "myfiles/hello.txt",
+ ],
+ "//conditions:default": [
+ "an_executable",
+ "mytests/foo.cc",
+ "mytests/an_executable",
+ "myfiles/hello.txt",
+ ],
+ }),
+ target = ":test-tar-remap-runfiles-full-paths",
)
pkg_tar(
@@ -340,23 +453,25 @@ py_test(
"pkg_tar_test.py",
],
data = [
+ ":test-pkg-tar-from-pkg-files-with-attributes",
+ ":test-pkg-tar-with-attributes",
+ ":test-remap-paths-tree-artifact",
":test-tar-empty_dirs.tar",
":test-tar-empty_files.tar",
":test-tar-files_dict.tar",
+ ":test-tar-long-filename",
":test-tar-mtime.tar",
+ ":test-tar-repackaging-long-filename.tar",
":test-tar-strip_prefix-dot.tar",
":test-tar-strip_prefix-empty.tar",
":test-tar-strip_prefix-etc.tar",
":test-tar-strip_prefix-none.tar",
":test-tar-strip_prefix-substring.tar",
- ":test_tar_leading_dotslash",
- ":test_tar_package_dir_substitution.tar",
- ":test-tar-long-filename",
- ":test-tar-repackaging-long-filename.tar",
":test-tar-tree-artifact",
":test-tar-tree-artifact-noroot",
- ":test-tar-with-runfiles",
":test-tree-input-with-strip-prefix",
+ ":test_tar_leading_dotslash",
+ ":test_tar_package_dir_substitution.tar",
"//tests:testdata/tar_test.tar",
"//tests:testdata/tar_test.tar.bz2",
"//tests:testdata/tar_test.tar.gz",
@@ -369,10 +484,11 @@ py_test(
":test-tar-inclusion-%s" % compression
for compression in SUPPORTED_TAR_COMPRESSIONS
],
+ imports = ["../.."],
python_version = "PY3",
deps = [
"//pkg/private/tar:tar_writer",
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
)
@@ -397,6 +513,37 @@ pkg_tar(
extension = ".tar.gz",
)
+pkg_files(
+ name = "test-pkg-files-with-attributes",
+ srcs = [
+ "//tests:testdata/loremipsum.txt",
+ ],
+ attributes = pkg_attributes(
+ gid = 1000,
+ group = "grp",
+ mode = "0440",
+ uid = 0,
+ user = "person",
+ ),
+ prefix = "/foo/bar",
+)
+
+pkg_tar(
+ name = "test-pkg-tar-from-pkg-files-with-attributes",
+ srcs = [
+ ":test-pkg-files-with-attributes",
+ ],
+)
+
+pkg_tar(
+ name = "test-pkg-tar-with-attributes",
+ srcs = [
+ "//tests:testdata/loremipsum.txt",
+ ],
+ owner = "0.1000",
+ package_dir = "/foo/bar",
+)
+
pkg_tar(
name = "test-tar-compression-from-extension-tgz",
srcs = [
@@ -424,10 +571,52 @@ py_test(
python_version = "PY3",
srcs_version = "PY3",
deps = [
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
)
+directory(
+ name = "generate_tree_with_prefix",
+ contents = "hello there",
+ filenames = [
+ "a/a",
+ "a/b",
+ ],
+ outdir = "tree_prefix_to_strip",
+)
+
+pkg_tar(
+ name = "test-tree-input-with-strip-prefix",
+ srcs = [
+ ":generate_tree_with_prefix",
+ ],
+ strip_prefix = "tree_prefix_to_strip",
+)
+
+directory(
+ name = "tree_artifact_to_rename",
+ contents = "hello there",
+ filenames = [
+ "a",
+ "rename_me/should_not_rename",
+ ],
+ outdir = "rename_me",
+)
+
+pkg_tar(
+ name = "test-remap-paths-tree-artifact",
+ srcs = [
+ ":tree_artifact_to_rename",
+ ],
+ remap_paths = {
+ "/rename_me": "a_new_name",
+ },
+)
+
+#
+# Test with symlinks
+#
+
link_tree(
name = "node_modules",
links = {
@@ -446,11 +635,12 @@ directory(
"foo/hello.txt",
"foo/bar/baz",
],
- links = {
- "foo/bar/hello": "../hello.txt",
- "foo/bar/alt_baz": "baz",
- "foo/alt_baz": "bar/baz",
- },
+ # TODO(https://github.com/bazelbuild/rules_pkg/issues/750)
+ #links = {
+ # "foo/bar/hello": "../hello.txt",
+ # "foo/bar/alt_baz": "baz",
+ # "foo/alt_baz": "bar/baz",
+ #},
)
# This target has symlinks 3 ways.
@@ -464,29 +654,59 @@ pkg_tar(
":tree_artifact_with_links",
"//tests:file_and_link",
],
+ symlinks = {
+ "tree_artifact/toss_in_another": "/foo",
+ },
+)
+
+verify_archive_test(
+ name = "relative_links_test",
+ min_size = 10,
+ must_contain = [
+ "BUILD",
+ "outer_BUILD",
+ "node_modules/.pnpm/bar@1.0.0/node_modules/bar",
+ ],
+ tags = ["nowindows"],
+ target = ":relative_links_tar",
+ verify_links = {
+ "node_modules/.pnpm/foo@1.0.0/node_modules/bar": "../../bar@1.0.0/node_modules/bar",
+ "tree_artifact/toss_in_another": "/foo",
+ },
)
pkg_tar(
name = "relative_links_re_tar",
+ package_dir = "new/base",
+ symlinks = {
+ # We expect package_dir to apply to this
+ "tree_artifact/toss_in_another": "some_target",
+ # But we protect the user from duplicating package_dir in their
+ # link. That was the old behavior of symlink.
+ "new/base/something/this": "that",
+ },
deps = [
":relative_links_tar",
],
)
-directory(
- name = "generate_tree_with_prefix",
- contents = "hello there",
- filenames = [
- "a/a",
- "a/b",
+verify_archive_test(
+ name = "relative_links_re_test",
+ min_size = 10,
+ must_contain = [
+ "new/base/BUILD",
+ "new/base/outer_BUILD",
+ "new/base/node_modules/.pnpm/bar@1.0.0/node_modules/bar",
],
- outdir = "tree_prefix_to_strip",
+ must_not_contain = [
+ "BUILD",
+ "new/base/new/base/something/this",
+ ],
+ tags = ["nowindows"],
+ target = ":relative_links_re_tar",
+ verify_links = {
+ "new/base/node_modules/.pnpm/foo@1.0.0/node_modules/bar": "../../bar@1.0.0/node_modules/bar",
+ "new/base/tree_artifact/toss_in_another": "some_target",
+ "new/base/something/this": "that",
+ },
)
-
-pkg_tar(
- name = "test-tree-input-with-strip-prefix",
- srcs = [
- ":generate_tree_with_prefix",
- ],
- strip_prefix = "tree_prefix_to_strip",
-) \ No newline at end of file
diff --git a/tests/tar/is_compressed_test.py b/tests/tar/is_compressed_test.py
index 6ed7386..5e55a06 100644
--- a/tests/tar/is_compressed_test.py
+++ b/tests/tar/is_compressed_test.py
@@ -15,7 +15,7 @@
import unittest
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
class IsCompressedTest(unittest.TestCase):
diff --git a/tests/tar/pkg_tar_test.py b/tests/tar/pkg_tar_test.py
index fabdffc..d18c49c 100644
--- a/tests/tar/pkg_tar_test.py
+++ b/tests/tar/pkg_tar_test.py
@@ -16,7 +16,7 @@
import tarfile
import unittest
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
from pkg.private.tar import tar_writer
PORTABLE_MTIME = 946684800 # 2000-01-01 00:00:00.000 UTC
@@ -104,17 +104,16 @@ class PkgTarTest(unittest.TestCase):
]
self.assertTarFileContent('test-tar-strip_prefix-substring.tar', content)
- def test_strip_prefix_dot(self):
+ def disabled_test_strip_prefix_dot(self):
content = [
{'name': 'etc'},
{'name': 'etc/nsswitch.conf'},
{'name': 'external'},
- {'name': 'external/bazel_tools'},
- {'name': 'external/bazel_tools/tools'},
- {'name': 'external/bazel_tools/tools/python'},
- {'name': 'external/bazel_tools/tools/python/runfiles'},
+ {'name': 'external/rules_python'},
+ {'name': 'external/rules_python/python'},
+ {'name': 'external/rules_python/python/runfiles'},
# This is brittle. In old bazel the next file would be
- # external/bazel_tools/tools/python/runfiles/runfiles.py, but there
+ # external/rules_python/python/runfiles/runfiles.py, but there
# is now _runfiles_constants.py, first. So this is too brittle.
{'halt': None},
]
@@ -195,6 +194,7 @@ class PkgTarTest(unittest.TestCase):
{'name': 'level1/some_value'},
{'name': 'level1/some_value/level3'},
{'name': 'level1/some_value/level3/BUILD'},
+ {'name': 'level1/some_value/level3/mydir'},
]
self.assertTarFileContent('test_tar_package_dir_substitution.tar', content)
@@ -244,20 +244,29 @@ class PkgTarTest(unittest.TestCase):
self.assertTarFileContent('test-tar-tree-artifact-noroot.tar',
noroot_content)
- def test_tar_with_runfiles(self):
- content = [
- {'name': 'BUILD' },
- {'name': 'a_program' },
- {'name': 'executable.sh' },
- ]
- self.assertTarFileContent('test-tar-with-runfiles.tar', content)
-
def test_tar_leading_dotslash(self):
content = [
{'name': './loremipsum.txt'},
]
self.assertTarFileContent('test_tar_leading_dotslash.tar', content)
+
+ def test_pkg_tar_with_attributes(self):
+ content = [
+ {'name': 'foo','uid': 0, 'gid': 1000, 'uname': '', 'gname': ''},
+ {'name': 'foo/bar','uid': 0, 'gid': 1000, 'uname': '', 'gname': ''},
+ {'name': 'foo/bar/loremipsum.txt','uid': 0, 'gid': 1000, 'uname': '', 'gname': ''},
+ ]
+ self.assertTarFileContent('test-pkg-tar-with-attributes.tar', content)
+
+ def test_pkg_files_with_attributes(self):
+ content = [
+ {'name': 'foo','uid': 0, 'gid': 1000, 'uname': 'person', 'gname': 'grp'},
+ {'name': 'foo/bar','uid': 0, 'gid': 1000, 'uname': 'person', 'gname': 'grp'},
+ {'name': 'foo/bar/loremipsum.txt','uid': 0, 'gid': 1000, 'uname': 'person', 'gname': 'grp'},
+ ]
+ self.assertTarFileContent('test-pkg-tar-from-pkg-files-with-attributes.tar', content)
+
def test_tar_with_tree_artifact_and_strip_prefix(self):
content = [
{'name': 'a', 'isdir': True},
@@ -266,6 +275,15 @@ class PkgTarTest(unittest.TestCase):
]
self.assertTarFileContent('test-tree-input-with-strip-prefix.tar', content)
+ def test_remap_paths_tree_artifact(self):
+ content = [
+ {'name': 'a_new_name', 'isdir': True},
+ {'name': 'a_new_name/a'},
+ {'name': 'a_new_name/rename_me', 'isdir': True},
+ {'name': 'a_new_name/rename_me/should_not_rename'},
+ ]
+ self.assertTarFileContent('test-remap-paths-tree-artifact.tar', content)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/tar/tar_writer_test.py b/tests/tar/tar_writer_test.py
index 39008ea..ad31b0c 100644
--- a/tests/tar/tar_writer_test.py
+++ b/tests/tar/tar_writer_test.py
@@ -17,7 +17,7 @@ import os
import tarfile
import unittest
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
from pkg.private.tar import tar_writer
from tests.tar import compressor
diff --git a/tests/util/defs.bzl b/tests/util/defs.bzl
index 463525c..34fea03 100644
--- a/tests/util/defs.bzl
+++ b/tests/util/defs.bzl
@@ -11,13 +11,11 @@
# 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 to aid testing"""
-load("//pkg/private:pkg_files.bzl", "add_label_list", "write_manifest")
-load("//pkg:providers.bzl", "PackageFilegroupInfo", "PackageSymlinkInfo")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
-load("@rules_python//python:defs.bzl", "py_binary")
+load("//pkg:providers.bzl", "PackageFilegroupInfo", "PackageSymlinkInfo")
+load("//pkg/private:pkg_files.bzl", "add_label_list", "create_mapping_context_from_ctx", "write_manifest") # buildifier: disable=bzl-visibility
def _directory_impl(ctx):
out_dir_file = ctx.actions.declare_directory(ctx.attr.outdir or ctx.attr.name)
@@ -32,7 +30,7 @@ def _directory_impl(ctx):
for link, target in ctx.attr.links.items():
args.add(link)
- args.add('@@' + target)
+ args.add("@@" + target)
ctx.actions.run(
outputs = [out_dir_file],
@@ -115,13 +113,16 @@ cc_binary in complexity, but does not depend on a large toolchain.""",
def _link_tree_impl(ctx):
links = []
prefix = ctx.attr.package_dir or ""
- if prefix and not prefix.endswith('/'):
+ if prefix and not prefix.endswith("/"):
prefix = prefix + "/"
for link, target in ctx.attr.links.items():
- print(' %s -> %s ' % (link, target))
+ # DBG print(' %s -> %s ' % (link, target))
links.append(
- (PackageSymlinkInfo(destination = prefix + link, target = target),
- ctx.label))
+ (
+ PackageSymlinkInfo(destination = prefix + link, target = target),
+ ctx.label,
+ ),
+ )
return [PackageFilegroupInfo(pkg_symlinks = links)]
link_tree = rule(
@@ -144,10 +145,9 @@ The keys of links are paths to create. The values are the target of the links."
)
def _write_content_manifest_impl(ctx):
- content_map = {} # content handled in the manifest
- file_deps = [] # inputs we depend on
- add_label_list(ctx, content_map, file_deps, ctx.attr.srcs)
- write_manifest(ctx, ctx.outputs.out, content_map, use_short_path = ctx.attr.use_short_path)
+ mapping_context = create_mapping_context_from_ctx(ctx, ctx.label)
+ add_label_list(mapping_context, ctx.attr.srcs)
+ write_manifest(ctx, ctx.outputs.out, mapping_context.content_map, use_short_path = ctx.attr.use_short_path)
_write_content_manifest = rule(
doc = """Helper rule to write the content manifest for a pkg_*.
@@ -183,7 +183,7 @@ def write_content_manifest(name, srcs, **kwargs):
srcs = srcs,
out = out,
use_short_path = use_short_path,
- **kwargs,
+ **kwargs
)
############################################################
diff --git a/tests/zip/BUILD b/tests/zip/BUILD
index 0a545ec..0727b2e 100644
--- a/tests/zip/BUILD
+++ b/tests/zip/BUILD
@@ -13,12 +13,12 @@
# limitations under the License.
# -*- coding: utf-8 -*-
+load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
+load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("//pkg:mappings.bzl", "pkg_attributes", "pkg_mkdirs", "pkg_mklink")
load("//pkg:zip.bzl", "pkg_zip")
load("//tests:my_package_name.bzl", "my_package_naming")
-load("//tests/util:defs.bzl", "directory", "fake_artifact")
-load("@rules_python//python:defs.bzl", "py_library", "py_test")
-load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
+load("//tests/util:defs.bzl", "directory")
package(default_applicable_licenses = ["//:license"])
@@ -29,9 +29,10 @@ py_library(
srcs = [
"zip_test_lib.py",
],
+ imports = ["../.."],
srcs_version = "PY3",
deps = [
- "@bazel_tools//tools/python/runfiles",
+ "@rules_python//python/runfiles",
],
)
@@ -235,6 +236,40 @@ pkg_zip(
package_variables = ":my_package_variables",
)
+# Different compressions
+pkg_zip(
+ name = "test_zip_deflated_level_3",
+ srcs = [
+ "//tests:testdata/loremipsum.txt",
+ ],
+ compression_level = 3,
+ compression_type = "deflated",
+)
+
+pkg_zip(
+ name = "test_zip_bzip2",
+ srcs = [
+ "//tests:testdata/loremipsum.txt",
+ ],
+ compression_type = "bzip2",
+)
+
+pkg_zip(
+ name = "test_zip_lzma",
+ srcs = [
+ "//tests:testdata/loremipsum.txt",
+ ],
+ compression_type = "lzma",
+)
+
+pkg_zip(
+ name = "test_zip_stored",
+ srcs = [
+ "//tests:testdata/loremipsum.txt",
+ ],
+ compression_type = "stored",
+)
+
py_test(
name = "zip_test",
srcs = [
@@ -246,10 +281,14 @@ py_test(
":test-zip-strip_prefix-none.zip",
":test-zip-strip_prefix-zipcontent.zip",
":test_zip_basic.zip",
+ ":test_zip_bzip2",
+ ":test_zip_deflated_level_3",
":test_zip_empty.zip",
+ ":test_zip_lzma",
":test_zip_package_dir0.zip",
":test_zip_package_dir_substitution.zip",
":test_zip_permissions.zip",
+ ":test_zip_stored",
":test_zip_timestamp.zip",
":test_zip_tree.zip",
],
@@ -284,7 +323,7 @@ py_test(
pkg_zip(
name = "unicode_names",
- srcs = ["//tests:utf8_files"]
+ srcs = ["//tests:utf8_files"],
)
py_test(
diff --git a/tests/zip/zip_test.py b/tests/zip/zip_test.py
index f110ef7..6978dc5 100644
--- a/tests/zip/zip_test.py
+++ b/tests/zip/zip_test.py
@@ -15,10 +15,11 @@
import datetime
import filecmp
import os
+import sys
import unittest
import zipfile
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
from tests.zip import zip_test_lib
HELLO_CRC = 2069210904
@@ -123,6 +124,33 @@ class ZipContentsTests(zip_test_lib.ZipContentsTestBase):
{"filename": "generate_tree/b/e"},
])
+ def test_compression_deflated(self):
+ if sys.version_info >= (3, 7):
+ self.assertZipFileContent("test_zip_deflated_level_3.zip", [
+ {"filename": "loremipsum.txt", "crc": LOREM_CRC, "size": 312},
+ ])
+ else:
+ # Python 3.6 doesn't support setting compresslevel, so the file size differs
+ self.assertZipFileContent("test_zip_deflated_level_3.zip", [
+ {"filename": "loremipsum.txt", "crc": LOREM_CRC, "size": 309},
+ ])
+
+ def test_compression_bzip2(self):
+ self.assertZipFileContent("test_zip_bzip2.zip", [
+ {"filename": "loremipsum.txt", "crc": LOREM_CRC, "size": 340},
+ ])
+
+ def test_compression_lzma(self):
+ self.assertZipFileContent("test_zip_lzma.zip", [
+ {"filename": "loremipsum.txt", "crc": LOREM_CRC, "size": 378},
+ ])
+
+ def test_compression_stored(self):
+ self.assertZipFileContent("test_zip_stored.zip", [
+ {"filename": "loremipsum.txt", "crc": LOREM_CRC, "size": 543},
+ ])
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/zip/zip_test_lib.py b/tests/zip/zip_test_lib.py
index ada8303..ebb0b60 100644
--- a/tests/zip/zip_test_lib.py
+++ b/tests/zip/zip_test_lib.py
@@ -17,7 +17,7 @@ import filecmp
import unittest
import zipfile
-from bazel_tools.tools.python.runfiles import runfiles
+from python.runfiles import runfiles
# Unix dir bit and Windows dir bit. Magic from zip spec
@@ -44,9 +44,7 @@ class ZipTest(unittest.TestCase):
def get_test_zip(self, zip_file):
"""Get the file path to a generated zip in the runfiles."""
- return self.data_files.Rlocation(
- "rules_pkg/tests/zip/" + zip_file
- )
+ return self.data_files.Rlocation("rules_pkg/tests/zip/" + zip_file)
class ZipContentsTestBase(ZipTest):
@@ -80,6 +78,8 @@ class ZipContentsTestBase(ZipTest):
elif "isexe" in expected:
got_mode = (info.external_attr >> 16) & UNIX_RX_BITS
self.assertEqual(oct(got_mode), oct(UNIX_RX_BITS))
+ elif "size" in expected:
+ self.assertEqual(info.compress_size, expected["size"])
else:
if "attr" in expected:
@@ -87,7 +87,7 @@ class ZipContentsTestBase(ZipTest):
if "attr_mask" in expected:
attr &= expected.get("attr_mask")
else:
- # I would argue this is a dumb choice, but it matchs the
+ # I would argue this is a dumb choice, but it matches the
# legacy rule implementation.
attr = 0o555
self.assertEqual(oct((info.external_attr >> 16) & UNIX_RWX_BITS),