Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: client/run_isolated.py

Issue 2443663002: Pass args in file from task_runner to run_isolated (Closed)
Patch Set: Respond to code review comments other than changes to options processing Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2012 The LUCI Authors. All rights reserved. 2 # Copyright 2012 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 """Runs a command with optional isolated input/output. 6 """Runs a command with optional isolated input/output.
7 7
8 Despite name "run_isolated", can run a generic non-isolated command specified as 8 Despite name "run_isolated", can run a generic non-isolated command specified as
9 args. 9 args.
10 10
11 If input isolated hash is provided, fetches it, creates a tree of hard links, 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. 12 appends args to the command in the fetched isolated and runs it.
13 To improve performance, keeps a local cache. 13 To improve performance, keeps a local cache.
14 The local cache can safely be deleted. 14 The local cache can safely be deleted.
15 15
16 Any ${EXECUTABLE_SUFFIX} on the command line will be replaced with ".exe" string 16 Any ${EXECUTABLE_SUFFIX} on the command line will be replaced with ".exe" string
17 on Windows and "" on other platforms. 17 on Windows and "" on other platforms.
18 18
19 Any ${ISOLATED_OUTDIR} on the command line will be replaced by the location of a 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 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 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. 22 and the .isolated file describing this directory will be printed to stdout.
23 23
24 Any ${SWARMING_BOT_FILE} on the command line will be replaced by the value of 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 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 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. 27 on_before_task() hook in the swarming server's custom bot_config.py.
28 """ 28 """
29 29
30 __version__ = '0.8.5' 30 __version__ = '0.8.5'
M-A Ruel 2016/10/24 16:26:52 don't forget to bump.
aludwin 2016/10/24 18:32:05 I haven't changed the file format itself, so is th
M-A Ruel 2016/10/24 18:34:11 You add a new flag. The API changes.
31 31
32 import base64 32 import base64
33 import collections 33 import collections
34 import json
34 import logging 35 import logging
35 import optparse 36 import optparse
36 import os 37 import os
37 import sys 38 import sys
38 import tempfile 39 import tempfile
39 import time 40 import time
40 41
41 from third_party.depot_tools import fix_encoding 42 from third_party.depot_tools import fix_encoding
42 43
43 from utils import file_path 44 from utils import file_path
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 install_packages_fn, options.use_symlinks) 817 install_packages_fn, options.use_symlinks)
817 return run_tha_test( 818 return run_tha_test(
818 command, options.isolated, None, isolated_cache, options.leak_temp_dir, 819 command, options.isolated, None, isolated_cache, options.leak_temp_dir,
819 options.json, options.root_dir, options.hard_timeout, 820 options.json, options.root_dir, options.hard_timeout,
820 options.grace_period, options.bot_file, args, install_packages_fn, 821 options.grace_period, options.bot_file, args, install_packages_fn,
821 options.use_symlinks) 822 options.use_symlinks)
822 except cipd.Error as ex: 823 except cipd.Error as ex:
823 print >> sys.stderr, ex.message 824 print >> sys.stderr, ex.message
824 return 1 825 return 1
825 826
827 def get_args(args):
828 if len(args) == 2 and args[0] == '-f':
M-A Ruel 2016/10/24 16:26:52 then create a temporary optparse with only the -f
829 # If the only args are "-f filename", load those
830 # instead.
831 argfile = args[1]
832 args = []
833 try:
834 f = open(argfile, 'r')
835 args = json.loads(f.read())
836 f.close()
837 except Exception as e:
838 print "Couldn't read arguments: %s"%e
839 return args
826 840
827 if __name__ == '__main__': 841 if __name__ == '__main__':
828 subprocess42.inhibit_os_error_reporting() 842 subprocess42.inhibit_os_error_reporting()
829 # Ensure that we are always running with the correct encoding. 843 # Ensure that we are always running with the correct encoding.
830 fix_encoding.fix_encoding() 844 fix_encoding.fix_encoding()
831 file_path.enable_symlink() 845 file_path.enable_symlink()
832 sys.exit(main(sys.argv[1:])) 846
847 sys.exit(main(get_args(sys.argv[1:])))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698