blob: 3d431d3dd84e651025133fdb48273362e86b97c3 [file]
"""Build step class for compiling SDK."""
from __future__ import absolute_import
import os
from slave.step import shell_step
class BaseSDKStep(shell_step.ShellStep):
"""Base step class for SDK build."""
def __init__(self, name, build_config, **kwargs):
"""Creates a BaseSDKStep instance."""
shell_step.ShellStep.__init__(
self,
name=name,
halt_on_failure=True,
num_retries=0,
**kwargs)
self._vendor_config = build_config['vendor_config']
class OssCreateTarStep(BaseSDKStep):
"""Tarball open source files step class for SDK build."""
def __init__(self, build_config, **kwargs):
"""Creates a OssCreateTarStep instance."""
BaseSDKStep.__init__(self, name='SDK: tarball open source files',
build_config=build_config, **kwargs)
def get_commands(self):
oss_sdk_dir = self._vendor_config['oss_sdk_dir']
oss_sdk_release_script = self._vendor_config['oss_sdk_release_script']
return [
self.ShellCommand(['mkdir', '-p', oss_sdk_dir]),
self.ShellCommand([oss_sdk_release_script, oss_sdk_dir]),
]
class CreateTarStep(BaseSDKStep):
"""Tarball prebuilt file step class for SDK build."""
def __init__(self, build_config, **kwargs):
"""Creates a CreateTarStep instance."""
BaseSDKStep.__init__(self, name='SDK: tar-ing build output',
build_config=build_config, **kwargs)
def get_commands(self):
prebuilt_file = self._vendor_config['prebuilt_file']
fake_work_dir = self._vendor_config['fake_work_dir']
return [self.ShellCommand(['tar', 'czf',
prebuilt_file,
'-C', fake_work_dir, '.'])]
class CreateLogDirStep(BaseSDKStep):
"""Tarball prebuilt file step class for SDK build."""
def __init__(self, build_config, **kwargs):
"""Creates a CreateLogDirStep instance."""
BaseSDKStep.__init__(self, name='SDK: ensure sdk log dir structure exists',
build_config=build_config, **kwargs)
def get_commands(self):
build_logs_dir = self._vendor_config['build_logs_dir']
return [self.ShellCommand(['mkdir', '-p', build_logs_dir])]
class ArchiveArtifactsStep(BaseSDKStep):
"""Copy SDK build artifacts to upload."""
def __init__(self, build_config, **kwargs):
"""Creates a ArchiveArtifactsStep instance."""
BaseSDKStep.__init__(self, name='SDK: archive artifacts',
build_config=build_config, **kwargs)
def get_commands(self):
commands = []
upload_dir = self.get_gcs_dir()
prebuilt_file = self._vendor_config['prebuilt_file']
commands += [self.ShellCommand(['cp', prebuilt_file, upload_dir])]
build_logs_dir = self._vendor_config['build_logs_dir']
if os.path.isdir(build_logs_dir) and os.listdir(build_logs_dir):
commands += [self.ShellCommand(['cp', '-r', build_logs_dir, upload_dir])]
oss_sdk_dir = self._vendor_config['oss_sdk_dir']
if os.path.isdir(oss_sdk_dir) and os.listdir(oss_sdk_dir):
commands += [self.ShellCommand(['cp', '-r', oss_sdk_dir, upload_dir])]
return commands
class CompileSDKStep(BaseSDKStep):
"""Build step class for compiling SDK build."""
def __init__(self, build_config, **kwargs):
"""Creates a CompileSDKStep instance."""
name = 'SDK: compile {} SDK'.format(build_config['vendor_config']['name'])
BaseSDKStep.__init__(self, name=name,
build_config=build_config, **kwargs)
self._product = build_config['product']
def get_commands(self):
commands = []
fake_prebuilt_dir = self._vendor_config['fake_prebuilt_dir'].format(
vendor=self._vendor_config['name'], product=self._product)
commands += [self.ShellCommand(['mkdir', '-p', fake_prebuilt_dir])]
build_script = self._vendor_config['build_script']
fake_work_dir = self._vendor_config['fake_work_dir']
build_command = [build_script, fake_work_dir]
if self._vendor_config['include_product_param']:
build_command.append(self._product)
build_command.append(self.build_number)
build_command.append(
'--venv_root={}'.format(self.get_step_data('virtual_env_root')))
commands += [self.ShellCommand(build_command)]
return commands
class CopySDKStep(BaseSDKStep):
"""Build step class for copying the built SDK output"""
def __init__(self, build_config, **kwargs):
"""Creats a CopySDKStep instance."""
name = 'SDK: copy {} SDK to eureka'.format(build_config.get('product'))
self._eureka_root = kwargs['eureka_root']
self._build_config = build_config
BaseSDKStep.__init__(
self, name=name, build_config=build_config, **kwargs)
def get_commands(self):
fake_work_dir = self._vendor_config['fake_work_dir']
return [
self.ShellCommand(
['cp', '-dprv', os.path.join(fake_work_dir, '.'),
str(self._eureka_root)])
]