| """OSS step class for building OTA's.""" |
| |
| from __future__ import absolute_import |
| import os |
| from slave.step import ota_step |
| import xml.etree.ElementTree as et |
| |
| from helpers import repo_utils |
| |
| MANIFEST_OSS_XML = 'manifest_oss.xml' |
| |
| |
| class OtaOssStep(ota_step.OtaStep): |
| """OSS creation step class for building OTA's.""" |
| |
| def __init__(self, |
| build_name, |
| name='populate oss manifest and tarball open source files', |
| **kwargs): |
| """Creates a OtaOssStep instance. |
| |
| Args: |
| build_name: Name of build (e.g. anchovy-eng, tvdefault-eng) |
| name: user-visible name of this step. |
| **kwargs: Any additional args to pass to BaseStep. |
| """ |
| ota_step.OtaStep.__init__(self, build_name=build_name, name=name, **kwargs) |
| |
| def _make_oss(self): |
| """Builds |build_name| OTA package for the |issue| and |patchset|. |
| |
| Returns: |
| True if the OTA package was built successfully, False otherwise. |
| """ |
| command = ['make', |
| 'release_oss', |
| 'OSS_ROOT=./{}'.format(self._dist_dir()),] |
| command += self.make_target_param(True) |
| |
| returncode, stdout, stderr = self.exec_subprocess(command) |
| if returncode != 0: |
| self._error_processor(stdout, stderr) |
| |
| return returncode == 0 |
| |
| def _compile_oss_manifest_and_save(self): |
| """Generates a manifest of oss projects for |product|.""" |
| product = self._build_name.split('-')[0] |
| oss_projects_file = os.path.join('vendor/eureka/tools/open_source/', |
| product + '_oss_project.txt') |
| repo_manifest_content = repo_utils.get_manifest(self._executor) |
| |
| if repo_manifest_content and os.path.isfile(oss_projects_file): |
| root = et.fromstring(repo_manifest_content) |
| with open(oss_projects_file, 'r') as f: |
| oss_project_list = f.read().splitlines() |
| for project in root.findall('project'): |
| if project.attrib['name'] not in oss_project_list: |
| root.remove(project) |
| oss_manifest_content = et.tostring(root, encoding='unicode') |
| with open(MANIFEST_OSS_XML, 'w') as f: |
| f.write(oss_manifest_content) |
| output_dir = self.get_gcs_dir() |
| self.exec_subprocess(['cp', MANIFEST_OSS_XML, output_dir]) |
| |
| def _clear_oss_artifacts(self): |
| """Removes all OTA artifacts leftover by previous builds.""" |
| ota_files = self.glob_files('out/dist/*/chromecast_oss.tgz') |
| if ota_files: |
| self.exec_subprocess(['rm', '-f'] + ota_files) |
| |
| def _archive_artifacts(self): |
| """Copies the artifacts for archival.""" |
| output_dir = self.get_gcs_dir() |
| |
| if self.build_system == 'catabuilder': |
| dist_files = self.glob_files( |
| '{}/chromecast_oss.tgz'.format(self._dist_dir())) |
| for f in dist_files: |
| self.exec_subprocess(['cp', '-r', f, output_dir]) |
| |
| def run(self): |
| self._clear_oss_artifacts() |
| self._compile_oss_manifest_and_save() |
| if not self._make_oss(): |
| return False |
| self._archive_artifacts() |
| |
| return True |