Skip to content
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

tools/compile_and_test_for_board: assert resultdir is valid #11516

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -190,6 +190,24 @@ def create_directory(directory, clean=False, mode=0o755):
os.makedirs(directory, mode=mode, exist_ok=True)


def is_in_directory(path, directory):
"""Return if `path` is inside `directory`.

>>> is_in_directory('RIOT/a/b/c', 'RIOT')
True
>>> is_in_directory('RIOT/../a', 'RIOT')
False

# Also work if path is absolute but not the directory
>>> curdir = os.path.abspath(os.curdir)
>>> is_in_directory(os.path.join(curdir, 'RIOT', 'a'), 'RIOT')
True
"""
directory = os.path.abspath(directory)
path = os.path.abspath(path)
return path.startswith(directory)


class RIOTApplication():
"""RIOT Application representation.

Expand All @@ -214,6 +232,10 @@ def __init__(self, board, riotdir, appdir, resultdir):
self.resultdir = os.path.join(resultdir, appdir)
self.logger = logging.getLogger('%s.%s' % (board, appdir))

# Currently not handling absolute directories or outside of RIOT
assert is_in_directory(self.resultdir, resultdir), \
"Application result directory is outside main result directory"

# Extract values from make
def name(self):
"""Get application name."""
Expand Down