[Coverage] Fix a bug in code coverage script.

Fix a bug in the script. The script requires that the target executable
specified in the commands to be relative to the root of the source,
which doesn't make sense, users should be allowed to use whatever path
as long as it points to the right place.

Bug: 
Change-Id: I152797da96d02b9f211dd9e56421ff551e84597c
Reviewed-on: https://chromium-review.googlesource.com/814734
Commit-Queue: Yuke Liao <[email protected]>
Reviewed-by: Max Moroz <[email protected]>
Reviewed-by: Abhishek Arya <[email protected]>
Cr-Commit-Position: refs/heads/master@{#522478}
diff --git a/tools/code_coverage/coverage.py b/tools/code_coverage/coverage.py
index 211f011..3b97955 100755
--- a/tools/code_coverage/coverage.py
+++ b/tools/code_coverage/coverage.py
@@ -408,17 +408,15 @@
   return target in GTEST_TARGET_NAMES
 
 
-def _ValidateCommandsAreRelativeToSrcRoot(commands):
+def _VerifyTargetExecutablesAreInBuildDirectory(commands):
+  """Verifies that the target executables specified in the commands are inside
+  the given build directory."""
   for command in commands:
     binary_path = _GetBinaryPath(command)
-    assert binary_path.startswith(BUILD_DIR), ('Target executable "%s" is '
-                                               'outside of the given build '
-                                               'directory: "%s". Please make '
-                                               'sure the command: "%s" is '
-                                               'relative to the root of the '
-                                               'checkout.' %
-                                               (binary_path, BUILD_DIR,
-                                                command))
+    binary_absolute_path = os.path.abspath(os.path.normpath(binary_path))
+    assert binary_absolute_path.startswith(os.path.abspath(BUILD_DIR)), (
+        'Target executable "%s" in command: "%s" is outside of '
+        'the given build directory: "%s".' % (binary_path, command, BUILD_DIR))
 
 
 def _ValidateBuildingWithClangCoverage():
@@ -553,7 +551,7 @@
       'Build directory: {} doesn\'t exist. '
       'Please run "gn gen" to generate.').format(BUILD_DIR)
   _ValidateBuildingWithClangCoverage()
-  _ValidateCommandsAreRelativeToSrcRoot(args.command)
+  _VerifyTargetExecutablesAreInBuildDirectory(args.command)
 
   absolute_filter_paths = []
   if args.filters: