Bug 1641886 [wpt PR 23851] - Support interpolating contain-intrinsic-size, a=testonly
[gecko.git] / security / generate_mapfile.py
blob4c88172d67b0e3b0bf8dc7abf8a16d97d60468ad
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 \
26 buildconfig.substs.get('GCC_USE_GNU_LD')
28 with open(input, 'r', encoding='utf-8') as f:
29 for line in f:
30 line = line.rstrip()
31 # On everything except MinGW, remove all lines containing ';-'
32 if not is_mingw and ';-' in line:
33 continue
34 # On OS X, remove all lines containing ';+'
35 if is_darwin and ';+' in line:
36 continue
37 # Remove the string ' DATA '.
38 line = line.replace(' DATA ', '')
39 # Remove the string ';+'
40 if not is_mingw:
41 line = line.replace(';+', '')
42 # Remove the string ';;'
43 line = line.replace(';;', '')
44 # If a ';' is present, remove everything after it,
45 # and on OS X, remove it as well.
46 i = line.find(';')
47 if i != -1:
48 if is_darwin or is_mingw:
49 line = line[:i]
50 else:
51 line = line[:i+1]
52 # On OS X, symbols get an underscore in front.
53 if line and is_darwin:
54 output.write('_')
55 output.write(line)
56 output.write('\n')