From 3c955a10c358f73a07ef627768e6154eea2d7334 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Sat, 2 Sep 2023 12:59:18 +0200 Subject: [PATCH 1/2] Framework: Fix issue with detect-mpi-comm-world.yml when base branch is out of sync with origin/develop --- .../test/utilities/check-mpi-comm-world-usage.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/commonTools/test/utilities/check-mpi-comm-world-usage.py b/commonTools/test/utilities/check-mpi-comm-world-usage.py index 81a6776f7d3d..680cabb1aa34 100644 --- a/commonTools/test/utilities/check-mpi-comm-world-usage.py +++ b/commonTools/test/utilities/check-mpi-comm-world-usage.py @@ -67,6 +67,9 @@ def parse_diff_output(changed_files): return files +def get_common_ancestor(target_branch, feature_branch): + cmd = ["git", "merge-base", target_branch, feature_branch] + return subprocess.check_output(cmd).decode("utf-8").strip() def get_changed_files_uncommitted(): """Get a dictionary of files and their changed lines where MPI_COMM_WORLD was added from uncommitted changes.""" @@ -75,10 +78,10 @@ def get_changed_files_uncommitted(): return parse_diff_output(result) - -def get_changed_files(start_commit, end_commit): - """Get a dictionary of files and their changed lines between two commits where MPI_COMM_WORLD was added.""" - cmd = ["git", "diff", "-U0", "--ignore-all-space", start_commit, end_commit] +def get_changed_files(target_branch, feature_branch): + """Get a dictionary of files and their changed lines between the common ancestor and feature_branch.""" + start_commit = get_common_ancestor(target_branch, feature_branch) + cmd = ["git", "diff", "-U0", "--ignore-all-space", start_commit, feature_branch, "--name-only"] result = subprocess.check_output(cmd).decode("utf-8") return parse_diff_output(result) From 28b83bd240cab4bfd0d583260c7737c37a2fce9d Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Sat, 2 Sep 2023 13:09:35 +0200 Subject: [PATCH 2/2] Framework: Remove check for uncommited changes from the check-mpi-comm-world-usage script, as it may provide incorrect output --- .../utilities/check-mpi-comm-world-usage.py | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/commonTools/test/utilities/check-mpi-comm-world-usage.py b/commonTools/test/utilities/check-mpi-comm-world-usage.py index 680cabb1aa34..827454ee1ab9 100644 --- a/commonTools/test/utilities/check-mpi-comm-world-usage.py +++ b/commonTools/test/utilities/check-mpi-comm-world-usage.py @@ -53,7 +53,6 @@ def parse_diff_output(changed_files): line_counter = 0 for line in lines: if line.startswith("+"): - line_counter += 1 if ( "MPI_COMM_WORLD" in line and not "CHECK: ALLOW MPI_COMM_WORLD" in line @@ -62,26 +61,30 @@ def parse_diff_output(changed_files): # and "CHECK: ALLOW MPI_COMM_WORLD" is not present changed_lines.append(start_line + line_counter) + line_counter += 1 + if changed_lines: files[file_name] = changed_lines return files + def get_common_ancestor(target_branch, feature_branch): cmd = ["git", "merge-base", target_branch, feature_branch] return subprocess.check_output(cmd).decode("utf-8").strip() -def get_changed_files_uncommitted(): - """Get a dictionary of files and their changed lines where MPI_COMM_WORLD was added from uncommitted changes.""" - cmd = ["git", "diff", "-U0", "--ignore-all-space", "HEAD"] - result = subprocess.check_output(cmd).decode("utf-8") - - return parse_diff_output(result) def get_changed_files(target_branch, feature_branch): """Get a dictionary of files and their changed lines between the common ancestor and feature_branch.""" start_commit = get_common_ancestor(target_branch, feature_branch) - cmd = ["git", "diff", "-U0", "--ignore-all-space", start_commit, feature_branch, "--name-only"] + cmd = [ + "git", + "diff", + "-U0", + "--ignore-all-space", + start_commit, + feature_branch + ] result = subprocess.check_output(cmd).decode("utf-8") return parse_diff_output(result) @@ -112,21 +115,12 @@ def print_occurences(changed_files, title): end_commit = parser.parse_args().head print(f"End commit: {end_commit}") - commited_occurences = get_changed_files(start_commit, end_commit) - uncommited_occurences = get_changed_files_uncommitted() - - mpi_comm_world_detected = commited_occurences or uncommited_occurences + mpi_comm_world_detected = get_changed_files(start_commit, end_commit) if mpi_comm_world_detected: - if commited_occurences: - print_occurences( - commited_occurences, "Detected MPI_COMM_WORLD in the following files:" - ) - if uncommited_occurences: - print_occurences( - uncommited_occurences, - "Detected MPI_COMM_WORLD in the following files (uncommited changes):", - ) + print_occurences( + mpi_comm_world_detected, "Detected MPI_COMM_WORLD in the following files:" + ) sys.exit(1) # Exit with an error code to fail the GitHub Action else: