tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

templates.mozbuild (7622B)


      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/.
      6 
      7 
      8 @template
      9 def Binary():
     10     """Generic template for target binaries. Meant to be used by other
     11     templates."""
     12 
     13     # Add -llog by default, since we use it all over the place.
     14     if CONFIG["OS_TARGET"] == "Android":
     15         OS_LIBS += ["log"]
     16 
     17 
     18 @template
     19 def MaybeAddProfiling(name):
     20     if (
     21         CONFIG["MOZ_ENABLE_FORKSERVER"]
     22         and CONFIG["NIGHTLY_BUILD"]
     23         and CONFIG["OS_TARGET"] == "Linux"
     24         and CONFIG["MOZ_PROFILE_GENERATE"] == "1"
     25     ):
     26         USE_LIBS += ["profiling"]
     27 
     28 
     29 @template
     30 def Program(name):
     31     """Template for program executables."""
     32     PROGRAM = name
     33 
     34     MaybeAddProfiling(name)
     35 
     36     Binary()
     37 
     38 
     39 @template
     40 def SimplePrograms(names, ext=".cpp"):
     41     """Template for simple program executables.
     42 
     43     Those have a single source with the same base name as the executable.
     44     """
     45     SIMPLE_PROGRAMS += names
     46     SOURCES += ["%s%s" % (name, ext) for name in names]
     47 
     48     Binary()
     49 
     50 
     51 @template
     52 def CppUnitTests(names, ext=".cpp"):
     53     """Template for C++ unit tests.
     54 
     55     Those have a single source with the same base name as the executable.
     56     """
     57     COMPILE_FLAGS["EXTRA_INCLUDES"] = [
     58         "-I%s/dist/include" % TOPOBJDIR,
     59         "-I%s/dist/include/testing" % TOPOBJDIR,
     60     ]
     61     CPP_UNIT_TESTS += names
     62     SOURCES += ["%s%s" % (name, ext) for name in names]
     63 
     64     Binary()
     65 
     66 
     67 @template
     68 def Library(name):
     69     """Template for libraries."""
     70     LIBRARY_NAME = name
     71 
     72 
     73 @template
     74 def AllowCompilerWarnings():
     75     COMPILE_FLAGS["WARNINGS_AS_ERRORS"] = []
     76     WASM_FLAGS["WARNINGS_AS_ERRORS"] = []
     77 
     78 
     79 @template
     80 def DisableCompilerWarnings():
     81     # Keep the -Wno-* flags to disable warnings that may be enabled through other means.
     82     def filter(flags):
     83         return [f for f in flags or [] if f.startswith("-Wno-")]
     84 
     85     COMPILE_FLAGS["WARNINGS_CFLAGS"] = filter(CONFIG["WARNINGS_CFLAGS"])
     86     COMPILE_FLAGS["WARNINGS_CXXFLAGS"] = filter(CONFIG["WARNINGS_CXXFLAGS"])
     87     HOST_COMPILE_FLAGS["WARNINGS_CFLAGS"] = filter(CONFIG["WARNINGS_HOST_CFLAGS"])
     88     HOST_COMPILE_FLAGS["WARNINGS_CXXFLAGS"] = filter(CONFIG["WARNINGS_HOST_CXXFLAGS"])
     89 
     90 
     91 @template
     92 def DisableWarningsForRust():
     93     """Template to disable warnings when compiling rust (rust build scripts
     94     compile C/C++ sources which we can't control easily). Meant to be used by
     95     other templates.
     96     """
     97     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
     98     AllowCompilerWarnings()
     99 
    100     # And furthermore, don't even show warnings for them, so they don't regress
    101     # the Compiler Warnings build metric
    102     # <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
    103     DisableCompilerWarnings()
    104 
    105 
    106 @template
    107 def RustLibrary(name, features=None, output_category=None, is_gkrust=False):
    108     """Template for Rust libraries."""
    109     Library(name)
    110 
    111     IS_RUST_LIBRARY = True
    112 
    113     DisableWarningsForRust()
    114 
    115     if features:
    116         RUST_LIBRARY_FEATURES = features
    117 
    118     if output_category:
    119         RUST_LIBRARY_OUTPUT_CATEGORY = output_category
    120 
    121     if is_gkrust:
    122         IS_GKRUST = True
    123 
    124 
    125 @template
    126 def RustProgram(name):
    127     """Template for Rust programs."""
    128     RUST_PROGRAMS += [name]
    129     DisableWarningsForRust()
    130 
    131 
    132 @template
    133 def SharedLibrary(name, output_category=None):
    134     """Template for shared libraries."""
    135     Library(name)
    136 
    137     FORCE_SHARED_LIB = True
    138 
    139     if output_category:
    140         SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
    141 
    142     MaybeAddProfiling(name)
    143 
    144     Binary()
    145 
    146 
    147 @template
    148 def Framework(name, output_category=None):
    149     """Template for OSX Frameworks."""
    150     SharedLibrary(name, output_category)
    151 
    152     IS_FRAMEWORK = True
    153 
    154 
    155 @template
    156 def HostProgram(name):
    157     """Template for build tools executables."""
    158     HOST_PROGRAM = name
    159 
    160 
    161 @template
    162 def HostSimplePrograms(names, ext=".cpp"):
    163     """Template for simple build tools executables.
    164 
    165     Those have a single source with the same base name as the executable.
    166     """
    167     HOST_SIMPLE_PROGRAMS += names
    168     HOST_SOURCES += ["%s%s" % (name.replace("host_", ""), ext) for name in names]
    169 
    170 
    171 @template
    172 def HostSharedLibrary(name):
    173     """Template for build tools libraries."""
    174     if name != "clang-plugin":
    175         error(
    176             "Please make sure host shared library support is complete "
    177             "before using for something else than the clang plugin"
    178         )
    179 
    180     HOST_LIBRARY_NAME = name
    181 
    182     FORCE_SHARED_LIB = True
    183 
    184 
    185 @template
    186 def HostLibrary(name):
    187     """Template for build tools libraries."""
    188     HOST_LIBRARY_NAME = name
    189 
    190 
    191 @template
    192 def HostRustLibrary(name, features=None):
    193     """Template for host Rust libraries."""
    194     HostLibrary(name)
    195 
    196     IS_RUST_LIBRARY = True
    197     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
    198     AllowCompilerWarnings()
    199 
    200     if features:
    201         HOST_RUST_LIBRARY_FEATURES = features
    202 
    203 
    204 @template
    205 def DisableStlWrapping():
    206     COMPILE_FLAGS["STL"] = []
    207 
    208 
    209 @template
    210 def NoVisibilityFlags():
    211     COMPILE_FLAGS["VISIBILITY"] = []
    212 
    213 
    214 @template
    215 def ForceInclude(*headers):
    216     """Force includes a set of header files in C++ compilations"""
    217     if CONFIG["CC_TYPE"] == "clang-cl":
    218         include_flag = "-FI"
    219     else:
    220         include_flag = "-include"
    221     for header in headers:
    222         CXXFLAGS += [include_flag, header]
    223 
    224 
    225 @template
    226 def GeneratedFile(name, *names, **kwargs):
    227     """Add one or more GENERATED_FILES with the given attributes.
    228 
    229     You must pass in at least one generated file (the "name" argument). Other
    230     names can be included as positional arguments after "name"."""
    231     script = kwargs.pop("script", None)
    232     entry_point = kwargs.pop("entry_point", None)
    233     inputs = kwargs.pop("inputs", [])
    234     flags = kwargs.pop("flags", [])
    235     force = kwargs.pop("force", False)
    236     if kwargs:
    237         error("Unrecognized argument(s) to GeneratedFile: %s" % ", ".join(kwargs))
    238     if entry_point and not script:
    239         error("entry_point cannot be provided if script is not provided")
    240     if script and ":" in script:
    241         error(
    242             "script should not include a `:`. If you want to provide an "
    243             "alternative entry point for your script, use the entry_point "
    244             "parameter."
    245         )
    246 
    247     key = (name,) + names if names else name
    248     GENERATED_FILES += [key]
    249     generated_file = GENERATED_FILES[key]
    250     if script and not entry_point:
    251         generated_file.script = script
    252     if script and entry_point:
    253         generated_file.script = script + ":" + entry_point
    254     generated_file.inputs = inputs
    255     generated_file.flags = flags
    256     generated_file.force = force
    257 
    258 
    259 @template
    260 def LegacyTest(*args, **kwargs):
    261     """Add one test to LEGACY_RUN_TESTS with the given attributes."""
    262 
    263     LEGACY_RUN_TESTS += [{"args": args}]
    264     test = LEGACY_RUN_TESTS[-1]
    265     test["env"] = kwargs.pop("env", None)
    266     test["description"] = kwargs.pop("description", None)
    267     test["depends"] = kwargs.pop("depends", ())
    268     if kwargs:
    269         error("Unrecognized argument(s) to LegacyTest: %s" % ", ".join(kwargs))
    270 
    271 
    272 @template
    273 def CbindgenHeader(name, inputs):
    274     """Add one GENERATED_FILES by running RunCbindgen.py"""
    275 
    276     inputs = ["!/config/cbindgen-metadata.json"] + inputs
    277     GeneratedFile(
    278         name, script="/build/RunCbindgen.py", entry_point="generate", inputs=inputs
    279     )
    280 
    281 
    282 include("gecko_templates.mozbuild")