twister: add option to create shorter build paths
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 shorter one like: "twister_links/test_0". Fixes #41929 Signed-off-by: Piotr Golyzniak <piotr.golyzniak@nordicsemi.no>
This commit is contained in:
parent
1563b2c990
commit
b618f4bf8e
2 changed files with 60 additions and 1 deletions
|
@ -2812,6 +2812,9 @@ class TestSuite(DisablePyTestCollectionMixin):
|
|||
# run integration tests only
|
||||
self.integration = False
|
||||
|
||||
# used during creating shorter build paths
|
||||
self.link_dir_counter = 0
|
||||
|
||||
self.pipeline = None
|
||||
self.version = "NA"
|
||||
|
||||
|
@ -3898,6 +3901,48 @@ class TestSuite(DisablePyTestCollectionMixin):
|
|||
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. Those links will be passed in the next
|
||||
steps to the CMake command.
|
||||
"""
|
||||
|
||||
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 created link. This link will be passed to CMake
|
||||
command. This action helps to limit path length which can be
|
||||
significant during building by CMake on Windows OS.
|
||||
"""
|
||||
|
||||
os.makedirs(instance.build_dir, exist_ok=True)
|
||||
|
||||
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}"]
|
||||
subprocess.call(command, shell=True)
|
||||
else: # for Linux and MAC OS
|
||||
os.symlink(instance.build_dir, link_path)
|
||||
|
||||
# Here original build directory is replaced with symbolic link. It will
|
||||
# be passed to CMake command
|
||||
instance.build_dir = link_path
|
||||
|
||||
self.link_dir_counter += 1
|
||||
|
||||
|
||||
class CoverageTool:
|
||||
""" Base class for every supported coverage tool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue