Skip to content

Commit

Permalink
Forbid hyphens in *.proto
Browse files Browse the repository at this point in the history
BUG=386125

Review URL: https://codereview.chromium.org/343543003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279913 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
andrewhayden@chromium.org committed Jun 26, 2014
1 parent 94cf2e6 commit ee26b9c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tools/protoc_wrapper/protoc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Handles building with system protobuf as an option.
"""

import fnmatch
import optparse
import os.path
import shutil
Expand Down Expand Up @@ -41,6 +42,26 @@ def ModifyHeader(header_file, extra_header):
f.write(''.join(header_contents))
return 0

def ScanForBadFiles(scan_root):
"""Scan for bad file names, see http://crbug.com/386125 for details.
Returns True if any filenames are bad. Outputs errors to stderr.
|scan_root| is the path to the directory to be recursively scanned.
"""
badname = False
real_scan_root = os.path.realpath(scan_root)
for dirpath, dirnames, filenames in os.walk(real_scan_root):
matches = fnmatch.filter(filenames, '*-*.proto')
if len(matches) > 0:
if not badname:
badname = True
sys.stderr.write('proto files must not have hyphens in their names ('
'see http://crbug.com/386125 for more information):\n')
for filename in matches:
sys.stderr.write(' ' + os.path.join(real_scan_root,
dirpath, filename) + '\n')
return badname


def RewriteProtoFilesForSystemProtobuf(path):
wrapper_dir = tempfile.mkdtemp()
Expand Down Expand Up @@ -84,6 +105,9 @@ def main(argv):
if len(args) < 2:
return 1

if ScanForBadFiles(options.proto_in_dir):
return 1

proto_path = options.proto_in_dir
if options.use_system_protobuf == 1:
proto_path = RewriteProtoFilesForSystemProtobuf(proto_path)
Expand Down

0 comments on commit ee26b9c

Please sign in to comment.