Fixes: #8210 Following changes has been made to ensure correct behavior on different system: - Python script to detect changes to directories, including empty ones. When files are modified the list is updated If sub-directories are added / removed a trigger file is touched to notify cmake to re-run - Windows: To detect changes to header files in include for parse_syscalls.py all files must be individual monitored. Hence all headers are globbed added to dependencies. CMake configure depends on the folders so the added / removed files are picked up. - Other: Folders are monitored through the python list file so that added / remove / modified Added / removed sub-directories are detected through trigger file in order to re-run cmake. Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import argparse
|
|
|
|
def touch(trigger):
|
|
# If no trigger file is provided then do a return.
|
|
if(trigger is None):
|
|
return
|
|
|
|
if os.path.exists(trigger):
|
|
os.utime(trigger, None)
|
|
else:
|
|
with open(trigger, 'w') as fp:
|
|
fp.write("")
|
|
|
|
|
|
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.')
|
|
|
|
parser.add_argument('-d', '--directory', required=True,
|
|
help='Directory to walk for sub-directory discovery')
|
|
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,
|
|
help='Trigger file to be be touched to re-run CMake')
|
|
|
|
args = parser.parse_args()
|
|
|
|
dirlist = []
|
|
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))
|
|
dirlist.extend(os.linesep)
|
|
|
|
new = ''.join(dirlist)
|
|
existing = ''
|
|
|
|
if os.path.exists(args.out_file):
|
|
with open(args.out_file, 'r') as fp:
|
|
existing = fp.read()
|
|
|
|
if new != existing:
|
|
touch(args.trigger_file)
|
|
|
|
# Always write the file to ensure dependencies to changed files are updated
|
|
with open(args.out_file, 'w') as fp:
|
|
fp.write(new)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|