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

Side by Side Diff: build/android/gyp/util/build_utils.py

Issue 153743008: Revert of Enable presubmit pylint in build/android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merging with changes to pylib/linker/test_case.py. Created 6 years, 10 months 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
« no previous file with comments | « build/android/gyp/util/build_device.py ('k') | build/android/gyp/util/md5_check.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import subprocess 11 import subprocess
12 import sys 12 import sys
13 import traceback
13 14
14 15
15 def MakeDirectory(dir_path): 16 def MakeDirectory(dir_path):
16 try: 17 try:
17 os.makedirs(dir_path) 18 os.makedirs(dir_path)
18 except OSError: 19 except OSError:
19 pass 20 pass
20 21
21 22
22 def DeleteDirectory(dir_path): 23 def DeleteDirectory(dir_path):
23 if os.path.exists(dir_path): 24 if os.path.exists(dir_path):
24 shutil.rmtree(dir_path) 25 shutil.rmtree(dir_path)
25 26
26 27
27 def Touch(path): 28 def Touch(path):
28 MakeDirectory(os.path.dirname(path)) 29 MakeDirectory(os.path.dirname(path))
29 with open(path, 'a'): 30 with open(path, 'a'):
30 os.utime(path, None) 31 os.utime(path, None)
31 32
32 33
33 def FindInDirectory(directory, filename_filter): 34 def FindInDirectory(directory, filter):
34 files = [] 35 files = []
35 for root, _dirnames, filenames in os.walk(directory): 36 for root, dirnames, filenames in os.walk(directory):
36 matched_files = fnmatch.filter(filenames, filename_filter) 37 matched_files = fnmatch.filter(filenames, filter)
37 files.extend((os.path.join(root, f) for f in matched_files)) 38 files.extend((os.path.join(root, f) for f in matched_files))
38 return files 39 return files
39 40
40 41
41 def FindInDirectories(directories, filename_filter): 42 def FindInDirectories(directories, filter):
42 all_files = [] 43 all_files = []
43 for directory in directories: 44 for directory in directories:
44 all_files.extend(FindInDirectory(directory, filename_filter)) 45 all_files.extend(FindInDirectory(directory, filter))
45 return all_files 46 return all_files
46 47
47 48
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
58 def CheckOptions(options, parser, required=None): 59 def CheckOptions(options, parser, required=[]):
59 if not required:
60 return
61 for option_name in required: 60 for option_name in required:
62 if not getattr(options, option_name): 61 if not getattr(options, option_name):
63 parser.error('--%s is required' % option_name.replace('_', '-')) 62 parser.error('--%s is required' % option_name.replace('_', '-'))
64 63
65 def WriteJson(obj, path, only_if_changed=False): 64 def WriteJson(obj, path, only_if_changed=False):
66 old_dump = None 65 old_dump = None
67 if os.path.exists(path): 66 if os.path.exists(path):
68 with open(path, 'r') as oldfile: 67 with open(path, 'r') as oldfile:
69 old_dump = oldfile.read() 68 old_dump = oldfile.read()
70 69
71 new_dump = json.dumps(obj) 70 new_dump = json.dumps(obj)
72 71
73 if not only_if_changed or old_dump != new_dump: 72 if not only_if_changed or old_dump != new_dump:
74 with open(path, 'w') as outfile: 73 with open(path, 'w') as outfile:
75 outfile.write(new_dump) 74 outfile.write(new_dump)
76 75
77 def ReadJson(path): 76 def ReadJson(path):
78 with open(path, 'r') as jsonfile: 77 with open(path, 'r') as jsonfile:
79 return json.load(jsonfile) 78 return json.load(jsonfile)
80 79
81 80
82 class CalledProcessError(Exception): 81 class CalledProcessError(Exception):
83 """This exception is raised when the process run by CheckOutput 82 """This exception is raised when the process run by CheckOutput
84 exits with a non-zero exit code.""" 83 exits with a non-zero exit code."""
85 84
86 def __init__(self, cwd, args, output): 85 def __init__(self, cwd, args, output):
87 super(CalledProcessError, self).__init__()
88 self.cwd = cwd 86 self.cwd = cwd
89 self.args = args 87 self.args = args
90 self.output = output 88 self.output = output
91 89
92 def __str__(self): 90 def __str__(self):
93 # A user should be able to simply copy and paste the command that failed 91 # A user should be able to simply copy and paste the command that failed
94 # into their shell. 92 # into their shell.
95 copyable_command = '( cd {}; {} )'.format(os.path.abspath(self.cwd), 93 copyable_command = '( cd {}; {} )'.format(os.path.abspath(self.cwd),
96 ' '.join(map(pipes.quote, self.args))) 94 ' '.join(map(pipes.quote, self.args)))
97 return 'Command failed: {}\n{}'.format(copyable_command, self.output) 95 return 'Command failed: {}\n{}'.format(copyable_command, self.output)
(...skipping 26 matching lines...) Expand all
124 # For a symlink, the modified time should be the greater of the link's 122 # For a symlink, the modified time should be the greater of the link's
125 # modified time and the modified time of the target. 123 # modified time and the modified time of the target.
126 return max(os.lstat(path).st_mtime, os.stat(path).st_mtime) 124 return max(os.lstat(path).st_mtime, os.stat(path).st_mtime)
127 125
128 126
129 def IsTimeStale(output, inputs): 127 def IsTimeStale(output, inputs):
130 if not os.path.exists(output): 128 if not os.path.exists(output):
131 return True 129 return True
132 130
133 output_time = GetModifiedTime(output) 131 output_time = GetModifiedTime(output)
134 for i in inputs: 132 for input in inputs:
135 if GetModifiedTime(i) > output_time: 133 if GetModifiedTime(input) > output_time:
136 return True 134 return True
137 return False 135 return False
138 136
139 137
140 def IsDeviceReady(): 138 def IsDeviceReady():
141 device_state = CheckOutput(['adb', 'get-state']) 139 device_state = CheckOutput(['adb', 'get-state'])
142 return device_state.strip() == 'device' 140 return device_state.strip() == 'device'
143 141
144 142
145 def PrintWarning(message): 143 def PrintWarning(message):
146 print 'WARNING: ' + message 144 print 'WARNING: ' + message
147 145
148 146
149 def PrintBigWarning(message): 147 def PrintBigWarning(message):
150 print '***** ' * 8 148 print '***** ' * 8
151 PrintWarning(message) 149 PrintWarning(message)
152 print '***** ' * 8 150 print '***** ' * 8
OLDNEW
« no previous file with comments | « build/android/gyp/util/build_device.py ('k') | build/android/gyp/util/md5_check.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698