summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDavid Pursell <dpursell@chromium.org>2015-05-29 10:39:03 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-01 16:59:41 +0000
commit13fa320573e6a59ad069b57069ef3af076109a2f (patch)
tree7633d46e0d2ffe5f98250f512946c51999688154 /cli
parentf67ce5620e7cf459ce1e409a379185aa0a986e5f (diff)
downloadchromite-13fa320573e6a59ad069b57069ef3af076109a2f.tar.gz
chroot: Enter chroot in workspace directory.
If the chroot is entered from a workspace directory, set the initial CWD inside the chroot to be the same relative directory. For example, entering the chroot from workspace/bricks will set the chroot CWD to /mnt/host/workspace/bricks. This allows users to work with relative paths outside the chroot and they will translate properly into the chroot. It also makes the starting CWD for `brillo chroot` more intuitive. Also removed the hidden brick/blueprint override arguments as they are broken and no longer necessary to translate relative paths. BUG=brillo:1013 TEST=cbuildbot/run_test TEST=brillo build --blueprint blueprints/helloworld_danger.json brillo image --blueprint blueprints/helloworld_danger.json TEST=build_packages --board=panther build_image --board=panther Change-Id: Ifb3baabda6ff2d472ee5232473bcbaa4af76289d Reviewed-on: https://chromium-review.googlesource.com/274088 Trybot-Ready: David Pursell <dpursell@chromium.org> Tested-by: David Pursell <dpursell@chromium.org> Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org> Commit-Queue: David Pursell <dpursell@chromium.org>
Diffstat (limited to 'cli')
-rw-r--r--cli/brillo/brillo_package.py2
-rw-r--r--cli/cros/cros_build.py2
-rw-r--r--cli/cros/cros_chroot.py8
-rw-r--r--cli/cros/cros_chroot_unittest.py27
-rw-r--r--cli/cros/cros_debug.py2
-rw-r--r--cli/cros/cros_deploy.py2
-rw-r--r--cli/cros/cros_image.py2
7 files changed, 37 insertions, 8 deletions
diff --git a/cli/brillo/brillo_package.py b/cli/brillo/brillo_package.py
index 886650dd4..2b20c4f40 100644
--- a/cli/brillo/brillo_package.py
+++ b/cli/brillo/brillo_package.py
@@ -174,5 +174,5 @@ To enable building a package from latest or stable ebuilds:
if self.options.create_source:
self._CreateSource()
if self.options.enable:
- commandline.RunInsideChroot(self, auto_detect_brick=True)
+ commandline.RunInsideChroot(self)
self._EnableBuild()
diff --git a/cli/cros/cros_build.py b/cli/cros/cros_build.py
index 81ad763eb..7fc966f0e 100644
--- a/cli/cros/cros_build.py
+++ b/cli/cros/cros_build.py
@@ -166,7 +166,7 @@ To just build a single package:
cros_build_lib.Die('--brick should not be used with board names. Use '
'--board=%s instead.' % self.brick.config['name'])
- commandline.RunInsideChroot(self, auto_detect_brick=True)
+ commandline.RunInsideChroot(self)
if not (self.build_pkgs or self.options.init_only):
cros_build_lib.Die('No packages found, nothing to build.')
diff --git a/cli/cros/cros_chroot.py b/cli/cros/cros_chroot.py
index 2d0327001..f3b92bd5a 100644
--- a/cli/cros/cros_chroot.py
+++ b/cli/cros/cros_chroot.py
@@ -7,10 +7,13 @@
from __future__ import print_function
import argparse
+import os
from chromite.cbuildbot import constants
from chromite.cli import command
+from chromite.lib import commandline
from chromite.lib import cros_build_lib
+from chromite.lib import path_util
from chromite.lib import workspace_lib
@@ -50,16 +53,19 @@ class ChrootCommand(command.CliCommand):
cmd = ['bash']
chroot_args = ['--log-level', self.options.log_level]
+ extra_env = {}
workspace_path = workspace_lib.WorkspacePath()
if workspace_path is not None:
chroot_args.extend(['--chroot', workspace_lib.ChrootPath(workspace_path),
'--workspace', workspace_path])
+ resolver = path_util.ChrootPathResolver(workspace_path=workspace_path)
+ extra_env[commandline.CHROOT_CWD_ENV_VAR] = resolver.ToChroot(os.getcwd())
result = cros_build_lib.RunCommand(cmd, print_cmd=False, error_code_ok=True,
cwd=constants.SOURCE_ROOT,
mute_output=False,
- enter_chroot=True,
+ enter_chroot=True, extra_env=extra_env,
chroot_args=chroot_args)
return result.returncode
diff --git a/cli/cros/cros_chroot_unittest.py b/cli/cros/cros_chroot_unittest.py
index 7e5cda3b4..a543b212e 100644
--- a/cli/cros/cros_chroot_unittest.py
+++ b/cli/cros/cros_chroot_unittest.py
@@ -8,10 +8,13 @@ from __future__ import print_function
import os
+from chromite.cbuildbot import constants
from chromite.cli import command_unittest
from chromite.cli.cros import cros_chroot
+from chromite.lib import commandline
from chromite.lib import cros_build_lib
from chromite.lib import cros_test_lib
+from chromite.lib import path_util
from chromite.lib import osutils
from chromite.lib import workspace_lib
@@ -29,7 +32,7 @@ class MockChrootCommand(command_unittest.MockCommand):
return command_unittest.MockCommand.Run(self, inst)
-class ChrootTest(cros_test_lib.MockTestCase):
+class ChrootTest(cros_test_lib.WorkspaceTestCase, cros_test_lib.MockTestCase):
"""Test the ChrootCommand."""
def SetupCommandMock(self, cmd_args):
@@ -67,7 +70,7 @@ class ChrootTest(cros_test_lib.MockTestCase):
self.cmd_mock.inst.options.log_level = 'notice'
# Pretend that we are outside the chroot so the logging level gets passed as
# an argument to cros_sdk.
- self.PatchObject(cros_build_lib, 'IsInsideChroot', return_value=False)
+ self.mock_inside.return_value = False
self.cmd_mock.inst.Run()
#Ensure that we exec'd with logging level notice.
@@ -107,6 +110,26 @@ class ChrootTest(cros_test_lib.MockTestCase):
# Ensure we pass along "--help" instead of processing it directly.
self.cmd_mock.rc_mock.assertCommandContains(['--help'])
+ def testNoWorkspace(self):
+ """Tests entering the chroot from outside a workspace."""
+ self.SetupCommandMock([])
+ self.cmd_mock.inst.Run()
+
+ # Make sure nothing was set in |extra_env|.
+ self.cmd_mock.rc_mock.assertCommandContains(extra_env={})
+
+ def testWorkspace(self):
+ """Tests entering the chroot from inside a workspace."""
+ self.SetupCommandMock([])
+ self.CreateWorkspace()
+ self.PatchObject(path_util.ChrootPathResolver, 'ToChroot',
+ return_value=constants.CHROOT_WORKSPACE_ROOT)
+ self.cmd_mock.inst.Run()
+
+ # Make sure CWD was set properly in |extra_env|.
+ self.cmd_mock.rc_mock.assertCommandContains(extra_env={
+ commandline.CHROOT_CWD_ENV_VAR: constants.CHROOT_WORKSPACE_ROOT})
+
class ChrootMoveTest(cros_test_lib.MockTempDirTestCase):
"""Test the ChrootCommand move functionality."""
diff --git a/cli/cros/cros_debug.py b/cli/cros/cros_debug.py
index 583cb5323..d08449d3e 100644
--- a/cli/cros/cros_debug.py
+++ b/cli/cros/cros_debug.py
@@ -126,7 +126,7 @@ To debug a process by its pid:
def Run(self):
"""Run cros debug."""
- commandline.RunInsideChroot(self, auto_detect_brick=True)
+ commandline.RunInsideChroot(self)
self.options.Freeze()
self._ReadOptions()
try:
diff --git a/cli/cros/cros_deploy.py b/cli/cros/cros_deploy.py
index 7f952709c..1977180a3 100644
--- a/cli/cros/cros_deploy.py
+++ b/cli/cros/cros_deploy.py
@@ -112,7 +112,7 @@ For more information of cros build usage:
def Run(self):
"""Run cros deploy."""
- commandline.RunInsideChroot(self, auto_detect_brick=True)
+ commandline.RunInsideChroot(self)
self.options.Freeze()
try:
deploy.Deploy(
diff --git a/cli/cros/cros_image.py b/cli/cros/cros_image.py
index cdd1f13a2..559d29260 100644
--- a/cli/cros/cros_image.py
+++ b/cli/cros/cros_image.py
@@ -55,7 +55,7 @@ class ImageCommand(command.CliCommand):
default='test', help="The image types to build.")
def Run(self):
- commandline.RunInsideChroot(self, auto_detect_brick=True)
+ commandline.RunInsideChroot(self)
# argparse does not behave well with nargs='*', default, and choices
# (http://bugs.python.org/issue9625). Before freezing options, we need to