Skip to content

Commit

Permalink
twister: add option to create shorter build paths
Browse files Browse the repository at this point in the history
Add possibility to create shorter build paths when --short-build-path
option is enabled. This can help during run Twister on Windows OS and
building programs by CMake which has a problem when paths with building
files are too long. The solution based on symbolic links which help to
connect "traditional" long paths with shorther one like:
"twister_links/test_0".

Fixes zephyrproject-rtos#41929

Signed-off-by: Piotr Golyzniak <piotr.golyzniak@nordicsemi.no>
  • Loading branch information
gopiotr committed Feb 7, 2022
1 parent c025abd commit 9198169
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
45 changes: 45 additions & 0 deletions scripts/pylib/twister/twisterlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,9 @@ def __init__(self, board_root_list=[], testcase_roots=[], outdir=None):
# run integration tests only
self.integration = False

# used during creating shorter build paths
self.link_dir_counter = 0

self.pipeline = None
self.version = "NA"

Expand Down Expand Up @@ -3876,6 +3879,48 @@ def verify_platforms_existence(self, platform_names_to_verify, log_info=""):
logger.error(f"{log_info} - unrecognized platform - {platform}")
sys.exit(2)

def create_build_dir_links(self):
"""
Iterate through all no-skipped instances in suite and create links
for each one build directories
"""

links_dir_name = "twister_links" # folder for all links
links_dir_path = os.path.join(self.outdir, links_dir_name)
if not os.path.exists(links_dir_path):
os.mkdir(links_dir_path)

for instance in self.instances.values():
if instance.status != "skipped":
self._create_build_dir_link(links_dir_path, instance)

def _create_build_dir_link(self, links_dir_path, instance):
"""
Create build directory with original "long" path. Next take shorter
path and link them with original path - create link. At the end
replace build_dir to shorter path. This action helps to limit path
length which can be significant during building by CMake on Windows
OS.
"""

os.makedirs(instance.build_dir)

link_name = f"test_{self.link_dir_counter}"
link_path = os.path.join(links_dir_path, link_name)

if os.name == "nt": # if OS is Windows
command = ["mklink", "/J", f"{link_path}", f"{instance.build_dir}"]
shell_option = True
else: # for Linux and MAC OS
command = ["ln", "-s", f"{instance.build_dir}", f"{link_path}"]
shell_option = False

subprocess.call(command, shell=shell_option)

instance.build_dir = link_path

self.link_dir_counter += 1


class CoverageTool:
""" Base class for every supported coverage tool
Expand Down
10 changes: 10 additions & 0 deletions scripts/twister
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,13 @@ structure in the main Zephyr tree: boards/<arch>/<board_name>/""")
help="Execute time-consuming test cases that have been marked "
"as 'slow' in testcase.yaml. Normally these are only built.")

parser.add_argument(
"--short-build-path",
action="store_true",
help="Create shorter build directory paths based on symbolic links. "
"This option can be useful on Windows OS where path length limit "
"occurs.")

parser.add_argument(
"--show-footprint", action="store_true",
help="Show footprint statistics and deltas since last release."
Expand Down Expand Up @@ -1236,6 +1243,9 @@ def main():
logger.info("Completed in %d seconds" % (duration))
return

if options.short_build_path:
suite.create_build_dir_links()

retries = options.retry_failed + 1
completed = 0

Expand Down

0 comments on commit 9198169

Please sign in to comment.