| import json |
| import os |
| import pathlib |
| import shutil |
| |
| from slave import base_recipe |
| from slave import base_step |
| from slave.step import code_coverage_step |
| |
| |
| def GetValidBuildNames(): |
| return ['incremental-coverage-e2e-mock-1', 'absolute-coverage-e2e-mock-1'] |
| |
| def CreateRecipe(build_name: str, **kwargs): |
| """Defines how this recipe gets built.""" |
| return CodeCoverageE2EMockRecipe(build_name, **kwargs) |
| |
| |
| class CodeCoverageE2EMockRecipe(base_recipe.BaseRecipe): |
| """Recipe to execute e2e fake build.""" |
| |
| def __init__(self, builder_name, data_manager, **kwargs): |
| base_recipe.BaseRecipe.__init__(self, data_manager=data_manager, **kwargs) |
| self._builder_name = builder_name |
| self._data_manager = data_manager |
| |
| def get_steps(self): |
| if 'code_health_project_path' in self._properties: |
| project_path = pathlib.Path(self._properties['code_health_project_path']) |
| else: |
| project_path = pathlib.Path(self._data_manager.get_project_path( |
| self._properties['patch_project'] |
| )) |
| config_file_path = project_path / 'recipe_config.json' |
| config = json.loads(config_file_path.read_text()) |
| return [ |
| code_coverage_step.CollectLcovCoverageStep( |
| lcov_files=config.get('input_lcov_files', []), |
| **self._step_kwargs, |
| ), |
| CodeCoverageE2EMockStep( |
| builder_name=self._builder_name, |
| output_files=config.get('output_files', []), |
| output_properties=config.get('output_properties', {}), |
| project_path=project_path, |
| **self._step_kwargs, |
| ), |
| ] |
| |
| |
| class CodeCoverageE2EMockStep(base_step.BaseStep): |
| |
| def __init__( |
| self, |
| builder_name, |
| output_files, |
| output_properties, |
| project_path, |
| **kwargs, |
| ): |
| base_step.BaseStep.__init__(self, name="code_coverage_e2e_mock", **kwargs) |
| self._builder_name = builder_name |
| self._properties = kwargs.get('properties', {}) |
| self._output_files = output_files |
| self._output_properties = output_properties |
| self._project_path = project_path |
| |
| def run(self): |
| for path in self._output_files: |
| path = pathlib.Path(path) |
| dest_dir = pathlib.Path(self.get_gcs_dir()) / path.parent |
| dest_dir.mkdir(exist_ok=True, parents=True) |
| shutil.copy(self._project_path / path, dest_dir) |
| |
| for key, value in self._output_properties.items(): |
| self.set_build_property(key, value) |
| |
| return True |