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

Side by Side Diff: appengine/components/tools/compile_proto.py

Issue 1148073005: Use luci-config for infrequently changing settings, part 2. (Closed) Base URL: git@github.com:luci/luci-py@master
Patch Set: fix pylint (??!) Created 5 years, 6 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 | « appengine/components/components/datastore_utils/config.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Swarming Authors. All rights reserved. 2 # Copyright 2014 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed by the Apache v2.0 license that can be 3 # Use of this source code is governed by the Apache v2.0 license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Compiles all *.proto files it finds into *_pb2.py.""" 6 """Compiles all *.proto files it finds into *_pb2.py."""
7 7
8 import logging 8 import logging
9 import optparse 9 import optparse
10 import os 10 import os
11 import re 11 import re
12 import shutil 12 import shutil
13 import subprocess 13 import subprocess
14 import sys 14 import sys
15 import tempfile 15 import tempfile
16 16
17 17
18 # Directory with this file.
19 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
20
21
18 # Printed if protoc is missing or too old. 22 # Printed if protoc is missing or too old.
19 PROTOC_INSTALL_HELP = r"""Could not find working protocol buffers compiler. 23 PROTOC_INSTALL_HELP = r"""Could not find working protocol buffers compiler.
20 24
21 To install it on Linux run install_protoc.py. 25 To install it on Linux and Mac run %s.
22 26
23 On Windows and Mac you are on your own. 27 On Windows you are on your own.
24 """ 28 """ % (os.path.join(THIS_DIR, 'install_protoc.py'))
25 29
26 30
27 # Directory with this file.
28 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
29
30 # Where to look for 'protoc' first (before hitting PATH). install_protoc.py 31 # Where to look for 'protoc' first (before hitting PATH). install_protoc.py
31 # installs protoc there. 32 # installs protoc there.
32 DEFAULT_PROTOC_DIR = os.path.join(THIS_DIR, 'protoc') 33 DEFAULT_PROTOC_DIR = os.path.join(THIS_DIR, 'protoc')
33 34
34 # Minimally required protoc version. 35 # Minimally required protoc version.
35 MIN_SUPPORTED_PROTOC_VERSION = (2, 5, 0) 36 MIN_SUPPORTED_PROTOC_VERSION = (2, 5, 0)
37 # Maximally supported protoc version.
38 MAX_SUPPORTED_PROTOC_VERSION = (2, 5, 9)
36 39
37 # Paths that should not be searched for *.proto. 40 # Paths that should not be searched for *.proto.
38 BLACKLISTED_PATHS = [ 41 BLACKLISTED_PATHS = [
39 re.compile(r'.*(/|\\)third_party(/|\\)?'), 42 re.compile(r'.*(/|\\)third_party(/|\\)?'),
40 ] 43 ]
41 44
42 45
43 def is_blacklisted(path, blacklist): 46 def is_blacklisted(path, blacklist):
44 """True if |path| matches any regexp in |blacklist|.""" 47 """True if |path| matches any regexp in |blacklist|."""
45 return any(b.match(path) for b in blacklist) 48 return any(b.match(path) for b in blacklist)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 protoc_version = get_protoc_version() 179 protoc_version = get_protoc_version()
177 if protoc_version is None or protoc_version < MIN_SUPPORTED_PROTOC_VERSION: 180 if protoc_version is None or protoc_version < MIN_SUPPORTED_PROTOC_VERSION:
178 if protoc_version: 181 if protoc_version:
179 existing = '.'.join(map(str, protoc_version)) 182 existing = '.'.join(map(str, protoc_version))
180 expected = '.'.join(map(str, MIN_SUPPORTED_PROTOC_VERSION)) 183 expected = '.'.join(map(str, MIN_SUPPORTED_PROTOC_VERSION))
181 print >> sys.stderr, ( 184 print >> sys.stderr, (
182 'protoc version is too old (%s), expecting at least %s.\n' % 185 'protoc version is too old (%s), expecting at least %s.\n' %
183 (existing, expected)) 186 (existing, expected))
184 sys.stderr.write(PROTOC_INSTALL_HELP) 187 sys.stderr.write(PROTOC_INSTALL_HELP)
185 return 1 188 return 1
189 # Make sure protoc produces code compatible with vendored libprotobuf.
190 if protoc_version > MAX_SUPPORTED_PROTOC_VERSION:
191 existing = '.'.join(map(str, protoc_version))
192 expected = '.'.join(map(str, MAX_SUPPORTED_PROTOC_VERSION))
193 print >> sys.stderr, (
194 'protoc version is too new (%s), expecting at most %s.\n' %
195 (existing, expected))
196 sys.stderr.write(PROTOC_INSTALL_HELP)
197 return 1
186 198
187 # Include default blacklisted paths. 199 # Include default blacklisted paths.
188 blacklisted_paths = list(blacklisted_paths or []) 200 blacklisted_paths = list(blacklisted_paths or [])
189 blacklisted_paths.extend(BLACKLISTED_PATHS) 201 blacklisted_paths.extend(BLACKLISTED_PATHS)
190 202
191 if options.check: 203 if options.check:
192 success = check_all_files(root_dir, import_paths, blacklisted_paths) 204 success = check_all_files(root_dir, import_paths, blacklisted_paths)
193 else: 205 else:
194 success = compile_all_files(root_dir, import_paths, blacklisted_paths) 206 success = compile_all_files(root_dir, import_paths, blacklisted_paths)
195 207
196 return int(not success) 208 return int(not success)
197 209
198 210
199 if __name__ == '__main__': 211 if __name__ == '__main__':
200 sys.exit(main(sys.argv[1:])) 212 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « appengine/components/components/datastore_utils/config.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698