|
5 | 5 | from __future__ import print_function, unicode_literals |
6 | 6 |
|
7 | 7 | import codecs |
8 | | -import json |
9 | 8 | import os |
10 | 9 | import subprocess |
11 | 10 | import sys |
12 | | - |
13 | | -from collections import Iterable |
| 11 | +import textwrap |
14 | 12 |
|
15 | 13 |
|
16 | 14 | base_dir = os.path.abspath(os.path.dirname(__file__)) |
17 | 15 | sys.path.insert(0, os.path.join(base_dir, 'python', 'mozbuild')) |
18 | 16 | from mozbuild.configure import ConfigureSandbox |
| 17 | +from mozbuild.util import ( |
| 18 | + indented_repr, |
| 19 | + encode, |
| 20 | +) |
19 | 21 |
|
20 | 22 |
|
21 | 23 | def main(argv): |
@@ -60,57 +62,44 @@ def sanitized_bools(v): |
60 | 62 | print("Creating config.status", file=sys.stderr) |
61 | 63 | encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8' |
62 | 64 | with codecs.open('config.status', 'w', encoding) as fh: |
63 | | - fh.write('#!%s\n' % config['PYTHON']) |
64 | | - fh.write('# coding=%s\n' % encoding) |
65 | | - # Because we're serializing as JSON but reading as python, the values |
66 | | - # for True, False and None are true, false and null, which don't exist. |
67 | | - # Define them. |
68 | | - fh.write('true, false, null = True, False, None\n') |
| 65 | + fh.write(textwrap.dedent('''\ |
| 66 | + #!%(python)s |
| 67 | + # coding=%(encoding)s |
| 68 | + from __future__ import unicode_literals |
| 69 | + from mozbuild.util import encode |
| 70 | + encoding = '%(encoding)s' |
| 71 | + ''') % {'python': config['PYTHON'], 'encoding': encoding}) |
| 72 | + # A lot of the build backend code is currently expecting byte |
| 73 | + # strings and breaks in subtle ways with unicode strings. (bug 1296508) |
69 | 74 | for k, v in sanitized_config.iteritems(): |
70 | | - fh.write('%s = ' % k) |
71 | | - json.dump(v, fh, sort_keys=True, indent=4, ensure_ascii=False) |
72 | | - fh.write('\n') |
| 75 | + fh.write('%s = encode(%s, encoding)\n' % (k, indented_repr(v))) |
73 | 76 | fh.write("__all__ = ['topobjdir', 'topsrcdir', 'defines', " |
74 | 77 | "'non_global_defines', 'substs', 'mozconfig']") |
75 | 78 |
|
76 | 79 | if config.get('MOZ_BUILD_APP') != 'js' or config.get('JS_STANDALONE'): |
77 | | - fh.write(''' |
78 | | -if __name__ == '__main__': |
79 | | - args = dict([(name, globals()[name]) for name in __all__]) |
80 | | - from mozbuild.config_status import config_status |
81 | | - config_status(**args) |
82 | | -''') |
83 | | - |
84 | | - # Running config.status standalone uses byte literals for all the config, |
85 | | - # instead of the unicode literals we have in sanitized_config right now. |
86 | | - # Some values in sanitized_config also have more complex types, such as |
87 | | - # EnumString, which using when calling config_status would currently break |
88 | | - # the build, as well as making it inconsistent with re-running |
89 | | - # config.status. Fortunately, EnumString derives from unicode, so it's |
90 | | - # covered by converting unicode strings. |
91 | | - # Moreover, a lot of the build backend code is currently expecting byte |
92 | | - # strings and breaks in subtle ways with unicode strings. |
93 | | - def encode(v): |
94 | | - if isinstance(v, dict): |
95 | | - return { |
96 | | - encode(k): encode(val) |
97 | | - for k, val in v.iteritems() |
98 | | - } |
99 | | - if isinstance(v, str): |
100 | | - return v |
101 | | - if isinstance(v, unicode): |
102 | | - return v.encode(encoding) |
103 | | - if isinstance(v, Iterable): |
104 | | - return [encode(i) for i in v] |
105 | | - return v |
| 80 | + fh.write(textwrap.dedent(''' |
| 81 | + if __name__ == '__main__': |
| 82 | + from mozbuild.config_status import config_status |
| 83 | + args = dict([(name, globals()[name]) for name in __all__]) |
| 84 | + config_status(**args) |
| 85 | + ''')) |
106 | 86 |
|
107 | 87 | # Other things than us are going to run this file, so we need to give it |
108 | 88 | # executable permissions. |
109 | 89 | os.chmod('config.status', 0o755) |
110 | 90 | if config.get('MOZ_BUILD_APP') != 'js' or config.get('JS_STANDALONE'): |
111 | 91 | os.environ[b'WRITE_MOZINFO'] = b'1' |
112 | 92 | from mozbuild.config_status import config_status |
113 | | - return config_status(args=[], **encode(sanitized_config)) |
| 93 | + |
| 94 | + # Some values in sanitized_config also have more complex types, such as |
| 95 | + # EnumString, which using when calling config_status would currently |
| 96 | + # break the build, as well as making it inconsistent with re-running |
| 97 | + # config.status. Fortunately, EnumString derives from unicode, so it's |
| 98 | + # covered by converting unicode strings. |
| 99 | + |
| 100 | + # A lot of the build backend code is currently expecting byte strings |
| 101 | + # and breaks in subtle ways with unicode strings. |
| 102 | + return config_status(args=[], **encode(sanitized_config, encoding)) |
114 | 103 | return 0 |
115 | 104 |
|
116 | 105 |
|
|
0 commit comments