# HG changeset patch
# User Kris Maglione <maglione.k@gmail.com>
# Date 1524868975 25200
# Node ID fe5d46cd794bfb3e8974d8213cb3fa752902ef3b
# Parent  0dabdf7580cc81b98ffc96a9c7072df386bbf897
Bug 1457321: Part 1 - Add bundled dictionaries to built_in_addons.json. r=ted,rhelmer

MozReview-Commit-ID: GxCSXXaz8kz

diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -101,9 +101,9 @@ ifdef MOZ_UPDATER
 	mv -f '$(dist_dest)/Contents/MacOS/updater.app/Contents/MacOS/org.mozilla.updater' '$(dist_dest)/Contents/Library/LaunchServices'
 	ln -s ../../../../Library/LaunchServices/org.mozilla.updater '$(dist_dest)/Contents/MacOS/updater.app/Contents/MacOS/org.mozilla.updater'
 endif
 	printf APPLMOZB > '$(dist_dest)/Contents/PkgInfo'
 endif
 
 .PHONY: features
 tools features::
-	$(PYTHON) -c 'import os, json; listing = {"system": sorted(os.listdir("$(DIST)/bin/browser/features"))}; print json.dumps(listing)' > $(DIST)/bin/browser/chrome/browser/content/browser/built_in_addons.json
+	$(call py_action,generate_builtin_addons,--features=browser/features browser/chrome/browser/content/browser/built_in_addons.json)
diff --git a/python/mozbuild/mozbuild/action/generate_builtin_addons.py b/python/mozbuild/mozbuild/action/generate_builtin_addons.py
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/action/generate_builtin_addons.py
@@ -0,0 +1,46 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+import argparse
+import json
+import os.path
+import sys
+
+import buildconfig
+
+
+def main(argv):
+    parser = argparse.ArgumentParser(
+        description='Produces a JSON manifest of built-in add-ons')
+    parser.add_argument('--features', type=str, dest='featuresdir',
+                        action='store', help=('The distribution sub-directory '
+                                              'containing feature add-ons'))
+    parser.add_argument('outputfile', help='File to write output to')
+    args = parser.parse_args(argv)
+
+    bindir = os.path.join(buildconfig.topobjdir, 'dist/bin')
+
+    def find_dictionaries(path):
+        dicts = {}
+        for filename in os.listdir(os.path.join(bindir, path)):
+            base, ext = os.path.splitext(filename)
+            if ext == '.dic':
+                dicts[base] = '%s/%s' % (path, filename)
+        return dicts
+
+    listing = {
+        "dictionaries": find_dictionaries("dictionaries"),
+    }
+    if args.featuresdir:
+        listing["system"] = sorted(os.listdir(os.path.join(bindir,
+                                                           args.featuresdir)))
+
+    with open(os.path.join(bindir, args.outputfile), 'w') as fh:
+        json.dump(listing, fh, sort_keys=True)
+
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv[1:]))
