michael@0: #!/usr/bin/env python michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import sys michael@0: import json michael@0: import buildconfig michael@0: michael@0: michael@0: def parse_cmdline(args): michael@0: """Take a list of strings in the format K=V and turn them into a python michael@0: dictionary""" michael@0: contents = {} michael@0: for arg in args: michael@0: key, s, value = arg.partition("=") michael@0: if s == '': michael@0: print "ERROR: Malformed command line key value pairing (%s)" % arg michael@0: exit(1) michael@0: contents[key.lower()] = value michael@0: return contents michael@0: michael@0: michael@0: def main(): michael@0: if len(sys.argv) < 2: michael@0: print "ERROR: You must specify an output file" michael@0: exit(1) michael@0: michael@0: all_key_value_pairs = {} michael@0: important_substitutions = [ michael@0: 'target_alias', 'target_cpu', 'target_os', 'target_vendor', michael@0: 'host_alias', 'host_cpu', 'host_os', 'host_vendor', michael@0: 'MOZ_UPDATE_CHANNEL', 'MOZ_APP_VENDOR', 'MOZ_APP_NAME', michael@0: 'MOZ_APP_VERSION', 'MOZ_APP_MAXVERSION', 'MOZ_APP_ID', michael@0: 'CC', 'CXX', 'LD', 'AS'] michael@0: michael@0: all_key_value_pairs = dict([(x.lower(), buildconfig.substs[x]) for x in important_substitutions]) michael@0: all_key_value_pairs.update(parse_cmdline(sys.argv[2:])) michael@0: michael@0: with open(sys.argv[1], "w+") as f: michael@0: json.dump(all_key_value_pairs, f, indent=2, sort_keys=True) michael@0: f.write('\n') michael@0: michael@0: michael@0: if __name__=="__main__": michael@0: main()