Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 : source : 828d43ec1b16edaac69c42f15561f26e209051f1
  • Loading branch information
mshal committed Nov 8, 2017
1 parent 534d643 commit 523accb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 46 deletions.
24 changes: 0 additions & 24 deletions config/Makefile.in
Expand Up @@ -55,30 +55,6 @@ export:: $(export-preqs)
GARBAGE_DIRS += system_wrappers
endif

ifdef WRAP_STL_INCLUDES
ifdef GNU_CXX
stl_compiler = gcc
else
ifdef _MSC_VER
stl_compiler = msvc
endif
endif
endif

ifdef stl_compiler
STL_WRAPPERS_SENTINEL = $(DIST)/stl_wrappers/sentinel

$(STL_WRAPPERS_SENTINEL): $(srcdir)/make-stl-wrappers.py $(srcdir)/$(stl_compiler)-stl-wrapper.template.h $(srcdir)/stl-headers $(GLOBAL_DEPS)
$(PYTHON) $(srcdir)/make-stl-wrappers.py stl_wrappers $(stl_compiler) $(srcdir)/$(stl_compiler)-stl-wrapper.template.h $(srcdir)/stl-headers
$(PYTHON) $(srcdir)/nsinstall.py -t stl_wrappers $(DIST)
touch $(STL_WRAPPERS_SENTINEL)

export:: $(STL_WRAPPERS_SENTINEL)

GARBAGE += $(STL_WRAPPERS_SENTINEL)
GARBAGE_DIRS += stl_wrappers
endif

GARBAGE += \
$(FINAL_LINK_COMPS) $(FINAL_LINK_LIBS) $(FINAL_LINK_COMP_NAMES) $(srcdir)/*.pyc *.pyc

Expand Down
26 changes: 4 additions & 22 deletions config/make-stl-wrappers.py
Expand Up @@ -22,31 +22,13 @@ def header_path(header, compiler):
# hope someone notices this ...
raise NotImplementedError(compiler)

def is_comment(line):
return re.match(r'\s*#.*', line)

def main(outdir, compiler, template_file, header_list_file):
if not os.path.isdir(outdir):
os.mkdir(outdir)

# The 'unused' arg is the output file from the file_generate action. We actually
# generate all the files in header_list
def gen_wrappers(unused, outdir, compiler, template_file, *header_list):
template = open(template_file, 'r').read()

for header in open(header_list_file, 'r'):
header = header.rstrip()
if 0 == len(header) or is_comment(header):
continue

for header in header_list:
path = header_path(header, compiler)
with FileAvoidWrite(os.path.join(outdir, header)) as f:
f.write(string.Template(template).substitute(HEADER=header,
HEADER_PATH=path))


if __name__ == '__main__':
if 5 != len(sys.argv):
print("""Usage:
python {0} OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
""".format(sys.argv[0]), file=sys.stderr)
sys.exit(1)

main(*sys.argv[1:])
21 changes: 21 additions & 0 deletions config/moz.build
Expand Up @@ -42,3 +42,24 @@ HOST_DEFINES = {
'UNICODE': True,
'_UNICODE': True,
}

include('stl-headers.mozbuild')
if CONFIG['WRAP_STL_INCLUDES']:
stl_compiler = None
if CONFIG['GNU_CXX']:
stl_compiler = 'gcc'
elif CONFIG['_MSC_VER']:
stl_compiler = 'msvc'

if stl_compiler:
template_file = SRCDIR + '/%s-stl-wrapper.template.h' % stl_compiler
output_dir = '../dist/stl_wrappers'
# We have to use a sentinel file as the first file because the
# file_generate action will create it for us, but we want to create all
# the files in gen_wrappers()
outputs = tuple(['stl.sentinel'] + ['%s/%s' % (output_dir, h) for h in stl_headers])
GENERATED_FILES += [outputs]
stl = GENERATED_FILES[outputs]
stl.script = 'make-stl-wrappers.py:gen_wrappers'
stl.flags = [output_dir, stl_compiler, template_file]
stl.flags.extend(stl_headers)
57 changes: 57 additions & 0 deletions config/stl-headers.mozbuild
@@ -0,0 +1,57 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# This list contains the of STL headers that have been reviewed for exception
# safety and approved. See
#
# https://bugzilla.mozilla.org/show_bug.cgi?id=551254
#
# At build time, each header listed here is converted into a "wrapper
# header" that is installed into dist/stl_includes.
#
# If you would like to request a new STL header <foo> be added, please
# file a Core:XPCOM bug with a title like "STL: Review exception
# safety of <foo> for gcc and MSVC".
stl_headers = [
'new',

# FIXME: these headers haven't been reviewed yet, but we use them
# unsafely in Gecko, so we might as well prevent them from
# throwing exceptions
'algorithm',
'atomic',
'deque',
'functional',
'ios',
'iosfwd',
'iostream',
'istream',
'iterator',
'limits',
'list',
'map',
'memory',
'ostream',
'set',
'stack',
'string',
'thread',
'type_traits',
'unordered_map',
'unordered_set',
'utility',
'vector',
'cassert',
'climits',
'cmath',
'cstdarg',
'cstdio',
'cstdlib',
'cstring',
'cwchar',
'tuple',
'xutility',
]
1 change: 1 addition & 0 deletions python/mozbuild/mozbuild/backend/recursivemake.py
Expand Up @@ -525,6 +525,7 @@ def consume_object(self, obj):
'.inc',
'.py',
'.rs',
'new', # 'new' is an output from make-stl-wrappers.py
)
tier = 'export' if any(f.endswith(export_suffixes) for f in obj.outputs) else 'misc'
self._no_skip[tier].add(backend_file.relobjdir)
Expand Down
1 change: 1 addition & 0 deletions python/mozbuild/mozbuild/frontend/sandbox.py
Expand Up @@ -111,6 +111,7 @@ class Sandbox(dict):
'sorted': alphabetical_sorted,
'int': int,
'set': set,
'tuple': tuple,
})

def __init__(self, context, finder=default_finder):
Expand Down

0 comments on commit 523accb

Please sign in to comment.