From 268cae137d150aaf05cc160e06b9808167782331 Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Tue, 21 May 2013 16:06:42 -0400 Subject: [PATCH] Bug 746546 - writemozinfo.py should use the buildconfig module, r=ted --- config/tests/unit-writemozinfo.py | 1 - config/writemozinfo.py | 45 ++++++++++++++++--------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/config/tests/unit-writemozinfo.py b/config/tests/unit-writemozinfo.py index d0fea9654499..e527fb088806 100755 --- a/config/tests/unit-writemozinfo.py +++ b/config/tests/unit-writemozinfo.py @@ -11,7 +11,6 @@ class TestBuildDict(unittest.TestCase): """ Test that missing required values raises. """ - self.assertRaises(Exception, build_dict, {}) self.assertRaises(Exception, build_dict, {'OS_TARGET':'foo'}) self.assertRaises(Exception, build_dict, {'TARGET_CPU':'foo'}) self.assertRaises(Exception, build_dict, {'MOZ_WIDGET_TOOLKIT':'foo'}) diff --git a/config/writemozinfo.py b/config/writemozinfo.py index c6938b0d0388..68f50ad93911 100755 --- a/config/writemozinfo.py +++ b/config/writemozinfo.py @@ -15,35 +15,38 @@ import re import sys import json +import buildconfig -def build_dict(env=os.environ): +def build_dict(env=None): """ Build a dict containing data about the build configuration from the environment. """ - d = {} + substs = env or buildconfig.substs + env = env or os.environ + # Check that all required variables are present first. required = ["TARGET_CPU", "OS_TARGET", "MOZ_WIDGET_TOOLKIT"] - missing = [r for r in required if r not in env] + missing = [r for r in required if r not in substs] if missing: raise Exception("Missing required environment variables: %s" % ', '.join(missing)) + d = {} + d['topsrcdir'] = substs.get('TOPSRCDIR', buildconfig.topsrcdir) + if 'MOZCONFIG' in env: mozconfig = env["MOZCONFIG"] if 'TOPSRCDIR' in env: mozconfig = os.path.join(env["TOPSRCDIR"], mozconfig) d['mozconfig'] = os.path.normpath(mozconfig) - if 'TOPSRCDIR' in env: - d["topsrcdir"] = env["TOPSRCDIR"] - # os - o = env["OS_TARGET"] + o = substs["OS_TARGET"] known_os = {"Linux": "linux", "WINNT": "win", "Darwin": "mac", - "Android": "b2g" if env["MOZ_WIDGET_TOOLKIT"] == "gonk" else "android"} + "Android": "b2g" if substs["MOZ_WIDGET_TOOLKIT"] == "gonk" else "android"} if o in known_os: d["os"] = known_os[o] else: @@ -51,16 +54,16 @@ def build_dict(env=os.environ): d["os"] = o.lower() # Widget toolkit, just pass the value directly through. - d["toolkit"] = env["MOZ_WIDGET_TOOLKIT"] + d["toolkit"] = substs["MOZ_WIDGET_TOOLKIT"] # Application name - if 'MOZ_APP_NAME' in env: - d["appname"] = env["MOZ_APP_NAME"] + if 'MOZ_APP_NAME' in substs: + d["appname"] = substs["MOZ_APP_NAME"] # processor - p = env["TARGET_CPU"] + p = substs["TARGET_CPU"] # for universal mac builds, put in a special value - if d["os"] == "mac" and "UNIVERSAL_BINARY" in env and env["UNIVERSAL_BINARY"] == "1": + if d["os"] == "mac" and "UNIVERSAL_BINARY" in substs and substs["UNIVERSAL_BINARY"] == "1": p = "universal-x86-x86_64" else: # do some slight massaging for some values @@ -78,24 +81,22 @@ def build_dict(env=os.environ): d["bits"] = 32 # other CPUs will wind up with unknown bits - # debug - d["debug"] = 'MOZ_DEBUG' in env and env['MOZ_DEBUG'] == '1' + d['debug'] = substs.get('MOZ_DEBUG') == '1' + d['crashreporter'] = substs.get('MOZ_CRASHREPORTER') == '1' + d['asan'] = substs.get('MOZ_ASAN') == '1' + d['tests_enabled'] = substs.get('ENABLE_TESTS') == "1" + d['bin_suffix'] = substs.get('BIN_SUFFIX', '') - # crashreporter - d["crashreporter"] = 'MOZ_CRASHREPORTER' in env and env['MOZ_CRASHREPORTER'] == '1' - - # asan - d["asan"] = 'MOZ_ASAN' in env and env['MOZ_ASAN'] == '1' return d -def write_json(file, env=os.environ): +def write_json(file, env=None): """ Write JSON data about the configuration specified in |env| to |file|, which may be a filename or file-like object. See build_dict for information about what environment variables are used, and what keys are produced. """ - build_conf = build_dict(env) + build_conf = build_dict(env=env) if isinstance(file, basestring): with open(file, "w") as f: json.dump(build_conf, f)