2006-10-31 09:44:31 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
defcheck.py -- Consistency check for the .def files.
|
|
|
|
Copyright (C) 2006 Simon Budig <simon@gimp.org>
|
|
|
|
|
2009-01-18 06:28:01 +08:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
2006-10-31 09:44:31 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2006-10-31 09:44:31 +08:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-10-31 09:44:31 +08:00
|
|
|
|
|
|
|
|
2007-05-06 21:12:25 +08:00
|
|
|
This is a hack to check the consistency of the .def files compared to
|
|
|
|
the respective libraries.
|
2006-10-31 09:44:31 +08:00
|
|
|
|
2007-05-06 21:12:25 +08:00
|
|
|
Invoke in the top level of the gimp source tree after compiling GIMP.
|
|
|
|
If srcdir != builddir, run it in the build directory and pass the name
|
|
|
|
of the source directory on the command-line.
|
|
|
|
|
|
|
|
Needs the tool "nm" to work
|
2006-10-31 09:44:31 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2006-11-09 05:42:32 +08:00
|
|
|
import sys, commands
|
|
|
|
|
2007-05-06 21:12:25 +08:00
|
|
|
from os import path
|
|
|
|
|
2006-11-09 05:42:32 +08:00
|
|
|
def_files = (
|
|
|
|
"libgimpbase/gimpbase.def",
|
|
|
|
"libgimpcolor/gimpcolor.def",
|
|
|
|
"libgimpconfig/gimpconfig.def",
|
|
|
|
"libgimp/gimp.def",
|
|
|
|
"libgimp/gimpui.def",
|
|
|
|
"libgimpmath/gimpmath.def",
|
|
|
|
"libgimpmodule/gimpmodule.def",
|
|
|
|
"libgimpthumb/gimpthumb.def",
|
|
|
|
"libgimpwidgets/gimpwidgets.def"
|
|
|
|
)
|
|
|
|
|
2006-11-09 06:47:44 +08:00
|
|
|
have_errors = 0
|
|
|
|
|
2007-05-06 21:12:25 +08:00
|
|
|
srcdir = None
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
srcdir = sys.argv[1]
|
|
|
|
if not path.exists(srcdir):
|
|
|
|
print "Directory '%s' does not exist" % srcdir
|
|
|
|
sys.exit (-1)
|
|
|
|
|
2006-11-09 05:42:32 +08:00
|
|
|
for df in def_files:
|
2007-05-06 21:12:25 +08:00
|
|
|
directory, name = path.split (df)
|
|
|
|
basename, extension = name.split (".")
|
|
|
|
libname = path.join(directory, ".libs", "lib" + basename + "-*.so")
|
2006-10-31 09:44:31 +08:00
|
|
|
|
2007-05-06 21:12:25 +08:00
|
|
|
filename = df
|
|
|
|
if srcdir:
|
|
|
|
filename = path.join(srcdir, df)
|
2006-11-09 05:42:32 +08:00
|
|
|
try:
|
2007-05-06 21:12:25 +08:00
|
|
|
defsymbols = file (filename).read ().split ()[1:]
|
2006-11-09 05:42:32 +08:00
|
|
|
except IOError, message:
|
|
|
|
print message
|
2007-05-06 21:12:25 +08:00
|
|
|
if not srcdir:
|
|
|
|
print "You should run this script from the toplevel source directory."
|
2006-11-09 05:42:32 +08:00
|
|
|
sys.exit (-1)
|
2006-10-31 09:44:31 +08:00
|
|
|
|
|
|
|
doublesymbols = []
|
|
|
|
for i in range (len (defsymbols)-1, 0, -1):
|
2006-11-09 06:47:44 +08:00
|
|
|
if defsymbols[i] in defsymbols[:i]:
|
2006-10-31 09:44:31 +08:00
|
|
|
doublesymbols.append ((defsymbols[i], i+2))
|
|
|
|
|
|
|
|
unsortindex = -1
|
2006-10-31 16:54:14 +08:00
|
|
|
for i in range (len (defsymbols)-1):
|
|
|
|
if defsymbols[i] > defsymbols[i+1]:
|
|
|
|
unsortindex = i+1
|
2006-10-31 09:44:31 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
status, nm = commands.getstatusoutput ("nm --defined-only --extern-only " +
|
|
|
|
libname)
|
|
|
|
if status != 0:
|
|
|
|
print "trouble reading %s - has it been compiled?" % libname
|
|
|
|
continue
|
|
|
|
|
|
|
|
nmsymbols = nm.split()[2::3]
|
|
|
|
nmsymbols = [s for s in nmsymbols if s[0] != '_']
|
|
|
|
|
|
|
|
missing_defs = [s for s in nmsymbols if s not in defsymbols]
|
|
|
|
missing_nms = [s for s in defsymbols if s not in nmsymbols]
|
|
|
|
|
|
|
|
if unsortindex >= 0 or missing_defs or missing_nms or doublesymbols:
|
|
|
|
print
|
2007-05-06 21:12:25 +08:00
|
|
|
print "Problem found in", filename
|
2006-10-31 09:44:31 +08:00
|
|
|
|
|
|
|
if missing_defs:
|
|
|
|
print " the following symbols are in the library,"
|
|
|
|
print " but are not listed in the .def-file:"
|
|
|
|
for s in missing_defs:
|
|
|
|
print " +", s
|
|
|
|
print
|
|
|
|
|
|
|
|
if missing_nms:
|
|
|
|
print " the following symbols are listed in the .def-file,"
|
|
|
|
print " but are not exported by the library."
|
|
|
|
for s in missing_nms:
|
|
|
|
print " -", s
|
|
|
|
print
|
|
|
|
|
|
|
|
if doublesymbols:
|
|
|
|
print " the following symbols are listed multiple times in the .def-file,"
|
|
|
|
for s in doublesymbols:
|
|
|
|
print " : %s (line %d)" % s
|
|
|
|
print
|
2008-09-04 16:37:32 +08:00
|
|
|
|
2006-10-31 09:44:31 +08:00
|
|
|
if unsortindex >= 0:
|
|
|
|
print " the .def-file is not properly sorted (line %d)" % (unsortindex + 2)
|
|
|
|
print
|
|
|
|
|
2006-11-09 06:47:44 +08:00
|
|
|
have_errors = -1
|
2006-11-08 06:21:39 +08:00
|
|
|
|
2006-11-09 06:47:44 +08:00
|
|
|
sys.exit (have_errors)
|