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
20 def build_dict(env
=None):
22 Build a dict containing data about the build configuration from
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
]
32 raise Exception("Missing required environment variables: %s" %
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
)
45 o
= substs
["OS_TARGET"]
46 known_os
= {"Linux": "linux",
49 "Android": "b2g" if substs
["MOZ_WIDGET_TOOLKIT"] == "gonk" else "android"}
53 # Allow unknown values, just lowercase them.
56 # Widget toolkit, just pass the value directly through.
57 d
["toolkit"] = substs
["MOZ_WIDGET_TOOLKIT"]
60 if 'MOZ_APP_NAME' in substs
:
61 d
["appname"] = substs
["MOZ_APP_NAME"]
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"
69 # do some slight massaging for some values
70 #TODO: retain specific values in case someone wants them?
71 if p
.startswith("arm"):
73 elif re
.match("i[3-9]86", p
):
76 # hardcoded list of 64-bit CPUs
77 if p
in ["x86_64", "ppc64"]:
79 # hardcoded list of known 32-bit CPUs
80 elif p
in ["x86", "arm", "ppc"]:
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', '')
92 def write_json(file, env
=None):
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.
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
)
104 json
.dump(build_conf
, file)
107 if __name__
== '__main__':
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
)