Merge V8 5.3.332.45.  DO NOT MERGE

Test: Manual

FPIIM-449

Change-Id: Id3254828b068abdea3cb10442e0172a8c9a98e03
(cherry picked from commit 13e2dadd00298019ed862f2b2fc5068bba730bcf)
diff --git a/tools/isolate_driver.py b/tools/isolate_driver.py
index d1b39b0..1542353 100644
--- a/tools/isolate_driver.py
+++ b/tools/isolate_driver.py
@@ -30,6 +30,16 @@
       'version': 1,
     }, f, indent=2, sort_keys=True)
 
+def rebase_directories(args, abs_base):
+  """Rebases all paths to be relative to abs_base."""
+  def replace(index):
+    args[index] = os.path.relpath(os.path.abspath(args[index]), abs_base)
+  for i, arg in enumerate(args):
+    if arg in ['--isolate', '--isolated']:
+      replace(i + 1)
+    if arg == '--path-variable':
+      # Path variables have a triple form: --path-variable NAME <path>.
+      replace(i + 2)
 
 def main():
   logging.basicConfig(level=logging.ERROR, format='%(levelname)7s %(message)s')
@@ -49,6 +59,14 @@
     print >> sys.stderr, 'Internal failure'
     return 1
 
+  # Make sure all paths are relative to the isolate file. This is an
+  # expectation of the go binaries. In gn, this script is not called
+  # relative to the isolate file, but relative to the product dir.
+  new_base = os.path.abspath(os.path.dirname(args[isolate]))
+  rebase_directories(args, new_base)
+  assert args[isolate] == os.path.basename(args[isolate])
+  os.chdir(new_base)
+
   # In 'prepare' mode just collect all required information for postponed
   # isolated.py invocation later, store it in *.isolated.gen.json file.
   if mode == 'prepare':