blob: 5bf0089bed0cbf66c741f563a6cce84b482e3517 [file]
"""Build step class for Dipper build."""
from __future__ import absolute_import
import os
from slave import base_step
class DipperStep(base_step.BaseStep):
"""Build step class for Dipper build."""
def __init__(self, build_name, name='Dipper build', **kwargs):
"""Create a Dipper instance.
Args:
build_name: Name of build (e.g. dipper-eng).
name: User-visible name of this step.
**kwargs: Any additional args to pass to BaseStep.
"""
base_step.BaseStep.__init__(self, name=name, **kwargs)
self._build_name = build_name
def _get_pip_local_path(self):
"""Gets the local python package folder.
Returns:
The local dipper-required python package folder as string.
"""
gcs_path = self._properties.get(
'gcs_mirror_path', '/workspace/gcs-mirror')
return os.path.expanduser(os.path.join(gcs_path,
'team-dipper/python_packages'))
def _build(self, variant, src_dir):
"""Build |build_name| artifacts by Dipper toolchain.
Args:
variant: "user" or "eng" variant
src_dir: the root path of source codes
Returns:
True if artifacts were built successfully; False if failed.
"""
os.environ['PIP_FIND_LINKS'] = self._get_pip_local_path()
build_command = [
os.path.join('build', 'build.sh'),
'--{variant}'.format(variant=variant),
]
returncode, stdout, stderr = self.exec_subprocess(
build_command, cwd=src_dir)
if returncode != 0:
self._error_processor(stdout, stderr)
return False
return True
def _copy(self, variant, src_dir):
"""Copy |build_name| artifacts to GCS.
Args:
variant: "user" or "eng" variant
src_dir: the root path of source codes
Returns:
True if artifacts were copied successfully; False if failed.
"""
artifacts_path = 'out/target/product/dipper'
artifacts_file = os.path.join(
artifacts_path, 'd6_artifacts-{variant}.zip'.format(variant=variant))
dist_dir = self.get_gcs_dir()
copy_command = [
'cp',
artifacts_file,
dist_dir
]
returncode, stdout, stderr = self.exec_subprocess(copy_command, cwd=src_dir)
if returncode != 0:
self._error_processor(stdout, stderr)
return False
return True
def run(self):
"""Build artifacts and copy to distribution(GCS).
Returns:
True if there were no errors.
"""
variant = "user" if self._build_name.endswith("user") else "eng"
src_dir = self.get_project_path('telink/d6')
return self._build(variant, src_dir) and self._copy(variant, src_dir)
def _error_processor(self, stdout, stderr):
if stdout:
self.add_review({'message': stdout})
if stderr:
self.add_review({'message': stderr})