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
19 def build_dict(env
=os
.environ
):
21 Build a dict containing data about the build configuration from
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
]
29 raise Exception("Missing required environment variables: %s" %
32 if 'MOZCONFIG' in env
:
33 d
["mozconfig"] = env
["MOZCONFIG"]
35 if 'TOPSRCDIR' in env
:
36 d
["topsrcdir"] = env
["TOPSRCDIR"]
40 known_os
= {"Linux": "linux",
43 "Android": "b2g" if env
["MOZ_WIDGET_TOOLKIT"] == "gonk" else "android"}
47 # Allow unknown values, just lowercase them.
50 # Widget toolkit, just pass the value directly through.
51 d
["toolkit"] = env
["MOZ_WIDGET_TOOLKIT"]
54 if 'MOZ_APP_NAME' in env
:
55 d
["appname"] = env
["MOZ_APP_NAME"]
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"
63 # do some slight massaging for some values
64 #TODO: retain specific values in case someone wants them?
65 if p
.startswith("arm"):
67 elif re
.match("i[3-9]86", p
):
70 # hardcoded list of 64-bit CPUs
71 if p
in ["x86_64", "ppc64"]:
73 # hardcoded list of known 32-bit CPUs
74 elif p
in ["x86", "arm", "ppc"]:
76 # other CPUs will wind up with unknown bits
79 d
["debug"] = 'MOZ_DEBUG' in env
and env
['MOZ_DEBUG'] == '1'
82 d
["crashreporter"] = 'MOZ_CRASHREPORTER' in env
and env
['MOZ_CRASHREPORTER'] == '1'
85 def write_json(file, env
=os
.environ
):
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.
92 build_conf
= build_dict(env
)
93 if isinstance(file, basestring
):
94 with
open(file, "w") as f
:
95 json
.dump(build_conf
, f
)
97 json
.dump(build_conf
, file)
100 if __name__
== '__main__':
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
)