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 json |
7 import os | 7 import os |
8 import pipes | 8 import pipes |
9 import shlex | 9 import shlex |
10 import shutil | 10 import shutil |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 # is addressed. | 54 # is addressed. |
55 gyp_string = gyp_string.replace('##', '$') | 55 gyp_string = gyp_string.replace('##', '$') |
56 return shlex.split(gyp_string) | 56 return shlex.split(gyp_string) |
57 | 57 |
58 | 58 |
59 def CheckOptions(options, parser, required=[]): | 59 def CheckOptions(options, parser, required=[]): |
60 for option_name in required: | 60 for option_name in required: |
61 if not getattr(options, option_name): | 61 if not getattr(options, option_name): |
62 parser.error('--%s is required' % option_name.replace('_', '-')) | 62 parser.error('--%s is required' % option_name.replace('_', '-')) |
63 | 63 |
| 64 def WriteJson(obj, path, only_if_changed=False): |
| 65 old_dump = None |
| 66 if os.path.exists(path): |
| 67 with open(path, 'r') as oldfile: |
| 68 old_dump = oldfile.read() |
| 69 |
| 70 new_dump = json.dumps(obj) |
| 71 |
| 72 if not only_if_changed or old_dump != new_dump: |
| 73 with open(path, 'w') as outfile: |
| 74 outfile.write(new_dump) |
64 | 75 |
65 def ReadJson(path): | 76 def ReadJson(path): |
66 with open(path, 'r') as jsonfile: | 77 with open(path, 'r') as jsonfile: |
67 return json.load(jsonfile) | 78 return json.load(jsonfile) |
68 | 79 |
69 | 80 |
70 # This can be used in most cases like subprocess.check_call. The output, | 81 # This can be used in most cases like subprocess.check_call. The output, |
71 # particularly when the command fails, better highlights the command's failure. | 82 # particularly when the command fails, better highlights the command's failure. |
72 # This call will directly exit on a failure in the subprocess so that no python | 83 # This call will directly exit on a failure in the subprocess so that no python |
73 # stacktrace is printed after the output of the failed command. | 84 # stacktrace is printed after the output of the failed command. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 121 |
111 def IsTimeStale(output, inputs): | 122 def IsTimeStale(output, inputs): |
112 if not os.path.exists(output): | 123 if not os.path.exists(output): |
113 return True | 124 return True |
114 | 125 |
115 output_time = GetModifiedTime(output) | 126 output_time = GetModifiedTime(output) |
116 for input in inputs: | 127 for input in inputs: |
117 if GetModifiedTime(input) > output_time: | 128 if GetModifiedTime(input) > output_time: |
118 return True | 129 return True |
119 return False | 130 return False |
OLD | NEW |