-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
project: Restricting projects from being located in west folder #132
project: Restricting projects from being located in west folder #132
Conversation
path = mp.get('path') | ||
if path is not None: | ||
path = os.path.normpath(path) | ||
for restricted_path in WEST_RESTRICTED_FOLDERS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be cleaner with a if X in Y
construction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we can't do a simple X in Y
here.
west
is restricted, but it could be that manifest states west/subfolder
and that is also forbidden, and wouldn't be matched in a X in Y
.
Thus we loop over WEST_RESTRICTED_FOILDERS
to see if there is a match on commonpath
between restricted and the path specified for the folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commonpath now changed to commonprefix to support 3.4, as commonpath is new in python 3.5
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>
5c79619
to
b57a372
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long to get to this, was traveling all last week
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: s/arte/are/
@@ -216,6 +219,18 @@ def _load(self, data, sections): | |||
format(name) + | |||
'be used to name a manifest project') | |||
|
|||
path = mp.get('path') | |||
if path is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not given, the implied path is the name of the project. What if I have a project named west/subproject
or so? Do we still fail?
If so, would you mind adding some test coverage (another invalid_xxx.yaml
should do it) to show that is true?
# Appending os.path.sep to ensure that eg. restricted path 'west/' and | ||
# 'west-ext/' common prefix does not match on the restricted path 'west/' | ||
restricted_path += os.path.sep | ||
if os.path.commonprefix([restricted_path, path + os.path.sep]) is restricted_path: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings need to be compared with ==
, not is
.
Does this really apply now @tejlmand ? |
Good question. Will push an update, if we still consider this relevant. |
Sure, we could restrict people from using |
Should we close this for now until we're ready to revisit? We still have the issue open, so we won't forget. |
@tejlmand ping? |
I'm going to close this for now so it doesn't keep showing up in the slack channel's pull reminders, as it's the only one that is currently doing that. Please reopen if you'd like. |
Fixes: #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.:
while still allowing folders, such as:
as project folder.
Signed-off-by: Torsten Rasmussen torsten.rasmussen@nordicsemi.no