Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / toolkit / mozapps / extensions / gen_built_in_addons.py
blob9e8078f2bcea75b2fde98178f5aa297123717be2
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import argparse
6 import json
7 import os.path
8 import sys
10 import buildconfig
11 import mozpack.path as mozpath
13 from mozpack.copier import FileRegistry
14 from mozpack.manifests import InstallManifest
17 # A list of build manifests, and their relative base paths, from which to
18 # extract lists of install files. These vary depending on which backend we're
19 # using, so nonexistent manifests are ignored.
20 manifest_paths = (
21 ("", "_build_manifests/install/dist_bin"),
22 ("", "faster/install_dist_bin"),
23 ("browser", "faster/install_dist_bin_browser"),
27 def get_registry(paths):
28 used_paths = set()
30 registry = FileRegistry()
31 for base, path in paths:
32 full_path = mozpath.join(buildconfig.topobjdir, path)
33 if not os.path.exists(full_path):
34 continue
36 used_paths.add(full_path)
38 reg = FileRegistry()
39 InstallManifest(full_path).populate_registry(reg)
41 for p, f in reg:
42 path = mozpath.join(base, p)
43 try:
44 registry.add(path, f)
45 except Exception:
46 pass
48 return registry, used_paths
51 def get_child(base, path):
52 """Returns the nearest parent of `path` which is an immediate child of
53 `base`"""
55 dirname = mozpath.dirname(path)
56 while dirname != base:
57 path = dirname
58 dirname = mozpath.dirname(path)
59 return path
62 def main(output, *args):
63 parser = argparse.ArgumentParser(
64 description="Produces a JSON manifest of built-in add-ons"
66 parser.add_argument(
67 "--features",
68 type=str,
69 dest="featuresdir",
70 action="store",
71 help=("The distribution sub-directory " "containing feature add-ons"),
73 args = parser.parse_args(args)
75 registry, inputs = get_registry(manifest_paths)
77 dicts = {}
78 for path in registry.match("dictionaries/*.dic"):
79 base, ext = os.path.splitext(mozpath.basename(path))
80 dicts[base] = path
82 listing = {
83 "dictionaries": dicts,
86 if args.featuresdir:
87 features = set()
88 for p in registry.match("%s/*" % args.featuresdir):
89 features.add(mozpath.basename(get_child(args.featuresdir, p)))
91 listing["system"] = sorted(features)
93 json.dump(listing, output, sort_keys=True)
95 return inputs
98 if __name__ == "__main__":
99 main(sys.stdout, *sys.argv[1:])