Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 4 | Static Analyzer qualification infrastructure: adding a new project to |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 5 | the Repository Directory. |
| 6 | |
| 7 | Add a new project for testing: build it and add to the Project Map file. |
| 8 | Assumes it's being run from the Repository Directory. |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 9 | The project directory should be added inside the Repository Directory and |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 10 | have the same name as the project ID |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 11 | |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 12 | The project should use the following files for set up: |
Devin Coughlin | 2cb767d | 2015-11-07 18:27:35 +0000 | [diff] [blame] | 13 | - cleanup_run_static_analyzer.sh - prepare the build environment. |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 14 | Ex: make clean can be a part of it. |
| 15 | - run_static_analyzer.cmd - a list of commands to run through scan-build. |
| 16 | Each command should be on a separate line. |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 17 | Choose from: configure, make, xcodebuild |
Devin Coughlin | 2cb767d | 2015-11-07 18:27:35 +0000 | [diff] [blame] | 18 | - download_project.sh - download the project into the CachedSource/ |
| 19 | directory. For example, download a zip of |
| 20 | the project source from GitHub, unzip it, |
| 21 | and rename the unzipped directory to |
| 22 | 'CachedSource'. This script is not called |
| 23 | when 'CachedSource' is already present, |
| 24 | so an alternative is to check the |
| 25 | 'CachedSource' directory into the |
| 26 | repository directly. |
| 27 | - CachedSource/ - An optional directory containing the source of the |
| 28 | project being analyzed. If present, |
| 29 | download_project.sh will not be called. |
George Karpenkov | a807660 | 2017-10-02 17:59:12 +0000 | [diff] [blame] | 30 | - changes_for_analyzer.patch - An optional patch file for any local |
| 31 | changes |
Devin Coughlin | 2cb767d | 2015-11-07 18:27:35 +0000 | [diff] [blame] | 32 | (e.g., to adapt to newer version of clang) |
| 33 | that should be applied to CachedSource |
| 34 | before analysis. To construct this patch, |
Hiroshi Inoue | 56939f7 | 2018-01-22 07:44:38 +0000 | [diff] [blame] | 35 | run the download script to download |
Devin Coughlin | 2cb767d | 2015-11-07 18:27:35 +0000 | [diff] [blame] | 36 | the project to CachedSource, copy the |
| 37 | CachedSource to another directory (for |
George Karpenkov | a807660 | 2017-10-02 17:59:12 +0000 | [diff] [blame] | 38 | example, PatchedSource) and make any |
Hiroshi Inoue | 56939f7 | 2018-01-22 07:44:38 +0000 | [diff] [blame] | 39 | needed modifications to the copied |
George Karpenkov | a807660 | 2017-10-02 17:59:12 +0000 | [diff] [blame] | 40 | source. |
Devin Coughlin | 2cb767d | 2015-11-07 18:27:35 +0000 | [diff] [blame] | 41 | Then run: |
| 42 | diff -ur CachedSource PatchedSource \ |
| 43 | > changes_for_analyzer.patch |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 44 | """ |
| 45 | import SATestBuild |
Valeriy Savchenko | fb4b565 | 2020-06-01 17:15:38 +0300 | [diff] [blame] | 46 | from ProjectMap import ProjectMap, ProjectInfo |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 47 | |
Valeriy Savchenko | 4902ca6 | 2020-05-21 18:28:36 +0300 | [diff] [blame] | 48 | import os |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 49 | import sys |
| 50 | |
George Karpenkov | a807660 | 2017-10-02 17:59:12 +0000 | [diff] [blame] | 51 | |
Valeriy Savchenko | 4a7b3d4 | 2020-06-02 18:21:45 +0300 | [diff] [blame] | 52 | def add_new_project(project: ProjectInfo): |
George Karpenkov | a807660 | 2017-10-02 17:59:12 +0000 | [diff] [blame] | 53 | """ |
| 54 | Add a new project for testing: build it and add to the Project Map file. |
Valeriy Savchenko | 4902ca6 | 2020-05-21 18:28:36 +0300 | [diff] [blame] | 55 | :param name: is a short string used to identify a project. |
George Karpenkov | a807660 | 2017-10-02 17:59:12 +0000 | [diff] [blame] | 56 | """ |
| 57 | |
Valeriy Savchenko | 4a7b3d4 | 2020-06-02 18:21:45 +0300 | [diff] [blame] | 58 | test_info = SATestBuild.TestInfo(project, |
Valeriy Savchenko | fb4b565 | 2020-06-01 17:15:38 +0300 | [diff] [blame] | 59 | is_reference_build=True) |
| 60 | tester = SATestBuild.ProjectTester(test_info) |
Valeriy Savchenko | 4902ca6 | 2020-05-21 18:28:36 +0300 | [diff] [blame] | 61 | |
| 62 | project_dir = tester.get_project_dir() |
| 63 | if not os.path.exists(project_dir): |
| 64 | print(f"Error: Project directory is missing: {project_dir}") |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 65 | sys.exit(-1) |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 66 | |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 67 | # Build the project. |
Valeriy Savchenko | 4902ca6 | 2020-05-21 18:28:36 +0300 | [diff] [blame] | 68 | tester.test() |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 69 | |
Valeriy Savchenko | 4902ca6 | 2020-05-21 18:28:36 +0300 | [diff] [blame] | 70 | # Add the project name to the project map. |
Valeriy Savchenko | fb4b565 | 2020-06-01 17:15:38 +0300 | [diff] [blame] | 71 | project_map = ProjectMap(should_exist=False) |
George Karpenkov | a807660 | 2017-10-02 17:59:12 +0000 | [diff] [blame] | 72 | |
Valeriy Savchenko | 4a7b3d4 | 2020-06-02 18:21:45 +0300 | [diff] [blame] | 73 | if is_existing_project(project_map, project): |
| 74 | print(f"Warning: Project with name '{project.name}' already exists.", |
Valeriy Savchenko | fb4b565 | 2020-06-01 17:15:38 +0300 | [diff] [blame] | 75 | file=sys.stdout) |
| 76 | print("Reference output has been regenerated.", file=sys.stdout) |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 77 | else: |
Valeriy Savchenko | 4a7b3d4 | 2020-06-02 18:21:45 +0300 | [diff] [blame] | 78 | project_map.projects.append(project) |
Valeriy Savchenko | fb4b565 | 2020-06-01 17:15:38 +0300 | [diff] [blame] | 79 | project_map.save() |
Anna Zaks | f0c4116 | 2011-10-06 23:26:27 +0000 | [diff] [blame] | 80 | |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 81 | |
Valeriy Savchenko | 4a7b3d4 | 2020-06-02 18:21:45 +0300 | [diff] [blame] | 82 | def is_existing_project(project_map: ProjectMap, project: ProjectInfo) -> bool: |
| 83 | return any(existing_project.name == project.name |
Valeriy Savchenko | fb4b565 | 2020-06-01 17:15:38 +0300 | [diff] [blame] | 84 | for existing_project in project_map.projects) |
Valeriy Savchenko | 4902ca6 | 2020-05-21 18:28:36 +0300 | [diff] [blame] | 85 | |
| 86 | |
Valeriy Savchenko | 4902ca6 | 2020-05-21 18:28:36 +0300 | [diff] [blame] | 87 | if __name__ == "__main__": |
Valeriy Savchenko | d9944da | 2020-06-03 15:29:42 +0300 | [diff] [blame] | 88 | print("SATestAdd.py should not be used on its own.") |
| 89 | print("Please use 'SATest.py add' instead") |
| 90 | sys.exit(1) |