cros_setup_toolchains: keep compiler path relativeness in shell wrapper for python sysroot wrapper

This is retry of
https://chromium-review.googlesource.com/1086958

Instead of enforcing relative path, I keep relativeness of compiler
path.

This is a part of effort for build cache sharing when using goma by
removing absolute path from compile result.

I confirmed this can build base_unittests on daisy and amd64-generic.
$ cros tryjob -g 1170666 chromiumos-sdk-tryjob
Tryjob submitted!
To view your tryjobs, visit:
  https://cros-goldeneye.corp.google.com/chromeos/healthmonitoring/buildDetails?buildbucketId=8938044742765812304

This is one of following patch series to call compiler in relative path.
https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1166926
https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1170666
https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1170712
https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/1170663

BUG=chromium:846610
Change-Id: I4815c07e95c61a37d8a9f6bf784dc1485832fa0d
Reviewed-on: https://chromium-review.googlesource.com/1170666
Commit-Ready: Takuto Ikuta <tikuta@chromium.org>
Tested-by: Takuto Ikuta <tikuta@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index ec26ee2..80baa24 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -767,10 +767,15 @@
       'path': path,
       'relroot': os.path.relpath('/', os.path.dirname(wrappath)),
   }
+
+  # Do not use exec here, because exec invokes script with absolute path in
+  # argv0. Keeping relativeness allows us to remove abs path from compile result
+  # and leads directory independent build cache sharing in some distributed
+  # build system.
   wrapper = """#!/bin/sh
-base=$(realpath "$0")
-basedir=${base%%/*}
-exec "${basedir}/%(relroot)s%(path)s" "$@"
+basedir=$(dirname "$0")
+"${basedir}/%(relroot)s%(path)s" "$@"
+exit "$?"
 """ % replacements
   root_wrapper = root + wrappath
   if os.path.islink(root_wrapper):