aboutsummaryrefslogtreecommitdiff
path: root/tools/isolate_driver.py
blob: d1b39b095828dc634d2d49b1d40b32ec9d1638d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# Copyright 2015 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Adaptor script called through build/isolate.gypi.

Slimmed down version of chromium's isolate driver that doesn't process dynamic
dependencies.
"""

import json
import logging
import os
import subprocess
import sys

TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))


def prepare_isolate_call(args, output):
  """Gathers all information required to run isolate.py later.

  Dumps it as JSON to |output| file.
  """
  with open(output, 'wb') as f:
    json.dump({
      'args': args,
      'dir': os.getcwd(),
      'version': 1,
    }, f, indent=2, sort_keys=True)


def main():
  logging.basicConfig(level=logging.ERROR, format='%(levelname)7s %(message)s')
  if len(sys.argv) < 2:
    print >> sys.stderr, 'Internal failure; mode required'
    return 1
  mode = sys.argv[1]
  args = sys.argv[1:]
  isolate = None
  isolated = None
  for i, arg in enumerate(args):
    if arg == '--isolate':
      isolate = i + 1
    if arg == '--isolated':
      isolated = i + 1
  if not isolate or not isolated:
    print >> sys.stderr, 'Internal failure'
    return 1

  # In 'prepare' mode just collect all required information for postponed
  # isolated.py invocation later, store it in *.isolated.gen.json file.
  if mode == 'prepare':
    prepare_isolate_call(args[1:], args[isolated] + '.gen.json')
    return 0

  swarming_client = os.path.join(TOOLS_DIR, 'swarming_client')
  sys.stdout.flush()
  return subprocess.call(
      [sys.executable, os.path.join(swarming_client, 'isolate.py')] + args)


if __name__ == '__main__':
  sys.exit(main())