Skip to content

Commit

Permalink
project: Restricting projects from being located in west folder
Browse files Browse the repository at this point in the history
Fixes: zephyrproject-rtos#102

This commit introduces a list of restricted folders that are compared
against project defined paths to ensure a manifest does not contain
paths ending in the west folder, e.g.:
- west
- west/foo
- foo/../west

while still allowing folders, such as:
- west-ext
as project folder.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
  • Loading branch information
tejlmand committed Nov 29, 2018
1 parent 11c79e7 commit 5c79619
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/west/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
'''Names of the special "meta-projects", which are reserved and cannot
be used to name a project in the manifest file.'''

WEST_RESTRICTED_FOLDERS = ['west']
'''Restricted folders that are used by "west" itself for "meta-projects"'''

MANIFEST_SECTIONS = ['manifest', 'west']
'''Sections in the manifest file'''

Expand Down Expand Up @@ -216,6 +219,15 @@ def _load(self, data, sections):
format(name) +
'be used to name a manifest project')

path = mp.get('path')
if path is not None:
path = os.path.normpath(path)
for restricted_path in WEST_RESTRICTED_FOLDERS:
if os.path.commonpath([restricted_path, path]):
self._malformed('the folder "{}" is restricted and '.
format(restricted_path) +
'cannot be used for local projects')

# Validate the project remote.
remote_name = mp.get('remote', default_remote_name)
if remote_name is None:
Expand All @@ -227,7 +239,7 @@ def _load(self, data, sections):
project = Project(name,
remotes_dict[remote_name],
defaults,
path=mp.get('path'),
path=path,
clone_depth=mp.get('clone-depth'),
revision=mp.get('revision'))

Expand Down
11 changes: 11 additions & 0 deletions tests/west/manifest/invalid_restricted_project_normalized_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
manifest:
defaults:
remote: testremote

remotes:
- name: testremote
url-base: https://example.com

projects:
- name: foo1
path: foo/../west
11 changes: 11 additions & 0 deletions tests/west/manifest/invalid_restricted_project_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
manifest:
defaults:
remote: testremote

remotes:
- name: testremote
url-base: https://example.com

projects:
- name: foo1
path: west
11 changes: 11 additions & 0 deletions tests/west/manifest/invalid_restricted_project_sub_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
manifest:
defaults:
remote: testremote

remotes:
- name: testremote
url-base: https://example.com

projects:
- name: foo1
path: west/foo
23 changes: 23 additions & 0 deletions tests/west/manifest/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ def test_path():
assert manifest.projects[0].path == 'sub/directory'
assert manifest.projects[0].abspath == os.path.realpath('/west_top/sub/directory')

def test_restricted_path():
# Projects are restricted from west/ folder, but folders containing west as
# part of path name, e.g. west-ext arte still allowed.
content = '''\
manifest:
remotes:
- name: testremote
url-base: https://example.com
projects:
- name: testproject
remote: testremote
path: west-ext
- name: testsubproject
remote: testremote
path: west-ext/sub
'''
with patch('west.util.west_topdir', return_value=os.path.realpath('/west_top')):
manifest = Manifest.from_data(yaml.safe_load(content))
assert manifest.projects[0].path == 'west-ext'
assert manifest.projects[0].abspath == os.path.realpath('/west_top/west-ext')
assert manifest.projects[1].path == 'west-ext/sub'
assert manifest.projects[1].abspath == os.path.realpath('/west_top/west-ext/sub')

def test_sections():
# Projects must be able to override their default paths.
content_wrong_west = '''\
Expand Down

0 comments on commit 5c79619

Please sign in to comment.