def addNewProject(ID, BuildMode): """ Add a new project for testing: build it and add to the Project Map file. :param ID: is a short string used to identify a project. """ CurDir = os.path.abspath(os.curdir) Dir = SATestBuild.getProjectDir(ID) if not os.path.exists(Dir): print "Error: Project directory is missing: %s" % Dir sys.exit(-1) # Build the project. SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True) # Add the project ID to the project map. ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) if os.path.exists(ProjectMapPath): FileMode = "r+b" else: print "Warning: Creating the Project Map file!!" FileMode = "w+b" with open(ProjectMapPath, FileMode) as PMapFile: if (isExistingProject(PMapFile, ID)): print >> sys.stdout, 'Warning: Project with ID \'', ID, \ '\' already exists.' print >> sys.stdout, "Reference output has been regenerated." else: PMapWriter = csv.writer(PMapFile) PMapWriter.writerow((ID, int(BuildMode))) print "The project map is updated: ", ProjectMapPath
def updateReferenceResults(ProjName, ProjBuildMode): ProjDir = SATestBuild.getProjectDir(ProjName) RefResultsPath = os.path.join(ProjDir, SATestBuild.getSBOutputDirName(IsReferenceBuild=True)) CreatedResultsPath = os.path.join(ProjDir, SATestBuild.getSBOutputDirName(IsReferenceBuild=False)) if not os.path.exists(CreatedResultsPath): print >> sys.stderr, "New results not found, was SATestBuild.py "\ "previously run?" sys.exit(-1) # Remove reference results. runCmd('git rm -r "%s"' % (RefResultsPath,)) # Replace reference results with a freshly computed once. runCmd('cp -r "%s" "%s"' % (CreatedResultsPath, RefResultsPath,)) # Run cleanup script. with open(SATestBuild.getBuildLogPath(RefResultsPath), "wb+") as PBuildLogFile: SATestBuild.runCleanupScript(ProjDir, PBuildLogFile) SATestBuild.normalizeReferenceResults(ProjDir, RefResultsPath, ProjBuildMode) # Clean up the generated difference results. SATestBuild.cleanupReferenceResults(RefResultsPath) # Remove the created .diffs file before adding. runCmd('rm -f "%s/*/%s"' % (RefResultsPath, SATestBuild.DiffsSummaryFileName)) runCmd('git add "%s"' % (RefResultsPath,))
def addNewProject(ID): CurDir = os.path.abspath(os.curdir) Dir = SATestBuild.getProjectDir(ID) if not os.path.exists(Dir): print "Error: Project directory is missing: %s" % Dir sys.exit(-1) # Build the project. SATestBuild.testProject(ID, True, Dir) # Add the project ID to the project map. ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) if os.path.exists(ProjectMapPath): PMapFile = open(ProjectMapPath, "r+b") else: print "Warning: Creating the Project Map file!!" PMapFile = open(ProjectMapPath, "w+b") try: PMapReader = csv.reader(PMapFile) for I in PMapReader: IID = I[0] if ID == IID: print >> sys.stderr, "Warning: Project with ID '", ID, "' already exists." sys.exit(-1) PMapWriter = csv.writer(PMapFile) PMapWriter.writerow((ID, Dir)) finally: PMapFile.close() print "The project map is updated: ", ProjectMapPath
def add_new_project(project: ProjectInfo): """ Add a new project for testing: build it and add to the Project Map file. :param name: is a short string used to identify a project. """ test_info = SATestBuild.TestInfo(project, is_reference_build=True) tester = SATestBuild.ProjectTester(test_info) project_dir = tester.get_project_dir() if not os.path.exists(project_dir): print(f"Error: Project directory is missing: {project_dir}") sys.exit(-1) # Build the project. tester.test() # Add the project name to the project map. project_map = ProjectMap(should_exist=False) if is_existing_project(project_map, project): print(f"Warning: Project with name '{project.name}' already exists.", file=sys.stdout) print("Reference output has been regenerated.", file=sys.stdout) else: project_map.projects.append(project) project_map.save()
def addNewProject(ID, BuildMode): CurDir = os.path.abspath(os.curdir) Dir = SATestBuild.getProjectDir(ID) if not os.path.exists(Dir): print "Error: Project directory is missing: %s" % Dir sys.exit(-1) # Build the project. SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True, Dir=Dir) # Add the project ID to the project map. ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) if os.path.exists(ProjectMapPath): PMapFile = open(ProjectMapPath, "r+b") else: print "Warning: Creating the Project Map file!!" PMapFile = open(ProjectMapPath, "w+b") try: if (isExistingProject(PMapFile, ID)): print >> sys.stdout, 'Warning: Project with ID \'', ID, \ '\' already exists.' print >> sys.stdout, "Reference output has been regenerated." else: PMapWriter = csv.writer(PMapFile) PMapWriter.writerow((ID, int(BuildMode))) print "The project map is updated: ", ProjectMapPath finally: PMapFile.close()
def addNewProject(ID): CurDir = os.path.abspath(os.curdir) Dir = SATestBuild.getProjectDir(ID) if not os.path.exists(Dir): print "Error: Project directory is missing: %s" % Dir sys.exit(-1) # Build the project. SATestBuild.testProject(ID, True, Dir) # Add the project ID to the project map. ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) if os.path.exists(ProjectMapPath): PMapFile = open(ProjectMapPath, "r+b") else: print "Warning: Creating the Project Map file!!" PMapFile = open(ProjectMapPath, "w+b") try: PMapReader = csv.reader(PMapFile) for I in PMapReader: IID = I[0] if ID == IID: print >> sys.stderr, 'Warning: Project with ID \'', ID, \ '\' already exists.' sys.exit(-1) PMapWriter = csv.writer(PMapFile) PMapWriter.writerow((ID, Dir)) finally: PMapFile.close() print "The project map is updated: ", ProjectMapPath
def addNewProject(ID, BuildMode) : CurDir = os.path.abspath(os.curdir) Dir = SATestBuild.getProjectDir(ID) if not os.path.exists(Dir): print "Error: Project directory is missing: %s" % Dir sys.exit(-1) # Build the project. SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True, Dir=Dir) # Add the project ID to the project map. ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) if os.path.exists(ProjectMapPath): PMapFile = open(ProjectMapPath, "r+b") else: print "Warning: Creating the Project Map file!!" PMapFile = open(ProjectMapPath, "w+b") try: if (isExistingProject(PMapFile, ID)) : print >> sys.stdout, 'Warning: Project with ID \'', ID, \ '\' already exists.' print >> sys.stdout, "Reference output has been regenerated." else: PMapWriter = csv.writer(PMapFile) PMapWriter.writerow( (ID, int(BuildMode)) ); print "The project map is updated: ", ProjectMapPath finally: PMapFile.close()
def main(argv): if len(argv) == 2 and argv[1] in ('-h', '--help'): print >> sys.stderr, "Update static analyzer reference results based "\ "\non the previous run of SATestBuild.py.\n"\ "\nN.B.: Assumes that SATestBuild.py was just run" sys.exit(1) with SATestBuild.projectFileHandler() as f: for (ProjName, ProjBuildMode) in SATestBuild.iterateOverProjects(f): updateReferenceResults(ProjName, int(ProjBuildMode))
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) with open(SATestBuild.get_project_map_path(), "r") as f: for project_name, build_mode in SATestBuild.get_projects(f): update_reference_results(project_name, int(build_mode))
def build(parser, args): SATestBuild.VERBOSE = args.verbose project_map = ProjectMap() projects = project_map.projects if args.projects: projects_arg = args.projects.split(",") available_projects = [project.name for project in projects] # validate that given projects are present in the project map file for manual_project in projects_arg: if manual_project not in available_projects: parser.error("Project '{project}' is not found in " "the project map file. Available projects are " "{all}.".format(project=manual_project, all=available_projects)) projects = [ project.with_fields(enabled=project.name in projects_arg) for project in projects ] tester = SATestBuild.RegressionTester(args.jobs, projects, args.override_compiler, args.extra_analyzer_config, args.regenerate, args.strictness) tests_passed = tester.test_all() if not tests_passed: sys.stderr.write("ERROR: Tests failed.\n") sys.exit(42)
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() tester.is_reference_build = True ref_results_path = tester.get_output_dir() tester.is_reference_build = False created_results_path = tester.get_output_dir() if not os.path.exists(created_results_path): print(f"Skipping project '{project.name}', " f"it doesn't have newer results.", file=sys.stderr) return build_log_path = SATestBuild.get_build_log_path(ref_results_path) build_log_dir = os.path.dirname(os.path.abspath(build_log_path)) os.makedirs(build_log_dir) with open(build_log_path, "w+") as build_log_file: def run_cmd(command: str): if Verbose: print(f"Executing {command}") check_call(command, shell=True, stdout=build_log_file) # 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. 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. shutil.copytree(created_results_path, ref_results_path, symlinks=True) # Run cleanup script. SATestBuild.run_cleanup_script(project_dir, build_log_file) SATestBuild.normalize_reference_results( project_dir, ref_results_path, project.mode) # Clean up the generated difference results. SATestBuild.cleanup_reference_results(ref_results_path) if git: run_cmd(f"git add '{ref_results_path}'")
def update_reference_results(project_name: str, build_mode: int): project_info = SATestBuild.ProjectInfo(project_name, build_mode) tester = SATestBuild.ProjectTester(project_info) project_dir = tester.get_project_dir() tester.is_reference_build = True ref_results_path = os.path.join(project_dir, tester.get_output_dir()) tester.is_reference_build = False created_results_path = os.path.join(project_dir, tester.get_output_dir()) if not os.path.exists(created_results_path): print("New results not found, was SATestBuild.py previously run?", file=sys.stderr) sys.exit(1) build_log_path = SATestBuild.get_build_log_path(ref_results_path) build_log_dir = os.path.dirname(os.path.abspath(build_log_path)) os.makedirs(build_log_dir) with open(build_log_path, "w+") as build_log_file: def run_cmd(command: str): if Verbose: print(f"Executing {command}") check_call(command, shell=True, stdout=build_log_file) # 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}'") shutil.rmtree(ref_results_path) # Replace reference results with a freshly computed once. shutil.copytree(created_results_path, ref_results_path, symlinks=True) # Run cleanup script. SATestBuild.run_cleanup_script(project_dir, build_log_file) SATestBuild.normalize_reference_results(project_dir, ref_results_path, build_mode) # Clean up the generated difference results. SATestBuild.cleanup_reference_results(ref_results_path) run_cmd(f"git add '{ref_results_path}'")
def updateReferenceResults(ProjName, ProjBuildMode): ProjDir = SATestBuild.getProjectDir(ProjName) RefResultsPath = os.path.join( ProjDir, SATestBuild.getSBOutputDirName(IsReferenceBuild=True)) CreatedResultsPath = os.path.join( ProjDir, SATestBuild.getSBOutputDirName(IsReferenceBuild=False)) if not os.path.exists(CreatedResultsPath): print("New results not found, was SATestBuild.py " "previously run?", file=sys.stderr) sys.exit(1) BuildLogPath = SATestBuild.getBuildLogPath(RefResultsPath) Dirname = os.path.dirname(os.path.abspath(BuildLogPath)) runCmd("mkdir -p '%s'" % Dirname) with open(BuildLogPath, "w+") as PBuildLogFile: # 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. runCmd('git rm -r -q "%s"' % (RefResultsPath, ), stdout=PBuildLogFile) runCmd('rm -rf "%s"' % (RefResultsPath, ), stdout=PBuildLogFile) # Replace reference results with a freshly computed once. runCmd('cp -r "%s" "%s"' % ( CreatedResultsPath, RefResultsPath, ), stdout=PBuildLogFile) # Run cleanup script. SATestBuild.runCleanupScript(ProjDir, PBuildLogFile) SATestBuild.normalizeReferenceResults(ProjDir, RefResultsPath, ProjBuildMode) # Clean up the generated difference results. SATestBuild.cleanupReferenceResults(RefResultsPath) runCmd('git add "%s"' % (RefResultsPath, ), stdout=PBuildLogFile)
def updateReferenceResults(ProjName, ProjBuildMode): ProjDir = SATestBuild.getProjectDir(ProjName) RefResultsPath = os.path.join( ProjDir, SATestBuild.getSBOutputDirName(IsReferenceBuild=True)) CreatedResultsPath = os.path.join( ProjDir, SATestBuild.getSBOutputDirName(IsReferenceBuild=False)) if not os.path.exists(CreatedResultsPath): print >> sys.stderr, "New results not found, was SATestBuild.py "\ "previously run?" sys.exit(-1) # 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. runCmd('git rm -r -q "%s"' % (RefResultsPath, )) runCmd('rm -rf "%s"' % (RefResultsPath, )) # Replace reference results with a freshly computed once. runCmd('cp -r "%s" "%s"' % ( CreatedResultsPath, RefResultsPath, )) # Run cleanup script. BuildLogPath = SATestBuild.getBuildLogPath(RefResultsPath) with open(BuildLogPath, "wb+") as PBuildLogFile: SATestBuild.runCleanupScript(ProjDir, PBuildLogFile) SATestBuild.normalizeReferenceResults(ProjDir, RefResultsPath, ProjBuildMode) # Clean up the generated difference results. SATestBuild.cleanupReferenceResults(RefResultsPath) # Remove the created .diffs file before adding. removeDiffsSummaryFiles(RefResultsPath) runCmd('git add "%s"' % (RefResultsPath, ))
def updateReferenceResults(ProjName, ProjBuildMode): ProjDir = SATestBuild.getProjectDir(ProjName) RefResultsPath = os.path.join( ProjDir, SATestBuild.getSBOutputDirName(IsReferenceBuild=True)) CreatedResultsPath = os.path.join( ProjDir, SATestBuild.getSBOutputDirName(IsReferenceBuild=False)) if not os.path.exists(CreatedResultsPath): print >> sys.stderr, "New results not found, was SATestBuild.py "\ "previously run?" sys.exit(-1) # 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. runCmd('git rm -r -q "%s"' % (RefResultsPath,)) runCmd('rm -rf "%s"' % (RefResultsPath,)) # Replace reference results with a freshly computed once. runCmd('cp -r "%s" "%s"' % (CreatedResultsPath, RefResultsPath,)) # Run cleanup script. BuildLogPath = SATestBuild.getBuildLogPath(RefResultsPath) with open(BuildLogPath, "wb+") as PBuildLogFile: SATestBuild.runCleanupScript(ProjDir, PBuildLogFile) SATestBuild.normalizeReferenceResults( ProjDir, RefResultsPath, ProjBuildMode) # Clean up the generated difference results. SATestBuild.cleanupReferenceResults(RefResultsPath) # Remove the created .diffs file before adding. removeDiffsSummaryFiles(RefResultsPath) runCmd('git add "%s"' % (RefResultsPath,))
def add_new_project(name: str, build_mode: int): """ Add a new project for testing: build it and add to the Project Map file. :param name: is a short string used to identify a project. """ project_info = SATestBuild.ProjectInfo(name, build_mode, is_reference_build=True) tester = SATestBuild.ProjectTester(project_info) project_dir = tester.get_project_dir() if not os.path.exists(project_dir): print(f"Error: Project directory is missing: {project_dir}") sys.exit(-1) # Build the project. tester.test() # Add the project name to the project map. project_map_path = SATestBuild.get_project_map_path(should_exist=False) if os.path.exists(project_map_path): file_mode = "r+" else: print("Warning: Creating the project map file!") file_mode = "w+" with open(project_map_path, file_mode) as map_file: if is_existing_project(map_file, name): print(f"Warning: Project with name '{name}' already exists.", file=sys.stdout) print("Reference output has been regenerated.", file=sys.stdout) else: map_writer = csv.writer(map_file) map_writer.writerow((name, build_mode)) print(f"The project map is updated: {project_map_path}")
def build(parser, args): import SATestBuild SATestBuild.VERBOSE = args.verbose projects = get_projects(parser, args.projects) tester = SATestBuild.RegressionTester(args.jobs, projects, args.override_compiler, args.extra_analyzer_config, args.regenerate, args.strictness) tests_passed = tester.test_all() if not tests_passed: sys.stderr.write("ERROR: Tests failed.\n") sys.exit(42)
def addNewProject(ID, BuildMode): """ Add a new project for testing: build it and add to the Project Map file. :param ID: is a short string used to identify a project. """ CurDir = os.path.abspath(os.curdir) Dir = SATestBuild.getProjectDir(ID) if not os.path.exists(Dir): print("Error: Project directory is missing: %s" % Dir) sys.exit(-1) # Build the project. # TODO: Repair this call. We give it a wrong amount wrong arguments and it # is not trivial to construct argparse arguments in here. # Requires refactoring of the 'testProject' function. SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True) # Add the project ID to the project map. ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) if os.path.exists(ProjectMapPath): FileMode = "r+" else: print("Warning: Creating the Project Map file!!") FileMode = "w+" with open(ProjectMapPath, FileMode) as PMapFile: if (isExistingProject(PMapFile, ID)): print('Warning: Project with ID \'', ID, '\' already exists.', file=sys.stdout) print("Reference output has been regenerated.", file=sys.stdout) else: PMapWriter = csv.writer(PMapFile) PMapWriter.writerow((ID, int(BuildMode))) print("The project map is updated: ", ProjectMapPath)