generate_build_files: more flexible Bazel deps

Include all internal headers in |test_support_sources|, since that's
easier than enumerating the ones specifically required for each test.

This incidentally removes test headers from |crypto_internal_headers|
and |ssl_internal_headers|.

Require the crypto and ssl libraries to be passed as arguments to
create_tests(), rather than hardcoding the names :crypto and :ssl

Change-Id: Idcc522298c5baca2a84635ad3a7fdcf6e4968a5a
Reviewed-on: https://boringssl-review.googlesource.com/8260
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/util/generate_build_files.py b/util/generate_build_files.py
index 76c390b..b3db148 100644
--- a/util/generate_build_files.py
+++ b/util/generate_build_files.py
@@ -151,16 +151,16 @@
       out.write(self.header)
 
       out.write('test_support_sources = [\n')
-      for filename in files['test_support']:
+      for filename in (files['test_support'] +
+                       files['crypto_internal_headers'] +
+                       files['ssl_internal_headers']):
         if os.path.basename(filename) == 'malloc.cc':
           continue
         out.write('    "%s",\n' % PathOf(filename))
 
       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(["%s"])\n' % PathOf("src/crypto/test/*.h"))
+      out.write('def create_tests(copts, crypto, ssl):\n')
       name_counts = {}
       for test in files['tests']:
         name = os.path.basename(test[0])
@@ -190,7 +190,7 @@
         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' %
+        out.write('      srcs = ["%s"] + test_support_sources,\n' %
             PathOf(src))
 
         data_files = []
@@ -216,11 +216,11 @@
 
         if 'ssl/' in test[0]:
           out.write('      deps = [\n')
-          out.write('          ":crypto",\n')
-          out.write('          ":ssl",\n')
+          out.write('          crypto,\n')
+          out.write('          ssl,\n')
           out.write('      ],\n')
         else:
-          out.write('      deps = [":crypto"],\n')
+          out.write('      deps = [crypto],\n')
         out.write('  )\n')
 
 
@@ -439,6 +439,10 @@
         continue
       hfiles.append(os.path.join(path, filename))
 
+      for (i, dirname) in enumerate(dirnames):
+        if not filter_func(dirname, True):
+          del dirnames[i]
+
   return hfiles
 
 
@@ -553,6 +557,9 @@
 
   test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
                                     AllFiles)
+  test_support_h_files = (
+      FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
+      FindHeaderFiles(os.path.join('src', 'ssl', 'test'), AllFiles))
 
   test_c_files = FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
   test_c_files += FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
@@ -604,7 +611,7 @@
       'ssl_internal_headers': ssl_internal_h_files,
       'tool': tool_c_files,
       'test': test_c_files,
-      'test_support': test_support_c_files,
+      'test_support': test_support_h_files + test_support_c_files,
       'tests': tests,
   }