cmake: Using symlinks on unix like os'es for dependencies
Fixes: #8380
This commit fixes the side-effect of PR #8211 where a 'ninja clean'
would try to remove dependency folders.
Changes:
- Symlinks are created during build and CMake targets now depends on
the symlinks. Thus, same behavior is achived with regards to
dependency handling, while at the same time, the output can be
cleaned as the dependencies are now attached to the symlinks.
- Dependencies have been changed so that generation of json files
depends on the trigger file and CMake depends upon the subdir txt
file. This prevents additional CMake runs after a clean.
Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
diff --git a/scripts/subfolder_list.py b/scripts/subfolder_list.py
index 252db4a..7c71c68 100644
--- a/scripts/subfolder_list.py
+++ b/scripts/subfolder_list.py
@@ -24,6 +24,8 @@
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')
parser.add_argument('-o', '--out-file', required=True,
help='File to write containing a list of all directories found')
parser.add_argument('-t', '--trigger-file', required=False,
@@ -32,11 +34,27 @@
args = parser.parse_args()
dirlist = []
- dirlist.extend(args.directory)
+ if(args.create_links is not None):
+ 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, '_')
+ if not os.path.exists(symlink):
+ os.symlink(directory, symlink)
+ dirlist.extend(symlink)
+ else:
+ dirlist.extend(args.directory)
dirlist.extend(os.linesep)
for root, dirs, files in os.walk(args.directory):
for subdir in dirs:
- dirlist.extend(os.path.join(root, subdir))
+ 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, '_')
+ if not os.path.exists(symlink):
+ os.symlink(directory, symlink)
+ dirlist.extend(symlink)
+ else:
+ dirlist.extend(os.path.join(root, subdir))
dirlist.extend(os.linesep)
new = ''.join(dirlist)
@@ -46,13 +64,15 @@
with open(args.out_file, 'r') as fp:
existing = fp.read()
- if new != existing:
- touch(args.trigger_file)
+ if new != existing:
+ with open(args.out_file, 'w') as fp:
+ fp.write(new)
+ else:
+ with open(args.out_file, 'w') as fp:
+ fp.write(new)
- # Always write the file to ensure dependencies to changed files are updated
- with open(args.out_file, 'w') as fp:
- fp.write(new)
-
+ # Always touch trigger file to ensure json files are updated
+ touch(args.trigger_file)
if __name__ == "__main__":
main()