summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbderrahim Kitouni <akitouni@gnome.org>2020-03-30 10:52:11 +0100
committerAbderrahim Kitouni <akitouni@gnome.org>2020-03-30 15:04:28 +0100
commit96ab48f82fc101ad28edc1a161316f9df7ff358e (patch)
treeb627dcc9b97f6856e50d14205471ee3a21b041a1
parent73ef1f2ea9ed3377a3aa951fd920e52202c16b45 (diff)
downloadbuildstream-abderrahim/absolute-whitelist.tar.gz
element.py: Accept absolute paths in overlap whitelistsabderrahim/absolute-whitelist
This allows use of variables such as %{prefix} and matches the documentation. To avoid breaking compatibility with older bst 1.x versions, it still accepts paths without the leading slash. based on 1ae1796854055f4b9e3202d9629e059b327f3a8d Fixes #721
-rw-r--r--buildstream/element.py4
-rw-r--r--tests/frontend/overlaps.py10
-rw-r--r--tests/frontend/overlaps/a-whitelisted-abs.bst13
-rw-r--r--tests/frontend/overlaps/b-whitelisted-abs.bst16
-rw-r--r--tests/frontend/overlaps/c-whitelisted-abs.bst11
-rw-r--r--tests/frontend/overlaps/collect-whitelisted-abs.bst9
6 files changed, 57 insertions, 6 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index 703f062da..ef871b7ad 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -2362,7 +2362,7 @@ class Element(Plugin):
if include_file and not exclude_file:
yield filename.lstrip(os.sep)
- def __file_is_whitelisted(self, pattern):
+ def __file_is_whitelisted(self, path):
# Considered storing the whitelist regex for re-use, but public data
# can be altered mid-build.
# Public data is not guaranteed to stay the same for the duration of
@@ -2374,7 +2374,7 @@ class Element(Plugin):
whitelist_expressions = [utils._glob2re(self.__variables.subst(exp.strip())) for exp in whitelist]
expression = ('^(?:' + '|'.join(whitelist_expressions) + ')$')
self.__whitelist_regex = re.compile(expression)
- return self.__whitelist_regex.match(pattern)
+ return self.__whitelist_regex.match(path) or self.__whitelist_regex.match(os.path.join(os.sep, path))
# __extract():
#
diff --git a/tests/frontend/overlaps.py b/tests/frontend/overlaps.py
index 99c312014..ad2211dde 100644
--- a/tests/frontend/overlaps.py
+++ b/tests/frontend/overlaps.py
@@ -47,20 +47,22 @@ def test_overlaps_error(cli, datafiles, use_fatal_warnings):
@pytest.mark.datafiles(DATA_DIR)
-def test_overlaps_whitelist(cli, datafiles):
+@pytest.mark.parametrize("element", ["collect-whitelisted.bst", "collect-whitelisted-abs.bst"])
+def test_overlaps_whitelist(cli, datafiles, element):
project_dir = str(datafiles)
gen_project(project_dir, True)
result = cli.run(project=project_dir, silent=True, args=[
- 'build', 'collect-whitelisted.bst'])
+ 'build', element])
result.assert_success()
@pytest.mark.datafiles(DATA_DIR)
-def test_overlaps_whitelist_ignored(cli, datafiles):
+@pytest.mark.parametrize("element", ["collect-whitelisted.bst", "collect-whitelisted-abs.bst"])
+def test_overlaps_whitelist_ignored(cli, datafiles, element):
project_dir = str(datafiles)
gen_project(project_dir, False)
result = cli.run(project=project_dir, silent=True, args=[
- 'build', 'collect-whitelisted.bst'])
+ 'build', element])
result.assert_success()
diff --git a/tests/frontend/overlaps/a-whitelisted-abs.bst b/tests/frontend/overlaps/a-whitelisted-abs.bst
new file mode 100644
index 000000000..e3b677ec8
--- /dev/null
+++ b/tests/frontend/overlaps/a-whitelisted-abs.bst
@@ -0,0 +1,13 @@
+kind: import
+config:
+ source: /
+ target: /
+depends:
+- b-whitelisted.bst
+sources:
+- kind: local
+ path: "a"
+public:
+ bst:
+ overlap-whitelist:
+ - "/file*"
diff --git a/tests/frontend/overlaps/b-whitelisted-abs.bst b/tests/frontend/overlaps/b-whitelisted-abs.bst
new file mode 100644
index 000000000..f09736669
--- /dev/null
+++ b/tests/frontend/overlaps/b-whitelisted-abs.bst
@@ -0,0 +1,16 @@
+kind: import
+config:
+ source: /
+ target: /
+depends:
+- c.bst
+sources:
+- kind: local
+ path: "b"
+variables:
+ FILE: /file
+public:
+ bst:
+ overlap-whitelist:
+ - /file2
+ - "%{FILE}3"
diff --git a/tests/frontend/overlaps/c-whitelisted-abs.bst b/tests/frontend/overlaps/c-whitelisted-abs.bst
new file mode 100644
index 000000000..47154b277
--- /dev/null
+++ b/tests/frontend/overlaps/c-whitelisted-abs.bst
@@ -0,0 +1,11 @@
+kind: import
+config:
+ source: /
+ target: /
+sources:
+- kind: local
+ path: "c"
+public:
+ bst:
+ overlap-whitelist:
+ - "/file*"
diff --git a/tests/frontend/overlaps/collect-whitelisted-abs.bst b/tests/frontend/overlaps/collect-whitelisted-abs.bst
new file mode 100644
index 000000000..e1850bbd7
--- /dev/null
+++ b/tests/frontend/overlaps/collect-whitelisted-abs.bst
@@ -0,0 +1,9 @@
+kind: compose
+
+depends:
+- filename: a-whitelisted-abs.bst
+ type: build
+- filename: b-whitelisted-abs.bst
+ type: build
+- filename: c.bst
+ type: build