From 874d6c574f910310d8a49d64f7e533b822f31b0c Mon Sep 17 00:00:00 2001 From: Noc <6710543+Noctunus@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:34:22 +0200 Subject: [PATCH] Added a new parameter --c4t-files to the dependency checker script. This new parameter expects a file which contains the proto files of the c4t branch, to detect whether a proto file with a certain version can be re-used instead of bumping up the version again needlessly. The file can be simply generated using the also added create_c4t_file_listing.sh script. Also added temp directory to the gitignore as by default the create_c4t_file_listing.sh will throw the listing in that directory. (#39) Co-authored-by: Noctunus --- .gitignore | 2 +- scripts/create_c4t_file_listing.sh | 8 ++++++++ scripts/dependency_checker.py | 28 +++++++++++++++++++++------- 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100755 scripts/create_c4t_file_listing.sh diff --git a/.gitignore b/.gitignore index 944c184..8514be9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ gen .vscode - +temp diff --git a/scripts/create_c4t_file_listing.sh b/scripts/create_c4t_file_listing.sh new file mode 100755 index 0000000..96e9ddf --- /dev/null +++ b/scripts/create_c4t_file_listing.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Simple helper script to just create a file which contains a listing of all the cmp proto files in the c4t branch +# This can then be used by the dependency checker to determine whether a new version of a proto file can be reused +# when it's not present in the c4t branch + +OUTFILE=${1:-temp/c4tfiles.txt} +git ls-tree -r --name-only origin/c4t proto/cmp | grep -oP "cmp/.*\.proto" > $OUTFILE diff --git a/scripts/dependency_checker.py b/scripts/dependency_checker.py index 9ce6a77..61fd219 100755 --- a/scripts/dependency_checker.py +++ b/scripts/dependency_checker.py @@ -31,17 +31,26 @@ def extract_command_line_args(): parser = argparse.ArgumentParser(description="Extract command line arguments") # Add the --print-graph and --fix flags - parser.add_argument('--print-graph', action='store_true', help="Enable graph printing") - parser.add_argument('--fix', action='store_true', help="Enable fix mode") + parser.add_argument('--print-graph', action='store_true', help="Enable graph printing ") + parser.add_argument('--fix', action='store_true', help="Enable fix mode which will try to fix the dependencies") + + # Add the --c4t-files argument, which takes a file input + parser.add_argument('--c4t-files', type=argparse.FileType('r'), help="File containing filenames of existing files in the c4t branch to decide the latest version for the --fix mode. The file can be generated by using the create_c4t_file_listing.sh script.") # Parse the arguments args = parser.parse_args() - # Extract the values of the flags + # Extract the values of the flags and file content print_graph = args.print_graph fix = args.fix + c4t_files = [] + + # If the --c4t-files argument is provided, read and store the filenames into an array + if args.c4t_files: + with args.c4t_files as file: + c4t_files = [line.strip() for line in file] # Strip out newline characters - return print_graph, fix + return print_graph, fix, c4t_files def find_latest_version(old_file, recent_files): match = file_pattern.match(old_file) @@ -110,7 +119,7 @@ def extract_proto_includes(proto_file_path): return includes -print_graph, fix = extract_command_line_args() +print_graph, fix, c4tfiles = extract_command_line_args() fixed_new_version_files = [] directory_path = "proto/" @@ -213,8 +222,13 @@ def print_dependency_graph(dep_dict): include_fixes.append( (wrong_include, correct_include) ) # First we need to create a new file with version+1 where we can make the changes - # But first let's check if the file has already been created in a previous iteration and just reuse it - if file in fixed_new_version_files: + # But first let's check some things: + # * If the file is not present in the c4t branch we can just apply the changes directly, as no new version is needed in that case + # * If the file was created in a previous iteration we can also apply the changes directly + if c4tfiles.count != 0 and file not in c4tfiles: + print(f"💡 The file {file} is not present in the c4t branch, therefore apply the changes directly") + search_replace_in_file(directory_path + file, include_fixes) + elif file in fixed_new_version_files: print(f"♻️ The file {file} was created in a previous iteration, therefore apply the changes directly") search_replace_in_file(directory_path + file, include_fixes) else: