Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Wrapper script to run java command as action with gn.""" | |
| 6 | |
| 7 import os | |
| 8 import subprocess | |
| 9 import sys | |
| 10 | |
| 11 EXIT_SUCCESS = 0 | |
| 12 EXIT_FAILURE = 1 | |
| 13 | |
| 14 | |
| 15 def IsExecutable(path): | |
| 16 """Returns whether file at |path| exists and is executable. | |
| 17 | |
| 18 Args: | |
| 19 path: absolute or relative path to test. | |
| 20 | |
| 21 Returns: | |
| 22 True if the file at |path| exists, False otherwise. | |
| 23 """ | |
| 24 return os.path.isfile(path) and os.access(path, os.X_OK) | |
| 25 | |
| 26 | |
| 27 def FindCommand(command): | |
| 28 """Lookup for |command| in PATH. | |
|
Eugene But (OOO till 7-30)
2015/10/09 15:52:36
NIT: s/Lookup/Looks up
Dirk Pranke
2015/10/09 20:03:12
Technically you want s/Lookup for/Looks up/ :)
sdefresne
2015/10/21 01:29:05
Fixed.
| |
| 29 | |
| 30 Args: | |
| 31 command: name of the command to lookup, if command is a relative or | |
| 32 absolute path (i.e. contains some path separator) then only that | |
| 33 path will be tested. | |
| 34 | |
| 35 Returns: | |
| 36 Full path to command or None if the command was not found. | |
| 37 """ | |
| 38 fpath, _ = os.path.split(command) | |
| 39 if fpath: | |
| 40 if IsExecutable(command): | |
| 41 return command | |
| 42 | |
| 43 for path in os.environ['PATH'].split(os.path.pathsep): | |
| 44 path = os.path.join(path, command) | |
| 45 if IsExecutable(path): | |
| 46 return path | |
| 47 | |
| 48 return None | |
| 49 | |
| 50 | |
| 51 def main(): | |
| 52 java_path = FindCommand('java') | |
|
Dirk Pranke
2015/10/09 20:03:12
This won't work right on windows. Do you care? If
sdefresne
2015/10/21 01:29:05
I've added support for PATHEXT to FindCommand and
| |
| 53 if not java_path: | |
| 54 sys.stderr.write('java: command not found\n') | |
| 55 sys.exit(EXIT_FAILURE) | |
| 56 | |
| 57 args = sys.argv[1:] | |
| 58 if len(args) < 2 or args[0] != '-jar': | |
| 59 sys.stderr.write('usage: %s -jar JARPATH [java_args]...\n' % sys.argv[0]) | |
| 60 sys.exit(EXIT_FAILURE) | |
| 61 | |
| 62 return subprocess.check_call([java_path] + args) | |
| 63 | |
| 64 | |
| 65 if __name__ == '__main__': | |
| 66 sys.exit(main()) | |
| OLD | NEW |