| """Build step class for building and testing test binaries.""" |
| |
| from __future__ import absolute_import |
| import logging |
| import os |
| import tempfile |
| |
| from helpers import cipd_upload_utils |
| from helpers import py_env_utils |
| from slave import base_step |
| |
| |
| class CatatesterBinariesException(Exception): |
| """Raised on step exceptions.""" |
| |
| |
| class CatatesterBinariesBuildStep(base_step.BaseStep): |
| """Step for building Catatester Binaries.""" |
| |
| def __init__(self, py3: bool, **kwargs): |
| """Creates a CatatesterBinariesBuildStep instance. |
| |
| Args: |
| **kwargs: Any additional args to pass to BaseStep. |
| """ |
| base_step.BaseStep.__init__(self, |
| name='build catatester binaries', |
| **kwargs) |
| self.py3 = py3 |
| |
| def _get_configs_path(self): # pylint: disable=method-hidden |
| """Path to the configs file.""" |
| continuous_tests = os.path.abspath( |
| self.get_project_path('continuous-tests')) |
| return os.path.join(continuous_tests, 'lab_system', 'master', 'config') |
| |
| def _get_python_path(self): |
| """Get the PYTHONPATH to execute tests with. |
| |
| This method was written based on test/setup_env.sh |
| """ |
| python_path = [] |
| |
| python_path.append(os.path.abspath(self.get_project_path('test'))) |
| |
| # continuous-tests/ has to be above all the other repositories |
| continuous_tests_repo = os.path.abspath( |
| self.get_project_path('continuous-tests')) |
| python_path.append(continuous_tests_repo) |
| |
| chromium_repo = os.path.abspath(self.get_project_path('chromium/src')) |
| chromium_telemetry_repo = os.path.join( |
| chromium_repo, 'third_party', 'catapult', 'telemetry') |
| python_path.append(chromium_telemetry_repo) |
| python_path.append(os.path.join( |
| chromium_telemetry_repo, 'third_party', 'websocket-client')) |
| python_path.append(os.path.join(chromium_repo, 'chromecast', 'tools')) |
| |
| python_path.append(os.path.join(continuous_tests_repo, 'cq')) |
| |
| python_path.append(os.path.abspath( |
| self.get_project_path('chromiumos/third_party/autotest'))) |
| python_path.append(os.path.abspath( |
| self.get_project_path('chromiumos/chromite'))) |
| |
| sprockets_repo = os.path.abspath(self.get_project_path('google/sprockets')) |
| python_path.append(sprockets_repo) |
| |
| return os.pathsep.join(python_path) |
| |
| def _get_env_path(self, venv_root): |
| """Prepends virtualenv bin directory to existing $PATH var.""" |
| venv_bin = os.path.join(venv_root, 'bin') |
| current_path_var = os.getenv('PATH') |
| return os.pathsep.join([venv_bin, current_path_var]) |
| |
| def _build_binaries(self, venv_root): |
| """Generates pyinstaller spec files and builds binaries. |
| |
| Returns True if build succeeds, else False. |
| """ |
| venv_root = self.get_step_data('virtual_env_root') |
| binary_generator = os.path.join( |
| self.get_project_path('test'), |
| 'swarming', 'pyinstaller_tools', 'binary_generator.py') |
| cmd = [binary_generator] |
| |
| env = {} |
| env['FRAGGLE_ROCK_CONFIG_FILES'] = self._get_configs_path() |
| env['PYTHONPATH'] = self._get_python_path() |
| env['PATH'] = self._get_env_path(venv_root) |
| |
| returncode, stdout, stderr = py_env_utils.exec_within_virtual_env( |
| self, venv_root, cmd, env=env) |
| |
| if returncode != 0: |
| logging.error('Failed to generate binaries: %s\n%s', stdout, stderr) |
| return False |
| |
| return True |
| |
| def run(self): |
| """Creates all catatester binaries. |
| |
| Sets a build property "review" with the output in case of failure. |
| |
| Returns: |
| True if there were no test errors, else False. |
| """ |
| venv_root = self.get_step_data('virtual_env_root') |
| success = self._build_binaries(venv_root) |
| if not success: |
| # TODO(adrexler): Provide more useful failure message |
| self.add_review({'message': 'Failed to generate all binaries.'}) |
| return success |