diff --git a/bin/cros_au_test_harness.py b/bin/cros_au_test_harness.py index eaed1ef2b9..eef95b6f8b 100755 --- a/bin/cros_au_test_harness.py +++ b/bin/cros_au_test_harness.py @@ -10,7 +10,7 @@ import sys import unittest sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) -from cros_build_lib import RunCommand, Info, Warning +from cros_build_lib import RunCommand, Info, Warning, ReinterpretPathForChroot _KVM_PID_FILE = '/tmp/harness_pid' _SCRIPTS_DIR = os.path.join(os.path.dirname(__file__), '..') @@ -18,6 +18,7 @@ _FULL_VDISK_SIZE = 6072 _FULL_STATEFULFS_SIZE = 2048 global base_image_path +global board global target_image_path _VERIFY_SUITE = 'suite_Smoke' @@ -106,9 +107,11 @@ class VirtualAUTest(unittest.TestCase, AUTest): Info('Qemu image not found, creating one.') RunCommand(['%s/image_to_vm.sh' % _SCRIPTS_DIR, '--full', - '--from %s' % os.path.dirname(base_image_path), + '--from %s' % ReinterpretPathForChroot( + os.path.dirname(base_image_path)), '--vdisk_size %s' % _FULL_VDISK_SIZE, '--statefulfs_size %s' % _FULL_STATEFULFS_SIZE, + '--board %s' % board, '--test_image'], enter_chroot=True) else: Info('Using existing VM image') @@ -153,6 +156,8 @@ if __name__ == '__main__': help='path to the base image.') parser.add_option('-t', '--target_image', help='path to the target image') + parser.add_option('-r', '--board', + help='board for the images') # Set the usage to include flags. parser.set_usage(parser.format_help()) # Parse existing sys.argv so we can pass rest to unittest.main. @@ -160,6 +165,7 @@ if __name__ == '__main__': base_image_path = options.base_image target_image_path = options.target_image + board = options.board if not base_image_path: parser.error('Need path to base image for vm.') @@ -167,4 +173,7 @@ if __name__ == '__main__': if not target_image_path: parser.error('Need path to target image to update with.') + if not board: + parser.error('Need board to convert base image to vm.') + unittest.main() diff --git a/bin/loman.py b/bin/loman.py index 0ae74e685e..c52a5b3d8c 100755 --- a/bin/loman.py +++ b/bin/loman.py @@ -11,17 +11,7 @@ import optparse import os import xml.etree.ElementTree as ElementTree -from cros_build_lib import Die - - -def _FindRepoDir(): - cwd = os.getcwd() - while cwd != '/': - repo_dir = os.path.join(cwd, '.repo') - if os.path.isdir(repo_dir): - return repo_dir - cwd = os.path.dirname(cwd) - return None +from cros_build_lib import Die, FindRepoDir def _ReadManifest(manifest, err_not_found=False): @@ -96,7 +86,7 @@ class LocalManifest: def main(argv): - repo_dir = _FindRepoDir() + repo_dir = FindRepoDir() if not repo_dir: Die("Unable to find repo dir.") diff --git a/get_latest_image.sh b/get_latest_image.sh index f8ed1e5f86..1c5d90f20e 100755 --- a/get_latest_image.sh +++ b/get_latest_image.sh @@ -21,8 +21,7 @@ eval set -- "${FLAGS_ARGV}" # Check on the board that they are trying to set up. if [ -z "$FLAGS_board" ] ; then - echo "Error: --board required." - exit 1 + die "Error: --board required." fi IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py index 71c908648f..47c8f96ae6 100644 --- a/lib/cros_build_lib.py +++ b/lib/cros_build_lib.py @@ -136,3 +136,36 @@ def Info(message): """ print >> sys.stderr, ( Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message)) + + +def FindRepoDir(): + """Returns the nearest higher-level repo dir from the cwd.""" + cwd = os.getcwd() + while cwd != '/': + repo_dir = os.path.join(cwd, '.repo') + if os.path.isdir(repo_dir): + return repo_dir + cwd = os.path.dirname(cwd) + return None + + +def ReinterpretPathForChroot(path): + """Returns reinterpreted path from outside the chroot for use inside. + + Keyword arguments: + path: The path to reinterpret. Must be in src tree. + """ + root_path = os.path.join(FindRepoDir(), '..') + + path_abs_path = os.path.abspath(path) + root_abs_path = os.path.abspath(root_path) + + # Strip the repository root from the path and strip first /. + relative_path = path_abs_path.replace(root_abs_path, '')[1:] + + if relative_path == path_abs_path: + raise Exception('Error: path is outside your src tree, cannot reinterpret.') + + new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path) + return new_path +