Skip to content

Commit 2fea117

Browse files
committed
Bug 1407432 - Move stl wrapper generation into moz.build; r=froydnj
This is fairly straightforward to represent as a GENERATED_FILES, though we have to take some care to construct the outputs tuple correctly. This script needs to run during export, and unfortunately none of the STL headers have proper file extensions, so the 'new' header is special-cased in the recursive make backend to serve as a marker for running it in the correct tier. We can't remove the stl-headers file yet because it is still used for the system header generation. MozReview-Commit-ID: 3tQTOY0LAsQ --HG-- extra : rebase_source : bd9f00e45a7bce4daaa0e1c16e22b28536658e37
1 parent fb26e05 commit 2fea117

File tree

6 files changed

+84
-46
lines changed

6 files changed

+84
-46
lines changed

config/Makefile.in

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,6 @@ export:: $(export-preqs)
5555
GARBAGE_DIRS += system_wrappers
5656
endif
5757

58-
ifdef WRAP_STL_INCLUDES
59-
ifdef GNU_CXX
60-
stl_compiler = gcc
61-
else
62-
ifdef _MSC_VER
63-
stl_compiler = msvc
64-
endif
65-
endif
66-
endif
67-
68-
ifdef stl_compiler
69-
STL_WRAPPERS_SENTINEL = $(DIST)/stl_wrappers/sentinel
70-
71-
$(STL_WRAPPERS_SENTINEL): $(srcdir)/make-stl-wrappers.py $(srcdir)/$(stl_compiler)-stl-wrapper.template.h $(srcdir)/stl-headers $(GLOBAL_DEPS)
72-
$(PYTHON) $(srcdir)/make-stl-wrappers.py stl_wrappers $(stl_compiler) $(srcdir)/$(stl_compiler)-stl-wrapper.template.h $(srcdir)/stl-headers
73-
$(PYTHON) $(srcdir)/nsinstall.py -t stl_wrappers $(DIST)
74-
touch $(STL_WRAPPERS_SENTINEL)
75-
76-
export:: $(STL_WRAPPERS_SENTINEL)
77-
78-
GARBAGE += $(STL_WRAPPERS_SENTINEL)
79-
GARBAGE_DIRS += stl_wrappers
80-
endif
81-
8258
GARBAGE += \
8359
$(FINAL_LINK_COMPS) $(FINAL_LINK_LIBS) $(FINAL_LINK_COMP_NAMES) $(srcdir)/*.pyc *.pyc
8460

config/make-stl-wrappers.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,13 @@ def header_path(header, compiler):
2222
# hope someone notices this ...
2323
raise NotImplementedError(compiler)
2424

25-
def is_comment(line):
26-
return re.match(r'\s*#.*', line)
27-
28-
def main(outdir, compiler, template_file, header_list_file):
29-
if not os.path.isdir(outdir):
30-
os.mkdir(outdir)
31-
25+
# The 'unused' arg is the output file from the file_generate action. We actually
26+
# generate all the files in header_list
27+
def gen_wrappers(unused, outdir, compiler, template_file, *header_list):
3228
template = open(template_file, 'r').read()
3329

34-
for header in open(header_list_file, 'r'):
35-
header = header.rstrip()
36-
if 0 == len(header) or is_comment(header):
37-
continue
38-
30+
for header in header_list:
3931
path = header_path(header, compiler)
4032
with FileAvoidWrite(os.path.join(outdir, header)) as f:
4133
f.write(string.Template(template).substitute(HEADER=header,
4234
HEADER_PATH=path))
43-
44-
45-
if __name__ == '__main__':
46-
if 5 != len(sys.argv):
47-
print("""Usage:
48-
python {0} OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
49-
""".format(sys.argv[0]), file=sys.stderr)
50-
sys.exit(1)
51-
52-
main(*sys.argv[1:])

config/moz.build

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,24 @@ HOST_DEFINES = {
4242
'UNICODE': True,
4343
'_UNICODE': True,
4444
}
45+
46+
include('stl-headers.mozbuild')
47+
if CONFIG['WRAP_STL_INCLUDES']:
48+
stl_compiler = None
49+
if CONFIG['GNU_CXX']:
50+
stl_compiler = 'gcc'
51+
elif CONFIG['_MSC_VER']:
52+
stl_compiler = 'msvc'
53+
54+
if stl_compiler:
55+
template_file = SRCDIR + '/%s-stl-wrapper.template.h' % stl_compiler
56+
output_dir = '../dist/stl_wrappers'
57+
# We have to use a sentinel file as the first file because the
58+
# file_generate action will create it for us, but we want to create all
59+
# the files in gen_wrappers()
60+
outputs = tuple(['stl.sentinel'] + ['%s/%s' % (output_dir, h) for h in stl_headers])
61+
GENERATED_FILES += [outputs]
62+
stl = GENERATED_FILES[outputs]
63+
stl.script = 'make-stl-wrappers.py:gen_wrappers'
64+
stl.flags = [output_dir, stl_compiler, template_file]
65+
stl.flags.extend(stl_headers)

config/stl-headers.mozbuild

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2+
# vim: set filetype=python:
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
# This list contains the of STL headers that have been reviewed for exception
8+
# safety and approved. See
9+
#
10+
# https://bugzilla.mozilla.org/show_bug.cgi?id=551254
11+
#
12+
# At build time, each header listed here is converted into a "wrapper
13+
# header" that is installed into dist/stl_includes.
14+
#
15+
# If you would like to request a new STL header <foo> be added, please
16+
# file a Core:XPCOM bug with a title like "STL: Review exception
17+
# safety of <foo> for gcc and MSVC".
18+
stl_headers = [
19+
'new',
20+
21+
# FIXME: these headers haven't been reviewed yet, but we use them
22+
# unsafely in Gecko, so we might as well prevent them from
23+
# throwing exceptions
24+
'algorithm',
25+
'atomic',
26+
'deque',
27+
'functional',
28+
'ios',
29+
'iosfwd',
30+
'iostream',
31+
'istream',
32+
'iterator',
33+
'limits',
34+
'list',
35+
'map',
36+
'memory',
37+
'ostream',
38+
'set',
39+
'stack',
40+
'string',
41+
'thread',
42+
'type_traits',
43+
'unordered_map',
44+
'unordered_set',
45+
'utility',
46+
'vector',
47+
'cassert',
48+
'climits',
49+
'cmath',
50+
'cstdarg',
51+
'cstdio',
52+
'cstdlib',
53+
'cstring',
54+
'cwchar',
55+
'tuple',
56+
'xutility',
57+
]

python/mozbuild/mozbuild/backend/recursivemake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ def consume_object(self, obj):
525525
'.inc',
526526
'.py',
527527
'.rs',
528+
'new', # 'new' is an output from make-stl-wrappers.py
528529
)
529530
tier = 'export' if any(f.endswith(export_suffixes) for f in obj.outputs) else 'misc'
530531
self._no_skip[tier].add(backend_file.relobjdir)

python/mozbuild/mozbuild/frontend/sandbox.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Sandbox(dict):
111111
'sorted': alphabetical_sorted,
112112
'int': int,
113113
'set': set,
114+
'tuple': tuple,
114115
})
115116

116117
def __init__(self, context, finder=default_finder):

0 commit comments

Comments
 (0)