mirror of
https://github.com/flatcar/scripts.git
synced 2025-11-26 21:11:54 +01:00
Update prebuilt to use cros_overlay_list as the definitive answer for which overlay to modify.
The last entry from the commands output will always be the one that we want. By using this we also avoid having to tack on -private and hope that people who created the overlay conformed to that naming convention. BUG=NA TEST=prebuilt_unittest updated and run Review URL: http://codereview.chromium.org/6348010
This commit is contained in:
parent
e70ccb91b1
commit
2c11e0d7bc
49
prebuilt.py
49
prebuilt.py
@ -54,7 +54,6 @@ _REL_HOST_PATH = 'host/%(target)s/%(version)s/packages'
|
||||
# Private overlays to look at for builds to filter
|
||||
# relative to build path
|
||||
_PRIVATE_OVERLAY_DIR = 'src/private-overlays'
|
||||
_BINHOST_BASE_DIR = 'src/overlays'
|
||||
_BINHOST_BASE_URL = 'http://commondatastorage.googleapis.com/chromeos-prebuilt'
|
||||
_PREBUILT_BASE_DIR = 'src/third_party/chromiumos-overlay/chromeos/config/'
|
||||
# Created in the event of new host targets becoming available
|
||||
@ -324,40 +323,54 @@ def GenerateUploadDict(base_local_path, base_remote_path, pkgs):
|
||||
|
||||
return upload_files
|
||||
|
||||
def GetBoardPathFromCrosOverlayList(build_path, target):
|
||||
"""Use the cros_overlay_list to determine the path to the board overlay
|
||||
Args:
|
||||
build_path: The path to the root of the build directory
|
||||
target: The target that we are looking for, could consist of board and
|
||||
board_variant, we handle that properly
|
||||
Returns:
|
||||
The last line from cros_overlay_list as a string
|
||||
"""
|
||||
script_dir = os.path.join(build_path, 'src/scripts/bin')
|
||||
cmd = ['./cros_overlay_list']
|
||||
if re.match('.*?_.*', target):
|
||||
(board, variant) = target.split('_')
|
||||
cmd += ['--board', board, '--variant', variant]
|
||||
elif re.match('.*?-\w+', target):
|
||||
cmd += ['--board', target]
|
||||
else:
|
||||
raise UnknownBoardFormat('Unknown format: %s' % target)
|
||||
|
||||
def DeterminePrebuiltConfFile(target):
|
||||
cmd_output = cros_build_lib.RunCommand(cmd, redirect_stdout=True,
|
||||
cwd=script_dir)
|
||||
# We only care about the last entry
|
||||
return cmd_output.output.splitlines().pop()
|
||||
|
||||
|
||||
def DeterminePrebuiltConfFile(build_path, target):
|
||||
"""Determine the prebuilt.conf file that needs to be updated for prebuilts.
|
||||
|
||||
Args:
|
||||
build_path: The path to the root of the build directory
|
||||
target: String representation of the board. This includes host and board
|
||||
targets
|
||||
|
||||
Returns
|
||||
A string path to a prebuilt.conf file to be updated.
|
||||
"""
|
||||
overlay_base_dir = _BINHOST_BASE_DIR
|
||||
# If this is a private checkout default to updating
|
||||
# private overlays over public.
|
||||
if os.path.exists(_PRIVATE_OVERLAY_DIR):
|
||||
overlay_base_dir = _PRIVATE_OVERLAY_DIR
|
||||
|
||||
if _HOST_TARGET == target:
|
||||
# We are host.
|
||||
# Without more examples of hosts this is a kludge for now.
|
||||
# TODO(Scottz): as new host targets come online expand this to
|
||||
# work more like boards.
|
||||
make_path = _PREBUILT_MAKE_CONF[target]
|
||||
elif re.match('.*?_.*', target):
|
||||
# We are a board variant
|
||||
overlay_str = 'overlay-variant-%s' % target.replace('_', '-')
|
||||
make_path = os.path.join(overlay_base_dir, overlay_str, 'prebuilt.conf')
|
||||
elif re.match('.*?-\w+', target):
|
||||
overlay_str = 'overlay-%s' % target
|
||||
make_path = os.path.join(overlay_base_dir, overlay_str, 'prebuilt.conf')
|
||||
else:
|
||||
raise UnknownBoardFormat('Unknown format: %s' % target)
|
||||
# We are a board
|
||||
board = GetBoardPathFromCrosOverlayList(build_path, target)
|
||||
make_path = os.path.join(board, 'prebuilt.conf')
|
||||
|
||||
return os.path.join(make_path)
|
||||
return make_path
|
||||
|
||||
|
||||
def UpdateBinhostConfFile(path, key, value):
|
||||
@ -420,7 +433,7 @@ def UploadPrebuilt(build_path, upload_location, version, binhost_base_url,
|
||||
package_path = os.path.join(board_path, 'packages')
|
||||
package_string = board
|
||||
url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version}
|
||||
git_file = os.path.join(build_path, DeterminePrebuiltConfFile(board))
|
||||
git_file = DeterminePrebuiltConfFile(build_path, board)
|
||||
binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'target',
|
||||
'%s.conf' % board)
|
||||
remote_location = '%s/%s' % (upload_location.rstrip('/'), url_suffix)
|
||||
|
||||
@ -195,42 +195,73 @@ class TestPrebuilt(unittest.TestCase):
|
||||
files = {'test': '/uasd'}
|
||||
self.assertEqual(prebuilt.RemoteUpload(files), set([('test', '/uasd')]))
|
||||
|
||||
def testDeterminePrebuiltConfHost(self):
|
||||
"""Test that the host prebuilt path comes back properly."""
|
||||
expected_path = os.path.join(prebuilt._PREBUILT_MAKE_CONF['amd64'])
|
||||
self.assertEqual(prebuilt.DeterminePrebuiltConfFile('fake_path', 'amd64'),
|
||||
expected_path)
|
||||
|
||||
def testDeterminePrebuiltConf(self):
|
||||
"""Test the different known variants of boards for proper path discovery."""
|
||||
targets = {'amd64': os.path.join(prebuilt._PREBUILT_MAKE_CONF['amd64']),
|
||||
'x86-generic': os.path.join(prebuilt._BINHOST_BASE_DIR,
|
||||
'overlay-x86-generic', 'prebuilt.conf'),
|
||||
'arm-tegra2_vogue': os.path.join(
|
||||
prebuilt._BINHOST_BASE_DIR,
|
||||
'overlay-variant-arm-tegra2-vogue', 'prebuilt.conf'),}
|
||||
for target in targets:
|
||||
self.assertEqual(prebuilt.DeterminePrebuiltConfFile(target),
|
||||
targets[target])
|
||||
fake_path = '/b/cbuild'
|
||||
script_path = os.path.join(fake_path, 'src/scripts/bin')
|
||||
public_overlay_path = os.path.join(fake_path, 'src/overlays')
|
||||
private_overlay_path = os.path.join(fake_path,
|
||||
prebuilt._PRIVATE_OVERLAY_DIR)
|
||||
path_dict = {'private_overlay_path': private_overlay_path,
|
||||
'public_overlay_path': public_overlay_path}
|
||||
# format for targets
|
||||
# board target key in dictionar
|
||||
# Tuple containing cmd run, expected results as cmd obj, and expected output
|
||||
|
||||
def testPrivatePrebuiltConf(self):
|
||||
"""Test that we get a different path for private prebuilts"""
|
||||
targets = {'amd64': os.path.join(prebuilt._PREBUILT_MAKE_CONF['amd64']),
|
||||
'x86-generic': os.path.join(
|
||||
prebuilt._PRIVATE_OVERLAY_DIR, 'overlay-x86-generic',
|
||||
'prebuilt.conf'),
|
||||
'arm-tegra2_vogue': os.path.join(
|
||||
prebuilt._PRIVATE_OVERLAY_DIR,
|
||||
'overlay-variant-arm-tegra2-vogue', 'prebuilt.conf'),}
|
||||
# Mock output from cros_overlay_list
|
||||
x86_out = ('%(private_overlay_path)s/chromeos-overlay\n'
|
||||
'%(public_overlay_path)s/overlay-x86-generic\n' % path_dict)
|
||||
|
||||
self.mox.StubOutWithMock(prebuilt.os.path, 'exists')
|
||||
# Add mocks for every target we check
|
||||
for mock_count in range(len(targets)):
|
||||
prebuilt.os.path.exists(prebuilt._PRIVATE_OVERLAY_DIR).AndReturn(True)
|
||||
x86_cmd = './cros_overlay_list --board x86-generic'
|
||||
x86_expected_path = os.path.join(public_overlay_path, 'overlay-x86-generic',
|
||||
'prebuilt.conf')
|
||||
# Mock output from cros_overlay_list
|
||||
tegra2_out = ('%(private_overlay_path)s/chromeos-overlay\n'
|
||||
'%(public_overlay_path)s/overlay-tegra2\n'
|
||||
'%(public_overlay_path)s/overlay-variant-tegra2-seaboard\n'
|
||||
'%(private_overlay_path)s/overlay-tegra2-private\n'
|
||||
'%(private_overlay_path)s/'
|
||||
'overlay-variant-tegra2-seaboard-private\n' % path_dict)
|
||||
tegra2_cmd = './cros_overlay_list --board tegra2 --variant seaboard'
|
||||
tegra2_expected_path = os.path.join(
|
||||
private_overlay_path, 'overlay-variant-tegra2-seaboard-private',
|
||||
'prebuilt.conf')
|
||||
|
||||
|
||||
targets = {'x86-generic': {'cmd': x86_cmd,
|
||||
'output': x86_out,
|
||||
'result': x86_expected_path},
|
||||
'tegra2_seaboard': {'cmd': tegra2_cmd,
|
||||
'output': tegra2_out,
|
||||
'result': tegra2_expected_path}
|
||||
}
|
||||
|
||||
self.mox.StubOutWithMock(prebuilt.cros_build_lib, 'RunCommand')
|
||||
for target, expected_results in targets.iteritems():
|
||||
# create command object for output
|
||||
cmd_result_obj = cros_build_lib.CommandResult()
|
||||
cmd_result_obj.output = expected_results['output']
|
||||
prebuilt.cros_build_lib.RunCommand(
|
||||
expected_results['cmd'].split(), redirect_stdout=True,
|
||||
cwd=script_path).AndReturn(cmd_result_obj)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
for target in targets:
|
||||
self.assertEqual(prebuilt.DeterminePrebuiltConfFile(target),
|
||||
targets[target])
|
||||
for target, expected_results in targets.iteritems():
|
||||
self.assertEqual(
|
||||
prebuilt.DeterminePrebuiltConfFile(fake_path, target),
|
||||
expected_results['result'])
|
||||
|
||||
def testDeterminePrebuiltConfGarbage(self):
|
||||
"""Ensure an exception is raised on bad input."""
|
||||
self.assertRaises(prebuilt.UnknownBoardFormat,
|
||||
prebuilt.DeterminePrebuiltConfFile, 'asdfasdf')
|
||||
prebuilt.DeterminePrebuiltConfFile,
|
||||
'fake_path', 'asdfasdf')
|
||||
|
||||
|
||||
class TestPackagesFileFiltering(unittest.TestCase):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user