From 523accbeb6d7887583b6eee9a33580a746603571 Mon Sep 17 00:00:00 2001 From: Mike Shal Date: Wed, 8 Nov 2017 17:42:27 -0500 Subject: [PATCH] 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 --- config/Makefile.in | 24 -------- config/make-stl-wrappers.py | 26 ++------- config/moz.build | 21 +++++++ config/stl-headers.mozbuild | 57 +++++++++++++++++++ .../mozbuild/backend/recursivemake.py | 1 + python/mozbuild/mozbuild/frontend/sandbox.py | 1 + 6 files changed, 84 insertions(+), 46 deletions(-) create mode 100644 config/stl-headers.mozbuild diff --git a/config/Makefile.in b/config/Makefile.in index e2e11dc0e27e7..976c657cac289 100644 --- a/config/Makefile.in +++ b/config/Makefile.in @@ -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 diff --git a/config/make-stl-wrappers.py b/config/make-stl-wrappers.py index c0ab21c7e50f6..dd070e6ffeea3 100644 --- a/config/make-stl-wrappers.py +++ b/config/make-stl-wrappers.py @@ -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:]) diff --git a/config/moz.build b/config/moz.build index 26ed1cba7527a..5ac0a8e499ee3 100644 --- a/config/moz.build +++ b/config/moz.build @@ -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) diff --git a/config/stl-headers.mozbuild b/config/stl-headers.mozbuild new file mode 100644 index 0000000000000..e2a18eca3384f --- /dev/null +++ b/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 be added, please +# file a Core:XPCOM bug with a title like "STL: Review exception +# safety of 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', +] diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index c13ce93538bd6..c68b27b719493 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -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) diff --git a/python/mozbuild/mozbuild/frontend/sandbox.py b/python/mozbuild/mozbuild/frontend/sandbox.py index 5a4e1e05d7f88..b2090802e6eac 100644 --- a/python/mozbuild/mozbuild/frontend/sandbox.py +++ b/python/mozbuild/mozbuild/frontend/sandbox.py @@ -111,6 +111,7 @@ class Sandbox(dict): 'sorted': alphabetical_sorted, 'int': int, 'set': set, + 'tuple': tuple, }) def __init__(self, context, finder=default_finder):