Skip to content

Commit

Permalink
python: subfolder_list.py now generates shorter link names
Browse files Browse the repository at this point in the history
Fixes: zephyrproject-rtos#24576

The name of the symbolic link would be constructed using the full path
name to the target folder.

This is not needed and caused the issue raised in zephyrproject-rtos#24576.

This has been fixed by no longer using the toplevel target directory
in the link name, for example:
Old style: _project_zephyr_workspace_zephyr_include_sys
New style: include_sys

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
  • Loading branch information
tejlmand authored and Sandeep Tripathy committed Apr 30, 2020
1 parent 0324415 commit 0b203d4
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions scripts/subfolder_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import argparse


def touch(trigger):
# If no trigger file is provided then do a return.
if trigger is None:
Expand All @@ -18,17 +19,20 @@ def touch(trigger):

def main():
parser = argparse.ArgumentParser(
description='This script will walk the specified directory and write the file specified \
with the list of all sub-directories found. If to the output file already \
exists, the file will only be updated in case sub-directories has been added \
or removed since previous invocation.')
description='This script will walk the specified directory and write \
the file specified with the list of all sub-directories \
found. If to the output file already exists, the file \
will only be updated in case sub-directories has been \
added or removed since previous invocation.')

parser.add_argument('-d', '--directory', required=True,
help='Directory to walk for sub-directory discovery')
parser.add_argument('-c', '--create-links', required=False,
help='Create links for each directory found in directory given')
help='Create links for each directory found in \
directory given')
parser.add_argument('-o', '--out-file', required=True,
help='File to write containing a list of all directories found')
help='File to write containing a list of all \
directories found')
parser.add_argument('-t', '--trigger-file', required=False,
help='Trigger file to be be touched to re-run CMake')

Expand All @@ -39,7 +43,8 @@ def main():
if not os.path.exists(args.create_links):
os.makedirs(args.create_links)
directory = args.directory
symlink = args.create_links + os.path.sep + directory.replace(os.path.sep, '_')
symbase = os.path.basename(directory)
symlink = args.create_links + os.path.sep + symbase
if not os.path.exists(symlink):
os.symlink(directory, symlink)
dirlist.extend(symlink)
Expand All @@ -50,16 +55,18 @@ def main():
dirs.sort()
for subdir in dirs:
if args.create_links is not None:
directory = os.path.join(root, subdir)
symlink = args.create_links + os.path.sep + directory.replace(os.path.sep, '_')
targetdirectory = os.path.join(root, subdir)
reldir = os.path.relpath(targetdirectory, directory)
linkname = symbase + '_' + reldir.replace(os.path.sep, '_')
symlink = args.create_links + os.path.sep + linkname
if not os.path.exists(symlink):
os.symlink(directory, symlink)
os.symlink(targetdirectory, symlink)
dirlist.extend(symlink)
else:
dirlist.extend(os.path.join(root, subdir))
dirlist.extend(os.linesep)

new = ''.join(dirlist)
new = ''.join(dirlist)
existing = ''

if os.path.exists(args.out_file):
Expand All @@ -76,5 +83,6 @@ def main():
# Always touch trigger file to ensure json files are updated
touch(args.trigger_file)


if __name__ == "__main__":
main()

0 comments on commit 0b203d4

Please sign in to comment.