Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / build / templates.mozbuild
blob8bf5a8bbc09371b6b55a66847934b4bf63357a40
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'] = []
59     WASM_FLAGS['WARNINGS_AS_ERRORS'] = []
61 @template
62 def DisableCompilerWarnings():
63     # Keep the -Wno-* flags to disable warnings that may be enabled through other means.
64     def filter(flags):
65         return [f for f in flags or [] if f.startswith('-Wno-')]
66     COMPILE_FLAGS['WARNINGS_CFLAGS'] = filter(CONFIG['WARNINGS_CFLAGS'])
67     COMPILE_FLAGS['WARNINGS_CXXFLAGS'] = filter(CONFIG['WARNINGS_CXXFLAGS'])
68     HOST_COMPILE_FLAGS['WARNINGS_CFLAGS'] = filter(CONFIG['WARNINGS_HOST_CFLAGS'])
69     HOST_COMPILE_FLAGS['WARNINGS_CXXFLAGS'] = filter(CONFIG['WARNINGS_HOST_CXXFLAGS'])
71 @template
72 def RustLibrary(name, features=None, output_category=None, is_gkrust=False):
73     '''Template for Rust libraries.'''
74     Library(name)
76     IS_RUST_LIBRARY = True
77     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
78     AllowCompilerWarnings()
80     # And furthermore, don't even show warnings for them, so they don't regress
81     # the Compiler Warnings build metric
82     # <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
83     DisableCompilerWarnings()
85     if features:
86         RUST_LIBRARY_FEATURES = features
88     if output_category:
89         RUST_LIBRARY_OUTPUT_CATEGORY = output_category
91     if is_gkrust:
92         IS_GKRUST = True
95 @template
96 def SharedLibrary(name, output_category=None):
97     '''Template for shared libraries.'''
98     Library(name)
100     FORCE_SHARED_LIB = True
102     if output_category:
103         SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
105     Binary()
108 @template
109 def Framework(name, output_category=None):
110     '''Template for OSX Frameworks.'''
111     SharedLibrary(name, output_category)
113     IS_FRAMEWORK = True
116 @template
117 def HostProgram(name):
118     '''Template for build tools executables.'''
119     HOST_PROGRAM = name
122 @template
123 def HostSimplePrograms(names, ext='.cpp'):
124     '''Template for simple build tools executables.
126     Those have a single source with the same base name as the executable.
127     '''
128     HOST_SIMPLE_PROGRAMS += names
129     HOST_SOURCES += ['%s%s' % (name.replace('host_', ''), ext)
130         for name in names]
133 @template
134 def HostSharedLibrary(name):
135     '''Template for build tools libraries.'''
136     if name != 'clang-plugin':
137         error('Please make sure host shared library support is complete '
138               'before using for something else than the clang plugin')
140     HOST_LIBRARY_NAME = name
142     FORCE_SHARED_LIB = True
144 @template
145 def HostLibrary(name):
146     '''Template for build tools libraries.'''
147     HOST_LIBRARY_NAME = name
149 @template
150 def HostRustLibrary(name, features=None):
151     '''Template for host Rust libraries.'''
152     HostLibrary(name)
154     IS_RUST_LIBRARY = True
155     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
156     AllowCompilerWarnings()
158     if features:
159         HOST_RUST_LIBRARY_FEATURES = features
161 @template
162 def DisableStlWrapping():
163     COMPILE_FLAGS['STL'] = []
165 @template
166 def NoVisibilityFlags():
167     COMPILE_FLAGS['VISIBILITY'] = []
169 @template
170 def ForceInclude(*headers):
171     """Force includes a set of header files in C++ compilations"""
172     if CONFIG['CC_TYPE'] == 'clang-cl':
173         include_flag = '-FI'
174     else:
175         include_flag = '-include'
176     for header in headers:
177         CXXFLAGS += [include_flag, header]
179 @template
180 def GeneratedFile(name, *names, **kwargs):
181     """Add one or more GENERATED_FILES with the given attributes.
183     You must pass in at least one generated file (the "name" argument). Other
184     names can be included as positional arguments after "name"."""
185     script = kwargs.pop('script', None)
186     entry_point = kwargs.pop('entry_point', None)
187     inputs = kwargs.pop('inputs', [])
188     flags = kwargs.pop('flags', [])
189     force = kwargs.pop('force', False)
190     if kwargs:
191         error('Unrecognized argument(s) to GeneratedFile: %s' %
192               ', '.join(kwargs))
193     if entry_point and not script:
194        error('entry_point cannot be provided if script is not provided')
195     if script and ':' in script:
196        error('script should not include a `:`. If you want to provide an '
197              'alternative entry point for your script, use the entry_point '
198              'parameter.')
200     key = (name,) + names if names else name
201     GENERATED_FILES += [key]
202     generated_file = GENERATED_FILES[key]
203     if script and not entry_point:
204         generated_file.script = script
205     if script and entry_point:
206         generated_file.script = script + ':' + entry_point
207     generated_file.inputs = inputs
208     generated_file.flags = flags
209     generated_file.force = force
211 @template
212 def CbindgenHeader(name, inputs):
213     """Add one GENERATED_FILES by running RunCbindgen.py"""
215     inputs = ['!/config/cbindgen-metadata.json'] + inputs
216     GeneratedFile(name, script='/build/RunCbindgen.py',
217                   entry_point='generate', inputs=inputs)
220 include('gecko_templates.mozbuild')