[zircon] [gn] Produce legacy .pkg files, so far just for FIDL & Banjo

The legacy Fuchsia GN build consumes .pkg files describing Zircon things.
Start producing these.  First the simplest cases: FIDL and Banjo.
Also produce a manifest of all .pkg files.

Bug: BLD-325
Bug: BLD-353
Test: gn gen && ninja, manual examination of the .pkg files

Change-Id: I75e88803f992e4bceebf80e7799094b924cc8a09
diff --git a/zircon/BUILD.gn b/zircon/BUILD.gn
index 266b1b5..aed278f 100644
--- a/zircon/BUILD.gn
+++ b/zircon/BUILD.gn
@@ -4,6 +4,7 @@
 
 import("$zx/public/gn/build_api_module.gni")
 import("$zx/public/gn/config/standard.gni")
+import("$zx/public/gn/legacy_pkg.gni")  # TODO(BLD-353): temporary hack
 import("$zx/public/gn/toolchain/c_utils.gni")
 import("$zx/public/gn/toolchain/environment_redirect.gni")
 import("$zx/public/gn/zbi.gni")
@@ -120,6 +121,25 @@
         "$zx/system/ulib:asan-manifest-$cpu",
       ]
     }
+
+    legacy_pkg("manifest-$cpu") {
+      testonly = true
+      data_keys = [ "legacy_pkg_manifest" ]
+      deps = [
+        ":legacy-$cpu",
+        ":tools",
+
+        # Separately listed because they're reached by dependencies only on x64.
+        "$zx/system/banjo/ddk-protocol-acpi",
+        "$zx/system/banjo/ddk-protocol-intelgpucore",
+        "$zx/system/banjo/ddk-protocol-intelhda-codec",
+        "$zx/system/banjo/ddk-protocol-intelhda-dsp",
+
+        # Separately listed because they're not reached by any dependencies.
+        "$zx/system/fidl/fuchsia-inspect",
+        "$zx/system/fidl/fuchsia-tracelink",
+      ]
+    }
   }
 }
 
diff --git a/zircon/public/gn/banjo.gni b/zircon/public/gn/banjo.gni
index 4bb6e28..d9a25a0 100644
--- a/zircon/public/gn/banjo.gni
+++ b/zircon/public/gn/banjo.gni
@@ -6,6 +6,7 @@
 # share much code.  Try to converge these more in the future.
 
 import("$zx/public/gn/fidl/fidlc.gni")
+import("$zx/public/gn/legacy_pkg.gni")  # TODO(BLD-353): temporary hack
 
 # List of BANJO support modules.  Each of these defines its own version of
 # $banjo_support_templates:
@@ -137,6 +138,33 @@
         banjo_rspfile =
             [ "--files" ] + rebase_path(invoker.sources, root_build_dir)
       }
+
+      # TODO(BLD-353): temporary hack
+      data_deps = [
+        ":$banjo_target.pkg",
+      ]
+    }
+
+    # TODO(BLD-353): temporary hack
+    legacy_pkg("$banjo_target.pkg") {
+      contents = [
+        "[package]",
+        "name=$banjo_target",
+        "library=$banjo_library_name",
+        "arch=banjo",
+        "type=banjo",
+        "[banjo]",
+      ]
+      foreach(file, invoker.sources) {
+        contents += [ "$file=SOURCE/" + rebase_path(file, "//") ]
+      }
+      if (defined(invoker.public_deps)) {
+        contents += [ "[banjo-deps]" ]
+        foreach(label, invoker.public_deps) {
+          contents += [ get_label_info(label, "name") + "=SOURCE/" +
+                        rebase_path(get_label_info(label, "dir"), "//") ]
+        }
+      }
     }
 
     # Produce a metadata response file from all the banjo_rspfile lists.
diff --git a/zircon/public/gn/fidl.gni b/zircon/public/gn/fidl.gni
index c01fa61..bef7701 100644
--- a/zircon/public/gn/fidl.gni
+++ b/zircon/public/gn/fidl.gni
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 import("$zx/public/gn/fidl/fidlc.gni")
+import("$zx/public/gn/legacy_pkg.gni")  # TODO(BLD-353): temporary hack
 
 # List of FIDL support modules.  Each of these defines its own version of
 # $fidl_support_fidlc and $fidl_support_templates.
@@ -212,6 +213,33 @@
         fidl_rspfile =
             [ "--files" ] + rebase_path(invoker.sources, root_build_dir)
       }
+
+      # TODO(BLD-353): temporary hack
+      data_deps = [
+        ":$fidl_target.pkg",
+      ]
+    }
+
+    # TODO(BLD-353): temporary hack
+    legacy_pkg("$fidl_target.pkg") {
+      contents = [
+        "[package]",
+        "name=$fidl_target",
+        "library=$fidl_name",
+        "arch=fidl",
+        "type=fidl",
+        "[fidl]",
+      ]
+      foreach(file, invoker.sources) {
+        contents += [ "$file=SOURCE/" + rebase_path(file, "//") ]
+      }
+      if (defined(invoker.public_deps)) {
+        contents += [ "[fidl-deps]" ]
+        foreach(label, invoker.public_deps) {
+          contents += [ get_label_info(label, "name") + "=SOURCE/" +
+                        rebase_path(get_label_info(label, "dir"), "//") ]
+        }
+      }
     }
 
     # Produce a metadata response file from all the fidl_rspfile lists.
diff --git a/zircon/public/gn/legacy_pkg.gni b/zircon/public/gn/legacy_pkg.gni
new file mode 100644
index 0000000..b3d269f
--- /dev/null
+++ b/zircon/public/gn/legacy_pkg.gni
@@ -0,0 +1,25 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# TODO(BLD-353): This is all temporary stuff to maintain rough compatibility
+# with the old makefile build as used by the higher-layer Fuchsia GN build.
+template("legacy_pkg") {
+  generated_file(target_name) {
+    outputs = [
+      "$root_build_dir/export/$target_name",
+    ]
+    output_conversion = "list lines"
+    forward_variables_from(invoker,
+                           [
+                             "contents",
+                             "data_keys",
+                             "deps",
+                             "walk_keys",
+                             "testonly",
+                           ])
+    metadata = {
+      legacy_pkg_manifest = [ target_name ]
+    }
+  }
+}