[boringssl] Split boringssl manifests

Currently, there is a single target in the fuchsia packaging system for
BoringSSL.  This means any packages that need libcrypto also get libssl,
netstack, bssl, the unit tests, and potentially other code they don't
want.  This CL modifies generate.py to split the manifests into three
separate files, allowing finer grained dependencies.

Change-Id: I574a5f0334e3718973c62c046eb89443384babed
diff --git a/BUILD.gn b/BUILD.gn
index 7efa9aa..7e114e3 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -607,7 +607,7 @@
   sources = [ "crypto/x509/x509_test.cc" ]
 }
 
-group("boringssl_tests") {
+group("unit_tests") {
   testonly = true
   deps = [
     ":aead_test",
diff --git a/fuchsia/generate.py b/fuchsia/generate.py
index e3ed2f0..69b05f5 100755
--- a/fuchsia/generate.py
+++ b/fuchsia/generate.py
@@ -184,7 +184,7 @@
     print 'Generated //' + os.path.relpath(build_gn, FUCHSIA_ROOT)
 
 
-  def generate_module(self):
+  def generate_manifest(self, module, odict):
     """Generates a module file that can be passed to '//packages/gn/gen.py'.
 
     Creates a JSON file that can be consumed by '//packages/gn/gen.py' to
@@ -193,40 +193,55 @@
     be passed when booting magenta.
 
     Args:
-      output: Path to the GN file to output.
+      module: Name of the GN file to output.
+      odict:  Dictionary to output as JSON.
     """
-    output = os.path.join(FUCHSIA_ROOT, 'packages', 'gn', 'boringssl')
-    # Gather imports.
-    imports = []
-    imports.append('netstack')
-    # Gather labels.
-    labels = []
-    labels.append('//third_party/boringssl:bssl')
-    labels.append('//third_party/boringssl:boringssl_tests')
-    # Gather binaries.
-    binaries = []
-    binaries.append({'binary': 'libcrypto.so', 'bootfs_path': 'lib/libcrypto.so'})
-    binaries.append({'binary': 'libssl.so', 'bootfs_path': 'lib/libssl.so'})
-    binaries.append({'binary': 'bssl', 'bootfs_path': 'bin/bssl'})
+    output = os.path.join(FUCHSIA_ROOT,
+      'packages', 'gn', module)
+
+    with open(output, 'w') as out:
+      json.dump(odict, out, indent=4, separators=(',', ': '))
+      out.write('\n')
+    print 'Generated //' + os.path.relpath(output, FUCHSIA_ROOT)
+
+  def generate_modules(self):
+    """Generates all module file for BoringSSL'.
+
+    Creates 3 JSON files:
+      //packages/gn/boringssl-libcrypto
+      //packages/gn/boringssl-libssl
+      //packages/gn/boringssl-bssl
+    """
+    # Create boringssl-libcrypto
+    odict = OrderedDict()
+    odict['labels'] = ['//third_party/boringssl:crypto']
+    odict['binaries'] = [{'binary': 'libcrypto.so',
+                          'bootfs_path': 'lib/libcrypto.so'}]
+    self.generate_manifest('boringssl_libcrypto', odict)
+    # Create boringssl-libssl
+    odict = OrderedDict()
+    odict['imports'] = ['boringssl_libcrypto', 'netstack']
+    odict['labels'] = ['//third_party/boringssl:ssl']
+    odict['binaries'] = [{'binary': 'libssl.so',
+                          'bootfs_path': 'lib/libssl.so'}]
+    self.generate_manifest('boringssl_libssl', odict)
+    # Create boringssl-bssl
+    odict = OrderedDict()
+    odict['imports'] = ['boringssl_libcrypto', 'boringssl_libssl']
+    odict['labels'] = ['//third_party/boringssl:bssl',
+                       '//third_party/boringssl:unit_tests']
+    binaries = [{'binary': 'bssl', 'bootfs_path': 'bin/bssl'}]
     for name in self._test_names:
       binaries.append({'binary': name, 'bootfs_path': 'test/boringssl/' + name})
-    # Gather resources.
+    odict['binaries'] = binaries
     resources = []
     path = os.path.relpath(BSSL_DIR, FUCHSIA_ROOT)
     for file in self._data_files:
       resources.append(
           {'file': '%s/%s' % (path, file),
            'bootfs_path': 'test/boringssl/data/%s' % os.path.basename(file)})
-    # Output JSON module file.
-    odict = OrderedDict()
-    odict['imports'] = imports
-    odict['labels'] = labels
-    odict['binaries'] = binaries
     odict['resources'] = resources
-    with open(output, 'w') as out:
-      json.dump(odict, out, indent=4, separators=(',', ': '))
-      out.write('\n')
-    print 'Generated //' + os.path.relpath(output, FUCHSIA_ROOT)
+    self.generate_manifest('boringssl', odict)
 
   def _generate_sources(self, out, paths, headers = None):
     """Generates a source list and writes it out to the GN file.
@@ -262,7 +277,7 @@
         out.write('unit_test("%s") {\n' % name)
         out.write('  sources = [ "%s" ]\n' % test)
         out.write('}\n\n')
-    out.write('group("boringssl_tests") {\n')
+    out.write('group("unit_tests") {\n')
     out.write('  testonly = true\n')
     out.write('  deps = [\n')
     for name, test in names.items():
@@ -284,7 +299,7 @@
   fb.generate_code(os.path.join('crypto', 'err'), 'err_data')
   fb.generate_test_spec()
   fb.generate_gn()
-  fb.generate_module()
+  fb.generate_modules()
   print '\nAll BoringSSL/Fuchsia build files generated.'
   return 0