maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
maruel | ea586f3 | 2016-04-05 11:11:33 -0700 | [diff] [blame] | 2 | # Copyright 2012 The LUCI Authors. All rights reserved. |
maruel | f1f5e2a | 2016-05-25 17:10:39 -0700 | [diff] [blame] | 3 | # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 | # that can be found in the LICENSE file. |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 5 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 6 | """Runs a command with optional isolated input/output. |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 7 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 8 | Despite name "run_isolated", can run a generic non-isolated command specified as |
| 9 | args. |
| 10 | |
| 11 | If input isolated hash is provided, fetches it, creates a tree of hard links, |
| 12 | appends args to the command in the fetched isolated and runs it. |
| 13 | To improve performance, keeps a local cache. |
| 14 | The local cache can safely be deleted. |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 15 | |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 16 | Any ${EXECUTABLE_SUFFIX} on the command line will be replaced with ".exe" string |
| 17 | on Windows and "" on other platforms. |
| 18 | |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 19 | Any ${ISOLATED_OUTDIR} on the command line will be replaced by the location of a |
| 20 | temporary directory upon execution of the command specified in the .isolated |
| 21 | file. All content written to this directory will be uploaded upon termination |
| 22 | and the .isolated file describing this directory will be printed to stdout. |
bpastene | 447c199 | 2016-06-20 15:21:47 -0700 | [diff] [blame] | 23 | |
| 24 | Any ${SWARMING_BOT_FILE} on the command line will be replaced by the value of |
| 25 | the --bot-file parameter. This file is used by a swarming bot to communicate |
| 26 | state of the host to tasks. It is written to by the swarming bot's |
| 27 | on_before_task() hook in the swarming server's custom bot_config.py. |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 28 | """ |
| 29 | |
aludwin | 7556e0c | 2016-10-26 08:46:10 -0700 | [diff] [blame^] | 30 | __version__ = '0.8.6' |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 31 | |
aludwin | 7556e0c | 2016-10-26 08:46:10 -0700 | [diff] [blame^] | 32 | import argparse |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 33 | import base64 |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 34 | import collections |
aludwin | 7556e0c | 2016-10-26 08:46:10 -0700 | [diff] [blame^] | 35 | import json |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 36 | import logging |
| 37 | import optparse |
| 38 | import os |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 39 | import sys |
| 40 | import tempfile |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 41 | import time |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 42 | |
vadimsh@chromium.org | a432647 | 2013-08-24 02:05:41 +0000 | [diff] [blame] | 43 | from third_party.depot_tools import fix_encoding |
| 44 | |
Vadim Shtayura | 6b555c1 | 2014-07-23 16:22:18 -0700 | [diff] [blame] | 45 | from utils import file_path |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 46 | from utils import fs |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 47 | from utils import large |
Marc-Antoine Ruel | f74cffe | 2015-07-15 15:21:34 -0400 | [diff] [blame] | 48 | from utils import logging_utils |
Marc-Antoine Ruel | cfb6085 | 2014-07-02 15:22:00 -0400 | [diff] [blame] | 49 | from utils import on_error |
Marc-Antoine Ruel | c44f572 | 2015-01-08 16:10:01 -0500 | [diff] [blame] | 50 | from utils import subprocess42 |
vadimsh@chromium.org | a432647 | 2013-08-24 02:05:41 +0000 | [diff] [blame] | 51 | from utils import tools |
vadimsh@chromium.org | 3e97deb | 2013-08-24 00:56:44 +0000 | [diff] [blame] | 52 | from utils import zip_package |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 53 | |
Vadim Shtayura | e34e13a | 2014-02-02 11:23:26 -0800 | [diff] [blame] | 54 | import auth |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 55 | import cipd |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 56 | import isolateserver |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 57 | |
vadimsh@chromium.org | a432647 | 2013-08-24 02:05:41 +0000 | [diff] [blame] | 58 | |
vadimsh@chromium.org | 8507106 | 2013-08-21 23:37:45 +0000 | [diff] [blame] | 59 | # Absolute path to this file (can be None if running from zip on Mac). |
tansell | a494944 | 2016-06-23 22:34:32 -0700 | [diff] [blame] | 60 | THIS_FILE_PATH = os.path.abspath( |
| 61 | __file__.decode(sys.getfilesystemencoding())) if __file__ else None |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 62 | |
| 63 | # Directory that contains this file (might be inside zip package). |
tansell | a494944 | 2016-06-23 22:34:32 -0700 | [diff] [blame] | 64 | BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__.decode( |
| 65 | sys.getfilesystemencoding()) else None |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 66 | |
| 67 | # Directory that contains currently running script file. |
maruel@chromium.org | 814d23f | 2013-10-01 19:08:00 +0000 | [diff] [blame] | 68 | if zip_package.get_main_script_path(): |
| 69 | MAIN_DIR = os.path.dirname( |
| 70 | os.path.abspath(zip_package.get_main_script_path())) |
| 71 | else: |
| 72 | # This happens when 'import run_isolated' is executed at the python |
| 73 | # interactive prompt, in that case __file__ is undefined. |
| 74 | MAIN_DIR = None |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 75 | |
maruel | e2f2cb8 | 2016-07-13 14:41:03 -0700 | [diff] [blame] | 76 | |
| 77 | # Magic variables that can be found in the isolate task command line. |
| 78 | ISOLATED_OUTDIR_PARAMETER = '${ISOLATED_OUTDIR}' |
| 79 | EXECUTABLE_SUFFIX_PARAMETER = '${EXECUTABLE_SUFFIX}' |
| 80 | SWARMING_BOT_FILE_PARAMETER = '${SWARMING_BOT_FILE}' |
| 81 | |
| 82 | |
csharp@chromium.org | ff2a466 | 2012-11-21 20:49:32 +0000 | [diff] [blame] | 83 | # The name of the log file to use. |
| 84 | RUN_ISOLATED_LOG_FILE = 'run_isolated.log' |
| 85 | |
maruel | e2f2cb8 | 2016-07-13 14:41:03 -0700 | [diff] [blame] | 86 | |
csharp@chromium.org | e217f30 | 2012-11-22 16:51:53 +0000 | [diff] [blame] | 87 | # The name of the log to use for the run_test_cases.py command |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 88 | RUN_TEST_CASES_LOG = 'run_test_cases.log' |
csharp@chromium.org | e217f30 | 2012-11-22 16:51:53 +0000 | [diff] [blame] | 89 | |
vadimsh@chromium.org | 87d6326 | 2013-04-04 19:34:21 +0000 | [diff] [blame] | 90 | |
maruel | e2f2cb8 | 2016-07-13 14:41:03 -0700 | [diff] [blame] | 91 | # Use short names for temporary directories. This is driven by Windows, which |
| 92 | # imposes a relatively short maximum path length of 260 characters, often |
| 93 | # referred to as MAX_PATH. It is relatively easy to create files with longer |
| 94 | # path length. A use case is with recursive depedency treesV like npm packages. |
| 95 | # |
| 96 | # It is recommended to start the script with a `root_dir` as short as |
| 97 | # possible. |
| 98 | # - ir stands for isolated_run |
| 99 | # - io stands for isolated_out |
| 100 | # - it stands for isolated_tmp |
| 101 | ISOLATED_RUN_DIR = u'ir' |
| 102 | ISOLATED_OUT_DIR = u'io' |
| 103 | ISOLATED_TMP_DIR = u'it' |
| 104 | |
| 105 | |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 106 | def get_as_zip_package(executable=True): |
| 107 | """Returns ZipPackage with this module and all its dependencies. |
| 108 | |
| 109 | If |executable| is True will store run_isolated.py as __main__.py so that |
| 110 | zip package is directly executable be python. |
| 111 | """ |
| 112 | # Building a zip package when running from another zip package is |
| 113 | # unsupported and probably unneeded. |
| 114 | assert not zip_package.is_zipped_module(sys.modules[__name__]) |
vadimsh@chromium.org | 8507106 | 2013-08-21 23:37:45 +0000 | [diff] [blame] | 115 | assert THIS_FILE_PATH |
| 116 | assert BASE_DIR |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 117 | package = zip_package.ZipPackage(root=BASE_DIR) |
| 118 | package.add_python_file(THIS_FILE_PATH, '__main__.py' if executable else None) |
Marc-Antoine Ruel | 8bee66d | 2014-08-28 19:02:07 -0400 | [diff] [blame] | 119 | package.add_python_file(os.path.join(BASE_DIR, 'isolated_format.py')) |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 120 | package.add_python_file(os.path.join(BASE_DIR, 'isolateserver.py')) |
Vadim Shtayura | e34e13a | 2014-02-02 11:23:26 -0800 | [diff] [blame] | 121 | package.add_python_file(os.path.join(BASE_DIR, 'auth.py')) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 122 | package.add_python_file(os.path.join(BASE_DIR, 'cipd.py')) |
tansell | e4288c3 | 2016-07-28 09:45:40 -0700 | [diff] [blame] | 123 | package.add_directory(os.path.join(BASE_DIR, 'libs')) |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 124 | package.add_directory(os.path.join(BASE_DIR, 'third_party')) |
| 125 | package.add_directory(os.path.join(BASE_DIR, 'utils')) |
| 126 | return package |
| 127 | |
| 128 | |
maruel | 03e1184 | 2016-07-14 10:50:16 -0700 | [diff] [blame] | 129 | def make_temp_dir(prefix, root_dir): |
| 130 | """Returns a new unique temporary directory.""" |
| 131 | return unicode(tempfile.mkdtemp(prefix=prefix, dir=root_dir)) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 132 | |
| 133 | |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 134 | def change_tree_read_only(rootdir, read_only): |
| 135 | """Changes the tree read-only bits according to the read_only specification. |
| 136 | |
| 137 | The flag can be 0, 1 or 2, which will affect the possibility to modify files |
| 138 | and create or delete files. |
| 139 | """ |
| 140 | if read_only == 2: |
| 141 | # Files and directories (except on Windows) are marked read only. This |
| 142 | # inhibits modifying, creating or deleting files in the test directory, |
| 143 | # except on Windows where creating and deleting files is still possible. |
Marc-Antoine Ruel | e4ad07e | 2014-10-15 20:22:29 -0400 | [diff] [blame] | 144 | file_path.make_tree_read_only(rootdir) |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 145 | elif read_only == 1: |
| 146 | # Files are marked read only but not the directories. This inhibits |
| 147 | # modifying files but creating or deleting files is still possible. |
Marc-Antoine Ruel | e4ad07e | 2014-10-15 20:22:29 -0400 | [diff] [blame] | 148 | file_path.make_tree_files_read_only(rootdir) |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 149 | elif read_only in (0, None): |
Marc-Antoine Ruel | f1d827c | 2014-11-24 15:22:25 -0500 | [diff] [blame] | 150 | # Anything can be modified. |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 151 | # TODO(maruel): This is currently dangerous as long as DiskCache.touch() |
| 152 | # is not yet changed to verify the hash of the content of the files it is |
| 153 | # looking at, so that if a test modifies an input file, the file must be |
| 154 | # deleted. |
Marc-Antoine Ruel | e4ad07e | 2014-10-15 20:22:29 -0400 | [diff] [blame] | 155 | file_path.make_tree_writeable(rootdir) |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 156 | else: |
| 157 | raise ValueError( |
| 158 | 'change_tree_read_only(%s, %s): Unknown flag %s' % |
| 159 | (rootdir, read_only, read_only)) |
| 160 | |
| 161 | |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 162 | def process_command(command, out_dir, bot_file): |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 163 | """Replaces variables in a command line. |
| 164 | |
| 165 | Raises: |
| 166 | ValueError if a parameter is requested in |command| but its value is not |
| 167 | provided. |
| 168 | """ |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 169 | def fix(arg): |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 170 | arg = arg.replace(EXECUTABLE_SUFFIX_PARAMETER, cipd.EXECUTABLE_SUFFIX) |
| 171 | replace_slash = False |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 172 | if ISOLATED_OUTDIR_PARAMETER in arg: |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 173 | if not out_dir: |
maruel | 7f63a27 | 2016-07-12 12:40:36 -0700 | [diff] [blame] | 174 | raise ValueError( |
| 175 | 'output directory is requested in command, but not provided; ' |
| 176 | 'please specify one') |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 177 | arg = arg.replace(ISOLATED_OUTDIR_PARAMETER, out_dir) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 178 | replace_slash = True |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 179 | if SWARMING_BOT_FILE_PARAMETER in arg: |
| 180 | if bot_file: |
| 181 | arg = arg.replace(SWARMING_BOT_FILE_PARAMETER, bot_file) |
| 182 | replace_slash = True |
| 183 | else: |
| 184 | logging.warning('SWARMING_BOT_FILE_PARAMETER found in command, but no ' |
| 185 | 'bot_file specified. Leaving parameter unchanged.') |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 186 | if replace_slash: |
| 187 | # Replace slashes only if parameters are present |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 188 | # because of arguments like '${ISOLATED_OUTDIR}/foo/bar' |
| 189 | arg = arg.replace('/', os.sep) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 190 | return arg |
| 191 | |
| 192 | return [fix(arg) for arg in command] |
| 193 | |
| 194 | |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 195 | def run_command(command, cwd, tmp_dir, hard_timeout, grace_period): |
| 196 | """Runs the command. |
| 197 | |
| 198 | Returns: |
| 199 | tuple(process exit code, bool if had a hard timeout) |
| 200 | """ |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 201 | logging.info('run_command(%s, %s)' % (command, cwd)) |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 202 | |
| 203 | env = os.environ.copy() |
| 204 | if sys.platform == 'darwin': |
tansell | a494944 | 2016-06-23 22:34:32 -0700 | [diff] [blame] | 205 | env['TMPDIR'] = tmp_dir.encode(sys.getfilesystemencoding()) |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 206 | elif sys.platform == 'win32': |
tansell | a494944 | 2016-06-23 22:34:32 -0700 | [diff] [blame] | 207 | env['TEMP'] = tmp_dir.encode(sys.getfilesystemencoding()) |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 208 | else: |
tansell | a494944 | 2016-06-23 22:34:32 -0700 | [diff] [blame] | 209 | env['TMP'] = tmp_dir.encode(sys.getfilesystemencoding()) |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 210 | exit_code = None |
| 211 | had_hard_timeout = False |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 212 | with tools.Profiler('RunTest'): |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 213 | proc = None |
| 214 | had_signal = [] |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 215 | try: |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 216 | # TODO(maruel): This code is imperfect. It doesn't handle well signals |
| 217 | # during the download phase and there's short windows were things can go |
| 218 | # wrong. |
| 219 | def handler(signum, _frame): |
| 220 | if proc and not had_signal: |
| 221 | logging.info('Received signal %d', signum) |
| 222 | had_signal.append(True) |
maruel | 556d905 | 2015-10-05 11:12:44 -0700 | [diff] [blame] | 223 | raise subprocess42.TimeoutExpired(command, None) |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 224 | |
| 225 | proc = subprocess42.Popen(command, cwd=cwd, env=env, detached=True) |
| 226 | with subprocess42.set_signal_handler(subprocess42.STOP_SIGNALS, handler): |
| 227 | try: |
| 228 | exit_code = proc.wait(hard_timeout or None) |
| 229 | except subprocess42.TimeoutExpired: |
| 230 | if not had_signal: |
| 231 | logging.warning('Hard timeout') |
| 232 | had_hard_timeout = True |
| 233 | logging.warning('Sending SIGTERM') |
| 234 | proc.terminate() |
| 235 | |
| 236 | # Ignore signals in grace period. Forcibly give the grace period to the |
| 237 | # child process. |
| 238 | if exit_code is None: |
| 239 | ignore = lambda *_: None |
| 240 | with subprocess42.set_signal_handler(subprocess42.STOP_SIGNALS, ignore): |
| 241 | try: |
| 242 | exit_code = proc.wait(grace_period or None) |
| 243 | except subprocess42.TimeoutExpired: |
| 244 | # Now kill for real. The user can distinguish between the |
| 245 | # following states: |
| 246 | # - signal but process exited within grace period, |
| 247 | # hard_timed_out will be set but the process exit code will be |
| 248 | # script provided. |
| 249 | # - processed exited late, exit code will be -9 on posix. |
| 250 | logging.warning('Grace exhausted; sending SIGKILL') |
| 251 | proc.kill() |
| 252 | logging.info('Waiting for proces exit') |
| 253 | exit_code = proc.wait() |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 254 | except OSError: |
| 255 | # This is not considered to be an internal error. The executable simply |
| 256 | # does not exit. |
maruel | a72f46e | 2016-02-24 11:05:45 -0800 | [diff] [blame] | 257 | sys.stderr.write( |
| 258 | '<The executable does not exist or a dependent library is missing>\n' |
| 259 | '<Check for missing .so/.dll in the .isolate or GN file>\n' |
| 260 | '<Command: %s>\n' % command) |
| 261 | if os.environ.get('SWARMING_TASK_ID'): |
| 262 | # Give an additional hint when running as a swarming task. |
| 263 | sys.stderr.write( |
| 264 | '<See the task\'s page for commands to help diagnose this issue ' |
| 265 | 'by reproducing the task locally>\n') |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 266 | exit_code = 1 |
| 267 | logging.info( |
| 268 | 'Command finished with exit code %d (%s)', |
| 269 | exit_code, hex(0xffffffff & exit_code)) |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 270 | return exit_code, had_hard_timeout |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 271 | |
| 272 | |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 273 | def fetch_and_map(isolated_hash, storage, cache, outdir, use_symlinks): |
| 274 | """Fetches an isolated tree, create the tree and returns (bundle, stats).""" |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 275 | start = time.time() |
| 276 | bundle = isolateserver.fetch_isolated( |
| 277 | isolated_hash=isolated_hash, |
| 278 | storage=storage, |
| 279 | cache=cache, |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 280 | outdir=outdir, |
| 281 | use_symlinks=use_symlinks) |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 282 | return bundle, { |
| 283 | 'duration': time.time() - start, |
| 284 | 'initial_number_items': cache.initial_number_items, |
| 285 | 'initial_size': cache.initial_size, |
| 286 | 'items_cold': base64.b64encode(large.pack(sorted(cache.added))), |
| 287 | 'items_hot': base64.b64encode( |
tansell | 9e04a8d | 2016-07-28 09:31:59 -0700 | [diff] [blame] | 288 | large.pack(sorted(set(cache.used) - set(cache.added)))), |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 292 | def delete_and_upload(storage, out_dir, leak_temp_dir): |
| 293 | """Deletes the temporary run directory and uploads results back. |
| 294 | |
| 295 | Returns: |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 296 | tuple(outputs_ref, success, stats) |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 297 | - outputs_ref: a dict referring to the results archived back to the isolated |
| 298 | server, if applicable. |
| 299 | - success: False if something occurred that means that the task must |
| 300 | forcibly be considered a failure, e.g. zombie processes were left |
| 301 | behind. |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 302 | - stats: uploading stats. |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 303 | """ |
| 304 | |
| 305 | # Upload out_dir and generate a .isolated file out of this directory. It is |
| 306 | # only done if files were written in the directory. |
| 307 | outputs_ref = None |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 308 | cold = [] |
| 309 | hot = [] |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 310 | start = time.time() |
| 311 | |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 312 | if fs.isdir(out_dir) and fs.listdir(out_dir): |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 313 | with tools.Profiler('ArchiveOutput'): |
| 314 | try: |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 315 | results, f_cold, f_hot = isolateserver.archive_files_to_storage( |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 316 | storage, [out_dir], None) |
| 317 | outputs_ref = { |
| 318 | 'isolated': results[0][0], |
| 319 | 'isolatedserver': storage.location, |
| 320 | 'namespace': storage.namespace, |
| 321 | } |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 322 | cold = sorted(i.size for i in f_cold) |
| 323 | hot = sorted(i.size for i in f_hot) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 324 | except isolateserver.Aborted: |
| 325 | # This happens when a signal SIGTERM was received while uploading data. |
| 326 | # There is 2 causes: |
| 327 | # - The task was too slow and was about to be killed anyway due to |
| 328 | # exceeding the hard timeout. |
| 329 | # - The amount of data uploaded back is very large and took too much |
| 330 | # time to archive. |
| 331 | sys.stderr.write('Received SIGTERM while uploading') |
| 332 | # Re-raise, so it will be treated as an internal failure. |
| 333 | raise |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 334 | |
| 335 | success = False |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 336 | try: |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 337 | if (not leak_temp_dir and fs.isdir(out_dir) and |
maruel | 6eeea7d | 2015-09-16 12:17:42 -0700 | [diff] [blame] | 338 | not file_path.rmtree(out_dir)): |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 339 | logging.error('Had difficulties removing out_dir %s', out_dir) |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 340 | else: |
| 341 | success = True |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 342 | except OSError as e: |
| 343 | # When this happens, it means there's a process error. |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 344 | logging.exception('Had difficulties removing out_dir %s: %s', out_dir, e) |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 345 | stats = { |
| 346 | 'duration': time.time() - start, |
| 347 | 'items_cold': base64.b64encode(large.pack(cold)), |
| 348 | 'items_hot': base64.b64encode(large.pack(hot)), |
| 349 | } |
| 350 | return outputs_ref, success, stats |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 351 | |
| 352 | |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 353 | def map_and_run( |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 354 | command, isolated_hash, storage, isolate_cache, leak_temp_dir, root_dir, |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 355 | hard_timeout, grace_period, bot_file, extra_args, install_packages_fn, |
| 356 | use_symlinks): |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 357 | """Runs a command with optional isolated input/output. |
| 358 | |
| 359 | See run_tha_test for argument documentation. |
| 360 | |
| 361 | Returns metadata about the result. |
| 362 | """ |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 363 | assert root_dir or root_dir is None |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 364 | assert bool(command) ^ bool(isolated_hash) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 365 | result = { |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 366 | 'duration': None, |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 367 | 'exit_code': None, |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 368 | 'had_hard_timeout': False, |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 369 | 'internal_failure': None, |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 370 | 'stats': { |
nodir | 5571571 | 2016-06-03 12:28:19 -0700 | [diff] [blame] | 371 | # 'isolated': { |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 372 | # 'cipd': { |
| 373 | # 'duration': 0., |
| 374 | # 'get_client_duration': 0., |
| 375 | # }, |
nodir | 5571571 | 2016-06-03 12:28:19 -0700 | [diff] [blame] | 376 | # 'download': { |
| 377 | # 'duration': 0., |
| 378 | # 'initial_number_items': 0, |
| 379 | # 'initial_size': 0, |
| 380 | # 'items_cold': '<large.pack()>', |
| 381 | # 'items_hot': '<large.pack()>', |
| 382 | # }, |
| 383 | # 'upload': { |
| 384 | # 'duration': 0., |
| 385 | # 'items_cold': '<large.pack()>', |
| 386 | # 'items_hot': '<large.pack()>', |
| 387 | # }, |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 388 | # }, |
| 389 | }, |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 390 | # 'cipd_pins': { |
| 391 | # 'packages': [ |
| 392 | # {'package_name': ..., 'version': ..., 'path': ...}, |
| 393 | # ... |
| 394 | # ], |
| 395 | # 'client_package': {'package_name': ..., 'version': ...}, |
| 396 | # }, |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 397 | 'outputs_ref': None, |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 398 | 'version': 5, |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 399 | } |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 400 | |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 401 | if root_dir: |
nodir | e5028a9 | 2016-04-29 14:38:21 -0700 | [diff] [blame] | 402 | file_path.ensure_tree(root_dir, 0700) |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 403 | elif isolate_cache.cache_dir: |
| 404 | root_dir = os.path.dirname(isolate_cache.cache_dir) |
maruel | e2f2cb8 | 2016-07-13 14:41:03 -0700 | [diff] [blame] | 405 | # See comment for these constants. |
| 406 | run_dir = make_temp_dir(ISOLATED_RUN_DIR, root_dir) |
maruel | 03e1184 | 2016-07-14 10:50:16 -0700 | [diff] [blame] | 407 | # storage should be normally set but don't crash if it is not. This can happen |
| 408 | # as Swarming task can run without an isolate server. |
maruel | e2f2cb8 | 2016-07-13 14:41:03 -0700 | [diff] [blame] | 409 | out_dir = make_temp_dir(ISOLATED_OUT_DIR, root_dir) if storage else None |
| 410 | tmp_dir = make_temp_dir(ISOLATED_TMP_DIR, root_dir) |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 411 | cwd = run_dir |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 412 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 413 | try: |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 414 | cipd_info = install_packages_fn(run_dir) |
| 415 | if cipd_info: |
| 416 | result['stats']['cipd'] = cipd_info['stats'] |
| 417 | result['cipd_pins'] = cipd_info['cipd_pins'] |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 418 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 419 | if isolated_hash: |
nodir | 5571571 | 2016-06-03 12:28:19 -0700 | [diff] [blame] | 420 | isolated_stats = result['stats'].setdefault('isolated', {}) |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 421 | bundle, isolated_stats['download'] = fetch_and_map( |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 422 | isolated_hash=isolated_hash, |
| 423 | storage=storage, |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 424 | cache=isolate_cache, |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 425 | outdir=run_dir, |
| 426 | use_symlinks=use_symlinks) |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 427 | if not bundle.command: |
| 428 | # Handle this as a task failure, not an internal failure. |
| 429 | sys.stderr.write( |
| 430 | '<The .isolated doesn\'t declare any command to run!>\n' |
| 431 | '<Check your .isolate for missing \'command\' variable>\n') |
| 432 | if os.environ.get('SWARMING_TASK_ID'): |
| 433 | # Give an additional hint when running as a swarming task. |
| 434 | sys.stderr.write('<This occurs at the \'isolate\' step>\n') |
| 435 | result['exit_code'] = 1 |
| 436 | return result |
| 437 | |
| 438 | change_tree_read_only(run_dir, bundle.read_only) |
| 439 | cwd = os.path.normpath(os.path.join(cwd, bundle.relative_cwd)) |
| 440 | command = bundle.command + extra_args |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 441 | |
nodir | 34d673c | 2016-05-24 09:30:48 -0700 | [diff] [blame] | 442 | command = tools.fix_python_path(command) |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 443 | command = process_command(command, out_dir, bot_file) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 444 | file_path.ensure_command_has_abs_path(command, cwd) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 445 | |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 446 | sys.stdout.flush() |
| 447 | start = time.time() |
| 448 | try: |
| 449 | result['exit_code'], result['had_hard_timeout'] = run_command( |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 450 | command, cwd, tmp_dir, hard_timeout, grace_period) |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 451 | finally: |
| 452 | result['duration'] = max(time.time() - start, 0) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 453 | except Exception as e: |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 454 | # An internal error occurred. Report accordingly so the swarming task will |
| 455 | # be retried automatically. |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 456 | logging.exception('internal failure: %s', e) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 457 | result['internal_failure'] = str(e) |
| 458 | on_error.report(None) |
| 459 | finally: |
| 460 | try: |
| 461 | if leak_temp_dir: |
| 462 | logging.warning( |
| 463 | 'Deliberately leaking %s for later examination', run_dir) |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 464 | else: |
maruel | 84537cb | 2015-10-16 14:21:28 -0700 | [diff] [blame] | 465 | # On Windows rmtree(run_dir) call above has a synchronization effect: it |
| 466 | # finishes only when all task child processes terminate (since a running |
| 467 | # process locks *.exe file). Examine out_dir only after that call |
| 468 | # completes (since child processes may write to out_dir too and we need |
| 469 | # to wait for them to finish). |
| 470 | if fs.isdir(run_dir): |
| 471 | try: |
| 472 | success = file_path.rmtree(run_dir) |
| 473 | except OSError as e: |
| 474 | logging.error('Failure with %s', e) |
| 475 | success = False |
| 476 | if not success: |
| 477 | print >> sys.stderr, ( |
| 478 | 'Failed to delete the run directory, forcibly failing\n' |
| 479 | 'the task because of it. No zombie process can outlive a\n' |
| 480 | 'successful task run and still be marked as successful.\n' |
| 481 | 'Fix your stuff.') |
| 482 | if result['exit_code'] == 0: |
| 483 | result['exit_code'] = 1 |
| 484 | if fs.isdir(tmp_dir): |
| 485 | try: |
| 486 | success = file_path.rmtree(tmp_dir) |
| 487 | except OSError as e: |
| 488 | logging.error('Failure with %s', e) |
| 489 | success = False |
| 490 | if not success: |
| 491 | print >> sys.stderr, ( |
| 492 | 'Failed to delete the temporary directory, forcibly failing\n' |
| 493 | 'the task because of it. No zombie process can outlive a\n' |
| 494 | 'successful task run and still be marked as successful.\n' |
| 495 | 'Fix your stuff.') |
| 496 | if result['exit_code'] == 0: |
| 497 | result['exit_code'] = 1 |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 498 | |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 499 | # This deletes out_dir if leak_temp_dir is not set. |
nodir | 9130f07 | 2016-05-27 13:59:08 -0700 | [diff] [blame] | 500 | if out_dir: |
nodir | 5571571 | 2016-06-03 12:28:19 -0700 | [diff] [blame] | 501 | isolated_stats = result['stats'].setdefault('isolated', {}) |
| 502 | result['outputs_ref'], success, isolated_stats['upload'] = ( |
nodir | 9130f07 | 2016-05-27 13:59:08 -0700 | [diff] [blame] | 503 | delete_and_upload(storage, out_dir, leak_temp_dir)) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 504 | if not success and result['exit_code'] == 0: |
| 505 | result['exit_code'] = 1 |
| 506 | except Exception as e: |
| 507 | # Swallow any exception in the main finally clause. |
nodir | 9130f07 | 2016-05-27 13:59:08 -0700 | [diff] [blame] | 508 | if out_dir: |
| 509 | logging.exception('Leaking out_dir %s: %s', out_dir, e) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 510 | result['internal_failure'] = str(e) |
| 511 | return result |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 512 | |
| 513 | |
Marc-Antoine Ruel | 0ec868b | 2015-08-12 14:12:46 -0400 | [diff] [blame] | 514 | def run_tha_test( |
nodir | 6b94569 | 2016-10-19 19:09:06 -0700 | [diff] [blame] | 515 | command, isolated_hash, storage, isolate_cache, leak_temp_dir, result_json, |
bpastene | 3ae0952 | 2016-06-10 17:12:59 -0700 | [diff] [blame] | 516 | root_dir, hard_timeout, grace_period, bot_file, extra_args, |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 517 | install_packages_fn, use_symlinks): |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 518 | """Runs an executable and records execution metadata. |
| 519 | |
| 520 | Either command or isolated_hash must be specified. |
| 521 | |
| 522 | If isolated_hash is specified, downloads the dependencies in the cache, |
| 523 | hardlinks them into a temporary directory and runs the command specified in |
| 524 | the .isolated. |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 525 | |
| 526 | A temporary directory is created to hold the output files. The content inside |
| 527 | this directory will be uploaded back to |storage| packaged as a .isolated |
| 528 | file. |
| 529 | |
| 530 | Arguments: |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 531 | command: the command to run, a list of strings. Mutually exclusive with |
| 532 | isolated_hash. |
Marc-Antoine Ruel | 35b5843 | 2014-12-08 17:40:40 -0500 | [diff] [blame] | 533 | isolated_hash: the SHA-1 of the .isolated file that must be retrieved to |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 534 | recreate the tree of files to run the target executable. |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 535 | The command specified in the .isolated is executed. |
| 536 | Mutually exclusive with command argument. |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 537 | storage: an isolateserver.Storage object to retrieve remote objects. This |
| 538 | object has a reference to an isolateserver.StorageApi, which does |
| 539 | the actual I/O. |
nodir | 6b94569 | 2016-10-19 19:09:06 -0700 | [diff] [blame] | 540 | isolate_cache: an isolateserver.LocalCache to keep from retrieving the |
| 541 | same objects constantly by caching the objects retrieved. |
| 542 | Can be on-disk or in-memory. |
Kenneth Russell | 61d4235 | 2014-09-15 11:41:16 -0700 | [diff] [blame] | 543 | leak_temp_dir: if true, the temporary directory will be deliberately leaked |
| 544 | for later examination. |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 545 | result_json: file path to dump result metadata into. If set, the process |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 546 | exit code is always 0 unless an internal error occurred. |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 547 | root_dir: path to the directory to use to create the temporary directory. If |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 548 | not specified, a random temporary directory is created. |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 549 | hard_timeout: kills the process if it lasts more than this amount of |
| 550 | seconds. |
| 551 | grace_period: number of seconds to wait between SIGTERM and SIGKILL. |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 552 | extra_args: optional arguments to add to the command stated in the .isolate |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 553 | file. Ignored if isolate_hash is empty. |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 554 | install_packages_fn: function (dir) => {"stats": cipd_stats, "pins": |
| 555 | cipd_pins}. Installs packages. |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 556 | use_symlinks: create tree with symlinks instead of hardlinks. |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 557 | |
| 558 | Returns: |
| 559 | Process exit code that should be used. |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 560 | """ |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 561 | assert bool(command) ^ bool(isolated_hash) |
| 562 | extra_args = extra_args or [] |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 563 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 564 | if any(ISOLATED_OUTDIR_PARAMETER in a for a in (command or extra_args)): |
| 565 | assert storage is not None, 'storage is None although outdir is specified' |
| 566 | |
maruel | a76b9ee | 2015-12-15 06:18:08 -0800 | [diff] [blame] | 567 | if result_json: |
| 568 | # Write a json output file right away in case we get killed. |
| 569 | result = { |
| 570 | 'exit_code': None, |
| 571 | 'had_hard_timeout': False, |
| 572 | 'internal_failure': 'Was terminated before completion', |
| 573 | 'outputs_ref': None, |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 574 | 'version': 5, |
maruel | a76b9ee | 2015-12-15 06:18:08 -0800 | [diff] [blame] | 575 | } |
| 576 | tools.write_json(result_json, result, dense=True) |
| 577 | |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 578 | # run_isolated exit code. Depends on if result_json is used or not. |
| 579 | result = map_and_run( |
nodir | 6b94569 | 2016-10-19 19:09:06 -0700 | [diff] [blame] | 580 | command, isolated_hash, storage, isolate_cache, leak_temp_dir, root_dir, |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 581 | hard_timeout, grace_period, bot_file, extra_args, install_packages_fn, |
| 582 | use_symlinks) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 583 | logging.info('Result:\n%s', tools.format_json(result, dense=True)) |
bpastene | 3ae0952 | 2016-06-10 17:12:59 -0700 | [diff] [blame] | 584 | |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 585 | if result_json: |
maruel | 05d5a88 | 2015-09-21 13:59:02 -0700 | [diff] [blame] | 586 | # We've found tests to delete 'work' when quitting, causing an exception |
| 587 | # here. Try to recreate the directory if necessary. |
nodir | e5028a9 | 2016-04-29 14:38:21 -0700 | [diff] [blame] | 588 | file_path.ensure_tree(os.path.dirname(result_json)) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 589 | tools.write_json(result_json, result, dense=True) |
| 590 | # Only return 1 if there was an internal error. |
| 591 | return int(bool(result['internal_failure'])) |
maruel@chromium.org | 781ccf6 | 2013-09-17 19:39:47 +0000 | [diff] [blame] | 592 | |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 593 | # Marshall into old-style inline output. |
| 594 | if result['outputs_ref']: |
| 595 | data = { |
| 596 | 'hash': result['outputs_ref']['isolated'], |
| 597 | 'namespace': result['outputs_ref']['namespace'], |
| 598 | 'storage': result['outputs_ref']['isolatedserver'], |
| 599 | } |
Marc-Antoine Ruel | c44f572 | 2015-01-08 16:10:01 -0500 | [diff] [blame] | 600 | sys.stdout.flush() |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 601 | print( |
| 602 | '[run_isolated_out_hack]%s[/run_isolated_out_hack]' % |
| 603 | tools.format_json(data, dense=True)) |
maruel | b76604c | 2015-11-11 11:53:44 -0800 | [diff] [blame] | 604 | sys.stdout.flush() |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 605 | return result['exit_code'] or int(bool(result['internal_failure'])) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 606 | |
| 607 | |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 608 | def install_packages( |
nodir | ff531b4 | 2016-06-23 13:05:06 -0700 | [diff] [blame] | 609 | run_dir, packages, service_url, client_package_name, |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 610 | client_version, cache_dir=None, timeout=None): |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 611 | """Installs packages. Returns stats, cipd client info and pins. |
| 612 | |
| 613 | pins and the cipd client info are in the form of: |
| 614 | [ |
| 615 | { |
| 616 | "path": path, "package_name": package_name, "version": version, |
| 617 | }, |
| 618 | ... |
| 619 | ] |
| 620 | (the cipd client info is a single dictionary instead of a list) |
| 621 | |
| 622 | such that they correspond 1:1 to all input package arguments from the command |
| 623 | line. These dictionaries make their all the way back to swarming, where they |
| 624 | become the arguments of CipdPackage. |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 625 | |
| 626 | Args: |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 627 | run_dir (str): root of installation. |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 628 | packages: packages to install, list [(path, package_name, version), ...] |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 629 | service_url (str): CIPD server url, e.g. |
| 630 | "https://chrome-infra-packages.appspot.com." |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 631 | client_package_name (str): CIPD package name of CIPD client. |
| 632 | client_version (str): Version of CIPD client. |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 633 | cache_dir (str): where to keep cache of cipd clients, packages and tags. |
| 634 | timeout: max duration in seconds that this function can take. |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 635 | """ |
| 636 | assert cache_dir |
nodir | ff531b4 | 2016-06-23 13:05:06 -0700 | [diff] [blame] | 637 | if not packages: |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 638 | return None |
| 639 | |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 640 | timeoutfn = tools.sliding_timeout(timeout) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 641 | start = time.time() |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 642 | cache_dir = os.path.abspath(cache_dir) |
| 643 | |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 644 | run_dir = os.path.abspath(run_dir) |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 645 | |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 646 | package_pins = [None]*len(packages) |
| 647 | def insert_pin(path, name, version, idx): |
| 648 | path = path.replace(os.path.sep, '/') |
| 649 | package_pins[idx] = { |
| 650 | 'package_name': name, |
| 651 | 'path': path, |
| 652 | 'version': version, |
| 653 | } |
| 654 | |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 655 | get_client_start = time.time() |
| 656 | client_manager = cipd.get_client( |
| 657 | service_url, client_package_name, client_version, cache_dir, |
| 658 | timeout=timeoutfn()) |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 659 | |
| 660 | by_path = collections.defaultdict(list) |
| 661 | for i, (path, name, version) in enumerate(packages): |
| 662 | path = path.replace('/', os.path.sep) |
| 663 | by_path[path].append((name, version, i)) |
| 664 | |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 665 | with client_manager as client: |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 666 | client_package = { |
| 667 | 'package_name': client.package_name, |
| 668 | 'version': client.instance_id, |
| 669 | } |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 670 | get_client_duration = time.time() - get_client_start |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 671 | for path, pkgs in sorted(by_path.iteritems()): |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 672 | site_root = os.path.abspath(os.path.join(run_dir, path)) |
| 673 | if not site_root.startswith(run_dir): |
| 674 | raise cipd.Error('Invalid CIPD package path "%s"' % path) |
| 675 | |
| 676 | # Do not clean site_root before installation because it may contain other |
| 677 | # site roots. |
| 678 | file_path.ensure_tree(site_root, 0770) |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 679 | pins = client.ensure( |
| 680 | site_root, [(name, vers) for name, vers, _ in pkgs], |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 681 | cache_dir=os.path.join(cache_dir, 'cipd_internal'), |
| 682 | timeout=timeoutfn()) |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 683 | for i, pin in enumerate(pins): |
| 684 | insert_pin(path, pin[0], pin[1], pkgs[i][2]) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 685 | file_path.make_tree_files_read_only(site_root) |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 686 | |
| 687 | total_duration = time.time() - start |
| 688 | logging.info( |
| 689 | 'Installing CIPD client and packages took %d seconds', total_duration) |
| 690 | |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 691 | assert None not in package_pins |
| 692 | |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 693 | return { |
iannucci | 96fcccc | 2016-08-30 15:52:22 -0700 | [diff] [blame] | 694 | 'stats': { |
| 695 | 'duration': total_duration, |
| 696 | 'get_client_duration': get_client_duration, |
| 697 | }, |
| 698 | 'cipd_pins': { |
| 699 | 'client_package': client_package, |
| 700 | 'packages': package_pins, |
| 701 | } |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 702 | } |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 703 | |
| 704 | |
| 705 | def create_option_parser(): |
Marc-Antoine Ruel | f74cffe | 2015-07-15 15:21:34 -0400 | [diff] [blame] | 706 | parser = logging_utils.OptionParserWithLogging( |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 707 | usage='%prog <options> [command to run or extra args]', |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 708 | version=__version__, |
| 709 | log_file=RUN_ISOLATED_LOG_FILE) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 710 | parser.add_option( |
maruel | 36a963d | 2016-04-08 17:15:49 -0700 | [diff] [blame] | 711 | '--clean', action='store_true', |
| 712 | help='Cleans the cache, trimming it necessary and remove corrupted items ' |
| 713 | 'and returns without executing anything; use with -v to know what ' |
| 714 | 'was done') |
| 715 | parser.add_option( |
maruel | 2e8d0f5 | 2016-07-16 07:51:29 -0700 | [diff] [blame] | 716 | '--no-clean', action='store_true', |
| 717 | help='Do not clean the cache automatically on startup. This is meant for ' |
| 718 | 'bots where a separate execution with --clean was done earlier so ' |
| 719 | 'doing it again is redundant') |
| 720 | parser.add_option( |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 721 | '--use-symlinks', action='store_true', |
| 722 | help='Use symlinks instead of hardlinks') |
| 723 | parser.add_option( |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 724 | '--json', |
| 725 | help='dump output metadata to json file. When used, run_isolated returns ' |
| 726 | 'non-zero only on internal failure') |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 727 | parser.add_option( |
maruel | 5c9e47b | 2015-12-18 13:02:30 -0800 | [diff] [blame] | 728 | '--hard-timeout', type='float', help='Enforce hard timeout in execution') |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 729 | parser.add_option( |
maruel | 5c9e47b | 2015-12-18 13:02:30 -0800 | [diff] [blame] | 730 | '--grace-period', type='float', |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 731 | help='Grace period between SIGTERM and SIGKILL') |
bpastene | 3ae0952 | 2016-06-10 17:12:59 -0700 | [diff] [blame] | 732 | parser.add_option( |
| 733 | '--bot-file', |
| 734 | help='Path to a file describing the state of the host. The content is ' |
| 735 | 'defined by on_before_task() in bot_config.') |
aludwin | 7556e0c | 2016-10-26 08:46:10 -0700 | [diff] [blame^] | 736 | parser.add_option( |
| 737 | '-a', '--argsfile', |
| 738 | # This is actually handled in parse_args; it's included here purely so it |
| 739 | # can make it into the help text. |
| 740 | help='Specify a file containing a JSON array of arguments to this ' |
| 741 | 'script. If --argsfile is provided, no other argument may be ' |
| 742 | 'provided on the command line.') |
Marc-Antoine Ruel | 1687b5e | 2014-02-06 17:47:53 -0500 | [diff] [blame] | 743 | data_group = optparse.OptionGroup(parser, 'Data source') |
| 744 | data_group.add_option( |
Marc-Antoine Ruel | 185ded4 | 2015-01-28 20:49:18 -0500 | [diff] [blame] | 745 | '-s', '--isolated', |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 746 | help='Hash of the .isolated to grab from the isolate server.') |
Marc-Antoine Ruel | f7d737d | 2014-12-10 15:36:29 -0500 | [diff] [blame] | 747 | isolateserver.add_isolate_server_options(data_group) |
Marc-Antoine Ruel | 1687b5e | 2014-02-06 17:47:53 -0500 | [diff] [blame] | 748 | parser.add_option_group(data_group) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 749 | |
Marc-Antoine Ruel | a57d7db | 2014-10-15 20:31:19 -0400 | [diff] [blame] | 750 | isolateserver.add_cache_options(parser) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 751 | |
| 752 | cipd.add_cipd_options(parser) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 753 | |
Kenneth Russell | 61d4235 | 2014-09-15 11:41:16 -0700 | [diff] [blame] | 754 | debug_group = optparse.OptionGroup(parser, 'Debugging') |
| 755 | debug_group.add_option( |
| 756 | '--leak-temp-dir', |
| 757 | action='store_true', |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 758 | help='Deliberately leak isolate\'s temp dir for later examination. ' |
| 759 | 'Default: %default') |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 760 | debug_group.add_option( |
| 761 | '--root-dir', help='Use a directory instead of a random one') |
Kenneth Russell | 61d4235 | 2014-09-15 11:41:16 -0700 | [diff] [blame] | 762 | parser.add_option_group(debug_group) |
| 763 | |
Vadim Shtayura | e34e13a | 2014-02-02 11:23:26 -0800 | [diff] [blame] | 764 | auth.add_auth_options(parser) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 765 | |
| 766 | parser.set_defaults(cache='cache', cipd_cache='cipd_cache') |
| 767 | return parser |
| 768 | |
| 769 | |
aludwin | 7556e0c | 2016-10-26 08:46:10 -0700 | [diff] [blame^] | 770 | def parse_args(args): |
| 771 | # Create a fake mini-parser just to get out the "-a" command. Note that |
| 772 | # it's not documented here; instead, it's documented in create_option_parser |
| 773 | # even though that parser will never actually get to parse it. This is |
| 774 | # because --argsfile is exclusive with all other options and arguments. |
| 775 | file_argparse = argparse.ArgumentParser(add_help=False) |
| 776 | file_argparse.add_argument('-a', '--argsfile') |
| 777 | (file_args, nonfile_args) = file_argparse.parse_known_args(args) |
| 778 | if file_args.argsfile: |
| 779 | if nonfile_args: |
| 780 | file_argparse.error('Can\'t specify --argsfile with' |
| 781 | 'any other arguments (%s)' % nonfile_args) |
| 782 | try: |
| 783 | with open(file_args.argsfile, 'r') as f: |
| 784 | args = json.load(f) |
| 785 | except (IOError, OSError, ValueError) as e: |
| 786 | # We don't need to error out here - "args" is now empty, |
| 787 | # so the call below to parser.parse_args(args) will fail |
| 788 | # and print the full help text. |
| 789 | print >> sys.stderr, 'Couldn\'t read arguments: %s' % e |
| 790 | |
| 791 | # Even if we failed to read the args, just call the normal parser now since it |
| 792 | # will print the correct help message. |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 793 | parser = create_option_parser() |
Marc-Antoine Ruel | 90c9816 | 2013-12-18 15:11:57 -0500 | [diff] [blame] | 794 | options, args = parser.parse_args(args) |
aludwin | 7556e0c | 2016-10-26 08:46:10 -0700 | [diff] [blame^] | 795 | return (parser, options, args) |
| 796 | |
| 797 | |
| 798 | def main(args): |
| 799 | (parser, options, args) = parse_args(args) |
maruel | 36a963d | 2016-04-08 17:15:49 -0700 | [diff] [blame] | 800 | |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 801 | isolated_cache = isolateserver.process_cache_options(options) |
maruel | 36a963d | 2016-04-08 17:15:49 -0700 | [diff] [blame] | 802 | if options.clean: |
| 803 | if options.isolated: |
| 804 | parser.error('Can\'t use --isolated with --clean.') |
| 805 | if options.isolate_server: |
| 806 | parser.error('Can\'t use --isolate-server with --clean.') |
| 807 | if options.json: |
| 808 | parser.error('Can\'t use --json with --clean.') |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 809 | isolated_cache.cleanup() |
maruel | 36a963d | 2016-04-08 17:15:49 -0700 | [diff] [blame] | 810 | return 0 |
maruel | 2e8d0f5 | 2016-07-16 07:51:29 -0700 | [diff] [blame] | 811 | if not options.no_clean: |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 812 | isolated_cache.cleanup() |
maruel | 36a963d | 2016-04-08 17:15:49 -0700 | [diff] [blame] | 813 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 814 | if not options.isolated and not args: |
| 815 | parser.error('--isolated or command to run is required.') |
| 816 | |
Vadim Shtayura | 5d1efce | 2014-02-04 10:55:43 -0800 | [diff] [blame] | 817 | auth.process_auth_options(parser, options) |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 818 | |
| 819 | isolateserver.process_isolate_server_options( |
| 820 | parser, options, True, False) |
| 821 | if not options.isolate_server: |
| 822 | if options.isolated: |
| 823 | parser.error('--isolated requires --isolate-server') |
| 824 | if ISOLATED_OUTDIR_PARAMETER in args: |
| 825 | parser.error( |
| 826 | '%s in args requires --isolate-server' % ISOLATED_OUTDIR_PARAMETER) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 827 | |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 828 | if options.root_dir: |
| 829 | options.root_dir = unicode(os.path.abspath(options.root_dir)) |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 830 | if options.json: |
| 831 | options.json = unicode(os.path.abspath(options.json)) |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame] | 832 | |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 833 | cipd.validate_cipd_options(parser, options) |
| 834 | |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 835 | install_packages_fn = lambda run_dir: install_packages( |
nodir | ff531b4 | 2016-06-23 13:05:06 -0700 | [diff] [blame] | 836 | run_dir, cipd.parse_package_args(options.cipd_packages), |
| 837 | options.cipd_server, options.cipd_client_package, |
| 838 | options.cipd_client_version, cache_dir=options.cipd_cache) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 839 | |
| 840 | try: |
nodir | 90bc8dc | 2016-06-15 13:35:21 -0700 | [diff] [blame] | 841 | command = [] if options.isolated else args |
| 842 | if options.isolate_server: |
| 843 | storage = isolateserver.get_storage( |
| 844 | options.isolate_server, options.namespace) |
| 845 | with storage: |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 846 | # Hashing schemes used by |storage| and |isolated_cache| MUST match. |
| 847 | assert storage.hash_algo == isolated_cache.hash_algo |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 848 | return run_tha_test( |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 849 | command, options.isolated, storage, isolated_cache, |
| 850 | options.leak_temp_dir, options.json, options.root_dir, |
| 851 | options.hard_timeout, options.grace_period, options.bot_file, args, |
| 852 | install_packages_fn, options.use_symlinks) |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 853 | return run_tha_test( |
nodir | 56efa45 | 2016-10-12 12:17:39 -0700 | [diff] [blame] | 854 | command, options.isolated, None, isolated_cache, options.leak_temp_dir, |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 855 | options.json, options.root_dir, options.hard_timeout, |
| 856 | options.grace_period, options.bot_file, args, install_packages_fn, |
| 857 | options.use_symlinks) |
nodir | be642ff | 2016-06-09 15:51:51 -0700 | [diff] [blame] | 858 | except cipd.Error as ex: |
| 859 | print >> sys.stderr, ex.message |
| 860 | return 1 |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 861 | |
| 862 | |
| 863 | if __name__ == '__main__': |
maruel | 8e4e40c | 2016-05-30 06:21:07 -0700 | [diff] [blame] | 864 | subprocess42.inhibit_os_error_reporting() |
csharp@chromium.org | bfb9874 | 2013-03-26 20:28:36 +0000 | [diff] [blame] | 865 | # Ensure that we are always running with the correct encoding. |
vadimsh@chromium.org | a432647 | 2013-08-24 02:05:41 +0000 | [diff] [blame] | 866 | fix_encoding.fix_encoding() |
maruel | 4409e30 | 2016-07-19 14:25:51 -0700 | [diff] [blame] | 867 | file_path.enable_symlink() |
aludwin | 7556e0c | 2016-10-26 08:46:10 -0700 | [diff] [blame^] | 868 | |
Marc-Antoine Ruel | 90c9816 | 2013-12-18 15:11:57 -0500 | [diff] [blame] | 869 | sys.exit(main(sys.argv[1:])) |