|
42 | 42 | diff -ur CachedSource PatchedSource \
|
43 | 43 | > changes_for_analyzer.patch
|
44 | 44 | """
|
45 |
| -from __future__ import absolute_import, division, print_function |
46 | 45 | import SATestBuild
|
47 | 46 |
|
48 |
| -import os |
49 | 47 | import csv
|
| 48 | +import os |
50 | 49 | import sys
|
51 | 50 |
|
| 51 | +from typing import IO |
52 | 52 |
|
53 |
| -def isExistingProject(PMapFile, projectID): |
54 |
| - PMapReader = csv.reader(PMapFile) |
55 |
| - for ProjectInfo in PMapReader: |
56 |
| - if projectID == ProjectInfo[0]: |
57 |
| - return True |
58 |
| - return False |
59 | 53 |
|
60 |
| - |
61 |
| -def addNewProject(ID, BuildMode): |
| 54 | +def add_new_project(name: str, build_mode: int): |
62 | 55 | """
|
63 | 56 | Add a new project for testing: build it and add to the Project Map file.
|
64 |
| - :param ID: is a short string used to identify a project. |
| 57 | + :param name: is a short string used to identify a project. |
65 | 58 | """
|
66 | 59 |
|
67 |
| - CurDir = os.path.abspath(os.curdir) |
68 |
| - Dir = SATestBuild.getProjectDir(ID) |
69 |
| - if not os.path.exists(Dir): |
70 |
| - print("Error: Project directory is missing: %s" % Dir) |
| 60 | + project_info = SATestBuild.ProjectInfo(name, build_mode, |
| 61 | + is_reference_build=True) |
| 62 | + tester = SATestBuild.ProjectTester(project_info) |
| 63 | + |
| 64 | + project_dir = tester.get_project_dir() |
| 65 | + if not os.path.exists(project_dir): |
| 66 | + print(f"Error: Project directory is missing: {project_dir}") |
71 | 67 | sys.exit(-1)
|
72 | 68 |
|
73 | 69 | # Build the project.
|
74 |
| - # TODO: Repair this call. We give it a wrong amount wrong arguments and it |
75 |
| - # is not trivial to construct argparse arguments in here. |
76 |
| - # Requires refactoring of the 'testProject' function. |
77 |
| - SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True) |
| 70 | + tester.test() |
78 | 71 |
|
79 |
| - # Add the project ID to the project map. |
80 |
| - ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) |
| 72 | + # Add the project name to the project map. |
| 73 | + project_map_path = SATestBuild.get_project_map_path(should_exist=False) |
81 | 74 |
|
82 |
| - if os.path.exists(ProjectMapPath): |
83 |
| - FileMode = "r+" |
| 75 | + if os.path.exists(project_map_path): |
| 76 | + file_mode = "r+" |
84 | 77 | else:
|
85 |
| - print("Warning: Creating the Project Map file!!") |
86 |
| - FileMode = "w+" |
| 78 | + print("Warning: Creating the project map file!") |
| 79 | + file_mode = "w+" |
87 | 80 |
|
88 |
| - with open(ProjectMapPath, FileMode) as PMapFile: |
89 |
| - if (isExistingProject(PMapFile, ID)): |
90 |
| - print('Warning: Project with ID \'', ID, |
91 |
| - '\' already exists.', file=sys.stdout) |
| 81 | + with open(project_map_path, file_mode) as map_file: |
| 82 | + if is_existing_project(map_file, name): |
| 83 | + print(f"Warning: Project with name '{name}' already exists.", |
| 84 | + file=sys.stdout) |
92 | 85 | print("Reference output has been regenerated.", file=sys.stdout)
|
93 | 86 | else:
|
94 |
| - PMapWriter = csv.writer(PMapFile) |
95 |
| - PMapWriter.writerow((ID, int(BuildMode))) |
96 |
| - print("The project map is updated: ", ProjectMapPath) |
| 87 | + map_writer = csv.writer(map_file) |
| 88 | + map_writer.writerow((name, build_mode)) |
| 89 | + print(f"The project map is updated: {project_map_path}") |
| 90 | + |
97 | 91 |
|
| 92 | +def is_existing_project(map_file: IO, project_name: str) -> bool: |
| 93 | + map_reader = csv.reader(map_file) |
98 | 94 |
|
| 95 | + for raw_info in map_reader: |
| 96 | + if project_name == raw_info[0]: |
| 97 | + return True |
| 98 | + |
| 99 | + return False |
| 100 | + |
| 101 | + |
| 102 | +# TODO: Use argparse |
99 | 103 | # TODO: Add an option not to build.
|
100 | 104 | # TODO: Set the path to the Repository directory.
|
101 |
| -if __name__ == '__main__': |
102 |
| - if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'): |
103 |
| - print('Add a new project for testing to the analyzer' |
104 |
| - '\nUsage: ', sys.argv[0], |
105 |
| - 'project_ID <mode>\n' |
106 |
| - 'mode: 0 for single file project, ' |
107 |
| - '1 for scan_build, ' |
108 |
| - '2 for single file c++11 project', file=sys.stderr) |
| 105 | +if __name__ == "__main__": |
| 106 | + if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help"): |
| 107 | + print("Add a new project for testing to the analyzer" |
| 108 | + "\nUsage: ", sys.argv[0], |
| 109 | + "project_ID <mode>\n" |
| 110 | + "mode: 0 for single file project, " |
| 111 | + "1 for scan_build, " |
| 112 | + "2 for single file c++11 project", file=sys.stderr) |
109 | 113 | sys.exit(-1)
|
110 | 114 |
|
111 |
| - BuildMode = 1 |
112 |
| - if (len(sys.argv) >= 3): |
113 |
| - BuildMode = int(sys.argv[2]) |
114 |
| - assert((BuildMode == 0) | (BuildMode == 1) | (BuildMode == 2)) |
| 115 | + build_mode = 1 |
| 116 | + if len(sys.argv) >= 3: |
| 117 | + build_mode = int(sys.argv[2]) |
| 118 | + |
| 119 | + assert((build_mode == 0) | (build_mode == 1) | (build_mode == 2)) |
115 | 120 |
|
116 |
| - addNewProject(sys.argv[1], BuildMode) |
| 121 | + add_new_project(sys.argv[1], build_mode) |
0 commit comments