Bug 1731994: part 8) Rename `nsIContentPermissionRequest`'s `isHandlingUserInput...
[gecko.git] / build / templates.mozbuild
blobde44168e3034ea05d6901be132db17f9265aa0da
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/.
7 @template
8 def Binary():
9     '''Generic template for target binaries. Meant to be used by other
10     templates.'''
12     # Add -llog by default, since we use it all over the place.
13     if CONFIG['OS_TARGET'] == 'Android':
14         OS_LIBS += ['log']
17 @template
18 def Program(name):
19     '''Template for program executables.'''
20     PROGRAM = name
22     Binary()
25 @template
26 def SimplePrograms(names, ext='.cpp'):
27     '''Template for simple program executables.
29     Those have a single source with the same base name as the executable.
30     '''
31     SIMPLE_PROGRAMS += names
32     SOURCES += ['%s%s' % (name, ext) for name in names]
34     Binary()
37 @template
38 def CppUnitTests(names, ext='.cpp'):
39     '''Template for C++ unit tests.
41     Those have a single source with the same base name as the executable.
42     '''
43     COMPILE_FLAGS['EXTRA_INCLUDES'] = ['-I%s/dist/include' % TOPOBJDIR,
44                                        '-I%s/dist/include/testing' % TOPOBJDIR]
45     CPP_UNIT_TESTS += names
46     SOURCES += ['%s%s' % (name, ext) for name in names]
48     Binary()
51 @template
52 def Library(name):
53     '''Template for libraries.'''
54     LIBRARY_NAME = name
56 @template
57 def AllowCompilerWarnings():
58     COMPILE_FLAGS['WARNINGS_AS_ERRORS'] = []
60 @template
61 def DisableCompilerWarnings():
62     COMPILE_FLAGS['WARNINGS_CFLAGS'] = []
64 @template
65 def RustLibrary(name, features=None, output_category=None, is_gkrust=False):
66     '''Template for Rust libraries.'''
67     Library(name)
69     IS_RUST_LIBRARY = True
70     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
71     AllowCompilerWarnings()
73     # And furthermore, don't even show warnings for them, so they don't regress
74     # the Compiler Warnings build metric
75     # <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
76     DisableCompilerWarnings()
78     if features:
79         RUST_LIBRARY_FEATURES = features
81     if output_category:
82         RUST_LIBRARY_OUTPUT_CATEGORY = output_category
84     if is_gkrust:
85         IS_GKRUST = True
88 @template
89 def SharedLibrary(name, output_category=None):
90     '''Template for shared libraries.'''
91     Library(name)
93     FORCE_SHARED_LIB = True
95     if output_category:
96         SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
98     Binary()
101 @template
102 def Framework(name, output_category=None):
103     '''Template for OSX Frameworks.'''
104     SharedLibrary(name, output_category)
106     IS_FRAMEWORK = True
109 @template
110 def HostProgram(name):
111     '''Template for build tools executables.'''
112     HOST_PROGRAM = name
115 @template
116 def HostSimplePrograms(names, ext='.cpp'):
117     '''Template for simple build tools executables.
119     Those have a single source with the same base name as the executable.
120     '''
121     HOST_SIMPLE_PROGRAMS += names
122     HOST_SOURCES += ['%s%s' % (name.replace('host_', ''), ext)
123         for name in names]
126 @template
127 def HostSharedLibrary(name):
128     '''Template for build tools libraries.'''
129     if name != 'clang-plugin':
130         error('Please make sure host shared library support is complete '
131               'before using for something else than the clang plugin')
133     HOST_LIBRARY_NAME = name
135     FORCE_SHARED_LIB = True
137 @template
138 def HostLibrary(name):
139     '''Template for build tools libraries.'''
140     HOST_LIBRARY_NAME = name
142 @template
143 def HostRustLibrary(name, features=None):
144     '''Template for host Rust libraries.'''
145     HostLibrary(name)
147     IS_RUST_LIBRARY = True
148     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
149     AllowCompilerWarnings()
151     if features:
152         HOST_RUST_LIBRARY_FEATURES = features
154 @template
155 def DisableStlWrapping():
156     COMPILE_FLAGS['STL'] = []
158 @template
159 def NoVisibilityFlags():
160     COMPILE_FLAGS['VISIBILITY'] = []
162 @template
163 def ForceInclude(*headers):
164     """Force includes a set of header files in C++ compilations"""
165     if CONFIG['CC_TYPE'] == 'clang-cl':
166         include_flag = '-FI'
167     else:
168         include_flag = '-include'
169     for header in headers:
170         CXXFLAGS += [include_flag, header]
172 @template
173 def GeneratedFile(name, *names, **kwargs):
174     """Add one or more GENERATED_FILES with the given attributes.
176     You must pass in at least one generated file (the "name" argument). Other
177     names can be included as positional arguments after "name"."""
178     script = kwargs.pop('script', None)
179     entry_point = kwargs.pop('entry_point', None)
180     inputs = kwargs.pop('inputs', [])
181     flags = kwargs.pop('flags', [])
182     force = kwargs.pop('force', False)
183     if kwargs:
184         error('Unrecognized argument(s) to GeneratedFile: %s' %
185               ', '.join(kwargs))
186     if entry_point and not script:
187        error('entry_point cannot be provided if script is not provided')
188     if script and ':' in script:
189        error('script should not include a `:`. If you want to provide an '
190              'alternative entry point for your script, use the entry_point '
191              'parameter.')
193     key = (name,) + names if names else name
194     GENERATED_FILES += [key]
195     generated_file = GENERATED_FILES[key]
196     if script and not entry_point:
197         generated_file.script = script
198     if script and entry_point:
199         generated_file.script = script + ':' + entry_point
200     generated_file.inputs = inputs
201     generated_file.flags = flags
202     generated_file.force = force
204 @template
205 def CbindgenHeader(name, inputs):
206     """Add one GENERATED_FILES by running RunCbindgen.py"""
208     inputs = ['!/config/cbindgen-metadata.json'] + inputs
209     GeneratedFile(name, script='/build/RunCbindgen.py',
210                   entry_point='generate', inputs=inputs)
213 include('gecko_templates.mozbuild')