Bug 849918 - Initial support for PannerNode's 3D positional audio (equalpower panning...
[gecko.git] / config / writemozinfo.py
blobabe94576774dd90d1d848b13af461ec33ef6b673
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
19 def build_dict(env=os.environ):
20 """
21 Build a dict containing data about the build configuration from
22 the environment.
23 """
24 d = {}
25 # Check that all required variables are present first.
26 required = ["TARGET_CPU", "OS_TARGET", "MOZ_WIDGET_TOOLKIT"]
27 missing = [r for r in required if r not in env]
28 if missing:
29 raise Exception("Missing required environment variables: %s" %
30 ', '.join(missing))
32 if 'MOZCONFIG' in env:
33 d["mozconfig"] = env["MOZCONFIG"]
35 if 'TOPSRCDIR' in env:
36 d["topsrcdir"] = env["TOPSRCDIR"]
38 # os
39 o = env["OS_TARGET"]
40 known_os = {"Linux": "linux",
41 "WINNT": "win",
42 "Darwin": "mac",
43 "Android": "b2g" if env["MOZ_WIDGET_TOOLKIT"] == "gonk" else "android"}
44 if o in known_os:
45 d["os"] = known_os[o]
46 else:
47 # Allow unknown values, just lowercase them.
48 d["os"] = o.lower()
50 # Widget toolkit, just pass the value directly through.
51 d["toolkit"] = env["MOZ_WIDGET_TOOLKIT"]
53 # Application name
54 if 'MOZ_APP_NAME' in env:
55 d["appname"] = env["MOZ_APP_NAME"]
57 # processor
58 p = env["TARGET_CPU"]
59 # for universal mac builds, put in a special value
60 if d["os"] == "mac" and "UNIVERSAL_BINARY" in env and env["UNIVERSAL_BINARY"] == "1":
61 p = "universal-x86-x86_64"
62 else:
63 # do some slight massaging for some values
64 #TODO: retain specific values in case someone wants them?
65 if p.startswith("arm"):
66 p = "arm"
67 elif re.match("i[3-9]86", p):
68 p = "x86"
69 d["processor"] = p
70 # hardcoded list of 64-bit CPUs
71 if p in ["x86_64", "ppc64"]:
72 d["bits"] = 64
73 # hardcoded list of known 32-bit CPUs
74 elif p in ["x86", "arm", "ppc"]:
75 d["bits"] = 32
76 # other CPUs will wind up with unknown bits
78 # debug
79 d["debug"] = 'MOZ_DEBUG' in env and env['MOZ_DEBUG'] == '1'
81 # crashreporter
82 d["crashreporter"] = 'MOZ_CRASHREPORTER' in env and env['MOZ_CRASHREPORTER'] == '1'
83 return d
85 def write_json(file, env=os.environ):
86 """
87 Write JSON data about the configuration specified in |env|
88 to |file|, which may be a filename or file-like object.
89 See build_dict for information about what environment variables are used,
90 and what keys are produced.
91 """
92 build_conf = build_dict(env)
93 if isinstance(file, basestring):
94 with open(file, "w") as f:
95 json.dump(build_conf, f)
96 else:
97 json.dump(build_conf, file)
100 if __name__ == '__main__':
101 try:
102 write_json(sys.argv[1] if len(sys.argv) > 1 else sys.stdout)
103 except Exception as e:
104 print(str(e), file=sys.stderr)
105 sys.exit(1)