diff --git a/clang/utils/analyzer/SATest.py b/clang/utils/analyzer/SATest.py --- a/clang/utils/analyzer/SATest.py +++ b/clang/utils/analyzer/SATest.py @@ -78,7 +78,7 @@ project_map = ProjectMap() for project in project_map.projects: - SATestUpdateDiffs.update_reference_results(project) + SATestUpdateDiffs.update_reference_results(project, args.git) def benchmark(parser, args): @@ -277,7 +277,8 @@ "update", help="Update static analyzer reference results based on the previous " "run of SATest build. Assumes that SATest build was just run.") - # TODO: add option to decide whether we should use git + upd_parser.add_argument("--git", action="store_true", + help="Stage updated results using git.") upd_parser.set_defaults(func=update) # docker subcommand diff --git a/clang/utils/analyzer/SATestUpdateDiffs.py b/clang/utils/analyzer/SATestUpdateDiffs.py --- a/clang/utils/analyzer/SATestUpdateDiffs.py +++ b/clang/utils/analyzer/SATestUpdateDiffs.py @@ -15,7 +15,7 @@ Verbose = 0 -def update_reference_results(project: ProjectInfo): +def update_reference_results(project: ProjectInfo, git: bool = False): test_info = SATestBuild.TestInfo(project) tester = SATestBuild.ProjectTester(test_info) project_dir = tester.get_project_dir() @@ -27,9 +27,10 @@ created_results_path = tester.get_output_dir() if not os.path.exists(created_results_path): - print("New results not found, was SATestBuild.py previously run?", + print(f"Skipping project '{project.name}', " + f"it doesn't have newer results.", file=sys.stderr) - sys.exit(1) + return build_log_path = SATestBuild.get_build_log_path(ref_results_path) build_log_dir = os.path.dirname(os.path.abspath(build_log_path)) @@ -45,7 +46,8 @@ # Remove reference results: in git, and then again for a good measure # with rm, as git might not remove things fully if there are empty # directories involved. - run_cmd(f"git rm -r -q '{ref_results_path}'") + if git: + run_cmd(f"git rm -r -q '{ref_results_path}'") shutil.rmtree(ref_results_path) # Replace reference results with a freshly computed once. @@ -60,22 +62,11 @@ # Clean up the generated difference results. SATestBuild.cleanup_reference_results(ref_results_path) - run_cmd(f"git add '{ref_results_path}'") + if git: + run_cmd(f"git add '{ref_results_path}'") -# TODO: use argparse -def main(argv): - if len(argv) == 2 and argv[1] in ("-h", "--help"): - print("Update static analyzer reference results based " - "\non the previous run of SATestBuild.py.\n" - "\nN.B.: Assumes that SATestBuild.py was just run", - file=sys.stderr) - sys.exit(1) - - project_map = ProjectMap() - for project in project_map.projects: - update_reference_results(project) - - -if __name__ == '__main__': - main(sys.argv) +if __name__ == "__main__": + print("SATestUpdateDiffs.py should not be used on its own.") + print("Please use 'SATest.py update' instead") + sys.exit(1)