Forbid hyphens in *.proto

BUG=386125

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

Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: ee26b9cab4a40f38997c44019d5e37fd0cef1b45
diff --git a/protoc_wrapper.py b/protoc_wrapper.py
index 69a7aec..e6ddf95 100755
--- a/protoc_wrapper.py
+++ b/protoc_wrapper.py
@@ -10,6 +10,7 @@
 - Handles building with system protobuf as an option.
 """
 
+import fnmatch
 import optparse
 import os.path
 import shutil
@@ -41,6 +42,26 @@
     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()
@@ -84,6 +105,9 @@
   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)