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