chrome-sdk: exit with the exit code of the command being run.

An error code from a command being executed in the chrome SDK
environment should be passed through by the SDK.  So have the SDK exit
with the exit code of the command it is running.

BUG=None
TEST=Local

Change-Id: I31a100e06c775b22fc151fbb283b57e579819dd3
Reviewed-on: https://gerrit.chromium.org/gerrit/64799
Commit-Queue: Ryan Cui <rcui@chromium.org>
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: Ryan Cui <rcui@chromium.org>
diff --git a/cros/commands/cros_chrome_sdk.py b/cros/commands/cros_chrome_sdk.py
index 9c4c602..730e39f 100644
--- a/cros/commands/cros_chrome_sdk.py
+++ b/cros/commands/cros_chrome_sdk.py
@@ -853,6 +853,8 @@
           # BASH_ENV, and ignores the --rcfile flag.
           extra_env = {'BASH_ENV': rcfile}
 
-        cros_build_lib.RunCommand(
+        cmd_result = cros_build_lib.RunCommand(
             bash_cmd, print_cmd=False, debug_level=logging.CRITICAL,
             error_code_ok=True, extra_env=extra_env, cwd=self.options.cwd)
+        if self.options.cmd:
+          return cmd_result.returncode
diff --git a/cros/commands/cros_chrome_sdk_unittest.py b/cros/commands/cros_chrome_sdk_unittest.py
index 42eb9a4..364e6d9 100755
--- a/cros/commands/cros_chrome_sdk_unittest.py
+++ b/cros/commands/cros_chrome_sdk_unittest.py
@@ -233,6 +233,15 @@
     with self.cache.Lookup(self.VERSION_KEY) as r:
       self.assertTrue(r.Exists())
 
+  def testErrorCodePassthrough(self):
+    """Test that error codes are passed through."""
+    self.SetupCommandMock()
+    with cros_test_lib.LoggingCapturer():
+      self.rc_mock.AddCmdResult(partial_mock.ListRegex('-- true'),
+                                returncode=5)
+      returncode = self.cmd_mock.inst.Run()
+      self.assertEquals(returncode, 5)
+
   def testLocalSDKPath(self):
     """Fetch components from a local --sdk-path."""
     sdk_dir = os.path.join(self.tempdir, 'sdk_dir')
diff --git a/scripts/cros.py b/scripts/cros.py
index eb5ab76..39af59c 100644
--- a/scripts/cros.py
+++ b/scripts/cros.py
@@ -28,7 +28,7 @@
 
 def _RunSubCommand(subcommand):
   """Helper function for testing purposes."""
-  subcommand.Run()
+  return subcommand.Run()
 
 
 def main(argv):
@@ -50,6 +50,8 @@
                    subcommand.upload_stats_timeout])
     # TODO: to make command completion faster, send an interrupt signal to the
     # stats uploader task after the subcommand completes.
-    _RunSubCommand(subcommand)
+    code = _RunSubCommand(subcommand)
+    if code is not None:
+      return code
 
   return 0