enter_chroot: Add a flag to specify the working directory in chroot.

Flag `--working_dir <path>` specifies enter_chroot.sh to run the
command in /mnt/host/source/<path>.  In interactive mode, this flag
specifies the default working directory of the shell.

BUG=None
TEST=manually test

Change-Id: I36a2eca9fbc2b38c5192a5e04ccde47dfe5830c2
Reviewed-on: https://chromium-review.googlesource.com/903665
Commit-Ready: Yong Hong <yhong@google.com>
Tested-by: Yong Hong <yhong@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh
index fd63be0..c5ab1d7 100755
--- a/sdk_lib/enter_chroot.sh
+++ b/sdk_lib/enter_chroot.sh
@@ -30,6 +30,9 @@
 DEFINE_string cache_dir "" "Directory to use for caching."
 DEFINE_string goma_dir "" "Goma installed directory."
 DEFINE_string goma_client_json "" "Service account json file for goma."
+DEFINE_string working_dir "" \
+  "The working directory relative to ${CHROOT_TRUNK_DIR} for the command in \
+chroot, must start with '/' if set."
 
 DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent."
 DEFINE_boolean early_make_chroot $FLAGS_FALSE \
@@ -604,6 +607,10 @@
   "BUILDBOT_BUILD=$FLAGS_build_number"
   "CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-{DEV-BUILD}}"
   "EXTERNAL_TRUNK_PATH=${FLAGS_trunk}"
+
+  # The default ~/.bash_profile in chroot will cd to $CHROOT_CWD instead of
+  # ~/trunk/src/script if that environment variable is set.
+  "CHROOT_CWD=${FLAGS_working_dir}"
 )
 
 # Translate C.UTF-8 into something we support. Remove this when our glibc