blob: ee8b33c92f404e240f36d7689ab0f5d918726682 [file] [log] [blame]
"""FCT steps for building OTA's."""
from __future__ import absolute_import
import os
import shutil
from slave import base_step
from slave.step import ota_step
class OtaFctCompileStep(ota_step.OtaStep):
"""FCT Compile step class for building OTA's."""
def __init__(self, build_name, factory_config,
name='build factory images', **kwargs):
"""Creates a OtaFctCompileStep instance.
Args:
build_name: Name of build (e.g. anchovy-eng, tvdefault-eng)
factory_config: hostboot or usbstick config. Each element of the
'factory_image_types' will be suffixed with 'image' to form the final
make target. For example, the list ['bft', 'sft'] will result in this
make command: 'make bftimage sftimage'
name: user-visible name of this step.
**kwargs: Any additional args to pass to BaseStep.
"""
self.factory_config = factory_config
ota_step.OtaStep.__init__(self, build_name=build_name, name=name, **kwargs)
def _make_fct(self):
"""Builds |build_name| FCT packages for the |issue| and |patchset|.
Returns:
True if the OTA package was built successfully, False otherwise.
"""
factory_image_types = self.factory_config.get('factory_image_types')
if not factory_image_types:
return True
command = ['make']
command += ['{}image'.format(t) for t in factory_image_types]
command += ['BUILD_NUMBER={}'.format(self.build_number)]
command += self.make_target_param(True)
returncode, stdout, stderr = self.exec_subprocess(command)
if returncode != 0:
self._error_processor(stdout, stderr)
return False
if not self._create_factory_dir():
return False
return self._copy_factory_target_files_to_out_artifacts(factory_image_types)
def _copy_factory_target_files_to_out_artifacts(self, factory_image_types):
"""These are used for resigning factory images e.g. prod reflashimage."""
product, variant = self._build_name.split('-')
for image_type in factory_image_types:
target_files_zip = self.factory_config['source_binary_path'].format(
product=product, variant=variant, image_type=image_type)
target_files_no_ext, zip_ext = os.path.splitext(
os.path.basename(target_files_zip))
dest_file_path = os.path.join(self._ota_archive_output_dir(), 'factory',
'{}-{}-{}-{}{}'.format(product, image_type,
target_files_no_ext,
self.build_number,
zip_ext))
returncode, _, _ = self.exec_subprocess(
['cp', target_files_zip, dest_file_path])
if returncode != 0:
return False
return True
def _create_factory_dir(self):
command = ['mkdir', '-p',
os.path.join(self._ota_archive_output_dir(), 'factory')]
returncode, _, _ = self.exec_subprocess(command)
return returncode == 0
def run(self):
return self._make_fct()