blob: 9d0919345182fcba13b3a90454ec6330fe9dbb8c [file] [log] [blame]
Anna Zaksf0c41162011-10-06 23:26:27 +00001#!/usr/bin/env python
2
3"""
Ted Kremenek3a0678e2015-09-08 03:50:52 +00004Static Analyzer qualification infrastructure: adding a new project to
Anna Zaksf0c41162011-10-06 23:26:27 +00005the 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 Kremenek3a0678e2015-09-08 03:50:52 +00009 The project directory should be added inside the Repository Directory and
Anna Zaksf0c41162011-10-06 23:26:27 +000010 have the same name as the project ID
Ted Kremenek3a0678e2015-09-08 03:50:52 +000011
Anna Zaksf0c41162011-10-06 23:26:27 +000012 The project should use the following files for set up:
Devin Coughlin2cb767d2015-11-07 18:27:35 +000013 - cleanup_run_static_analyzer.sh - prepare the build environment.
Anna Zaksf0c41162011-10-06 23:26:27 +000014 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 Kremenek3a0678e2015-09-08 03:50:52 +000017 Choose from: configure, make, xcodebuild
Devin Coughlin2cb767d2015-11-07 18:27:35 +000018 - 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 Karpenkova8076602017-10-02 17:59:12 +000030 - changes_for_analyzer.patch - An optional patch file for any local
31 changes
Devin Coughlin2cb767d2015-11-07 18:27:35 +000032 (e.g., to adapt to newer version of clang)
33 that should be applied to CachedSource
34 before analysis. To construct this patch,
Hiroshi Inoue56939f72018-01-22 07:44:38 +000035 run the download script to download
Devin Coughlin2cb767d2015-11-07 18:27:35 +000036 the project to CachedSource, copy the
37 CachedSource to another directory (for
George Karpenkova8076602017-10-02 17:59:12 +000038 example, PatchedSource) and make any
Hiroshi Inoue56939f72018-01-22 07:44:38 +000039 needed modifications to the copied
George Karpenkova8076602017-10-02 17:59:12 +000040 source.
Devin Coughlin2cb767d2015-11-07 18:27:35 +000041 Then run:
42 diff -ur CachedSource PatchedSource \
43 > changes_for_analyzer.patch
Anna Zaksf0c41162011-10-06 23:26:27 +000044"""
45import SATestBuild
Valeriy Savchenkofb4b5652020-06-01 17:15:38 +030046from ProjectMap import ProjectMap, ProjectInfo
Anna Zaksf0c41162011-10-06 23:26:27 +000047
Valeriy Savchenko4902ca62020-05-21 18:28:36 +030048import os
Anna Zaksf0c41162011-10-06 23:26:27 +000049import sys
50
George Karpenkova8076602017-10-02 17:59:12 +000051
Valeriy Savchenko4a7b3d42020-06-02 18:21:45 +030052def add_new_project(project: ProjectInfo):
George Karpenkova8076602017-10-02 17:59:12 +000053 """
54 Add a new project for testing: build it and add to the Project Map file.
Valeriy Savchenko4902ca62020-05-21 18:28:36 +030055 :param name: is a short string used to identify a project.
George Karpenkova8076602017-10-02 17:59:12 +000056 """
57
Valeriy Savchenko4a7b3d42020-06-02 18:21:45 +030058 test_info = SATestBuild.TestInfo(project,
Valeriy Savchenkofb4b5652020-06-01 17:15:38 +030059 is_reference_build=True)
60 tester = SATestBuild.ProjectTester(test_info)
Valeriy Savchenko4902ca62020-05-21 18:28:36 +030061
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 Zaksf0c41162011-10-06 23:26:27 +000065 sys.exit(-1)
Ted Kremenek3a0678e2015-09-08 03:50:52 +000066
Anna Zaksf0c41162011-10-06 23:26:27 +000067 # Build the project.
Valeriy Savchenko4902ca62020-05-21 18:28:36 +030068 tester.test()
Anna Zaksf0c41162011-10-06 23:26:27 +000069
Valeriy Savchenko4902ca62020-05-21 18:28:36 +030070 # Add the project name to the project map.
Valeriy Savchenkofb4b5652020-06-01 17:15:38 +030071 project_map = ProjectMap(should_exist=False)
George Karpenkova8076602017-10-02 17:59:12 +000072
Valeriy Savchenko4a7b3d42020-06-02 18:21:45 +030073 if is_existing_project(project_map, project):
74 print(f"Warning: Project with name '{project.name}' already exists.",
Valeriy Savchenkofb4b5652020-06-01 17:15:38 +030075 file=sys.stdout)
76 print("Reference output has been regenerated.", file=sys.stdout)
Anna Zaksf0c41162011-10-06 23:26:27 +000077 else:
Valeriy Savchenko4a7b3d42020-06-02 18:21:45 +030078 project_map.projects.append(project)
Valeriy Savchenkofb4b5652020-06-01 17:15:38 +030079 project_map.save()
Anna Zaksf0c41162011-10-06 23:26:27 +000080
Ted Kremenek3a0678e2015-09-08 03:50:52 +000081
Valeriy Savchenko4a7b3d42020-06-02 18:21:45 +030082def is_existing_project(project_map: ProjectMap, project: ProjectInfo) -> bool:
83 return any(existing_project.name == project.name
Valeriy Savchenkofb4b5652020-06-01 17:15:38 +030084 for existing_project in project_map.projects)
Valeriy Savchenko4902ca62020-05-21 18:28:36 +030085
86
Valeriy Savchenko4902ca62020-05-21 18:28:36 +030087if __name__ == "__main__":
Valeriy Savchenkod9944da2020-06-03 15:29:42 +030088 print("SATestAdd.py should not be used on its own.")
89 print("Please use 'SATest.py add' instead")
90 sys.exit(1)