Don't hardcode GTest sources.

We've already converted err_test and forgot. Instead, recognize GTest
vs. normal tests by their contents. This hack can be removed later once
all the tests are converted.

BUG=129

Change-Id: Iaa56e0f3c316faaee5458a4bba9b977dc6efb1e8
Reviewed-on: https://boringssl-review.googlesource.com/13844
Reviewed-by: Steven Valdez <svaldez@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/util/generate_build_files.py b/util/generate_build_files.py
index 8be7c90..a3435f2 100644
--- a/util/generate_build_files.py
+++ b/util/generate_build_files.py
@@ -50,20 +50,6 @@
     ],
 }
 
-# For now, GTest-based tests are specified manually. Once everything has updated
-# to support GTest, these will be determined automatically by looking for files
-# ending with _test.cc.
-CRYPTO_TEST_SOURCES = [
-    'src/crypto/dh/dh_test.cc',
-    'src/crypto/dsa/dsa_test.cc',
-]
-DECREPIT_TEST_SOURCES = [
-    'src/decrepit/decrepit_test.cc',
-]
-SSL_TEST_SOURCES = [
-    'src/ssl/ssl_test.cc',
-]
-
 PREFIX = None
 
 
@@ -464,13 +450,6 @@
   non-test sources."""
   if is_dir:
     return dent != 'test'
-  # For now, GTest-based tests are specified manually.
-  if dent in [os.path.basename(p) for p in CRYPTO_TEST_SOURCES]:
-    return False
-  if dent in [os.path.basename(p) for p in DECREPIT_TEST_SOURCES]:
-    return False
-  if dent in [os.path.basename(p) for p in SSL_TEST_SOURCES]:
-    return False
   return '_test.' in dent or dent.startswith('example_')
 
 
@@ -624,6 +603,11 @@
   return asmfiles
 
 
+def IsGTest(path):
+  with open(path) as f:
+    return "#include <gtest/gtest.h>" in f.read()
+
+
 def main(platforms):
   crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTests)
   ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
@@ -643,8 +627,17 @@
       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)
+  test_c_files = []
+  crypto_test_files = ['src/crypto/test/gtest_main.cc']
+  # TODO(davidben): Remove this loop once all tests are converted.
+  for path in FindCFiles(os.path.join('src', 'crypto'), OnlyTests):
+    if IsGTest(path):
+      crypto_test_files.append(path)
+    else:
+      test_c_files.append(path)
+
+  ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
+  ssl_test_files.append('src/crypto/test/gtest_main.cc')
 
   fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
 
@@ -689,15 +682,14 @@
       'crypto': crypto_c_files,
       'crypto_headers': crypto_h_files,
       'crypto_internal_headers': crypto_internal_h_files,
-      'crypto_test': sorted(CRYPTO_TEST_SOURCES +
-                            ['src/crypto/test/gtest_main.cc']),
+      'crypto_test': sorted(crypto_test_files),
       'fuzz': fuzz_c_files,
       'ssl': ssl_source_files,
       'ssl_c': [s for s in ssl_source_files if s.endswith('.c')],
       'ssl_cc': [s for s in ssl_source_files if s.endswith('.cc')],
       'ssl_headers': ssl_h_files,
       'ssl_internal_headers': ssl_internal_h_files,
-      'ssl_test': sorted(SSL_TEST_SOURCES + ['src/crypto/test/gtest_main.cc']),
+      'ssl_test': sorted(ssl_test_files),
       'tool': tool_c_files,
       'tool_headers': tool_h_files,
       'test': test_c_files,