Updating Bazel outputs to work on other platforms.

Bazel on Mac requires some alterations to the generated build files.
This change updates generate_build_files.py to emit suitable Bazel
files. This will require some tweaks to projects that build with Bazel.

Change-Id: I3d68ec754b8abaa41a348f86c32434477f2c5e1c
Reviewed-on: https://boringssl-review.googlesource.com/6146
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/util/generate_build_files.py b/util/generate_build_files.py
index 2eae98a..9254590 100644
--- a/util/generate_build_files.py
+++ b/util/generate_build_files.py
@@ -190,7 +190,7 @@
     out.write(']\n')
 
   def WriteFiles(self, files, asm_outputs):
-    with open('BUILD.generated', 'w+') as out:
+    with open('BUILD.generated.bzl', 'w+') as out:
       out.write(self.header)
 
       self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
@@ -209,7 +209,7 @@
         self.PrintVariableSection(
             out, 'crypto_sources_%s' % arch, asm_files)
 
-    with open('BUILD.generated_tests', 'w+') as out:
+    with open('BUILD.generated_tests.bzl', 'w+') as out:
       out.write(self.header)
 
       out.write('test_support_sources = [\n')
@@ -217,8 +217,12 @@
         if os.path.basename(filename) == 'malloc.cc':
           continue
         out.write('    "%s",\n' % filename)
-      out.write('] + glob(["src/crypto/test/*.h"])\n\n')
 
+      out.write(']\n\n')
+
+      out.write('def create_tests(copts):\n')
+      out.write('  test_support_sources_complete = test_support_sources + \\\n')
+      out.write('      native.glob(["src/crypto/test/*.h"])\n')
       name_counts = {}
       for test in files['tests']:
         name = os.path.basename(test[0])
@@ -245,39 +249,39 @@
         else:
           raise ValueError("Can't find source for %s" % test[0])
 
-        out.write('cc_test(\n')
-        out.write('    name = "%s",\n' % name)
-        out.write('    size = "small",\n')
-        out.write('    srcs = ["%s"] + test_support_sources,\n' % src)
+        out.write('  native.cc_test(\n')
+        out.write('      name = "%s",\n' % name)
+        out.write('      size = "small",\n')
+        out.write('      srcs = ["%s"] + test_support_sources_complete,\n' % src)
 
         data_files = []
         if len(test) > 1:
 
-          out.write('    args = [\n')
+          out.write('      args = [\n')
           for arg in test[1:]:
             if '/' in arg:
-              out.write('        "$(location src/%s)",\n' % arg)
+              out.write('          "$(location src/%s)",\n' % arg)
               data_files.append('src/%s' % arg)
             else:
-              out.write('        "%s",\n' % arg)
-          out.write('    ],\n')
+              out.write('          "%s",\n' % arg)
+          out.write('      ],\n')
 
-        out.write('    copts = boringssl_copts,\n')
+        out.write('      copts = copts,\n')
 
         if len(data_files) > 0:
-          out.write('    data = [\n')
+          out.write('      data = [\n')
           for filename in data_files:
-            out.write('        "%s",\n' % filename)
-          out.write('    ],\n')
+            out.write('          "%s",\n' % filename)
+          out.write('      ],\n')
 
         if 'ssl/' in test[0]:
-          out.write('    deps = [\n')
-          out.write('        ":crypto",\n')
-          out.write('        ":ssl",\n')
-          out.write('    ],\n')
+          out.write('      deps = [\n')
+          out.write('          ":crypto",\n')
+          out.write('          ":ssl",\n')
+          out.write('      ],\n')
         else:
-          out.write('    deps = [":crypto"],\n')
-        out.write(')\n')
+          out.write('      deps = [":crypto"],\n')
+        out.write('  )\n')
 
 
 def FindCMakeFiles(directory):