cros_setup_toolchains: allow importing outside of the chroot
To simplify other modules, allow this one to be imported outside of the
chroot. We'll delay the chroot error checking to the main() loop so that
we still die if people try to run us outside of the chroot.
We do however allow --show-board-cfg outside of the chroot now. This is
because that code doesn't rely on portage at all -- it just reads all the
toolchain.conf files.
BUG=None
TEST=`./bin/cros_setup_toolchains` fails outside of the chroot
TEST=`cros_setup_toolchains` works inside of the chroot
TEST=`python -c 'from chromite.scripts import cros_setup_toolchains'` works inside of the chroot
CQ-DEPEND=CL:39149
Change-Id: I98b985b1f9a43056e3c34eac8934866eee660aa4
Reviewed-on: https://gerrit.chromium.org/gerrit/39150
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index b7cf17b..0d68c4d 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -17,13 +17,11 @@
from chromite.lib import cros_build_lib
from chromite.lib import osutils
-# Some sanity checks first.
-if not cros_build_lib.IsInsideChroot():
- print '%s: This needs to be run inside the chroot' % sys.argv[0]
- sys.exit(1)
-# Only import portage after we've checked that we're inside the chroot.
-# Outside may not have portage, in which case the above may not happen.
-import portage
+if cros_build_lib.IsInsideChroot():
+ # Only import portage after we've checked that we're inside the chroot.
+ # Outside may not have portage, in which case the above may not happen.
+ # We'll check in main() if the operation needs portage.
+ import portage
EMERGE_CMD = os.path.join(constants.CHROMITE_BIN_DIR, 'parallel_emerge')
@@ -638,6 +636,8 @@
print ','.join(tuples)
return 0
+ cros_build_lib.AssertInsideChroot()
+
# This has to be always run as root.
if not os.getuid() == 0:
print "%s: This script must be run as root!" % sys.argv[0]