OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
| 6 import argparse |
6 import os | 7 import os |
7 import shutil | 8 import shutil |
8 import sys | 9 import sys |
9 import subprocess | 10 import subprocess |
10 import tarfile | 11 import tarfile |
11 import tempfile | 12 import tempfile |
12 import urllib2 | 13 import urllib2 |
13 | 14 |
14 THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | 15 THIS_DIR = os.path.dirname(os.path.abspath(__file__)) |
15 | 16 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 write_version = False | 94 write_version = False |
94 | 95 |
95 if write_version: | 96 if write_version: |
96 with open(version_file, 'w') as f: | 97 with open(version_file, 'w') as f: |
97 f.write(version) | 98 f.write(version) |
98 | 99 |
99 return bin_location | 100 return bin_location |
100 | 101 |
101 | 102 |
102 def main(mode=None): | 103 def main(mode=None): |
| 104 parser = argparse.ArgumentParser() |
| 105 parser.add_argument('--running-as-hook', action='store_true') |
| 106 args, rest_args = parser.parse_known_args() |
| 107 |
| 108 # Exit early if this is being invoked from `gclient runhooks` |
| 109 # and INSTALL_NODE_FOR_DEVTOOLS=1 isn't present in the environment. |
| 110 if (args.running_as_hook and |
| 111 os.environ.get('INSTALL_NODE_FOR_DEVTOOLS', '0') != '1'): |
| 112 return 0 |
| 113 |
103 version = os.environ.get('NODE_VERSION', DEFAULT_VERSION) | 114 version = os.environ.get('NODE_VERSION', DEFAULT_VERSION) |
104 try: | 115 try: |
105 tmp_dir = tempfile.mkdtemp(dir=THIS_DIR) | 116 tmp_dir = tempfile.mkdtemp(dir=THIS_DIR) |
106 bin_location = install_latest_node_js(version, tmp_dir) | 117 bin_location = install_latest_node_js(version, tmp_dir) |
107 finally: | 118 finally: |
108 if os.path.exists(tmp_dir): | 119 if os.path.exists(tmp_dir): |
109 shutil.rmtree(tmp_dir) | 120 shutil.rmtree(tmp_dir) |
110 | 121 |
111 if mode == 'npm': | 122 if mode == 'npm': |
112 # TODO(hinoka): How about Windows...? | 123 # TODO(hinoka): How about Windows...? |
113 bin_location = os.path.join(os.path.dirname(bin_location), 'npm') | 124 bin_location = os.path.join(os.path.dirname(bin_location), 'npm') |
114 | 125 |
115 return subprocess.call([bin_location, ] + sys.argv[1:]) | 126 return subprocess.call([bin_location, ] + rest_args) |
116 | 127 |
117 | 128 |
118 if __name__ == '__main__': | 129 if __name__ == '__main__': |
119 sys.exit(main()) | 130 sys.exit(main()) |
OLD | NEW |