OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import fnmatch | 5 import fnmatch |
| 6 import json |
6 import os | 7 import os |
7 import pipes | 8 import pipes |
8 import shlex | 9 import shlex |
9 import shutil | 10 import shutil |
10 import subprocess | 11 import subprocess |
11 import sys | 12 import sys |
12 import traceback | 13 import traceback |
13 | 14 |
14 | 15 |
15 def MakeDirectory(dir_path): | 16 def MakeDirectory(dir_path): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 def ParseGypList(gyp_string): | 49 def ParseGypList(gyp_string): |
49 # The ninja generator doesn't support $ in strings, so use ## to | 50 # The ninja generator doesn't support $ in strings, so use ## to |
50 # represent $. | 51 # represent $. |
51 # TODO(cjhopman): Remove when | 52 # TODO(cjhopman): Remove when |
52 # https://code.google.com/p/gyp/issues/detail?id=327 | 53 # https://code.google.com/p/gyp/issues/detail?id=327 |
53 # is addressed. | 54 # is addressed. |
54 gyp_string = gyp_string.replace('##', '$') | 55 gyp_string = gyp_string.replace('##', '$') |
55 return shlex.split(gyp_string) | 56 return shlex.split(gyp_string) |
56 | 57 |
57 | 58 |
| 59 def CheckOptions(options, parser, required=[]): |
| 60 for option_name in required: |
| 61 if not getattr(options, option_name): |
| 62 parser.error('--%s is required' % option_name.replace('_', '-')) |
| 63 |
| 64 |
| 65 def ReadJson(path): |
| 66 with open(path, 'r') as jsonfile: |
| 67 return json.load(jsonfile) |
| 68 |
| 69 |
58 # This can be used in most cases like subprocess.check_call. The output, | 70 # This can be used in most cases like subprocess.check_call. The output, |
59 # particularly when the command fails, better highlights the command's failure. | 71 # particularly when the command fails, better highlights the command's failure. |
60 # This call will directly exit on a failure in the subprocess so that no python | 72 # This call will directly exit on a failure in the subprocess so that no python |
61 # stacktrace is printed after the output of the failed command. | 73 # stacktrace is printed after the output of the failed command. |
62 def CheckCallDie(args, cwd=None): | 74 def CheckCallDie(args, cwd=None): |
63 if not cwd: | 75 if not cwd: |
64 cwd = os.getcwd() | 76 cwd = os.getcwd() |
65 | 77 |
66 child = subprocess.Popen(args, | 78 child = subprocess.Popen(args, |
67 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd) | 79 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd) |
(...skipping 13 matching lines...) Expand all Loading... |
81 if stdout: | 93 if stdout: |
82 print stdout, | 94 print stdout, |
83 | 95 |
84 # Directly exit to avoid printing stacktrace. | 96 # Directly exit to avoid printing stacktrace. |
85 sys.exit(child.returncode) | 97 sys.exit(child.returncode) |
86 | 98 |
87 else: | 99 else: |
88 if stdout: | 100 if stdout: |
89 print stdout, | 101 print stdout, |
90 | 102 |
OLD | NEW |