Blame security/generate_mapfile.py

Packit f0b94e
#!/usr/bin/env python
Packit f0b94e
Packit f0b94e
# This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
# License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit f0b94e
Packit f0b94e
# This script processes NSS .def files according to the rules defined in
Packit f0b94e
# a comment at the top of each one. The files are used to define the
Packit f0b94e
# exports from NSS shared libraries, with -DEFFILE on Windows, a linker
Packit f0b94e
# script on Linux, or with -exported_symbols_list on OS X.
Packit f0b94e
#
Packit f0b94e
# The NSS build system processes them using a series of sed replacements,
Packit f0b94e
# but the Mozilla build system is already running a Python script to generate
Packit f0b94e
# the file so it's simpler to just do the replacement in Python.
Packit f0b94e
#
Packit f0b94e
# One difference between the NSS build system and Mozilla's is that
Packit f0b94e
# Mozilla's supports building on Linux for Windows using MinGW. MinGW
Packit f0b94e
# expects all lines containing ;+ removed and all ;- tokens removed.
Packit f0b94e
Packit f0b94e
import buildconfig
Packit f0b94e
Packit f0b94e
Packit f0b94e
def main(output, input):
Packit f0b94e
    is_darwin = buildconfig.substs['OS_ARCH'] == 'Darwin'
Packit f0b94e
    is_mingw = "WINNT" == buildconfig.substs['OS_ARCH'] and buildconfig.substs['GCC_USE_GNU_LD']
Packit f0b94e
Packit f0b94e
    with open(input, 'rb') as f:
Packit f0b94e
        for line in f:
Packit f0b94e
            line = line.rstrip()
Packit f0b94e
            # On everything except MinGW, remove all lines containing ';-'
Packit f0b94e
            if not is_mingw and ';-' in line:
Packit f0b94e
                continue
Packit f0b94e
            # On OS X, remove all lines containing ';+'
Packit f0b94e
            if is_darwin and ';+' in line:
Packit f0b94e
                continue
Packit f0b94e
            # Remove the string ' DATA '.
Packit f0b94e
            line = line.replace(' DATA ', '')
Packit f0b94e
            # Remove the string ';+'
Packit f0b94e
            if not is_mingw:
Packit f0b94e
                line = line.replace(';+', '')
Packit f0b94e
            # Remove the string ';;'
Packit f0b94e
            line = line.replace(';;', '')
Packit f0b94e
            # If a ';' is present, remove everything after it,
Packit f0b94e
            # and on OS X, remove it as well.
Packit f0b94e
            i = line.find(';')
Packit f0b94e
            if i != -1:
Packit f0b94e
                if is_darwin or is_mingw:
Packit f0b94e
                    line = line[:i]
Packit f0b94e
                else:
Packit f0b94e
                    line = line[:i+1]
Packit f0b94e
            # On OS X, symbols get an underscore in front.
Packit f0b94e
            if line and is_darwin:
Packit f0b94e
                output.write('_')
Packit f0b94e
            output.write(line)
Packit f0b94e
            output.write('\n')