Bug 865244 - Implement AudioContext.destination.maxChannelCount. r=ehsan
[gecko.git] / config / writemozinfo.py
blob68f50ad939117519e3be7364a17dd7082d5ee0ac
1 #!/usr/bin/env python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # This script is run during configure, taking variables set in configure
8 # and producing a JSON file that describes some portions of the build
9 # configuration, such as the target OS and CPU.
11 # The output file is intended to be used as input to the mozinfo package.
12 from __future__ import print_function
13 import os
14 import re
15 import sys
16 import json
18 import buildconfig
20 def build_dict(env=None):
21 """
22 Build a dict containing data about the build configuration from
23 the environment.
24 """
25 substs = env or buildconfig.substs
26 env = env or os.environ
28 # Check that all required variables are present first.
29 required = ["TARGET_CPU", "OS_TARGET", "MOZ_WIDGET_TOOLKIT"]
30 missing = [r for r in required if r not in substs]
31 if missing:
32 raise Exception("Missing required environment variables: %s" %
33 ', '.join(missing))
35 d = {}
36 d['topsrcdir'] = substs.get('TOPSRCDIR', buildconfig.topsrcdir)
38 if 'MOZCONFIG' in env:
39 mozconfig = env["MOZCONFIG"]
40 if 'TOPSRCDIR' in env:
41 mozconfig = os.path.join(env["TOPSRCDIR"], mozconfig)
42 d['mozconfig'] = os.path.normpath(mozconfig)
44 # os
45 o = substs["OS_TARGET"]
46 known_os = {"Linux": "linux",
47 "WINNT": "win",
48 "Darwin": "mac",
49 "Android": "b2g" if substs["MOZ_WIDGET_TOOLKIT"] == "gonk" else "android"}
50 if o in known_os:
51 d["os"] = known_os[o]
52 else:
53 # Allow unknown values, just lowercase them.
54 d["os"] = o.lower()
56 # Widget toolkit, just pass the value directly through.
57 d["toolkit"] = substs["MOZ_WIDGET_TOOLKIT"]
59 # Application name
60 if 'MOZ_APP_NAME' in substs:
61 d["appname"] = substs["MOZ_APP_NAME"]
63 # processor
64 p = substs["TARGET_CPU"]
65 # for universal mac builds, put in a special value
66 if d["os"] == "mac" and "UNIVERSAL_BINARY" in substs and substs["UNIVERSAL_BINARY"] == "1":
67 p = "universal-x86-x86_64"
68 else:
69 # do some slight massaging for some values
70 #TODO: retain specific values in case someone wants them?
71 if p.startswith("arm"):
72 p = "arm"
73 elif re.match("i[3-9]86", p):
74 p = "x86"
75 d["processor"] = p
76 # hardcoded list of 64-bit CPUs
77 if p in ["x86_64", "ppc64"]:
78 d["bits"] = 64
79 # hardcoded list of known 32-bit CPUs
80 elif p in ["x86", "arm", "ppc"]:
81 d["bits"] = 32
82 # other CPUs will wind up with unknown bits
84 d['debug'] = substs.get('MOZ_DEBUG') == '1'
85 d['crashreporter'] = substs.get('MOZ_CRASHREPORTER') == '1'
86 d['asan'] = substs.get('MOZ_ASAN') == '1'
87 d['tests_enabled'] = substs.get('ENABLE_TESTS') == "1"
88 d['bin_suffix'] = substs.get('BIN_SUFFIX', '')
90 return d
92 def write_json(file, env=None):
93 """
94 Write JSON data about the configuration specified in |env|
95 to |file|, which may be a filename or file-like object.
96 See build_dict for information about what environment variables are used,
97 and what keys are produced.
98 """
99 build_conf = build_dict(env=env)
100 if isinstance(file, basestring):
101 with open(file, "w") as f:
102 json.dump(build_conf, f)
103 else:
104 json.dump(build_conf, file)
107 if __name__ == '__main__':
108 try:
109 write_json(sys.argv[1] if len(sys.argv) > 1 else sys.stdout)
110 except Exception as e:
111 print(str(e), file=sys.stderr)
112 sys.exit(1)