Bug 1867925 - Mark some storage-access-api tests as intermittent after wpt-sync....
[gecko.git] / build / templates.mozbuild
blob811b96bb7e6f3ac26555bbeb294151debeb3f7a2
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/.
8 @template
9 def Binary():
10     """Generic template for target binaries. Meant to be used by other
11     templates."""
13     # Add -llog by default, since we use it all over the place.
14     if CONFIG["OS_TARGET"] == "Android":
15         OS_LIBS += ["log"]
18 @template
19 def Program(name):
20     """Template for program executables."""
21     PROGRAM = name
23     Binary()
26 @template
27 def SimplePrograms(names, ext=".cpp"):
28     """Template for simple program executables.
30     Those have a single source with the same base name as the executable.
31     """
32     SIMPLE_PROGRAMS += names
33     SOURCES += ["%s%s" % (name, ext) for name in names]
35     Binary()
38 @template
39 def CppUnitTests(names, ext=".cpp"):
40     """Template for C++ unit tests.
42     Those have a single source with the same base name as the executable.
43     """
44     COMPILE_FLAGS["EXTRA_INCLUDES"] = [
45         "-I%s/dist/include" % TOPOBJDIR,
46         "-I%s/dist/include/testing" % TOPOBJDIR,
47     ]
48     CPP_UNIT_TESTS += names
49     SOURCES += ["%s%s" % (name, ext) for name in names]
51     Binary()
54 @template
55 def Library(name):
56     """Template for libraries."""
57     LIBRARY_NAME = name
60 @template
61 def AllowCompilerWarnings():
62     COMPILE_FLAGS["WARNINGS_AS_ERRORS"] = []
63     WASM_FLAGS["WARNINGS_AS_ERRORS"] = []
66 @template
67 def DisableCompilerWarnings():
68     # Keep the -Wno-* flags to disable warnings that may be enabled through other means.
69     def filter(flags):
70         return [f for f in flags or [] if f.startswith("-Wno-")]
72     COMPILE_FLAGS["WARNINGS_CFLAGS"] = filter(CONFIG["WARNINGS_CFLAGS"])
73     COMPILE_FLAGS["WARNINGS_CXXFLAGS"] = filter(CONFIG["WARNINGS_CXXFLAGS"])
74     HOST_COMPILE_FLAGS["WARNINGS_CFLAGS"] = filter(CONFIG["WARNINGS_HOST_CFLAGS"])
75     HOST_COMPILE_FLAGS["WARNINGS_CXXFLAGS"] = filter(CONFIG["WARNINGS_HOST_CXXFLAGS"])
78 @template
79 def RustLibrary(name, features=None, output_category=None, is_gkrust=False):
80     """Template for Rust libraries."""
81     Library(name)
83     IS_RUST_LIBRARY = True
84     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
85     AllowCompilerWarnings()
87     # And furthermore, don't even show warnings for them, so they don't regress
88     # the Compiler Warnings build metric
89     # <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
90     DisableCompilerWarnings()
92     if features:
93         RUST_LIBRARY_FEATURES = features
95     if output_category:
96         RUST_LIBRARY_OUTPUT_CATEGORY = output_category
98     if is_gkrust:
99         IS_GKRUST = True
102 @template
103 def SharedLibrary(name, output_category=None):
104     """Template for shared libraries."""
105     Library(name)
107     FORCE_SHARED_LIB = True
109     if output_category:
110         SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
112     Binary()
115 @template
116 def Framework(name, output_category=None):
117     """Template for OSX Frameworks."""
118     SharedLibrary(name, output_category)
120     IS_FRAMEWORK = True
123 @template
124 def HostProgram(name):
125     """Template for build tools executables."""
126     HOST_PROGRAM = name
129 @template
130 def HostSimplePrograms(names, ext=".cpp"):
131     """Template for simple build tools executables.
133     Those have a single source with the same base name as the executable.
134     """
135     HOST_SIMPLE_PROGRAMS += names
136     HOST_SOURCES += ["%s%s" % (name.replace("host_", ""), ext) for name in names]
139 @template
140 def HostSharedLibrary(name):
141     """Template for build tools libraries."""
142     if name != "clang-plugin":
143         error(
144             "Please make sure host shared library support is complete "
145             "before using for something else than the clang plugin"
146         )
148     HOST_LIBRARY_NAME = name
150     FORCE_SHARED_LIB = True
153 @template
154 def HostLibrary(name):
155     """Template for build tools libraries."""
156     HOST_LIBRARY_NAME = name
159 @template
160 def HostRustLibrary(name, features=None):
161     """Template for host Rust libraries."""
162     HostLibrary(name)
164     IS_RUST_LIBRARY = True
165     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
166     AllowCompilerWarnings()
168     if features:
169         HOST_RUST_LIBRARY_FEATURES = features
172 @template
173 def DisableStlWrapping():
174     COMPILE_FLAGS["STL"] = []
177 @template
178 def NoVisibilityFlags():
179     COMPILE_FLAGS["VISIBILITY"] = []
182 @template
183 def ForceInclude(*headers):
184     """Force includes a set of header files in C++ compilations"""
185     if CONFIG["CC_TYPE"] == "clang-cl":
186         include_flag = "-FI"
187     else:
188         include_flag = "-include"
189     for header in headers:
190         CXXFLAGS += [include_flag, header]
193 @template
194 def GeneratedFile(name, *names, **kwargs):
195     """Add one or more GENERATED_FILES with the given attributes.
197     You must pass in at least one generated file (the "name" argument). Other
198     names can be included as positional arguments after "name"."""
199     script = kwargs.pop("script", None)
200     entry_point = kwargs.pop("entry_point", None)
201     inputs = kwargs.pop("inputs", [])
202     flags = kwargs.pop("flags", [])
203     force = kwargs.pop("force", False)
204     if kwargs:
205         error("Unrecognized argument(s) to GeneratedFile: %s" % ", ".join(kwargs))
206     if entry_point and not script:
207         error("entry_point cannot be provided if script is not provided")
208     if script and ":" in script:
209         error(
210             "script should not include a `:`. If you want to provide an "
211             "alternative entry point for your script, use the entry_point "
212             "parameter."
213         )
215     key = (name,) + names if names else name
216     GENERATED_FILES += [key]
217     generated_file = GENERATED_FILES[key]
218     if script and not entry_point:
219         generated_file.script = script
220     if script and entry_point:
221         generated_file.script = script + ":" + entry_point
222     generated_file.inputs = inputs
223     generated_file.flags = flags
224     generated_file.force = force
227 @template
228 def CbindgenHeader(name, inputs):
229     """Add one GENERATED_FILES by running RunCbindgen.py"""
231     inputs = ["!/config/cbindgen-metadata.json"] + inputs
232     GeneratedFile(
233         name, script="/build/RunCbindgen.py", entry_point="generate", inputs=inputs
234     )
237 include("gecko_templates.mozbuild")