Bug 1860959 [wpt PR 42048] - [webaudio] Convert test to testharness, a=testonly
[gecko.git] / security / generate_mapfile.py
blob244f499f74c588fd325c55e0a78ffeb824345e16
1 #!/usr/bin/env 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 # This script processes NSS .def files according to the rules defined in
8 # a comment at the top of each one. The files are used to define the
9 # exports from NSS shared libraries, with -DEFFILE on Windows, a linker
10 # script on Linux, or with -exported_symbols_list on OS X.
12 # The NSS build system processes them using a series of sed replacements,
13 # but the Mozilla build system is already running a Python script to generate
14 # the file so it's simpler to just do the replacement in Python.
16 # One difference between the NSS build system and Mozilla's is that
17 # Mozilla's supports building on Linux for Windows using MinGW. MinGW
18 # expects all lines containing ;+ removed and all ;- tokens removed.
20 import buildconfig
23 def main(output, input):
24 is_darwin = buildconfig.substs["OS_ARCH"] == "Darwin"
25 is_mingw = "WINNT" == buildconfig.substs["OS_ARCH"] and buildconfig.substs.get(
26 "GCC_USE_GNU_LD"
29 with open(input, "r", encoding="utf-8") as f:
30 for line in f:
31 line = line.rstrip()
32 # On everything except MinGW, remove all lines containing ';-'
33 if not is_mingw and ";-" in line:
34 continue
35 # On OS X, remove all lines containing ';+'
36 if is_darwin and ";+" in line:
37 continue
38 # Remove the string ' DATA '.
39 line = line.replace(" DATA ", "")
40 # Remove the string ';+'
41 if not is_mingw:
42 line = line.replace(";+", "")
43 # Remove the string ';;'
44 line = line.replace(";;", "")
45 # If a ';' is present, remove everything after it,
46 # and on OS X, remove it as well.
47 i = line.find(";")
48 if i != -1:
49 if is_darwin or is_mingw:
50 line = line[:i]
51 else:
52 line = line[: i + 1]
53 # On OS X, symbols get an underscore in front.
54 if line and is_darwin:
55 output.write("_")
56 output.write(line)
57 output.write("\n")