--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/releasing/blocks/framework/src/SymbianUtils/Readelf.py Thu Sep 02 15:02:14 2010 +0800
@@ -0,0 +1,63 @@
+#
+# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+# All rights reserved.
+# This component and the accompanying materials are made available
+# under the terms of "Eclipse Public License v1.0"
+# which accompanies this distribution, and is available
+# at the URL "http://www.eclipse.org/legal/epl-v10.html".
+#
+# Initial Contributors:
+# Nokia Corporation - initial contribution.
+#
+# Contributors:
+#
+# Description:
+# Extract library API from ELF-files
+#
+
+import os
+import sys
+import re
+
+from SymbianUtils import SymbianUtilsError
+
+class Readelf(object):
+ '''
+ Methods for extracting a library API. Blocks.Packaging.ComponentBuilder.Rule
+ and Blocks.Packaging.PackageModel.API make use of Readelf.
+ '''
+ class ConfigurationError(SymbianUtilsError):
+ ''' Missing required binaries '''
+
+ class Failed(SymbianUtilsError):
+ ''' The external binary returned an error '''
+
+ if sys.platform == "win32":
+ readelf = os.path.normpath(os.path.join(os.path.dirname(__file__), "bin", "readelf.exe"))
+ elif "linux" in sys.platform:
+ readelf = "/usr/bin/readelf"
+
+ if not os.path.isfile(readelf):
+ raise ConfigurationError, "Cannot find readelf command (%s)" % readelf
+
+ @classmethod
+ def getInterface(cls, path):
+ '''
+
+ @param path: The file to inspect
+ @return: The interface - relevant parts from the symbol table as read from file by I{readelf}
+ @rtype: Dictionary
+ '''
+ path = os.path.normpath(path)
+ api = {}
+ binary = cls.readelf + " -Ws " + path + " 2>&1"
+ rex = re.compile(r'^\s*(\d+):\s+\d+\s+\d+\s+FUNC\s+GLOBAL\s+DEFAULT\s+\d+\s+(.*)@@.*')
+ fo = os.popen(binary, "r", -1)
+ for line in fo:
+ match = rex.search(line)
+ if match:
+ api[match.group(1)] = match.group(2)
+ if fo.close():
+ # "Not an ELF file", "No such file", etc.
+ raise cls.Failed("readelf unable to get interface for '%s': %s" % (path, line.strip()))
+ return api
\ No newline at end of file