Skip to content

Commit

Permalink
Added a new parameter --c4t-files to the dependency checker script.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
2 people authored and mo-c4t committed Sep 20, 2024
1 parent b08c1cf commit 874d6c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gen
.vscode

temp
8 changes: 8 additions & 0 deletions scripts/create_c4t_file_listing.sh
Original file line number Diff line number Diff line change
@@ -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
28 changes: 21 additions & 7 deletions scripts/dependency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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/"

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 874d6c5

Please sign in to comment.