[clang] 10851f9 - [analyzer][tests] Fix SATest update functionality

Valeriy Savchenko via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 3 08:21:53 PDT 2020


Author: Valeriy Savchenko
Date: 2020-08-03T18:21:15+03:00
New Revision: 10851f9db5f7d163135374b8dfc945e1b4a9c7d6

URL: https://github.com/llvm/llvm-project/commit/10851f9db5f7d163135374b8dfc945e1b4a9c7d6
DIFF: https://github.com/llvm/llvm-project/commit/10851f9db5f7d163135374b8dfc945e1b4a9c7d6.diff

LOG: [analyzer][tests] Fix SATest update functionality

Summary:
Not all projects in the project map file might have newer results
for updating, we should handle this situation gracefully.

Additionally, not every user of the test system would want storing
reference results in git.  For this reason, git functionality is now
optional.

Differential Revision: https://reviews.llvm.org/D84303

Added: 
    

Modified: 
    clang/utils/analyzer/SATest.py
    clang/utils/analyzer/SATestUpdateDiffs.py

Removed: 
    


################################################################################
diff  --git a/clang/utils/analyzer/SATest.py b/clang/utils/analyzer/SATest.py
index 46e636ad2895..86571902502f 100755
--- a/clang/utils/analyzer/SATest.py
+++ b/clang/utils/analyzer/SATest.py
@@ -78,7 +78,7 @@ def update(parser, args):
 
     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 @@ def main():
         "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
index 920fa15e4c6f..69b3383beaf1 100644
--- 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 @@ def update_reference_results(project: ProjectInfo):
     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 @@ def run_cmd(command: str):
         # 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 @@ def run_cmd(command: str):
         # Clean up the generated 
diff erence 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)


        


More information about the cfe-commits mailing list