Skip to content
Snippets Groups Projects
Commit 3ae078ce authored by Abderrahim Kitouni's avatar Abderrahim Kitouni Committed by Javier Jardón
Browse files

element.py: Accept absolute paths in overlap whitelists

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 1ae17968

Fixes #721
parent da6a3333
No related branches found
No related tags found
Loading
......@@ -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():
#
......
......@@ -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()
......
kind: import
config:
source: /
target: /
depends:
- b-whitelisted.bst
sources:
- kind: local
path: "a"
public:
bst:
overlap-whitelist:
- "/file*"
kind: import
config:
source: /
target: /
depends:
- c.bst
sources:
- kind: local
path: "b"
variables:
FILE: /file
public:
bst:
overlap-whitelist:
- /file2
- "%{FILE}3"
kind: import
config:
source: /
target: /
sources:
- kind: local
path: "c"
public:
bst:
overlap-whitelist:
- "/file*"
kind: compose
depends:
- filename: a-whitelisted-abs.bst
type: build
- filename: b-whitelisted-abs.bst
type: build
- filename: c.bst
type: build
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment