aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAri Hausman-Cohen <arihc@google.com>2016-05-09 14:50:18 -0700
committerAri Hausman-Cohen <arihc@google.com>2016-05-09 17:22:26 -0700
commit567e5d85d6ca03464b4b0804a4fe86a470d9f488 (patch)
treeda7ad425ca3b4be5af1a8812d33e22bc8cb49202
parentae13a180487a8f9314e76ec827f2dfe8ce09e2bd (diff)
downloadbdk-567e5d85d6ca03464b4b0804a4fe86a470d9f488.tar.gz
Removed OS stuff from core.util.
With the exception of DEPRECATED_GetDefaultOSPath. Now, use methods of <platform>.os. BUG: 28637815 TEST: Unit tests pass, ran affected commands Change-Id: I8b3ff07580a9c03ea662ac39de9955966f57f109
-rw-r--r--cli/lib/bsp/device.py18
-rw-r--r--cli/lib/bsp/device_unittest.py32
-rw-r--r--cli/lib/commands/bsp/download.py6
-rw-r--r--cli/lib/commands/bsp/list.py4
-rw-r--r--cli/lib/commands/bsp/refresh.py2
-rw-r--r--cli/lib/commands/bsp/status.py3
-rw-r--r--cli/lib/commands/v2/root/init.py18
-rw-r--r--cli/lib/core/build_unittest.py2
-rw-r--r--cli/lib/core/image_build_unittest.py4
-rw-r--r--cli/lib/core/provision_unittest.py6
-rw-r--r--cli/lib/core/tool.py38
-rw-r--r--cli/lib/core/tool_unittest.py26
-rw-r--r--cli/lib/core/util.py47
-rw-r--r--cli/lib/core/util_stub.py26
-rw-r--r--cli/lib/core/util_unittest.py34
-rw-r--r--cli/lib/environment/toolchain_util_unittest.py2
-rw-r--r--cli/lib/project/platform.py3
-rw-r--r--cli/lib/project/platform_unittest.py2
18 files changed, 85 insertions, 188 deletions
diff --git a/cli/lib/bsp/device.py b/cli/lib/bsp/device.py
index 8570659..5e966b0 100644
--- a/cli/lib/bsp/device.py
+++ b/cli/lib/bsp/device.py
@@ -90,13 +90,13 @@ class Device(object):
self.version = '0.0.0'
self._package_map = package_map
- def status(self, os_version='', verbose=False):
+ def status(self, os_=None, verbose=False):
"""Checks the status of a device.
Args:
- os_version: (optional) The os version to check the status of this
- device against. If empty, ignore LINKED/UNRECOGNIZED;
- only worry about INSTALLED/MISSING/NOT_INSTALLED.
+ os_: (optional) The os to check the status of this device against.
+ If empty, ignore LINKED/UNRECOGNIZED; only worry about
+ INSTALLED/MISSING/NOT_INSTALLED.
verbose: (optional) If True, also return details of subpackages.
Returns:
@@ -112,8 +112,8 @@ class Device(object):
packages_string += '\n * {0}'.format(pkg.name)
for (subpackage, relpath) in subpackage_map.iteritems():
subpackage_path = ''
- if os_version:
- subpackage_path = util.GetOSPath(os_version, relpath)
+ if os_:
+ subpackage_path = os_.path(relpath)
(subpackage_status, subpackage_string) = pkg.subpackage_status(
subpackage, subpackage_path)
packages_string += '\n * {0}'.format(subpackage_string)
@@ -195,11 +195,11 @@ class Device(object):
raise PackageUnlinkError('{} from {}: {}'.format(self.name, os_,
errors))
- def unrecognized_paths(self, os_version):
+ def unrecognized_paths(self, os_):
"""Get the paths of unrecognized subpackages of this device.
Args:
- os_version: The OS version to check for unrecognized paths in.
+ os_: The OS to check for unrecognized paths in.
Returns:
A list of paths of unrecognized subpackages of this device.
@@ -207,7 +207,7 @@ class Device(object):
result = []
for (pkg, subpackage_map) in self._package_map.iteritems():
for (subpackage, relpath) in subpackage_map.iteritems():
- subpackage_path = util.GetOSPath(os_version, relpath)
+ subpackage_path = os_.path(relpath)
status_, _ = pkg.subpackage_status(subpackage, subpackage_path)
if status_ == status.UNRECOGNIZED:
result.append(subpackage_path)
diff --git a/cli/lib/bsp/device_unittest.py b/cli/lib/bsp/device_unittest.py
index a1afab3..0985d0b 100644
--- a/cli/lib/bsp/device_unittest.py
+++ b/cli/lib/bsp/device_unittest.py
@@ -57,7 +57,7 @@ class DeviceTest(unittest.TestCase):
self.stub_open = stubs.StubOpen(self.stub_os)
self.stub_hashlib = stubs.StubHashlib()
self.stub_tar_package = package_stub.StubTarPackage('tarball_version')
- self.stub_util = util_stub.StubUtil(os_version=self._OS_VERSION)
+ self.stub_util = util_stub.StubUtil()
device.os = self.stub_os
device.open = self.stub_open.open
@@ -69,7 +69,8 @@ class DeviceTest(unittest.TestCase):
'test_device', 'Test Device', 'test_vendor', 'test_arch',
{self.package1: {'subpackage_1': 'path1', 'subpackage_2': 'path2'},
self.package2: {'subpackage_2': 'path3'}})
- self.os_ = operating_system_stub.StubOperatingSystem(root=self._OS_PATH)
+ self.os_ = operating_system_stub.StubOperatingSystem(
+ root=self._OS_PATH, version=self._OS_VERSION)
def test_init(self):
# Check all public attributes.
@@ -120,19 +121,19 @@ class DeviceTest(unittest.TestCase):
device.Device.from_dict(self.dev_json, 'a_name', self.packages)
def test_status_installed(self):
- self.assertEqual(self.dev.status(self._OS_VERSION)[0], status.INSTALLED)
+ self.assertEqual(self.dev.status(self.os_)[0], status.INSTALLED)
self.assertEqual(self.dev.status()[0], status.INSTALLED)
def test_status_linked(self):
self.package1.subpackages['subpackage_1'] = status.LINKED
- self.assertEqual(self.dev.status(self._OS_VERSION)[0], status.LINKED)
+ self.assertEqual(self.dev.status(self.os_)[0], status.LINKED)
self.assertEqual(self.dev.status()[0], status.INSTALLED)
def test_status_unrecognized(self):
self.package1.subpackages['subpackage_1'] = status.LINKED
self.package1.subpackages['subpackage_2'] = status.UNRECOGNIZED
# Also test that this beats out linked.
- self.assertEqual(self.dev.status(self._OS_VERSION)[0],
+ self.assertEqual(self.dev.status(self.os_)[0],
status.UNRECOGNIZED)
# In certain situations, this could also be missing, but that's more
# complex to code into stubs.
@@ -144,7 +145,7 @@ class DeviceTest(unittest.TestCase):
self.package2.subpackages['subpackage_2'] = status.MISSING
# Also test that this beats out linked and unrecognized.
self.assertEqual(self.dev.status()[0], status.MISSING)
- self.assertEqual(self.dev.status(self._OS_VERSION)[0], status.MISSING)
+ self.assertEqual(self.dev.status(self.os_)[0], status.MISSING)
def test_status_not_installed(self):
@@ -154,7 +155,7 @@ class DeviceTest(unittest.TestCase):
# Also test that this beats out missing and unrecognized
# (and transitively linked).
self.assertEqual(self.dev.status()[0], status.NOT_INSTALLED)
- self.assertEqual(self.dev.status(self._OS_VERSION)[0],
+ self.assertEqual(self.dev.status(self.os_)[0],
status.NOT_INSTALLED)
def test_is_available(self):
@@ -297,13 +298,10 @@ class DeviceTest(unittest.TestCase):
self.package1.subpackages['subpackage_1'] = status.NOT_INSTALLED
self.package1.subpackages['subpackage_2'] = status.UNRECOGNIZED
self.package2.subpackages['subpackage_2'] = status.UNRECOGNIZED
- result = self.dev.unrecognized_paths(self._OS_VERSION)
- self.assertIn(self.stub_util.GetOSPath(self._OS_VERSION, 'path2'),
- result)
- self.assertIn(self.stub_util.GetOSPath(self._OS_VERSION, 'path3'),
- result)
- self.assertNotIn(self.stub_util.GetOSPath(self._OS_VERSION, 'path1'),
- result)
+ result = self.dev.unrecognized_paths(self.os_)
+ self.assertIn(self.os_.path('path2'), result)
+ self.assertIn(self.os_.path('path3'), result)
+ self.assertNotIn(self.os_.path('path1'), result)
def test_match_tarball(self):
matching = package.TarPackage('match', None,
@@ -364,11 +362,11 @@ class DeviceTest(unittest.TestCase):
self.dev.install(auto_accept=True, link_os=self.os_)
self.assertTrue(self.dev.is_available())
self.assertEqual(self.package1.subpackage_status(
- 'subpackage_1', self._OS_VERSION)[0], status.LINKED)
+ 'subpackage_1', link1)[0], status.LINKED)
self.assertEqual(self.package1.subpackage_status(
- 'subpackage_2', self._OS_VERSION)[0], status.LINKED)
+ 'subpackage_2', link2)[0], status.LINKED)
self.assertEqual(self.package2.subpackage_status(
- 'subpackage_2', self._OS_VERSION)[0], status.LINKED)
+ 'subpackage_2', link3)[0], status.LINKED)
def test_failed_install(self):
self.package1.downloaded = False
diff --git a/cli/lib/commands/bsp/download.py b/cli/lib/commands/bsp/download.py
index defc26d..54421cf 100644
--- a/cli/lib/commands/bsp/download.py
+++ b/cli/lib/commands/bsp/download.py
@@ -64,7 +64,6 @@ class Update(clicommand.Command):
return 1
os_ = bsp_manifest.operating_systems['brillo']
- os_version = os_.version
link_os = os_ if args.link else ''
try:
@@ -75,8 +74,7 @@ class Update(clicommand.Command):
print e
# Print and return the results.
- (device_status, status_string) = device_.status(os_version,
- verbose=True)
+ (device_status, status_string) = device_.status(os_, verbose=True)
print status_string
if device_status <= status.LINKED:
# LINKED or INSTALLED
@@ -85,7 +83,7 @@ class Update(clicommand.Command):
return 0
elif device_status == status.UNRECOGNIZED:
print 'The following paths exist but do not link to BSP packages:'
- for path in device_.unrecognized_paths(os_version):
+ for path in device_.unrecognized_paths(os_):
print ' * ' + path
print ('If this is not intentional, consider '
'removing them and installing again.')
diff --git a/cli/lib/commands/bsp/list.py b/cli/lib/commands/bsp/list.py
index 8d75896..72e3a26 100644
--- a/cli/lib/commands/bsp/list.py
+++ b/cli/lib/commands/bsp/list.py
@@ -43,11 +43,11 @@ class List(clicommand.Command):
bsp_manifest = manifest.Manifest.from_json(manifest_file)
devices = []
- os_version = util.GetOSVersion()
+ os_ = bsp_manifest.operating_systems['brillo']
for short_name in sorted(bsp_manifest.devices):
device = bsp_manifest.devices[short_name]
- (_, status_string) = device.status(os_version, verbose)
+ (_, status_string) = device.status(os_, verbose)
devices.append((short_name, status_string))
return devices
diff --git a/cli/lib/commands/bsp/refresh.py b/cli/lib/commands/bsp/refresh.py
index e8c0330..2feb16d 100644
--- a/cli/lib/commands/bsp/refresh.py
+++ b/cli/lib/commands/bsp/refresh.py
@@ -65,7 +65,7 @@ class Refresh(clicommand.Command):
extract_only.keys())
return 1
- os_version = util.GetOSVersion()
+ os_version = bsp_manifest.operating_systems['brillo'].version
link_os = os_version if args.link else ''
print 'Cleaning up...'
diff --git a/cli/lib/commands/bsp/status.py b/cli/lib/commands/bsp/status.py
index e55aac1..9ad5c47 100644
--- a/cli/lib/commands/bsp/status.py
+++ b/cli/lib/commands/bsp/status.py
@@ -36,6 +36,7 @@ class Status(clicommand.Command):
if not device:
print 'Unrecognized device name:', args.device
return 1
+ os_ = bsp_manifest.operating_systems['brillo']
- print device.status(util.GetOSVersion(), verbose=True)[1]
+ print device.status(os_, verbose=True)[1]
return 0
diff --git a/cli/lib/commands/v2/root/init.py b/cli/lib/commands/v2/root/init.py
index d85a1e7..3011336 100644
--- a/cli/lib/commands/v2/root/init.py
+++ b/cli/lib/commands/v2/root/init.py
@@ -21,6 +21,7 @@ from __future__ import print_function
import os
+from bsp import operating_system
from cli import clicommand
from core import util
from project import platform
@@ -39,12 +40,12 @@ IMAGE_SPEC_TEMPLATE = """\
to a working image as well as what other runtime dependencies are
needed.
- This sample pack requires the brillo core, then copies the contents of
+ This sample pack requires the os core, then copies the contents of
service/{project}/bin/ to the /system/bin/ folder of the output
image. -->
<packs namespace="{project}">
<pack name="main">
- <!-- Example rules to require brillo core and copy binaries to the image.
+ <!-- Example rules to require os core and copy binaries to the image.
<requires pack="os.core"/>
<copy recurse="true" from="service/{project}/bin/" to="/system/bin/"/>
-->
@@ -58,11 +59,11 @@ IMAGE_SPEC_TEMPLATE = """\
build of the OS (no/minimal debugging) and the other uses a "userdebug"
build which includes debugging information. -->
<target name="{project}-release" pack="{project}.main"
- os="brillo" os-version="{os_version}"
+ os="{os_name}" os-version="{os_version}"
board="{board}" board-version="{board_version}"
build="user"/>
<target name="{project}-userdebug" pack="{project}.main"
- os="brillo" os-version="{os_version}"
+ os="{os_name}" os-version="{os_version}"
board="{board}" board-version="{board_version}"
build="userdebug"/>
</targets>
@@ -79,8 +80,10 @@ class Init(clicommand.Command):
parser.add_argument('--board_version',
default='0.0.0',
help='The BSP version to use.')
+ parser.add_argument('--os_name', default='brillo',
+ help='The OS name.')
parser.add_argument('--os_version',
- default=util.GetOSVersion(),
+ default='',
help='The OS version.')
parser.add_argument('--project',
default=os.path.basename(os.getcwd()),
@@ -92,7 +95,7 @@ class Init(clicommand.Command):
# Create a platform object to check if requested OS and BSP
# are compatible (will raise if not), and then warn if the
# components need to be downloaded.
- platform_ = platform.Platform('brillo', args.os_version,
+ platform_ = platform.Platform(args.os_name, args.os_version,
args.board, args.board_version,
platform.BUILD_TYPE_USERDEBUG)
try:
@@ -102,7 +105,8 @@ class Init(clicommand.Command):
sample = IMAGE_SPEC_TEMPLATE.format(
board=args.board, board_version=args.board_version,
- os_version=args.os_version, project=args.project)
+ os_name=args.os_name, os_version=args.os_version,
+ project=args.project)
if os.path.isfile(filename):
choice = util.GetUserInput('The file {} already exists. Do you '
diff --git a/cli/lib/core/build_unittest.py b/cli/lib/core/build_unittest.py
index d50f958..f79d5bb 100644
--- a/cli/lib/core/build_unittest.py
+++ b/cli/lib/core/build_unittest.py
@@ -36,7 +36,7 @@ class BuildPlatformTest(unittest.TestCase):
def setUp(self):
self.stub_os = stubs.StubOs()
- self.stub_util = util_stub.StubUtil(os_version=self._OS_VERSION)
+ self.stub_util = util_stub.StubUtil()
self.stub_subprocess = stubs.StubSubprocess()
# Allow BuildPlatform() to make the directory for the log file.
diff --git a/cli/lib/core/image_build_unittest.py b/cli/lib/core/image_build_unittest.py
index d15a595..b923ced 100644
--- a/cli/lib/core/image_build_unittest.py
+++ b/cli/lib/core/image_build_unittest.py
@@ -63,7 +63,7 @@ class BuildImageBase(TestData):
self.stub_shutil = stubs.StubShutil(self.stub_os)
self.stub_subprocess = stubs.StubSubprocess()
self.stub_sysroot_generator = sysroot_stub.StubSysrootGenerator()
- self.stub_util = util_stub.StubUtil(os_version=self._BRILLO_VERSION)
+ self.stub_util = util_stub.StubUtil()
image_build.os = self.stub_os
image_build.open = self.stub_open.open
@@ -256,12 +256,14 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_sysroot_generator = sysroot_stub.StubSysrootGenerator()
self.stub_os = stubs.StubOs()
+ self.stub_shutil = stubs.StubShutil(self.stub_os)
self.stub_open = stubs.StubOpen(self.stub_os)
self.stub_glob = stubs.StubGlob(self.stub_os)
image_build.glob = self.stub_glob
image_build.os = self.stub_os
image_build.open = self.stub_open.open
+ image_build.shutil = self.stub_shutil
image_build.sysroot = self.stub_sysroot_generator
metadata_split = self.metadata_cache_dir.split('/')
diff --git a/cli/lib/core/provision_unittest.py b/cli/lib/core/provision_unittest.py
index 2485026..5cdd966 100644
--- a/cli/lib/core/provision_unittest.py
+++ b/cli/lib/core/provision_unittest.py
@@ -43,7 +43,8 @@ class ProvisionDeviceTest(unittest.TestCase):
# Necessary paths derived from our constants.
_PLATFORM_BUILD_OUT = os.path.join('/platform', _BUILD_TYPE)
- _PRODUCT_BUILD_OUT = util.GetAndroidProductOut(_PLATFORM_BUILD_OUT, _BSP)
+ _PRODUCT_BUILD_OUT = os.path.join(_PLATFORM_BUILD_OUT, 'target', 'product',
+ _BSP)
_PROVISION_DEVICE_PATH = os.path.join(_PRODUCT_BUILD_OUT,
'provision-device')
_DEFAULT_SYSTEM_IMAGE_PATH = os.path.join(_PRODUCT_BUILD_OUT, 'system.img')
@@ -58,8 +59,7 @@ class ProvisionDeviceTest(unittest.TestCase):
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,
- os_version=self._OS_VERSION)
+ self.stub_util = util_stub.StubUtil(arch=self._HOST_ARCH)
provision.os = self.stub_os
provision.shutil = self.stub_shutil
diff --git a/cli/lib/core/tool.py b/cli/lib/core/tool.py
index cbab9ff..502550e 100644
--- a/cli/lib/core/tool.py
+++ b/cli/lib/core/tool.py
@@ -79,35 +79,22 @@ class ToolWrapper(object):
def set_cwd(self, cwd):
self._cwd = cwd
- def set_android_environment(self, source_top=None, build_out=None,
- bsp=None):
+ def set_android_environment(self, platform):
"""Sets Android environment variables.
Android has a few common variables used by a variety of tools. This
- function sets any environment variables that can be derived from
- the given arguments.
-
- All arguments are optional, any variables that depend on missing
- arguments will not be modified. Requirements are:
- ANDROID_BUILD_TOP: source_top
- ANDROID_HOST_OUT: build_out
- ANDROID_PRODUCT_OUT: build_out, bsp
+ function sets ANDROID_BUILD_TOP, ANDROID_HOST_OUT, and
+ ANDROID_PRODUCT_OUT.
Args:
- source_top: root of the source tree.
- build_out: root of the build output folder.
- bsp: the BSP name.
+ platform: The project.Platform the tool is being used for.
"""
- if source_top:
- self.environment['ANDROID_BUILD_TOP'] = source_top
+ self.environment['ANDROID_BUILD_TOP'] = platform.os.root
- if build_out:
- self.environment['ANDROID_HOST_OUT'] = os.path.join(
- build_out, 'host', util.GetHostArch())
+ self.environment['ANDROID_HOST_OUT'] = os.path.join(
+ platform.build_cache, 'host', util.GetHostArch())
- if build_out and bsp:
- self.environment['ANDROID_PRODUCT_OUT'] = util.GetAndroidProductOut(
- build_out, bsp)
+ self.environment['ANDROID_PRODUCT_OUT'] = platform.product_out_cache
def add_caller_env_path(self):
"""Adds the caller's PATH environment variable.
@@ -193,9 +180,7 @@ class HostToolWrapper(ToolWrapper):
"""
# Initialize path to '' at first so we can use ANDROID_HOST_OUT.
super(HostToolWrapper, self).__init__('', env=env)
- self.set_android_environment(source_top=platform.os.root,
- build_out=platform.build_cache,
- bsp=platform.device.name)
+ self.set_android_environment(platform)
self._tool_path = os.path.join(self.environment['ANDROID_HOST_OUT'],
'bin', path)
@@ -254,10 +239,7 @@ class ProvisionDeviceTool(ToolWrapper):
"""
super(ProvisionDeviceTool, self).__init__(
os.path.join(provision_dir, 'provision-device'), env=env)
- self.set_android_environment(
- source_top=platform.os.root,
- build_out=platform.build_cache,
- bsp=platform.device.name)
+ self.set_android_environment(platform)
# Adjust ANDROID_PRODUCT_OUT to use the provision dir instead of
# just the platform build.
self.environment['ANDROID_PRODUCT_OUT'] = provision_dir
diff --git a/cli/lib/core/tool_unittest.py b/cli/lib/core/tool_unittest.py
index 9f09093..229d7ec 100644
--- a/cli/lib/core/tool_unittest.py
+++ b/cli/lib/core/tool_unittest.py
@@ -32,7 +32,7 @@ class ToolWrapperTest(unittest.TestCase):
def setUp(self):
self.stub_os = stubs.StubOs()
self.stub_subprocess = stubs.StubSubprocess()
- self.stub_util = util_stub.StubUtil()
+ self.stub_util = util_stub.StubUtil(arch='host_test_arch')
tool.os = self.stub_os
tool.util = self.stub_util
@@ -40,7 +40,9 @@ class ToolWrapperTest(unittest.TestCase):
self.platform = platform_stub.StubPlatform(
os_version='12.34', os_root='/source', board='board_name',
- should_link=True, build_cache='/build/out')
+ should_link=True, device_arch='test_arch',
+ build_cache='/build/out',
+ product_out_cache='/build/out/target/product/board_name')
def test_run(self):
"""Tests a basic tool run."""
@@ -128,26 +130,18 @@ class ToolWrapperTest(unittest.TestCase):
t.add_caller_env_path()
self.assertEqual('/foo:/bar', t.environment['PATH'])
- def test_source_top(self):
- """Tests setting source_top."""
+ def test_android_env(self):
+ """Tests setting android environment."""
t = tool.ToolWrapper('/my/tool')
- t.set_android_environment(source_top='/foo')
- command = self.stub_subprocess.AddCommand(['/my/tool'])
-
- t.run()
- command.AssertCallContained(env={'ANDROID_BUILD_TOP': '/foo'})
- def test_build_out_and_bsp(self):
- """Tests passing build_top and bsp to the tool."""
- self.stub_util.arch = 'test_arch'
- t = tool.ToolWrapper('/my/tool')
- t.set_android_environment(build_out='/build/out', bsp='bar')
+ t.set_android_environment(self.platform)
command = self.stub_subprocess.AddCommand(['/my/tool'])
t.run()
command.AssertCallContained(env={
- 'ANDROID_HOST_OUT': '/build/out/host/test_arch',
- 'ANDROID_PRODUCT_OUT': '/build/out/target/product/bar'
+ 'ANDROID_BUILD_TOP': '/source',
+ 'ANDROID_HOST_OUT': '/build/out/host/host_test_arch',
+ 'ANDROID_PRODUCT_OUT': '/build/out/target/product/board_name'
})
def test_host_tool_wrapper(self):
diff --git a/cli/lib/core/util.py b/cli/lib/core/util.py
index 3e8349b..3204a22 100644
--- a/cli/lib/core/util.py
+++ b/cli/lib/core/util.py
@@ -72,38 +72,16 @@ def GetBDKVersion():
vars()['bdk_version'] = version
return version
-# TODO(b/28527859): replace via Platform.
-def GetOSVersion():
- """Find the OS version"""
- # TODO(b/27653682): Separate versions for OS & BDK.
- # Note: this function will be removed once OSes are downloaded like
- # BSPs. At that point, code should check the manifest for available
- # versions.
- return GetBDKVersion()
-
-# TODO(b/28527859): move into Platform.
-def GetOSPath(os_version, *relpath_args):
- """Find a path relative to the base of an OS.
- Raises:
- OSVersionError: The designated OS is not installed.
- """
- if os_version != GetOSVersion():
- raise OSVersionError('Brillo {} is not installed '
- '(installed version is: {}, the BDK does not yet '
- 'support installing additional versions).'.format(
- os_version, GetOSVersion()))
- # For now, the BDK is actually under the OS at <os>/tools/bdk,
- # so we can figure out where the OS is based on that.
- return GetBDKPath('..', '..', *relpath_args)
-
-# TODO(b/28527859): move into Platform.
def DEPRECATED_GetDefaultOSPath(*relpath):
- """DEPRECATED - use GetOSPath.
+ """DEPRECATED - use <platform>.os.path.
- For use by legacy brunch commands without a target os version.
+ For use by legacy brunch commands without a target platform.
+ Not compatible with out-of-tree BDK.
"""
- return GetOSPath(GetOSVersion(), *relpath)
+ # Assume we're using in-tree BDK, which is located
+ # at <os_path>/tools/bdk.
+ return GetBDKPath('..', '..', *relpath)
def GetProductDir():
@@ -116,19 +94,6 @@ def GetProductDir():
return None
-def GetAndroidProductOut(platform_build_out, board):
- """Returns the ANDROID_PRODUCT_OUT directory.
-
- Args:
- platform_build_out: root directory of the platform build output.
- board: board name.
-
- Returns:
- Path to the product build output directory.
- """
- return os.path.join(platform_build_out, 'target', 'product', board)
-
-
def FindProjectSpec():
"""Walks from cwd upward to find the project spec."""
p = os.getcwd()
diff --git a/cli/lib/core/util_stub.py b/cli/lib/core/util_stub.py
index 9a8353d..46008fb 100644
--- a/cli/lib/core/util_stub.py
+++ b/cli/lib/core/util_stub.py
@@ -38,16 +38,16 @@ class StubUtil(object):
PROJECT_SPEC_FILENAME = 'unittest_project_spec.xml'
def __init__(self, bdk_path='/some/bdk/path',
- user_data_path='/user/data/path', os_path='/os/path',
- bdk_version='99.99', os_version='88.88', arch='fake_arch'):
+ user_data_path='/user/data/path',
+ bdk_version='99.99', arch='fake_arch',
+ deprecated_os_path='/no/longer/a/thing'):
self.bdk_path = bdk_path
self.user_data_path = user_data_path
- self.os_path = os_path
self.bdk_version = bdk_version
- self.os_version = os_version
self.arch = arch
self.arch_is_supported = True
self.project_spec = None
+ self.deprecated_os_path = deprecated_os_path
def GetBDKPath(self, *relpath):
return os.path.abspath(os.path.join(self.bdk_path, *relpath))
@@ -55,25 +55,11 @@ class StubUtil(object):
def GetUserDataPath(self, *relpath):
return os.path.join(self.user_data_path, *relpath)
- def DEPRECATED_GetDefaultOSPath(self, *relpath):
- return os.path.join(self.os_path, *relpath)
-
- def GetOSPath(self, version, *relpath):
- if version != self.os_version:
- raise self.OSVersionError(
- 'Invalid OS version: {} (expected {})'.format(version,
- self.os_version))
- return os.path.join(self.os_path, *relpath)
-
def GetBDKVersion(self):
return self.bdk_version
- def GetOSVersion(self):
- return self.os_version
-
- @staticmethod
- def GetAndroidProductOut(platform_out, board):
- return util.GetAndroidProductOut(platform_out, board)
+ def DEPRECATED_GetDefaultOSPath(self, *relpath):
+ return os.path.join(self.deprecated_os_path, *relpath)
@classmethod
def AsShellArgs(cls, ary):
diff --git a/cli/lib/core/util_unittest.py b/cli/lib/core/util_unittest.py
index 71ef2a4..8391692 100644
--- a/cli/lib/core/util_unittest.py
+++ b/cli/lib/core/util_unittest.py
@@ -46,35 +46,6 @@ class UtilTest(unittest.TestCase):
self.stub_os.path.should_exist = [util.GetBDKPath('VERSION')]
self.assertEqual(util.GetBDKVersion(), '123.45')
- def test_os_version(self):
- self.stub_open.files[util.GetBDKPath('VERSION')] = (
- stubs.StubFile('67.89'))
- self.stub_os.path.should_exist = [util.GetBDKPath('VERSION')]
- self.assertEqual(util.GetOSVersion(), '67.89')
-
- def test_os_path(self):
- self.stub_open.files[util.GetBDKPath('VERSION')] = (
- stubs.StubFile('01.23'))
- self.stub_os.path.should_exist = [util.GetBDKPath('VERSION')]
- # We use startswith since it might also be .pyc if unit tests have been
- # previously run.
- self.assertTrue(__file__.startswith(
- util.GetOSPath('01.23', 'tools', 'bdk', 'cli', 'lib', 'core',
- 'util_unittest.py')))
- # Error should complain about requested version.
- with self.assertRaisesRegexp(util.OSVersionError, '4.5'):
- util.GetOSPath('4.5')
-
- def test_deprecated_default_os_path(self):
- self.stub_open.files[util.GetBDKPath('VERSION')] = (
- stubs.StubFile('01.23'))
- self.stub_os.path.should_exist = [util.GetBDKPath('VERSION')]
- # We use startswith since it might also be .pyc if unit tests have been
- # previously run.
- self.assertTrue(__file__.startswith(
- util.DEPRECATED_GetDefaultOSPath('tools', 'bdk', 'cli', 'lib',
- 'core', 'util_unittest.py')))
-
def test_get_product_dir(self):
self.stub_os.cwd = '/long/way/down/to/the/bottom/turtle/'
self.stub_os.path.should_exist = [
@@ -109,11 +80,6 @@ class UtilTest(unittest.TestCase):
self.stub_os.path.join('/other', util.PROJECT_SPEC_FILENAME)]
self.assertEqual(util.FindProjectSpec(), None)
- def test_android_product_out(self):
- self.assertEqual(
- util.GetAndroidProductOut('platform/dir/', 'board_name'),
- 'platform/dir/target/product/board_name')
-
def test_get_host(self):
self.stub_os.SetUname(('Linux', 'host_name.website.com',
'99.99-awesome', 'stuff', 'x86_64'))
diff --git a/cli/lib/environment/toolchain_util_unittest.py b/cli/lib/environment/toolchain_util_unittest.py
index 20dd349..d88f4a5 100644
--- a/cli/lib/environment/toolchain_util_unittest.py
+++ b/cli/lib/environment/toolchain_util_unittest.py
@@ -36,7 +36,7 @@ class ToolchainUtilTest(unittest.TestCase):
self.stub_os = stubs.StubOs()
self.stub_open = stubs.StubOpen(self.stub_os)
self.stub_glob = stubs.StubGlob(self.stub_os)
- self.stub_util = util_stub.StubUtil(os_version=self.OS_VERSION)
+ self.stub_util = util_stub.StubUtil()
toolchain_util.os = self.stub_os
toolchain_util.open = self.stub_open.open
diff --git a/cli/lib/project/platform.py b/cli/lib/project/platform.py
index 7b07fb1..6353ff8 100644
--- a/cli/lib/project/platform.py
+++ b/cli/lib/project/platform.py
@@ -190,7 +190,8 @@ class Platform(object):
@property
def product_out_cache(self):
- return util.GetAndroidProductOut(self.build_cache, self.device.name)
+ return os.path.join(self.build_cache, 'target', 'product',
+ self.device.name)
@property
def toolchain(self):
diff --git a/cli/lib/project/platform_unittest.py b/cli/lib/project/platform_unittest.py
index 28035a5..c3d096e 100644
--- a/cli/lib/project/platform_unittest.py
+++ b/cli/lib/project/platform_unittest.py
@@ -45,7 +45,7 @@ class PlatformTest(unittest.TestCase):
self.stub_manifest = manifest_stub.StubManifestModule(self.stub_op_sys)
self.stub_os = stubs.StubOs()
self.stub_user_config = user_config_stub.StubUserConfig()
- self.stub_util = util_stub.StubUtil(os_version=self._OS_VERSION)
+ self.stub_util = util_stub.StubUtil()
platform.manifest = self.stub_manifest
platform.os = self.stub_os