diff options
author | Ari Hausman-Cohen <arihc@google.com> | 2016-04-19 14:53:04 -0700 |
---|---|---|
committer | Ari Hausman-Cohen <arihc@google.com> | 2016-04-19 16:23:27 -0700 |
commit | ac55299928158ebef338a55de42ee1ff387fb2f5 (patch) | |
tree | e740292af39ed0eeb9416c8e39987047a4762756 | |
parent | 632538b57420881af0206c1402e892a49ee5fff9 (diff) | |
download | bdk-ac55299928158ebef338a55de42ee1ff387fb2f5.tar.gz |
link BDKv2 provision tool.
Provision requires linking.
BUG: 28274249
TEST: unit tests
Change-Id: I18a6205b9ab0218bcd8a03729643e7122215306c
-rw-r--r-- | cli/lib/commands/v2/root/flash.py | 7 | ||||
-rw-r--r-- | cli/lib/core/provision.py | 27 | ||||
-rw-r--r-- | cli/lib/core/provision_unittest.py | 37 | ||||
-rw-r--r-- | cli/lib/core/tool.py | 17 | ||||
-rw-r--r-- | cli/lib/core/tool_unittest.py | 11 | ||||
-rw-r--r-- | cli/lib/project/target_stub.py | 3 |
6 files changed, 56 insertions, 46 deletions
diff --git a/cli/lib/commands/v2/root/flash.py b/cli/lib/commands/v2/root/flash.py index 16317a8..22e4cfe 100644 --- a/cli/lib/commands/v2/root/flash.py +++ b/cli/lib/commands/v2/root/flash.py @@ -53,18 +53,17 @@ class Flash(clicommand.Command): print str(error) return 1 - platform_build_out = target.platform_build_cache() system_image_dir = spec.config.output_dir # TODO(http://b/27503751): make sure the device exists and potentially # put it in fastboot mode if it's not. provision_args = ['-s', args.s] if args.s else [] - provision.provision_device(target, platform_build_out, - system_image_dir, provision_args) + provision.provision_device(target, system_image_dir, provision_args) if args.reboot: - fastboot_tool = tool.HostToolWrapper('fastboot', platform_build_out) + fastboot_tool = tool.HostToolWrapper( + 'fastboot', target.platform_build_cache()) fastboot_tool.run(provision_args + ['reboot']) return 0 diff --git a/cli/lib/core/provision.py b/cli/lib/core/provision.py index c8f5258..2063845 100644 --- a/cli/lib/core/provision.py +++ b/cli/lib/core/provision.py @@ -99,14 +99,11 @@ class _ProvisionDir(object): shutil.rmtree(self.temp_dir, ignore_errors=True) -def _get_provision_tool(os_source_dir, platform_build_out, bsp): +def _get_provision_tool(target): """Creates a ProvisionDeviceTool with proper settings. Args: - os_source_dir: the Brillo source root, needed by provision to - locate prebuilt vendor binaries. - platform_build_out: platform build output directory. - bsp: BSP name. + target: The Target to get the provision tool for. Returns: The created ProvisionDeviceTool. @@ -116,10 +113,10 @@ def _get_provision_tool(os_source_dir, platform_build_out, bsp): """ # The provision-device script needs fastboot to be on PATH, so we create # a fastboot tool to add it's parent directory to the provision tool PATH. - fastboot_tool = tool.HostToolWrapper('fastboot', platform_build_out) + fastboot_tool = tool.HostToolWrapper('fastboot', + target.platform_build_cache()) provision_tool = tool.ProvisionDeviceTool( - os_source_dir, platform_build_out, bsp, - env={'PATH': os.path.dirname(fastboot_tool.path())}) + target, env={'PATH': os.path.dirname(fastboot_tool.path())}) for t in (fastboot_tool, provision_tool): if not t.exists(): @@ -130,8 +127,7 @@ def _get_provision_tool(os_source_dir, platform_build_out, bsp): return provision_tool -def provision_device(target, platform_build_out, system_image_dir=None, - provision_args=None): +def provision_device(target, system_image_dir=None, provision_args=None): """Provisions the attached device using the `provision-device` script. Requires that the platform has been built so that the image files, @@ -139,26 +135,21 @@ def provision_device(target, platform_build_out, system_image_dir=None, Args: target: the project Target object. - platform_build_out: the root of the platform build output. system_image_dir: directory containing the custom system.img to flash. If None or the system.img file does not exist, uses the default system.img from platform_build_out instead. provision_args: list of string args to pass to provision-device. - Returns: - The `provision-device` exit code. - Raises: MissingBuildError: the platform has not been built yet. core.util.OSVersionError: the target requests an invalid os version. + core.tool.Error: (or a subclass) a problem occurs running the tool. """ - os_source_dir = util.GetOSPath(target.os_version) - provision_tool = _get_provision_tool(os_source_dir, platform_build_out, - target.board) + provision_tool = _get_provision_tool(target) # Combine the platform ANDROID_PRODUCT_OUT directory with our system.img. with _ProvisionDir(provision_tool.environment['ANDROID_PRODUCT_OUT'], system_image_dir) as provision_dir: # Point provision-device to the new directory. provision_tool.environment['ANDROID_PRODUCT_OUT'] = provision_dir - return provision_tool.run(provision_args) + provision_tool.run(provision_args) diff --git a/cli/lib/core/provision_unittest.py b/cli/lib/core/provision_unittest.py index d5dc10b..eb4bba4 100644 --- a/cli/lib/core/provision_unittest.py +++ b/cli/lib/core/provision_unittest.py @@ -20,7 +20,9 @@ import os import unittest +from bsp import device_stub from core import provision +from core import tool from core import util from core import util_stub import error @@ -36,9 +38,12 @@ class ProvisionDeviceTest(unittest.TestCase): _CUSTOM_SYSTEM_IMAGE_PATH = os.path.join(_CUSTOM_SYSTEM_IMAGE_DIR, 'system.img') _HOST_ARCH = 'foo_arch' - _PLATFORM_BUILD_OUT = '/platform' + _OS_VERSION = '55.55' + _PLATFORM_OUT = '/platform' + _BUILD_TYPE = 'userdebug' # Necessary paths derived from our constants. + _PLATFORM_BUILD_OUT = os.path.join(_PLATFORM_OUT, _BUILD_TYPE) _PRODUCT_BUILD_OUT = util.GetAndroidProductOut(_PLATFORM_BUILD_OUT, _BSP) _PROVISION_DEVICE_PATH = os.path.join(_PRODUCT_BUILD_OUT, 'provision-device') @@ -47,13 +52,15 @@ class ProvisionDeviceTest(unittest.TestCase): _HOST_BUILD_OUT = os.path.join(_PLATFORM_BUILD_OUT, 'host', _HOST_ARCH) _FASTBOOT_PATH = os.path.join(_HOST_BUILD_OUT, 'bin', 'fastboot') + def setUp(self): """Overrides imported modules with stubs.""" self.stub_os = stubs.StubOs() self.stub_shutil = stubs.StubShutil(self.stub_os) self.stub_tempfile = stubs.StubTempfile(self.stub_os) self.stub_subprocess = stubs.StubSubprocess() - self.stub_util = util_stub.StubUtil(arch=self._HOST_ARCH) + self.stub_util = util_stub.StubUtil(arch=self._HOST_ARCH, + os_version=self._OS_VERSION) provision.os = self.stub_os provision.shutil = self.stub_shutil @@ -64,8 +71,11 @@ class ProvisionDeviceTest(unittest.TestCase): provision.tool.subprocess = self.stub_subprocess provision.tool.util = self.stub_util + self.device = device_stub.StubDevice() self.target = target_stub.StubTarget( - board=self._BSP, os_version=self.stub_util.GetOSVersion()) + board=self._BSP, os_version=self._OS_VERSION, + device=self.device, + platform_dir=self._PLATFORM_OUT, build_type=self._BUILD_TYPE) # Give more obvious names to some commonly used variables. self.provision_temp_dir = self.stub_tempfile.temp_dir @@ -88,13 +98,14 @@ class ProvisionDeviceTest(unittest.TestCase): self._PROVISION_DEVICE_PATH, os.path.join(self.provision_temp_dir, 'provision-device'))) self.stub_os.should_makedirs.append(self.provision_temp_dir) + self.device.should_link_version = self._OS_VERSION def test_call(self): """Tests a successful provision-device call.""" self.prepare_os_files() command = self.stub_subprocess.AddCommand() - provision.provision_device(self.target, self._PLATFORM_BUILD_OUT) + provision.provision_device(self.target) # provision-device environment must have: # * PATH contain the fastboot executable. # * ANDROID_BUILD_TOP point to the OS source root. @@ -114,7 +125,7 @@ class ProvisionDeviceTest(unittest.TestCase): self.stub_os.environ['PATH'] = '/foo/bar:/baz' command = self.stub_subprocess.AddCommand() - provision.provision_device(self.target, self._PLATFORM_BUILD_OUT) + provision.provision_device(self.target) self.assertEqual( self.stub_os.path.dirname(self._FASTBOOT_PATH) + ':/foo/bar:/baz', command.GetCallArgs()[1]['env']['PATH']) @@ -145,7 +156,7 @@ class ProvisionDeviceTest(unittest.TestCase): # up. self.stub_subprocess.AddCommand(side_effect=check_symlinks) - provision.provision_device(self.target, self._PLATFORM_BUILD_OUT) + provision.provision_device(self.target) def test_custom_system_image(self): """Tests that a custom system.img is used if provided.""" @@ -163,8 +174,7 @@ class ProvisionDeviceTest(unittest.TestCase): self.stub_subprocess.AddCommand(side_effect=check_custom_image_link) provision.provision_device( - self.target, self._PLATFORM_BUILD_OUT, - system_image_dir=self._CUSTOM_SYSTEM_IMAGE_DIR) + self.target, system_image_dir=self._CUSTOM_SYSTEM_IMAGE_DIR) def test_custom_system_image_missing(self): """Tests specifying a nonexistent custom system.img.""" @@ -184,8 +194,7 @@ class ProvisionDeviceTest(unittest.TestCase): self.stub_subprocess.AddCommand(side_effect=check_default_image_link) provision.provision_device( - self.target, self._PLATFORM_BUILD_OUT, - system_image_dir=self._CUSTOM_SYSTEM_IMAGE_DIR) + self.target, system_image_dir=self._CUSTOM_SYSTEM_IMAGE_DIR) def test_provision_exit_code(self): """Tests non-zero exit codes are propagated.""" @@ -194,8 +203,8 @@ class ProvisionDeviceTest(unittest.TestCase): errno = error.GENERIC_ERRNO + 1 self.stub_subprocess.AddCommand(ret_code=errno) - with self.assertRaises(error.Error) as e: - provision.provision_device(self.target, self._PLATFORM_BUILD_OUT) + with self.assertRaises(tool.Error) as e: + provision.provision_device(self.target) self.assertEqual(errno, e.exception.errno) def test_fastboot_missing(self): @@ -205,7 +214,7 @@ class ProvisionDeviceTest(unittest.TestCase): self.stub_subprocess.AddCommand() with self.assertRaises(provision.MissingBuildError): - provision.provision_device(self.target, self._PLATFORM_BUILD_OUT) + provision.provision_device(self.target) def test_provision_device_missing(self): """Tests failure when provision-device is missing.""" @@ -214,4 +223,4 @@ class ProvisionDeviceTest(unittest.TestCase): self.stub_subprocess.AddCommand() with self.assertRaises(provision.MissingBuildError): - provision.provision_device(self.target, self._PLATFORM_BUILD_OUT) + provision.provision_device(self.target) diff --git a/cli/lib/core/tool.py b/cli/lib/core/tool.py index 96f1da7..3bafcb3 100644 --- a/cli/lib/core/tool.py +++ b/cli/lib/core/tool.py @@ -249,26 +249,31 @@ class ProvisionDeviceTool(ToolWrapper): they will have to call provision-device manually. """ - def __init__(self, source_top, build_out, bsp, env=None): + def __init__(self, target, env=None): """Initializes a ProvisionDeviceTool. Args: - source_top: root of the source tree with the vendor BSP binaries. - build_out: root of the build output folder where the tool lives. - bsp: the BSP name. + target: The Target to provision. env: a dictionary of additional environmental variables to set. """ # Initialize path to '' at first so we can use ANDROID_PRODUCT_OUT. super(ProvisionDeviceTool, self).__init__('', env=env) - self.set_android_environment(source_top=source_top, build_out=build_out, - bsp=bsp) + self.set_android_environment( + source_top=util.GetOSPath(target.os_version), + build_out=target.platform_build_cache(), + bsp=target.board) self._tool_path = os.path.join(self.environment['ANDROID_PRODUCT_OUT'], 'provision-device') + self._target = target # provision-device is a shell script, so it needs to know PATH in order # to find utilities. self.add_caller_env_path() + def run(self, arg_array=None): + with self._target.get_device().linked(self._target.os_version): + super(ProvisionDeviceTool, self).run(arg_array) + class BrunchToolWrapper(ToolWrapper): """Legacy tool wrapper used by Brunch. diff --git a/cli/lib/core/tool_unittest.py b/cli/lib/core/tool_unittest.py index 4bca8f1..db67412 100644 --- a/cli/lib/core/tool_unittest.py +++ b/cli/lib/core/tool_unittest.py @@ -19,9 +19,11 @@ import unittest +from bsp import device_stub from core import config from core import tool from core import util_stub +from project import target_stub from test import stubs @@ -163,8 +165,13 @@ class ToolWrapperTest(unittest.TestCase): def test_provision_device_tool(self): """Tests ProvisionDeviceTool construction.""" self.stub_util.arch = 'test_arch' - t = tool.ProvisionDeviceTool(source_top='/source', - build_out='/build/out', bsp='board_name') + self.stub_util.os_version = '12.34' + self.stub_util.os_path = '/source' + target = target_stub.StubTarget( + os_version='12.34', board='board_name', build_type='out', + device=device_stub.StubDevice(should_link_version='12.34'), + platform_dir='/build') + t = tool.ProvisionDeviceTool(target) command = self.stub_subprocess.AddCommand() t.run() diff --git a/cli/lib/project/target_stub.py b/cli/lib/project/target_stub.py index 1059a63..2f4f993 100644 --- a/cli/lib/project/target_stub.py +++ b/cli/lib/project/target_stub.py @@ -20,7 +20,6 @@ import os - from core import util from project import target @@ -58,7 +57,7 @@ class StubTarget(object): return os.path.join(self.platform_dir, *relpath) def platform_build_cache(self, *relpath): - return self.platform_cache('build_type_specific', *relpath) + return self.platform_cache(self.build_type, *relpath) def create_submap(self, _packmap): if self._submap_raises: |