[build] Remove JSON package machinery

There are no longer any clients.

Change-Id: I2a1984d305bf9dfe5588692005ee0676e8695c3a
diff --git a/BUILD.gn b/BUILD.gn
index e395dad..c56b824 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -3,7 +3,6 @@
 # found in the LICENSE file.
 
 import("//build/config/fuchsia/zircon.gni")
-import("//build/gn/packages.gni")
 import("//build/testing/platforms.gni")
 
 declare_args() {
@@ -33,6 +32,12 @@
   # A list of package labels to include in the 'base' package set. Used by the
   # board definition rather than the product definition.
   board_package_labels = []
+
+  # Does nothing.
+  #
+  # Will be removed after 30 April 2019.
+  allow_layer_guesswork = false
+  board_packages = []
 }
 
 # Write a file that can be sourced by `fx`.  This file is produced
@@ -65,14 +70,10 @@
     "//build/images:packages",
     "//sdk:core",
   ]
-  if (preinstall_package_labels != []
-      || monolith_package_labels != []
-      || base_package_labels != []
-      || cache_package_labels != []) {
+  if (base_package_labels != [] || cache_package_labels != []) {
     deps += [ "//build/images" ]
   }
-  if (available_package_labels != []
-      || universe_package_labels != []) {
+  if (universe_package_labels != []) {
     deps += [ "//build/images:updates" ]
   }
 }
diff --git a/build/gn/BUILD.gn b/build/gn/BUILD.gn
index e08ab94..d4b1d87 100644
--- a/build/gn/BUILD.gn
+++ b/build/gn/BUILD.gn
@@ -3,7 +3,6 @@
 # found in the LICENSE file.
 
 import("//build/compiled_action.gni")
-import("//build/gn/packages.gni")
 
 # Generates breakpad symbol data for unstripped binaries.
 #
diff --git a/build/gn/check-layer-dependencies.py b/build/gn/check-layer-dependencies.py
deleted file mode 100755
index 8d40019..0000000
--- a/build/gn/check-layer-dependencies.py
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2017 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.
-
-import argparse
-import os
-import subprocess
-import sys
-
-FUCHSIA_ROOT = os.path.dirname(  # $root
-    os.path.dirname(             # build
-    os.path.dirname(             # gn
-    os.path.abspath(__file__))))
-GN = os.path.join(FUCHSIA_ROOT, "buildtools", "gn")
-
-# The layers of the Fuchsia cake
-# Note that these must remain ordered by increasing proximity to the silicon.
-LAYERS = [
-  'topaz',
-  'peridot',
-  'garnet',
-  'zircon',
-]
-
-def main():
-    parser = argparse.ArgumentParser('check-layer-dependencies',
-            formatter_class=argparse.ArgumentDefaultsHelpFormatter)
-    parser.add_argument('--layer',
-                        help='[required] Name of the layer to inspect',
-                        choices=LAYERS)
-    parser.add_argument('--out',
-                        help='Build output directory',
-                        default='out/debug-x64')
-    args = parser.parse_args()
-    layer = args.layer
-    out = args.out
-    if not layer:
-        parser.print_help()
-        return 1
-
-    layer_index = LAYERS.index(layer)
-    create_labels = lambda layers: list(map(lambda l: '//%s' % l, layers))
-    upper_layers = create_labels(LAYERS[0:layer_index])
-    lower_layers = create_labels(LAYERS[layer_index:])
-    public_labels = subprocess.check_output(
-            [GN, 'ls', out, '//%s/public/*' % layer]).splitlines()
-    is_valid = True
-
-    for label in public_labels:
-        deps = subprocess.check_output(
-            [GN, 'desc', out, label, 'deps']).splitlines()
-        for dep in deps:
-            # We should never depend on upper layers.
-            for upper_layer in upper_layers:
-                if dep.startswith(upper_layer):
-                    is_valid = False
-                    print('Upper layer violation')
-                    print('  Label %s' % label)
-                    print('  Dep   %s' % dep)
-            # If we depend on the same layer or a layer below, that dependency
-            # should be located in its layer's public directory.
-            for lower_layer in lower_layers:
-                if (dep.startswith(lower_layer)
-                        and not dep.startswith('%s/public' % lower_layer)):
-                    is_valid = False
-                    print('Lower layer violation')
-                    print('  Label %s' % label)
-                    print('  Dep   %s' % dep)
-    return 0 if is_valid else 1
-
-
-if __name__ == '__main__':
-    sys.exit(main())
diff --git a/build/gn/find_vendor_repo.py b/build/gn/find_vendor_repo.py
deleted file mode 100755
index c4b3c90..0000000
--- a/build/gn/find_vendor_repo.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2018 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.
-
-from __future__ import absolute_import
-from __future__ import print_function
-
-import argparse
-import os
-import sys
-import xml.etree.ElementTree
-
-
-def main():
-    parser = argparse.ArgumentParser(
-        description='Identify the vendor repository, if specified, in the Jiri manifest file',
-        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
-    args = parser.parse_args()
-
-    manifest = os.path.join(os.path.dirname(__file__),
-                            os.path.pardir, os.path.pardir, '.jiri_manifest')
-
-    tree = xml.etree.ElementTree.parse(manifest)
-
-    for elt in tree.iter('overrides'):
-      for project in elt.findall('project'):
-        name = project.attrib.get('name', '')
-        if name.startswith('vendor/'):
-            print(name)
-            return 0
-    return 0
-
-
-if __name__ == '__main__':
-    sys.exit(main())
diff --git a/build/gn/packages.gni b/build/gn/packages.gni
deleted file mode 100644
index 637e3e7c..0000000
--- a/build/gn/packages.gni
+++ /dev/null
@@ -1,64 +0,0 @@
-# Copyright 2017 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.
-
-declare_args() {
-  # If a package is referenced in monolith and in preinstall, monolith takes
-  # priority, and the package will be added to OTA images as part of the
-  # verified boot set of static packages.
-
-  # Does nothing.
-  #
-  # Will be removed after 30 April 2019.
-  allow_layer_guesswork = false
-
-  # These arguments should be set by the board definition gni file.
-
-  # A list of packages included in the monolith from the board definition.
-  # This list is appended with the list from the product definition and any
-  # additional specified packages
-  board_packages = []
-}
-
-monolith = []
-preinstall = []
-available = []
-
-monolith += board_packages
-
-# Resolve all the JSON files and their dependencies
-# into lists of GN labels:
-# monolith - package labels for base system and verified boot image
-# preinstall - package labels for preinstall, but not OTA
-# available - package labels for the install and update repository
-_preprocessed_products = exec_script("preprocess_products.py",
-                                     [
-                                       "--monolith=$monolith",
-                                       "--preinstall=$preinstall",
-                                       "--available=$available",
-                                     ],
-                                     "json")
-
-# Tell GN that the files preprocess_products.py ran are inputs to the
-# generation step, by declaring them as file inputs to a (silly) exec_script
-# invocation.
-exec_script("/bin/sh",
-            [
-              "-c",
-              ":",
-            ],
-            "",
-            _preprocessed_products.files_read)
-
-monolith_package_labels = []
-foreach(pkg, _preprocessed_products.monolith) {
-  monolith_package_labels += [ get_label_info(pkg, "label_no_toolchain") ]
-}
-preinstall_package_labels = []
-foreach(pkg, _preprocessed_products.preinstall) {
-  preinstall_package_labels += [ get_label_info(pkg, "label_no_toolchain") ]
-}
-available_package_labels = []
-foreach(pkg, _preprocessed_products.available) {
-  available_package_labels += [ get_label_info(pkg, "label_no_toolchain") ]
-}
diff --git a/build/gn/paths.py b/build/gn/paths.py
deleted file mode 100644
index a50d9eb..0000000
--- a/build/gn/paths.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2016 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.
-
-import os
-import platform
-
-SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
-FUCHSIA_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir))
-GN_PATH = os.path.join(FUCHSIA_ROOT, "buildtools", "gn")
-BUILDTOOLS_PATH = os.path.join(FUCHSIA_ROOT, "buildtools", '%s-%s' % (
-    platform.system().lower().replace('darwin', 'mac'),
-    {
-        'x86_64': 'x64',
-        'aarch64': 'arm64',
-    }[platform.machine()],
-))
-DEBUG_OUT_DIR = os.path.join(FUCHSIA_ROOT, "out", "debug-x64")
-RELEASE_OUT_DIR = os.path.join(FUCHSIA_ROOT, "out", "release-x64")
-
-_BUILD_TOOLS = {}
-
-def build_tool(package, tool):
-    """Return the full path of TOOL binary in PACKAGE.
-
-    This will raise an assertion failure if the binary doesn't exist.
-    This function memoizes its results, so there's not much need to
-    cache its results in calling code.
-    """
-
-    path = _BUILD_TOOLS.get((package, tool))
-    if path is None:
-        path = os.path.join(BUILDTOOLS_PATH, package, 'bin', tool)
-        assert os.path.exists(path), "No '%s' tool in '%s'" % (tool, package)
-        _BUILD_TOOLS[package, tool] = path
-    return path
diff --git a/build/gn/prepreprocess_build_packages.py b/build/gn/prepreprocess_build_packages.py
deleted file mode 100755
index 14f5834..0000000
--- a/build/gn/prepreprocess_build_packages.py
+++ /dev/null
@@ -1,147 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2017 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.
-
-import argparse
-import json
-import os.path
-import paths
-import sys
-
-
-USE_GN_LABELS = True
-
-
-class PackageImportsResolver:
-    """Recursively resolves imports in build packages. See
-       https://fuchsia.googlesource.com/fuchsia/+/master/docs/development/build/packages.md
-       for more information about build packages.
-
-       An observer may be used to perform additional work whenever an
-       import is resolved. This observer needs to implement a method with this
-       signature:
-
-       def import_resolved(self, config, config_path)
-
-       where config is the JSON file representing the build package.
-
-       If there was an error reading some of the input files, `None` will be
-       returned.
-       """
-
-    def __init__(self, observer=None):
-        self.observer = observer
-        self._errored = False
-
-    def resolve(self, imports):
-        return self.resolve_imports(imports)
-
-    def errored(self):
-        return self._errored
-
-    def resolve_imports(self, import_queue):
-
-        def detect_duplicate_keys(pairs):
-            keys = set()
-            result = {}
-            for k, v in pairs:
-                if k in keys:
-                    raise Exception("Duplicate key %s" % k)
-                keys.add(k)
-                result[k] = v
-            return result
-
-        imported = set(import_queue)
-        while import_queue:
-            config_name = import_queue.pop()
-            config_path = os.path.join(paths.FUCHSIA_ROOT, config_name)
-            if USE_GN_LABELS and not os.path.isfile(config_path):
-                # If the bundle starts with "//", then it is already a label.
-                if config_name.startswith("//"):
-                    self.observer.import_resolved_from_gn(config_name)
-                    continue
-                dir_path = os.path.dirname(config_path)
-                if os.path.isfile(os.path.join(dir_path, "BUILD.gn")):
-                    self.observer.import_resolved_from_gn_legacy(config_name)
-                    continue
-            try:
-                with open(config_path) as f:
-                    try:
-                        config = json.load(f,
-                            object_pairs_hook=detect_duplicate_keys)
-                        self.observer.import_resolved(config, config_path)
-                        for i in config.get("imports", []):
-                            if i not in imported:
-                                import_queue.append(i)
-                                imported.add(i)
-                    except Exception as e:
-                        import traceback
-                        traceback.print_exc()
-                        sys.stderr.write(
-                            "Failed to parse config %s, error %s\n" %
-                            (config_path, str(e)))
-                        self._errored = True
-                        return None
-            except IOError, e:
-                self._errored = True
-                sys.stderr.write("Failed to read package '%s' from '%s'.\n" %
-                                 (config_name, config_path))
-                if "/" not in config_name:
-                    sys.stderr.write("""
-Package names are relative to the root of the source tree but the requested
-path did not contain a '/'. Did you mean 'build/gn/%s' instead?
-    """ % config_name)
-                return None
-        return imported
-
-
-def legacy_config_name_to_label(config_name):
-    parts = config_name.rsplit('/', 1)
-    return "//%s:%s" % (parts[0], parts[1])
-
-
-class PackageLabelObserver:
-    def __init__(self):
-        self.json_result = {
-            'targets': [],
-            'data_deps': [],
-            'host_tests': [],
-            'files_read': [],
-        }
-
-    def import_resolved_from_gn(self, config_name):
-        self.json_result["targets"].append(config_name)
-
-    def import_resolved_from_gn_legacy(self, config_name):
-        self.import_resolved_from_gn(legacy_config_name_to_label(config_name))
-
-    def import_resolved(self, config, config_path):
-        self.json_result['targets'] += config.get('packages', [])
-        self.json_result['data_deps'] += config.get('labels', [])
-        self.json_result['host_tests'] += config.get('host_tests', [])
-        self.json_result['files_read'].append(config_path)
-
-
-def main():
-    parser = argparse.ArgumentParser(description='''
-Determine labels and Fuchsia packages included in the current build.
-''')
-    parser.add_argument('--packages',
-                        help='JSON list of packages',
-                        required=True)
-    args = parser.parse_args()
-
-    observer = PackageLabelObserver()
-    imports_resolver = PackageImportsResolver(observer)
-    imported = imports_resolver.resolve_imports(json.loads(args.packages))
-
-    if imported == None:
-        return 1
-
-    json.dump(observer.json_result, sys.stdout, sort_keys=True)
-
-    return 0
-
-if __name__ == "__main__":
-    sys.exit(main())
diff --git a/build/gn/preprocess_products.py b/build/gn/preprocess_products.py
deleted file mode 100755
index 89adf13..0000000
--- a/build/gn/preprocess_products.py
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2018 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.
-
-import argparse
-import json
-import os.path
-import paths
-import sys
-from prepreprocess_build_packages import PackageImportsResolver, PackageLabelObserver
-
-
-def preprocess_packages(packages):
-    observer = PackageLabelObserver()
-    imports_resolver = PackageImportsResolver(observer)
-    imported = imports_resolver.resolve_imports(packages)
-
-    if imports_resolver.errored():
-        raise ImportError
-
-    if imported == None:
-        return None
-
-    return observer.json_result
-
-
-def main():
-    parser = argparse.ArgumentParser(description="""
-Merge a list of product definitions to unique lists of GN labels:
-
-monolith   - the list of packages included in the base system images
-preinstall - the list of packages preinstall, but not part of OTA
-available  - the list of packages installable and updatable
-files_read - a list of files used to compute all of the above
-""")
-    parser.add_argument("--monolith",
-                        help="List of package definitions for the monolith",
-                        required=True)
-    parser.add_argument("--preinstall",
-                        help="List of package definitions for preinstalled packages",
-                        required=True)
-    parser.add_argument("--available",
-                        help="List of package definitions for available packages",
-                        required=True)
-    args = parser.parse_args()
-
-    build_packages = {
-        "monolith": set(),
-        "preinstall": set(),
-        "available": set(),
-        "files_read": set(),
-    }
-
-
-    # Parse monolith, preinstall, and available sets.
-    build_packages["monolith"].update(json.loads(args.monolith))
-    build_packages["preinstall"].update(json.loads(args.preinstall))
-    build_packages["available"].update(json.loads(args.available))
-
-    try:
-        monolith_results = preprocess_packages(list(build_packages["monolith"]))
-        preinstall_results = preprocess_packages(list(build_packages["preinstall"]))
-        available_results = preprocess_packages(list(build_packages["available"]))
-    except ImportError:
-        return 1
-
-    for res in (monolith_results, preinstall_results, available_results):
-        if res is None:
-            continue
-        if res["files_read"]:
-            build_packages["files_read"].update(res["files_read"])
-
-    monolith_targets = set(monolith_results["targets"] if monolith_results else ())
-    preinstall_targets = set(preinstall_results["targets"] if preinstall_results else ())
-    available_targets = set(available_results["targets"] if available_results else ())
-
-    # preinstall_targets must not include monolith targets
-    preinstall_targets -= monolith_targets
-
-    # available_targets must include monolith and preinstall targets
-    available_targets |= monolith_targets | preinstall_targets
-
-    print(json.dumps({
-        "monolith": list(monolith_targets),
-        "preinstall": list(preinstall_targets),
-        "available": list(available_targets),
-        "files_read": list(build_packages["files_read"]),
-    }))
-
-    return 0
-
-if __name__ == "__main__":
-    sys.exit(main())
diff --git a/build/images/BUILD.gn b/build/images/BUILD.gn
index 2309c58..2ad8b3b 100644
--- a/build/images/BUILD.gn
+++ b/build/images/BUILD.gn
@@ -7,7 +7,6 @@
 import("//build/config/clang/clang.gni")
 import("//build/config/fuchsia/zbi.gni")
 import("//build/config/fuchsia/zircon.gni")
-import("//build/gn/packages.gni")
 import("//build/images/boot.gni")
 import("//build/images/collect_blob_manifest.gni")
 import("//build/images/custom_signing.gni")
@@ -104,19 +103,19 @@
 group("monolith_packages") {
   testonly = true
   visibility = [ ":*" ]
-  public_deps = monolith_package_labels + [ "//:additional_base_packages" ]
+  public_deps = [ "//:additional_base_packages" ]
 }
 
 group("preinstall_packages") {
   testonly = true
   visibility = [ ":*" ]
-  public_deps = preinstall_package_labels + [ "//:additional_cache_packages" ]
+  public_deps = [ "//:additional_cache_packages" ]
 }
 
 group("available_packages") {
   testonly = true
   visibility = [ ":*" ]
-  public_deps = available_package_labels + [
+  public_deps = [
                   ":monolith_packages",
                   ":preinstall_packages",
                   "//:additional_universe_packages",
diff --git a/docs/development/build/products.md b/docs/development/build/products.md
index 17e5e3a..ec039b9 100644
--- a/docs/development/build/products.md
+++ b/docs/development/build/products.md
@@ -51,17 +51,4 @@
 By convention, the `default` product for a higher layer should be additive
 from the layer below.
 
-## Inspecting Products
-
-As products reference [packages](packages.md) and packages may reference
-other packages, it is useful to be able to inspect the expanded and filtered
-set of build labels that will make up each package set in a product. The
-[preprocess products][preprocess-products-py] script is the tool that
-produces this for the build and can be run by hand:
-
-```bash
-$ python build/gn/preprocess_products.py --products '["garnet/products/default"]'
-```
-
 [products-source]: /products/
-[preprocess-products-py]: /build/gn/preprocess_products.py