diff options
| -rw-r--r-- | lldb/scripts/Python/buildSwigPython.py | 1452 | ||||
| -rw-r--r-- | lldb/scripts/Python/finishSwigPythonLLDB.py | 658 | ||||
| -rw-r--r-- | lldb/scripts/Python/modify-python-lldb.py | 2 | ||||
| -rw-r--r-- | lldb/scripts/buildSwigWrapperClasses.py | 406 | ||||
| -rw-r--r-- | lldb/scripts/finishSwigWrapperClasses.py | 225 | ||||
| -rw-r--r-- | lldb/scripts/utilsArgsParse.py | 248 | ||||
| -rw-r--r-- | lldb/scripts/utilsDebug.py | 215 | ||||
| -rw-r--r-- | lldb/scripts/utilsOsType.py | 36 | 
8 files changed, 1614 insertions, 1628 deletions
diff --git a/lldb/scripts/Python/buildSwigPython.py b/lldb/scripts/Python/buildSwigPython.py index 59c73591510..493c397008e 100644 --- a/lldb/scripts/Python/buildSwigPython.py +++ b/lldb/scripts/Python/buildSwigPython.py @@ -1,798 +1,794 @@  """ Python SWIG wrapper creation script Windows/LINUX/OSX platform -	-------------------------------------------------------------------------- -	File:			buildSwigPython.py - -	Overview: 		Creates SWIG Python C++ Script Bridge wrapper code. This -					script is called by build-swig-wrapper-classes.py in turn. -					 -	Gotchas:		Python debug complied pythonXX_d.lib is required for SWIG -					to build correct LLDBWrapperPython.cpp in order for Visual -					Studio to compile successfully. The release version of the  -					Python lib will not work.  -					LLDB (dir) CMakeLists.txt uses windows environmental -					variables $PYTHON_INCLUDE and $PYTHON_LIB to locate -					Python files required for the build. - -	Copyright:		None. -	-------------------------------------------------------------------------- -	 +    -------------------------------------------------------------------------- +    File:      buildSwigPython.py + +    Overview:  Creates SWIG Python C++ Script Bridge wrapper code. This +               script is called by build-swig-wrapper-classes.py in turn. + +    Gotchas:   Python debug complied pythonXX_d.lib is required for SWIG +               to build correct LLDBWrapperPython.cpp in order for Visual +               Studio to compile successfully. The release version of the +               Python lib will not work. +               LLDB (dir) CMakeLists.txt uses windows environmental +               variables $PYTHON_INCLUDE and $PYTHON_LIB to locate +               Python files required for the build. + +    Copyright: None. +    -------------------------------------------------------------------------- +  """  # Python modules: -import os			# Provide directory and file handling, determine OS information -import sys			# sys.executable -import time			# Time access and conversions -import subprocess 	# Call external programs -import shutil		# File handling +import os         # Provide directory and file handling, determine OS information +import sys        # sys.executable +import subprocess # Call external programs +import shutil     # File handling  # Third party modules:  # In-house modules: -import utilsOsType	# Determine the OS type this script is running on -import utilsDebug 	# Debug Python scripts +import utilsOsType # Determine the OS type this script is running on +import utilsDebug  # Debug Python scripts  # User facing text:  strMsgLldbDisablePythonEnv = "Python build aborted as LLDB_DISABLE_PYTHON \ -environmental variable is defined"; +environmental variable is defined"  strMsgLldbDisableGccEnv = "Python build aborted as GCC_PREPROCESSOR_DEFINITIONS \ -environmental variable is defined"; -strMsgHdrFiles = "Header files are:"; -strMsgIFaceFiles = "SWIG interface files are"; -strErrMsgProgFail = "Program failure: ";      -strMsgFileNewrSwigOpFile = "\'%s\' is newer than \'%s\'\nSWIG file will need to be re-built"; -strMsgFileNotExist = "\'%s\' could not be found\nSWIG file will need to be re-built"; -strErrMsgOsTypeUnknown = "Unable to determine current OS type"; -strMsgNotNeedUpdate = "Everything is up-to-date"; -strMsgSwigNeedRebuild = "SWIG needs to be re-run"; +environmental variable is defined" +strMsgHdrFiles = "Header files are:" +strMsgIFaceFiles = "SWIG interface files are" +strErrMsgProgFail = "Program failure: " +strMsgFileNewrSwigOpFile = "\'%s\' is newer than \'%s\'\nSWIG file will need to be re-built" +strMsgFileNotExist = "\'%s\' could not be found\nSWIG file will need to be re-built" +strErrMsgOsTypeUnknown = "Unable to determine current OS type" +strMsgNotNeedUpdate = "Everything is up-to-date" +strMsgSwigNeedRebuild = "SWIG needs to be re-run"  strErrMsgSwigParamsMissing = "This script was not passed either '--swigExePath \ -or the '--swigExeName' argument. Both are required."; -strMsgSwigExecute = "SWIG executing the following:\n\'%s'"; -strErrMsgSwigExecute = "SWIG failed: %s"; -strErrMsgPythonExecute = "Python script '%s' failed: %s"; -strMsgSwigNoGenDep = "SWIG ran with no generated dependencies, script exit early"; -strMsgSwigGenDep = "SWIG ran and generated dependencies, script exit early, deleted '%s'"; -strErrMsgFrameWkPyDirNotExist = "Unable to find the LLDB. Framework directory is '%s'"; -strMsgFoundLldbFrameWkDir = "Found '%s'"; -strErrMsgModifyPythonLldbPyFileNotFound = "Unable to find '%s' in '%s'"; +or the '--swigExeName' argument. Both are required." +strMsgSwigExecute = "SWIG executing the following:\n\'%s'" +strErrMsgSwigExecute = "SWIG failed: %s" +strErrMsgPythonExecute = "Python script '%s' failed: %s" +strMsgSwigNoGenDep = "SWIG ran with no generated dependencies, script exit early" +strMsgSwigGenDep = "SWIG ran and generated dependencies, script exit early, deleted '%s'" +strErrMsgFrameWkPyDirNotExist = "Unable to find the LLDB. Framework directory is '%s'" +strMsgFoundLldbFrameWkDir = "Found '%s'" +strErrMsgModifyPythonLldbPyFileNotFound = "Unable to find '%s' in '%s'"  #++--------------------------------------------------------------------------- -# Details:	Retrieve the list of hard coded lldb header file names and -#			put in the program's dictArgs map container. Make paths compatible -#			with the current OS.  -#			Note this does not necessarily match the content of those  -#			directories. The resultant header string is inserted into the  -#			dictionary vDictArgs key "--headerFiles". -# Args:		vDictArgs	- (RW) Program input parameters. -# Returns:	Bool		- True = success, False = failure. -# Throws:	None. +# Details: Retrieve the list of hard coded lldb header file names and +#          put in the program's dictArgs map container. Make paths compatible +#          with the current OS. +#          Note this does not necessarily match the content of those +#          directories. The resultant header string is inserted into the +#          dictionary vDictArgs key "--headerFiles". +# Args:    vDictArgs - (RW) Program input parameters. +# Returns: Bool - True = success, False = failure. +# Throws: None.  #-- -def get_header_files( vDictArgs ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script get_header_files()" ); -	listHeaderFiles = [ "/include/lldb/API/lldb.h", # .sh has /include/lldb/lldb.h 21/11/2013 -						"/include/lldb/lldb-defines.h", -						"/include/lldb/lldb-enumerations.h", -						"/include/lldb/lldb-forward.h", -						"/include/lldb/lldb-forward-rtti.h", -						"/include/lldb/lldb-types.h", -						"/include/lldb/API/SBAddress.h", -            "/include/lldb/API/SBAttachInfo.h", -						"/include/lldb/API/SBBlock.h", -						"/include/lldb/API/SBBreakpoint.h", -						"/include/lldb/API/SBBreakpointLocation.h", -						"/include/lldb/API/SBBroadcaster.h", -						"/include/lldb/API/SBCommandInterpreter.h", -						"/include/lldb/API/SBCommandReturnObject.h", -						"/include/lldb/API/SBCommunication.h", -						"/include/lldb/API/SBCompileUnit.h", -						"/include/lldb/API/SBData.h", -						"/include/lldb/API/SBDebugger.h", -						"/include/lldb/API/SBError.h", -						"/include/lldb/API/SBEvent.h", -						"/include/lldb/API/SBExpressionOptions.h", -						"/include/lldb/API/SBFileSpec.h", -						"/include/lldb/API/SBFrame.h", -						"/include/lldb/API/SBFunction.h", -						"/include/lldb/API/SBHostOS.h", -						"/include/lldb/API/SBInputReader.h", -						"/include/lldb/API/SBInstruction.h", -						"/include/lldb/API/SBInstructionList.h", -						"/include/lldb/API/SBLanguageRuntime.h", -						"/include/lldb/API/SBLaunchInfo.h", -						"/include/lldb/API/SBLineEntry.h", -						"/include/lldb/API/SBListener.h", -						"/include/lldb/API/SBModule.h", -						"/include/lldb/API/SBModuleSpec.h", -						"/include/lldb/API/SBProcess.h", -						"/include/lldb/API/SBSourceManager.h", -						"/include/lldb/API/SBStream.h", -						"/include/lldb/API/SBStringList.h", -						"/include/lldb/API/SBSymbol.h", -						"/include/lldb/API/SBSymbolContext.h", -						"/include/lldb/API/SBSymbolContextList.h", -						"/include/lldb/API/SBTarget.h", -						"/include/lldb/API/SBThread.h", -						"/include/lldb/API/SBThreadCollection.h", -						"/include/lldb/API/SBType.h", -						"/include/lldb/API/SBTypeCategory.h", -						"/include/lldb/API/SBTypeFilter.h", -						"/include/lldb/API/SBTypeFormat.h", -						"/include/lldb/API/SBTypeNameSpecifier.h", -						"/include/lldb/API/SBTypeSummary.h", -						"/include/lldb/API/SBTypeSynthetic.h", -						"/include/lldb/API/SBValue.h", -						"/include/lldb/API/SBValueList.h", -						"/include/lldb/API/SBWatchpoint.h" ]; -	bDebug = "-d" in vDictArgs; -	strRt = vDictArgs[ "--srcRoot" ]; -	strRt = os.path.normcase( strRt ); -	 -	strHeaderFiles = ""; -	for strHdr in listHeaderFiles[ 0: len( listHeaderFiles ) ]: -		strHdr = os.path.normcase( strHdr ); -		strHeaderFiles += " %s%s" % (strRt, strHdr); -	 -	if bDebug: -		print(strMsgHdrFiles); -		print(strHeaderFiles); -		 -	vDictArgs[ "--headerFiles" ] = strHeaderFiles; -	 -	return True; +def get_header_files(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_header_files()") +    listHeaderFiles = ["/include/lldb/API/lldb.h", # .sh has /include/lldb/lldb.h 21/11/2013 +                       "/include/lldb/lldb-defines.h", +                       "/include/lldb/lldb-enumerations.h", +                       "/include/lldb/lldb-forward.h", +                       "/include/lldb/lldb-forward-rtti.h", +                       "/include/lldb/lldb-types.h", +                       "/include/lldb/API/SBAddress.h", +                       "/include/lldb/API/SBAttachInfo.h", +                       "/include/lldb/API/SBBlock.h", +                       "/include/lldb/API/SBBreakpoint.h", +                       "/include/lldb/API/SBBreakpointLocation.h", +                       "/include/lldb/API/SBBroadcaster.h", +                       "/include/lldb/API/SBCommandInterpreter.h", +                       "/include/lldb/API/SBCommandReturnObject.h", +                       "/include/lldb/API/SBCommunication.h", +                       "/include/lldb/API/SBCompileUnit.h", +                       "/include/lldb/API/SBData.h", +                       "/include/lldb/API/SBDebugger.h", +                       "/include/lldb/API/SBError.h", +                       "/include/lldb/API/SBEvent.h", +                       "/include/lldb/API/SBExpressionOptions.h", +                       "/include/lldb/API/SBFileSpec.h", +                       "/include/lldb/API/SBFrame.h", +                       "/include/lldb/API/SBFunction.h", +                       "/include/lldb/API/SBHostOS.h", +                       "/include/lldb/API/SBInputReader.h", +                       "/include/lldb/API/SBInstruction.h", +                       "/include/lldb/API/SBInstructionList.h", +                       "/include/lldb/API/SBLanguageRuntime.h", +                       "/include/lldb/API/SBLaunchInfo.h", +                       "/include/lldb/API/SBLineEntry.h", +                       "/include/lldb/API/SBListener.h", +                       "/include/lldb/API/SBModule.h", +                       "/include/lldb/API/SBModuleSpec.h", +                       "/include/lldb/API/SBProcess.h", +                       "/include/lldb/API/SBSourceManager.h", +                       "/include/lldb/API/SBStream.h", +                       "/include/lldb/API/SBStringList.h", +                       "/include/lldb/API/SBSymbol.h", +                       "/include/lldb/API/SBSymbolContext.h", +                       "/include/lldb/API/SBSymbolContextList.h", +                       "/include/lldb/API/SBTarget.h", +                       "/include/lldb/API/SBThread.h", +                       "/include/lldb/API/SBThreadCollection.h", +                       "/include/lldb/API/SBType.h", +                       "/include/lldb/API/SBTypeCategory.h", +                       "/include/lldb/API/SBTypeFilter.h", +                       "/include/lldb/API/SBTypeFormat.h", +                       "/include/lldb/API/SBTypeNameSpecifier.h", +                       "/include/lldb/API/SBTypeSummary.h", +                       "/include/lldb/API/SBTypeSynthetic.h", +                       "/include/lldb/API/SBValue.h", +                       "/include/lldb/API/SBValueList.h", +                       "/include/lldb/API/SBWatchpoint.h"] +    bDebug = "-d" in vDictArgs +    strRt = vDictArgs["--srcRoot"] +    strRt = os.path.normcase(strRt) + +    strHeaderFiles = "" +    for strHdr in listHeaderFiles[0: len(listHeaderFiles)]: +        strHdr = os.path.normcase(strHdr) +        strHeaderFiles += " %s%s" % (strRt, strHdr) + +    if bDebug: +        print(strMsgHdrFiles) +        print(strHeaderFiles) + +    vDictArgs["--headerFiles"] = strHeaderFiles + +    return True  #++--------------------------------------------------------------------------- -# Details:	Retrieve the list of hard coded lldb SWIG interface file names and -#			put in the program's dictArgs map container. Make paths compatible -#			with the current OS.  -#			Note this does not necessarily match the content of those  -#			directories. The resultant interface string is inserted into the  -#			dictionary vDictArgs key "--ifaceFiles". -# Args:		vDictArgs	- (RW) Program input parameters. -# Returns:	Bool		- True = success, False = failure. -# Throws:	None. +# Details: Retrieve the list of hard coded lldb SWIG interface file names and +#          put in the program's dictArgs map container. Make paths compatible +#          with the current OS. +#          Note this does not necessarily match the content of those +#          directories. The resultant interface string is inserted into the +#          dictionary vDictArgs key "--ifaceFiles". +# Args:    vDictArgs - (RW) Program input parameters. +# Returns: Bool - True = success, False = failure. +# Throws:  None.  #-- -def get_interface_files( vDictArgs ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script get_interface_files()" ); -	listIFaceFiles = [ 	"/scripts/interface/SBAddress.i", -            "/scripts/interface/SBAttachInfo.i", -						"/scripts/interface/SBBlock.i", -						"/scripts/interface/SBBreakpoint.i", -						"/scripts/interface/SBBreakpointLocation.i", -						"/scripts/interface/SBBroadcaster.i", -						"/scripts/interface/SBCommandInterpreter.i", -						"/scripts/interface/SBCommandReturnObject.i", -						"/scripts/interface/SBCommunication.i", -						"/scripts/interface/SBCompileUnit.i", -						"/scripts/interface/SBData.i", -						"/scripts/interface/SBDebugger.i", -						"/scripts/interface/SBDeclaration.i", -						"/scripts/interface/SBError.i", -						"/scripts/interface/SBEvent.i", -						"/scripts/interface/SBExpressionOptions.i", -						"/scripts/interface/SBFileSpec.i", -						"/scripts/interface/SBFrame.i", -						"/scripts/interface/SBFunction.i", -						"/scripts/interface/SBHostOS.i", -						"/scripts/interface/SBInputReader.i", -						"/scripts/interface/SBInstruction.i", -						"/scripts/interface/SBInstructionList.i", -						"/scripts/interface/SBLanguageRuntime.i", -						"/scripts/interface/SBLaunchInfo.i", -						"/scripts/interface/SBLineEntry.i", -						"/scripts/interface/SBListener.i", -						"/scripts/interface/SBModule.i", -						"/scripts/interface/SBModuleSpec.i", -						"/scripts/interface/SBProcess.i", -						"/scripts/interface/SBSourceManager.i", -						"/scripts/interface/SBStream.i", -						"/scripts/interface/SBStringList.i", -						"/scripts/interface/SBSymbol.i", -						"/scripts/interface/SBSymbolContext.i", -						"/scripts/interface/SBTarget.i", -						"/scripts/interface/SBThread.i", -						"/scripts/interface/SBThreadCollection.i", -						"/scripts/interface/SBType.i", -						"/scripts/interface/SBTypeCategory.i", -						"/scripts/interface/SBTypeFilter.i", -						"/scripts/interface/SBTypeFormat.i", -						"/scripts/interface/SBTypeNameSpecifier.i", -						"/scripts/interface/SBTypeSummary.i", -						"/scripts/interface/SBTypeSynthetic.i", -						"/scripts/interface/SBValue.i", -						"/scripts/interface/SBValueList.i", -						"/scripts/interface/SBWatchpoint.i" ];	 -	bDebug = "-d" in vDictArgs; -	strRt = vDictArgs[ "--srcRoot" ]; -	strRt = os.path.normcase( strRt ); -	 -	strInterfaceFiles = ""; -	for strIFace in listIFaceFiles[ 0: len( listIFaceFiles ) ]: -		strIFace = os.path.normcase( strIFace ); -		strInterfaceFiles += " %s%s" % (strRt, strIFace); -	 -	if bDebug: -		print(strMsgIFaceFiles); -		print(strInterfaceFiles); -	 -	vDictArgs[ "--ifaceFiles" ] = strInterfaceFiles; -		 -	return True; +def get_interface_files(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_interface_files()") +    listIFaceFiles = ["/scripts/interface/SBAddress.i", +                      "/scripts/interface/SBAttachInfo.i", +                      "/scripts/interface/SBBlock.i", +                      "/scripts/interface/SBBreakpoint.i", +                      "/scripts/interface/SBBreakpointLocation.i", +                      "/scripts/interface/SBBroadcaster.i", +                      "/scripts/interface/SBCommandInterpreter.i", +                      "/scripts/interface/SBCommandReturnObject.i", +                      "/scripts/interface/SBCommunication.i", +                      "/scripts/interface/SBCompileUnit.i", +                      "/scripts/interface/SBData.i", +                      "/scripts/interface/SBDebugger.i", +                      "/scripts/interface/SBDeclaration.i", +                      "/scripts/interface/SBError.i", +                      "/scripts/interface/SBEvent.i", +                      "/scripts/interface/SBExpressionOptions.i", +                      "/scripts/interface/SBFileSpec.i", +                      "/scripts/interface/SBFrame.i", +                      "/scripts/interface/SBFunction.i", +                      "/scripts/interface/SBHostOS.i", +                      "/scripts/interface/SBInputReader.i", +                      "/scripts/interface/SBInstruction.i", +                      "/scripts/interface/SBInstructionList.i", +                      "/scripts/interface/SBLanguageRuntime.i", +                      "/scripts/interface/SBLaunchInfo.i", +                      "/scripts/interface/SBLineEntry.i", +                      "/scripts/interface/SBListener.i", +                      "/scripts/interface/SBModule.i", +                      "/scripts/interface/SBModuleSpec.i", +                      "/scripts/interface/SBProcess.i", +                      "/scripts/interface/SBSourceManager.i", +                      "/scripts/interface/SBStream.i", +                      "/scripts/interface/SBStringList.i", +                      "/scripts/interface/SBSymbol.i", +                      "/scripts/interface/SBSymbolContext.i", +                      "/scripts/interface/SBTarget.i", +                      "/scripts/interface/SBThread.i", +                      "/scripts/interface/SBThreadCollection.i", +                      "/scripts/interface/SBType.i", +                      "/scripts/interface/SBTypeCategory.i", +                      "/scripts/interface/SBTypeFilter.i", +                      "/scripts/interface/SBTypeFormat.i", +                      "/scripts/interface/SBTypeNameSpecifier.i", +                      "/scripts/interface/SBTypeSummary.i", +                      "/scripts/interface/SBTypeSynthetic.i", +                      "/scripts/interface/SBValue.i", +                      "/scripts/interface/SBValueList.i", +                      "/scripts/interface/SBWatchpoint.i"] +    bDebug = "-d" in vDictArgs +    strRt = vDictArgs["--srcRoot"] +    strRt = os.path.normcase(strRt) + +    strInterfaceFiles = "" +    for strIFace in listIFaceFiles[0: len(listIFaceFiles)]: +        strIFace = os.path.normcase(strIFace) +        strInterfaceFiles += " %s%s" % (strRt, strIFace) + +    if bDebug: +        print(strMsgIFaceFiles) +        print(strInterfaceFiles) + +    vDictArgs["--ifaceFiles"] = strInterfaceFiles + +    return True  #++--------------------------------------------------------------------------- -# Details:	Compare which file is newer. -# Args:		vFile1	- (R) File name path. -#			vFile2 	- (R) File name path. -# Returns:	Int	- 0 = both not exist, 1 = file 1 newer, 2 = file 2 newer, -#			3 = file 1 not exist. -# Throws:	None. +# Details: Compare which file is newer. +# Args:    vFile1 - (R) File name path. +#          vFile2 - (R) File name path. +# Returns: Int - 0 = both not exist, 1 = file 1 newer, 2 = file 2 newer, +#          3 = file 1 not exist. +# Throws:  None.  #-- -def which_file_is_newer( vFile1, vFile2 ): -	bF1 = os.path.exists( vFile1 ); -	bF2	= os.path.exists( vFile2 ); -	if bF1 == False and bF2 == False: -		return 0; # Both files not exist -	if bF1 == False: -		return 3; # File 1 not exist -	if bF2 == False: -		return 1; # File 1 is newer / file 2 not exist -	f1Stamp = os.path.getmtime( vFile1 ); -	f2Stamp = os.path.getmtime( vFile2 ); -	if f1Stamp > f2Stamp: -		return 1; # File 1 is newer  -		 -	return 2; # File 2 is newer than file 1  -		 +def which_file_is_newer(vFile1, vFile2): +    bF1 = os.path.exists(vFile1) +    bF2 = os.path.exists(vFile2) +    if bF1 == False and bF2 == False: +        return 0 # Both files not exist +    if bF1 == False: +        return 3 # File 1 not exist +    if bF2 == False: +        return 1 # File 1 is newer / file 2 not exist +    f1Stamp = os.path.getmtime(vFile1) +    f2Stamp = os.path.getmtime(vFile2) +    if f1Stamp > f2Stamp: +        return 1 # File 1 is newer + +    return 2 # File 2 is newer than file 1 +  #++--------------------------------------------------------------------------- -# Details:	Determine whether the specified file exists. -# Args:		vDictArgs			- (R) Program input parameters. -#			vstrFileNamePath	- (R) Check this file exists. -# Returns:	Bool	- True = Files exists, false = not found. -# Throws:	None. +# Details: Determine whether the specified file exists. +# Args:    vDictArgs - (R) Program input parameters. +#          vstrFileNamePath - (R) Check this file exists. +# Returns: Bool - True = Files exists, false = not found. +# Throws:  None.  #-- -def check_file_exists( vDictArgs, vstrFileNamePath ): -	bExists = False; -	bDebug = "-d" in vDictArgs; -	 -	if os.path.exists( vstrFileNamePath ): -		bExists = True; -	elif bDebug: -		print((strMsgFileNotExist % vstrFileNamePath)); -	 -	return bExists; +def check_file_exists(vDictArgs, vstrFileNamePath): +    bExists = False +    bDebug = "-d" in vDictArgs + +    if os.path.exists(vstrFileNamePath): +        bExists = True +    elif bDebug: +        print((strMsgFileNotExist % vstrFileNamePath)) + +    return bExists  #++--------------------------------------------------------------------------- -# Details:	Determine whether the specified file is newer than the  -#			LLDBWrapPython.cpp file. -# Args:		vDictArgs				- (R) Program input parameters. -#			vstrSwigOpFileNamePath	- (R) LLDBWrapPython.cpp file. -#			vstrFileNamePath		- (R) Specific file. -# Returns:	Bool	- True = SWIG update required, false = no update required. -# Throws:	None. +# Details: Determine whether the specified file is newer than the +#          LLDBWrapPython.cpp file. +# Args:    vDictArgs - (R) Program input parameters. +#          vstrSwigOpFileNamePath - (R) LLDBWrapPython.cpp file. +#          vstrFileNamePath - (R) Specific file. +# Returns: Bool - True = SWIG update required, false = no update required. +# Throws:  None.  #-- -def check_newer_file( vDictArgs, vstrSwigOpFileNamePath, vstrFileNamePath ): -	bNeedUpdate = False; -	bDebug = "-d" in vDictArgs; -	 -	strMsg = ""; -	nResult = which_file_is_newer( vstrFileNamePath, vstrSwigOpFileNamePath ); -	if nResult == 1: -		strMsg = strMsgFileNewrSwigOpFile % (vstrFileNamePath,  -											 vstrSwigOpFileNamePath); -		bNeedUpdate = True; -	elif nResult == 3: -		strMsg = strMsgFileNotExist % vstrFileNamePath; -		bNeedUpdate = True; -	 -	if bNeedUpdate and bDebug: -		print(strMsg); -	 -	return bNeedUpdate; +def check_newer_file(vDictArgs, vstrSwigOpFileNamePath, vstrFileNamePath): +    bNeedUpdate = False +    bDebug = "-d" in vDictArgs + +    strMsg = "" +    nResult = which_file_is_newer(vstrFileNamePath, vstrSwigOpFileNamePath) +    if nResult == 1: +        strMsg = strMsgFileNewrSwigOpFile % (vstrFileNamePath, +                                             vstrSwigOpFileNamePath) +        bNeedUpdate = True +    elif nResult == 3: +        strMsg = strMsgFileNotExist % vstrFileNamePath +        bNeedUpdate = True + +    if bNeedUpdate and bDebug: +        print(strMsg) + +    return bNeedUpdate  #++--------------------------------------------------------------------------- -# Details:	Determine whether the any files in the list are newer than the  -#			LLDBWrapPython.cpp file. -# Args:		vDictArgs				- (R) Program input parameters. -#			vstrSwigOpFileNamePath	- (R) LLDBWrapPython.cpp file. -#			vstrFiles				- (R) Multi string file names ' ' delimiter. -# Returns:	Bool	- True = SWIG update required, false = no update required. -# Throws:	None. +# Details: Determine whether the any files in the list are newer than the +#          LLDBWrapPython.cpp file. +# Args:    vDictArgs - (R) Program input parameters. +#          vstrSwigOpFileNamePath - (R) LLDBWrapPython.cpp file. +#          vstrFiles - (R) Multi string file names ' ' delimiter. +# Returns: Bool - True = SWIG update required, false = no update required. +# Throws:  None.  #-- -def check_newer_files( vDictArgs, vstrSwigOpFileNamePath, vstrFiles ): -	bNeedUpdate = False; -	  -	listFiles = vstrFiles.split(); -	for strFile in listFiles: -		if check_newer_file( vDictArgs, vstrSwigOpFileNamePath, strFile ): -			bNeedUpdate = True; -			break; -			 -	return bNeedUpdate; +def check_newer_files(vDictArgs, vstrSwigOpFileNamePath, vstrFiles): +    bNeedUpdate = False + +    listFiles = vstrFiles.split() +    for strFile in listFiles: +        if check_newer_file(vDictArgs, vstrSwigOpFileNamePath, strFile): +            bNeedUpdate = True +            break + +    return bNeedUpdate  #++--------------------------------------------------------------------------- -# Details:	Retrieve the directory path for Python's dist_packages/ -#			site_package folder on a Windows platform. -# Args:		vDictArgs	- (R) Program input parameters. -# Returns:	Bool - True = function success, False = failure. -#			Str	- Python Framework directory path. -#			strErrMsg - Error description on task failure. -# Throws:	None. +# Details: Retrieve the directory path for Python's dist_packages/ +#          site_package folder on a Windows platform. +# Args:    vDictArgs - (R) Program input parameters. +# Returns: Bool - True = function success, False = failure. +#          Str - Python Framework directory path. +#          strErrMsg - Error description on task failure. +# Throws:  None.  #-- -def get_framework_python_dir_windows( vDictArgs ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script get_framework_python_dir_windows()" ); -	bOk = True; -	strWkDir = ""; -	strErrMsg = ""; -	  -	# We are being built by LLVM, so use the PYTHON_INSTALL_DIR argument, -	# and append the python version directory to the end of it.  Depending  -	# on the system other stuff may need to be put here as well. -	from distutils.sysconfig import get_python_lib; -	strPythonInstallDir = ""; -	bHaveArgPrefix = "--prefix" in vDictArgs; -	if bHaveArgPrefix:  -		strPythonInstallDir = vDictArgs[ "--prefix" ]; -	if strPythonInstallDir.__len__() != 0: -		strWkDir = get_python_lib( True, False, strPythonInstallDir ); -	else: -		strWkDir = get_python_lib( True, False ); -	strWkDir += "/lldb"; -	strWkDir = os.path.normcase( strWkDir ); -	 -	return (bOk, strWkDir, strErrMsg); +def get_framework_python_dir_windows(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_framework_python_dir_windows()") +    bOk = True +    strWkDir = "" +    strErrMsg = "" + +    # We are being built by LLVM, so use the PYTHON_INSTALL_DIR argument, +    # and append the python version directory to the end of it.  Depending +    # on the system other stuff may need to be put here as well. +    from distutils.sysconfig import get_python_lib +    strPythonInstallDir = "" +    bHaveArgPrefix = "--prefix" in vDictArgs +    if bHaveArgPrefix: +        strPythonInstallDir = vDictArgs["--prefix"] +    if strPythonInstallDir.__len__() != 0: +        strWkDir = get_python_lib(True, False, strPythonInstallDir) +    else: +        strWkDir = get_python_lib(True, False) +    strWkDir += "/lldb" +    strWkDir = os.path.normcase(strWkDir) + +    return (bOk, strWkDir, strErrMsg)  #++--------------------------------------------------------------------------- -# Details:	Retrieve the directory path for Python's dist_packages/ -#			site_package folder on a UNIX style platform. -# Args:		vDictArgs	- (R) Program input parameters. -# Returns:	Bool - True = function success, False = failure. -#			Str	- Python Framework directory path. -#			strErrMsg - Error description on task failure. -# Throws:	None. +# Details: Retrieve the directory path for Python's dist_packages/ +#          site_package folder on a UNIX style platform. +# Args:    vDictArgs - (R) Program input parameters. +# Returns: Bool - True = function success, False = failure. +#          Str - Python Framework directory path. +#          strErrMsg - Error description on task failure. +# Throws:  None.  #-- -def get_framework_python_dir_other_platforms( vDictArgs ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script get_framework_python_dir_other_platform()" ); -	bOk = True; -	strWkDir = ""; -	strErrMsg = ""; -	bDbg = "-d" in vDictArgs; -	 -	bMakeFileCalled = "-m" in vDictArgs; -	if bMakeFileCalled: -		dbg.dump_text( "Built by LLVM" ); -		return get_framework_python_dir_windows( vDictArgs ); -	else: -		dbg.dump_text( "Built by XCode" ); -		# We are being built by XCode, so all the lldb Python files can go -		# into the LLDB.framework/Resources/Python subdirectory. -		strWkDir = vDictArgs[ "--targetDir" ]; -		strWkDir += "/LLDB.framework"; -		if os.path.exists( strWkDir ): -			if bDbg: -				print((strMsgFoundLldbFrameWkDir % strWkDir)); -			strWkDir += "/Resources/Python/lldb"; -			strWkDir = os.path.normcase( strWkDir ); -		else: -			bOk = False; -			strErrMsg = strErrMsgFrameWkPyDirNotExist % strWkDir;	 -	 -	return (bOk, strWkDir, strErrMsg); +def get_framework_python_dir_other_platforms(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_framework_python_dir_other_platform()") +    bOk = True +    strWkDir = "" +    strErrMsg = "" +    bDbg = "-d" in vDictArgs + +    bMakeFileCalled = "-m" in vDictArgs +    if bMakeFileCalled: +        dbg.dump_text("Built by LLVM") +        return get_framework_python_dir_windows(vDictArgs) +    else: +        dbg.dump_text("Built by XCode") +        # We are being built by XCode, so all the lldb Python files can go +        # into the LLDB.framework/Resources/Python subdirectory. +        strWkDir = vDictArgs["--targetDir"] +        strWkDir += "/LLDB.framework" +        if os.path.exists(strWkDir): +            if bDbg: +                print((strMsgFoundLldbFrameWkDir % strWkDir)) +            strWkDir += "/Resources/Python/lldb" +            strWkDir = os.path.normcase(strWkDir) +        else: +            bOk = False +            strErrMsg = strErrMsgFrameWkPyDirNotExist % strWkDir + +    return (bOk, strWkDir, strErrMsg)  #++--------------------------------------------------------------------------- -# Details:	Retrieve the directory path for Python's dist_packages/ -#			site_package folder depending on the type of OS platform being  -#			used. -# Args:		vDictArgs	- (R) Program input parameters. -# Returns:	Bool - True = function success, False = failure. -#			Str	- Python Framework directory path. -#			strErrMsg - Error description on task failure. -# Throws:	None. +# Details: Retrieve the directory path for Python's dist_packages/ +#          site_package folder depending on the type of OS platform being +#          used. +# Args:    vDictArgs - (R) Program input parameters. +# Returns: Bool - True = function success, False = failure. +#          Str - Python Framework directory path. +#          strErrMsg - Error description on task failure. +# Throws:  None.  #-- -def get_framework_python_dir( vDictArgs ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script get_framework_python_dir()" ); -	bOk = True; -	strWkDir = ""; -	strErrMsg = ""; -	  -	eOSType = utilsOsType.determine_os_type(); -	if eOSType == utilsOsType.EnumOsType.Unknown: -		bOk = False; -		strErrMsg = strErrMsgOsTypeUnknown; -	elif eOSType == utilsOsType.EnumOsType.Windows: -		bOk, strWkDir, strErrMsg = get_framework_python_dir_windows( vDictArgs ); -	else: -		bOk, strWkDir, strErrMsg = get_framework_python_dir_other_platforms( vDictArgs ); -			 -	return (bOk, strWkDir, strErrMsg); +def get_framework_python_dir(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_framework_python_dir()") +    bOk = True +    strWkDir = "" +    strErrMsg = "" + +    eOSType = utilsOsType.determine_os_type() +    if eOSType == utilsOsType.EnumOsType.Unknown: +        bOk = False +        strErrMsg = strErrMsgOsTypeUnknown +    elif eOSType == utilsOsType.EnumOsType.Windows: +        bOk, strWkDir, strErrMsg = get_framework_python_dir_windows(vDictArgs) +    else: +        bOk, strWkDir, strErrMsg = get_framework_python_dir_other_platforms(vDictArgs) + +    return (bOk, strWkDir, strErrMsg)  #++--------------------------------------------------------------------------- -# Details:	Retrieve the configuration build path if present and valid (using -#			parameter --cfgBlddir or copy the Python Framework directory. -# Args:		vDictArgs				- (R) Program input parameters. -#			vstrFrameworkPythonDir	- (R) Python framework directory. -# Returns:	Bool - True = function success, False = failure. -#			Str	- Config directory path. -#			strErrMsg - Error description on task failure. -# Throws:	None. +# Details: Retrieve the configuration build path if present and valid (using +#          parameter --cfgBlddir or copy the Python Framework directory. +# Args:    vDictArgs - (R) Program input parameters. +#          vstrFrameworkPythonDir - (R) Python framework directory. +# Returns: Bool - True = function success, False = failure. +#          Str - Config directory path. +#          strErrMsg - Error description on task failure. +# Throws:  None.  #-- -def get_config_build_dir( vDictArgs, vstrFrameworkPythonDir ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script get_config_build_dir()" ); -	bOk = True; -	strErrMsg = ""; -	 -	strConfigBldDir = ""; -	bHaveConfigBldDir = "--cfgBldDir" in vDictArgs; -	if bHaveConfigBldDir: -		strConfigBldDir = vDictArgs[ "--cfgBldDir" ]; -	if (bHaveConfigBldDir == False) or (strConfigBldDir.__len__() == 0): -		strConfigBldDir = vstrFrameworkPythonDir; -	 -	return (bOk, strConfigBldDir, strErrMsg); +def get_config_build_dir(vDictArgs, vstrFrameworkPythonDir): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_config_build_dir()") +    bOk = True +    strErrMsg = "" + +    strConfigBldDir = "" +    bHaveConfigBldDir = "--cfgBldDir" in vDictArgs +    if bHaveConfigBldDir: +        strConfigBldDir = vDictArgs["--cfgBldDir"] +    if (bHaveConfigBldDir == False) or (strConfigBldDir.__len__() == 0): +        strConfigBldDir = vstrFrameworkPythonDir + +    return (bOk, strConfigBldDir, strErrMsg)  """  Removes given file, ignoring error if it doesn't exist.  """  def remove_ignore_enoent(filename): -	try: -		os.remove( filename ); -	except OSError as e: -		import errno -		if e.errno != errno.ENOENT: -			raise -		pass +    try: +        os.remove(filename) +    except OSError as e: +        import errno +        if e.errno != errno.ENOENT: +            raise  #++--------------------------------------------------------------------------- -# Details:	Do a SWIG code rebuild. Any number returned by SWIG which is not -#			zero is treated as an error. The generate dependencies flag decides -#			how SWIG is rebuilt and if set false will cause the script to exit -#			immediately with the exit status + 200 if status is not zero.  -# Args:		vDictArgs			- (R) Program input parameters. -#			vstrSwigDepFile		- (R) SWIG dependency file. -#			vstrCfgBldDir		- (R) Configuration build directory. -#			vstrSwigOpFile		- (R) SWIG output file. -#			vstrSwigIpFile		- (R) SWIG input file. -# Returns:	Bool 		- True = function success, False = failure. -#			strMsg 		- Error or status message. -#			nExitResult	- Exit result of SWIG executable. -#						- 0 = Success. -#						- 1 = Success, exit this script and parent script. -#						- +200 = A SWIG error status result. -# Throws:	None. +# Details: Do a SWIG code rebuild. Any number returned by SWIG which is not +#          zero is treated as an error. The generate dependencies flag decides +#          how SWIG is rebuilt and if set false will cause the script to exit +#          immediately with the exit status + 200 if status is not zero. +# Args:    vDictArgs - (R) Program input parameters. +#          vstrSwigDepFile - (R) SWIG dependency file. +#          vstrCfgBldDir - (R) Configuration build directory. +#          vstrSwigOpFile - (R) SWIG output file. +#          vstrSwigIpFile - (R) SWIG input file. +# Returns: Bool - True = function success, False = failure. +#          strMsg - Error or status message. +#          nExitResult - Exit result of SWIG executable. +#                      - 0 = Success. +#                      - 1 = Success, exit this script and parent script. +#                      - +200 = A SWIG error status result. +# Throws:  None.  #-- -def do_swig_rebuild( vDictArgs, vstrSwigDepFile, vstrCfgBldDir,  -					 vstrSwigOpFile, vstrSwigIpFile ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script do_swig_rebuild()" ); -	bOk = True; -	strMsg = ""; -	bDbg = "-d" in vDictArgs; -	bGenDependencies = "-M" in vDictArgs; -	strSwigExePath = vDictArgs[ "--swigExePath" ]; -	strSwigExeName = vDictArgs[ "--swigExeName" ]; -	strSrcRoot = vDictArgs[ "--srcRoot" ]; -	 -	# Build SWIG path to executable -	if strSwigExePath != "": -		strSwig = "%s/%s" % (strSwigExePath, strSwigExeName); -		strSwig = os.path.normcase( strSwig ); -	else: -		strSwig = strSwigExeName; -	 -	strCfg = vstrCfgBldDir; -	strOp = vstrSwigOpFile; -	strIp = vstrSwigIpFile; -	strSi = os.path.normcase( "./." ); -	strRoot = strSrcRoot + "/include"; -	strRoot = os.path.normcase( strRoot ); -	strDep = ""; -	if bGenDependencies: -		strDep = vstrSwigDepFile + ".tmp"; -	 -	# Build the SWIG args list -	strCmd = "%s " % strSwig; -	strCmd += "-c++ "; -	strCmd += "-shadow "; -	strCmd += "-python "; -	strCmd += "-threads "; -	strCmd += "-I\"%s\" " % strRoot; -	strCmd += "-I\"%s\" " % strSi; -	strCmd += "-D__STDC_LIMIT_MACROS "; -	strCmd += "-D__STDC_CONSTANT_MACROS "; -	if bGenDependencies: -		strCmd += "-MMD -MF \"%s\" " % strDep; -	strCmd += "-outdir \"%s\" " % strCfg; -	strCmd += "-o \"%s\" " % strOp; -	strCmd += "\"%s\" " % strIp; -	if bDbg: -		print((strMsgSwigExecute % strCmd)); - -	# Execute SWIG -	process = subprocess.Popen( strCmd, stdout=subprocess.PIPE,  -								stderr=subprocess.PIPE, shell=True ); -	# Wait for SWIG process to terminate -	strStdOut, strStdErr = process.communicate(); -	nResult = process.returncode; -	if nResult != 0: -		bOk = False; -		nResult += 200; -		strMsg = strErrMsgSwigExecute % strStdErr;  -	else: -		if bDbg and (strStdOut.__len__() != 0): -			strMsg = strStdOut; -	 -	if bGenDependencies: -		if bOk: -			if os.path.exists( strDep ): -				shutil.move( strDep, vstrSwigDepFile ); -		else: -			os.remove( strDep );  -			nResult = 1; # Exit this script and parent script -			if bDbg: -				strMsg = strMsgSwigGenDep % strDep; -	else: -		strMsg = strMsgSwigNoGenDep + strMsg; -		 -	return bOk, strMsg, nResult; +def do_swig_rebuild(vDictArgs, vstrSwigDepFile, vstrCfgBldDir, +                    vstrSwigOpFile, vstrSwigIpFile): +    dbg = utilsDebug.CDebugFnVerbose("Python script do_swig_rebuild()") +    bOk = True +    strMsg = "" +    bDbg = "-d" in vDictArgs +    bGenDependencies = "-M" in vDictArgs +    strSwigExePath = vDictArgs["--swigExePath"] +    strSwigExeName = vDictArgs["--swigExeName"] +    strSrcRoot = vDictArgs["--srcRoot"] + +    # Build SWIG path to executable +    if strSwigExePath != "": +        strSwig = "%s/%s" % (strSwigExePath, strSwigExeName) +        strSwig = os.path.normcase(strSwig) +    else: +        strSwig = strSwigExeName + +    strCfg = vstrCfgBldDir +    strOp = vstrSwigOpFile +    strIp = vstrSwigIpFile +    strSi = os.path.normcase("./.") +    strRoot = strSrcRoot + "/include" +    strRoot = os.path.normcase(strRoot) +    strDep = "" +    if bGenDependencies: +        strDep = vstrSwigDepFile + ".tmp" + +    # Build the SWIG args list +    strCmd = "%s " % strSwig +    strCmd += "-c++ " +    strCmd += "-shadow " +    strCmd += "-python " +    strCmd += "-threads " +    strCmd += "-I\"%s\" " % strRoot +    strCmd += "-I\"%s\" " % strSi +    strCmd += "-D__STDC_LIMIT_MACROS " +    strCmd += "-D__STDC_CONSTANT_MACROS " +    if bGenDependencies: +        strCmd += "-MMD -MF \"%s\" " % strDep +    strCmd += "-outdir \"%s\" " % strCfg +    strCmd += "-o \"%s\" " % strOp +    strCmd += "\"%s\" " % strIp +    if bDbg: +        print((strMsgSwigExecute % strCmd)) + +    # Execute SWIG +    process = subprocess.Popen(strCmd, stdout=subprocess.PIPE, +                               stderr=subprocess.PIPE, shell=True) +    # Wait for SWIG process to terminate +    strStdOut, strStdErr = process.communicate() +    nResult = process.returncode +    if nResult != 0: +        bOk = False +        nResult += 200 +        strMsg = strErrMsgSwigExecute % strStdErr +    else: +        if bDbg and (strStdOut.__len__() != 0): +            strMsg = strStdOut + +    if bGenDependencies: +        if bOk: +            if os.path.exists(strDep): +                shutil.move(strDep, vstrSwigDepFile) +        else: +            os.remove(strDep) +            nResult = 1 # Exit this script and parent script +            if bDbg: +                strMsg = strMsgSwigGenDep % strDep +    else: +        strMsg = strMsgSwigNoGenDep + strMsg + +    return bOk, strMsg, nResult  #++--------------------------------------------------------------------------- -# Details:	Execute another Python script from this script in a separate  -#			process. No data is passed back to the caller script. It is  -#			assumed should any exit result be returned that -ve numbers are -#			error conditions. A zero or +ve numbers mean ok/warning/status. -# Args:		vDictArgs	- (R) Program input parameters. -#			vstrArgs	- (R) Space separated parameters passed to python. -# Returns:	Bool - True = function success, False = failure. -#			strMsg - Error or status message. -# Throws:	None. +# Details: Execute another Python script from this script in a separate +#          process. No data is passed back to the caller script. It is +#          assumed should any exit result be returned that -ve numbers are +#          error conditions. A zero or +ve numbers mean ok/warning/status. +# Args:    vDictArgs - (R) Program input parameters. +#          vstrArgs - (R) Space separated parameters passed to python. +# Returns: Bool - True = function success, False = failure. +#          strMsg - Error or status message. +# Throws:  None.  #-- -def run_python_script( vDictArgs, vstrArgs ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script run_python_script()" ); -	bOk = True; -	strMsg = ""; -	bDbg = "-d" in vDictArgs; -	 -	strPy = "%s %s" % (sys.executable, vstrArgs); -	process = subprocess.Popen( strPy, shell=True ); -	strStdOut, strStdErr = process.communicate(); -	nResult = process.returncode; -	if nResult < 0: -		bOk = False; -		strErr = strStdErr; -		if strErr == None: -			strErr = "No error given"; -		strMsg = strErrMsgPythonExecute % (vstrArgs, strErr);  -	else: -		if bDbg: -			strOut = strStdOut; -			if strOut == None: -				strOut = "No status given"; -			strMsg = strOut; -				 -	return bOk, strMsg; -	 +def run_python_script(vDictArgs, vstrArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script run_python_script()") +    bOk = True +    strMsg = "" +    bDbg = "-d" in vDictArgs + +    strPy = "%s %s" % (sys.executable, vstrArgs) +    process = subprocess.Popen(strPy, shell=True) +    strStdOut, strStdErr = process.communicate() +    nResult = process.returncode +    if nResult < 0: +        bOk = False +        strErr = strStdErr +        if strErr == None: +            strErr = "No error given" +        strMsg = strErrMsgPythonExecute % (vstrArgs, strErr) +    else: +        if bDbg: +            strOut = strStdOut +            if strOut == None: +                strOut = "No status given" +            strMsg = strOut + +    return bOk, strMsg +  #++--------------------------------------------------------------------------- -# Details:	Implement the iterator protocol and/or eq/ne operators for some  -#			lldb objects. -# 			Append global variable to lldb Python module. -# 			And initialize the lldb debugger subsystem. -# Args:		vDictArgs		- (R) Program input parameters. -#			vstrCfgBldDir	- (R) Configuration build directory. -# Returns:	Bool - True = function success, False = failure. -#			strMsg - Error or status message. -# Throws:	None. +# Details: Implement the iterator protocol and/or eq/ne operators for some +#          lldb objects. +#          Append global variable to lldb Python module. +#          And initialize the lldb debugger subsystem. +# Args:    vDictArgs - (R) Program input parameters. +#          vstrCfgBldDir - (R) Configuration build directory. +# Returns: Bool - True = function success, False = failure. +#          strMsg - Error or status message. +# Throws:  None.  #-- -def do_modify_python_lldb( vDictArgs, vstrCfgBldDir ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script do_modify_python_lldb()" ); -	bOk = True; -	strMsg = ""; -	bDbg = "-d" in vDictArgs; -	strCwd = vDictArgs[ "--srcRoot" ]; # /llvm/tools/lldb -	strCwd += "/scripts/Python"; -	strPyScript = "modify-python-lldb.py"; -	strPath = "%s/%s" % (strCwd, strPyScript); -	strPath = os.path.normcase( strPath ); -	 -	bOk = os.path.exists( strPath ); -	if not bOk: -		strMsg = strErrMsgModifyPythonLldbPyFileNotFound % (strPyScript, strPath); -		return bOk, strMsg; -		 -	strPyArgs = "%s %s" % (strPath, vstrCfgBldDir); -	bOk, strMsg = run_python_script( vDictArgs, strPyArgs ); -	 -	return bOk, strMsg; +def do_modify_python_lldb(vDictArgs, vstrCfgBldDir): +    dbg = utilsDebug.CDebugFnVerbose("Python script do_modify_python_lldb()") +    bOk = True +    strMsg = "" +    bDbg = "-d" in vDictArgs +    strCwd = vDictArgs["--srcRoot"] # /llvm/tools/lldb +    strCwd += "/scripts/Python" +    strPyScript = "modify-python-lldb.py" +    strPath = "%s/%s" % (strCwd, strPyScript) +    strPath = os.path.normcase(strPath) + +    bOk = os.path.exists(strPath) +    if not bOk: +        strMsg = strErrMsgModifyPythonLldbPyFileNotFound % (strPyScript, strPath) +        return bOk, strMsg + +    strPyArgs = "%s %s" % (strPath, vstrCfgBldDir) +    bOk, strMsg = run_python_script(vDictArgs, strPyArgs) + +    return bOk, strMsg  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------  """ Details: Program main entry point fn. Called by another Python script. -	 -	-------------------------------------------------------------------------- -	Details: This script is to be called by another Python script. It is not -			 intended to be called directly i.e from the command line. -			 If environmental variable "LLDB_DISABLE_PYTHON" is defined/exists  -			 it will cause the script to end early creating nothing. -			 If environmental variable "GCC_PREPROCESSOR_DEFINITIONS" is   -			 defined/exists it will cause the script to end early creating  -			 nothing. -	Args:	vDictArgs	- (R) Map of parameter names to values. Used to for the -							  the SWIG required parameters to create code. Note -							  this container does get amended with more data. -			-d (optional)	Determines whether or not this script  -							outputs additional information when running. -			-m (optional) 	Specify called from Makefile system. If given locate -							the LLDBWrapPython.cpp in --srcRoot/source folder  -							else in the	--targetDir folder. -			-M (optional) 	Specify want SWIG to generate a dependency file. -			--srcRoot		The root of the lldb source tree. -			--targetDir 	Where the lldb framework/shared library gets put. -			--cfgBldDir 	Where the buildSwigPythonLLDB.py program will  -			(optional)		put the lldb.py file it generated from running  -							SWIG. -			--prefix  		Is the root directory used to determine where  -			(optional)		third-party modules for scripting languages should  -							be installed. Where non-Darwin systems want to put  -							the .py and .so files so that Python can find them  -							automatically. Python install directory. -			--swigExePath	File path the SWIG executable. (Determined and  -							passed by buildSwigWrapperClasses.py to here) -			--swigExeName	The file name of the SWIG executable. (Determined   -							and passed by buildSwigWrapperClasses.py to  -							here) -	Results:	0 		Success -				1		Success, generated dependencies removed  -						LLDBWrapPython.cpp.d. -				-100+	Error from this script to the caller script. -				-100	Error program failure with optional message. -				-200+	- 200 +- the SWIG exit result. -		 -	-------------------------------------------------------------------------- -							 + +    -------------------------------------------------------------------------- +    Details: This script is to be called by another Python script. It is not +             intended to be called directly i.e from the command line. +             If environmental variable "LLDB_DISABLE_PYTHON" is defined/exists +             it will cause the script to end early creating nothing. +             If environmental variable "GCC_PREPROCESSOR_DEFINITIONS" is +             defined/exists it will cause the script to end early creating +             nothing. +    Args:     vDictArgs - (R) Map of parameter names to values. Used to for the +                              the SWIG required parameters to create code. Note +                              this container does get amended with more data. +            -d (optional)   Determines whether or not this script +                            outputs additional information when running. +            -m (optional)   Specify called from Makefile system. If given locate +                            the LLDBWrapPython.cpp in --srcRoot/source folder +                            else in the --targetDir folder. +            -M (optional)   Specify want SWIG to generate a dependency file. +            --srcRoot       The root of the lldb source tree. +            --targetDir     Where the lldb framework/shared library gets put. +            --cfgBldDir     Where the buildSwigPythonLLDB.py program will +            (optional)      put the lldb.py file it generated from running +                            SWIG. +            --prefix        Is the root directory used to determine where +            (optional)      third-party modules for scripting languages should +                            be installed. Where non-Darwin systems want to put +                            the .py and .so files so that Python can find them +                            automatically. Python install directory. +            --swigExePath   File path the SWIG executable. (Determined and +                            passed by buildSwigWrapperClasses.py to here) +            --swigExeName   The file name of the SWIG executable. (Determined +                            and passed by buildSwigWrapperClasses.py to +                            here) +    Results:    0 Success +                1 Success, generated dependencies removed +                  LLDBWrapPython.cpp.d. +                -100+ Error from this script to the caller script. +                -100 Error program failure with optional message. +                -200+ - 200 +- the SWIG exit result. + +    -------------------------------------------------------------------------- +  """ -def main( vDictArgs ): -	dbg = utilsDebug.CDebugFnVerbose( "Python script main()" ); -	bOk = True; -	strMsg = ""; -	strErrMsgProgFail = ""; -	 -	if not("--swigExePath" in vDictArgs) and ("--swigExeName" in vDictArgs): -		strErrMsgProgFail += strErrMsgSwigParamsMissing; -		return (-100, strErrMsgProgFail );	 -	 -	bDebug = "-d" in vDictArgs; -	 -	strSwigDepFile = ""; -	strSwigDepOptions = ""; -	bGenDependencies = "-M" in vDictArgs; -	if bGenDependencies: -		strSwigDepFile = vDictArgs[ "--targetDir" ] + "/LLDBWrapPython.cpp.d"; -		strSwigDepOptions = "-MMD -MF \"%s.tmp\"" % strSwigDepFile; -		strSwigDepFile = os.path.normcase( strSwigDepFile ); -		strSwigDepOptions = os.path.normcase( strSwigDepOptions ); -		 -	bMakeFileCalled = "-m" in vDictArgs; -	strSwigOutputFile = "" -	if bMakeFileCalled: -		strSwigOutputFile = vDictArgs[ "--targetDir" ] + "/LLDBWrapPython.cpp"; -	else: -		strSwigOutputFile = vDictArgs[ "--srcRoot" ] + "/source/LLDBWrapPython.cpp"; -	strSwigOutputFile = os.path.normcase( strSwigOutputFile ); -	 -	strRt = vDictArgs[ "--srcRoot" ]; -	strSwigInputFile = strRt + "/scripts/lldb.swig"; -	strSwigPythonExtensions = strRt + "/scripts/Python/python-extensions.swig"; -	strSwigPythonWrapper = strRt + "/scripts/Python/python-wrapper.swig"; -	strSwigPythonTypemaps = strRt + "/scripts/Python/python-typemaps.swig"; -	strSwigPythonSwigsafecast = strRt + "/scripts/Python/python-swigsafecast.swig"; -	strSwigInputFile = os.path.normcase( strSwigInputFile ); -	strSwigPythonExtensions = os.path.normcase( strSwigPythonExtensions ); -	strSwigPythonWrapper = os.path.normcase( strSwigPythonWrapper ); -	strSwigPythonTypemaps = os.path.normcase( strSwigPythonTypemaps ); -	strSwigPythonSwigsafecast = os.path.normcase( strSwigPythonSwigsafecast ); - -	strEnvVarLLDBDisablePython = os.getenv( "LLDB_DISABLE_PYTHON", None ); -	# We don't want Python for this build, but touch the output file so we  -	# don't have to conditionalize the build on this as well. -    # Note, at present iOS doesn't have Python, so if you're building for  +def main(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script main()") +    bOk = True +    strMsg = "" + +    if not("--swigExePath" in vDictArgs) and ("--swigExeName" in vDictArgs): +        strErrMsgProgFail += strErrMsgSwigParamsMissing +        return (-100, strErrMsgProgFail) + +    bDebug = "-d" in vDictArgs + +    strSwigDepFile = "" +    strSwigDepOptions = "" +    bGenDependencies = "-M" in vDictArgs +    if bGenDependencies: +        strSwigDepFile = vDictArgs["--targetDir"] + "/LLDBWrapPython.cpp.d" +        strSwigDepOptions = "-MMD -MF \"%s.tmp\"" % strSwigDepFile +        strSwigDepFile = os.path.normcase(strSwigDepFile) +        strSwigDepOptions = os.path.normcase(strSwigDepOptions) + +    bMakeFileCalled = "-m" in vDictArgs +    strSwigOutputFile = "" +    if bMakeFileCalled: +        strSwigOutputFile = vDictArgs["--targetDir"] + "/LLDBWrapPython.cpp" +    else: +        strSwigOutputFile = vDictArgs["--srcRoot"] + "/source/LLDBWrapPython.cpp" +    strSwigOutputFile = os.path.normcase(strSwigOutputFile) + +    strRt = vDictArgs["--srcRoot"] +    strSwigInputFile = strRt + "/scripts/lldb.swig" +    strSwigPythonExtensions = strRt + "/scripts/Python/python-extensions.swig" +    strSwigPythonWrapper = strRt + "/scripts/Python/python-wrapper.swig" +    strSwigPythonTypemaps = strRt + "/scripts/Python/python-typemaps.swig" +    strSwigPythonSwigsafecast = strRt + "/scripts/Python/python-swigsafecast.swig" +    strSwigInputFile = os.path.normcase(strSwigInputFile) +    strSwigPythonExtensions = os.path.normcase(strSwigPythonExtensions) +    strSwigPythonWrapper = os.path.normcase(strSwigPythonWrapper) +    strSwigPythonTypemaps = os.path.normcase(strSwigPythonTypemaps) +    strSwigPythonSwigsafecast = os.path.normcase(strSwigPythonSwigsafecast) + +    strEnvVarLLDBDisablePython = os.getenv("LLDB_DISABLE_PYTHON", None) +    # We don't want Python for this build, but touch the output file so we +    # don't have to conditionalize the build on this as well. +    # Note, at present iOS doesn't have Python, so if you're building for      # iOS be sure to set LLDB_DISABLE_PYTHON to 1. -	if (strEnvVarLLDBDisablePython != None) and \ -	   (strEnvVarLLDBDisablePython == "1"): -		remove_ignore_enoent( strSwigOutputFile ) -		open( strSwigOutputFile, 'w' ).close(); # Touch the file -		if bDebug: -			strMsg = strMsgLldbDisablePythonEnv; -		return (0, strMsg ); -		 -	# If this project is being built with LLDB_DISABLE_PYTHON defined, -	# don't bother generating Python swig bindings -- we don't have -	# Python available. -	strEnvVarGccPreprocessDefs = os.getenv( "GCC_PREPROCESSOR_DEFINITIONS",  -											None ); -	if (strEnvVarGccPreprocessDefs != None) or \ -	   (strEnvVarLLDBDisablePython != None): -		remove_ignore_enoent( strSwigOutputFile ) -		open( strSwigOutputFile, 'w' ).close(); # Touch the file -		if bDebug: -			strMsg = strMsgLldbDisableGccEnv; -		return (0, strMsg); -		 -	bOk = bOk and get_header_files( vDictArgs ); -	bOk = bOk and get_interface_files( vDictArgs ); -	 -	strFrameworkPythonDir = ""; -	if bOk:  -		bNeedUpdate = (check_file_exists( vDictArgs, strSwigOutputFile ) == False); -		dbg.dump_object( "check_file_exists strSwigOutputFile, bNeedUpdate =", bNeedUpdate); -		if bNeedUpdate == False: -			bNeedUpdate = check_newer_files( vDictArgs, strSwigOutputFile, vDictArgs[ "--headerFiles" ] ); -			dbg.dump_object( "check_newer_files header files than strSwigOutputFile, bNeedUpdate =", bNeedUpdate); -		if bNeedUpdate == False: -			bNeedUpdate = check_newer_files( vDictArgs, strSwigOutputFile, vDictArgs[ "--ifaceFiles" ] ); -			dbg.dump_object( "check_newer_files iface files than strSwigOutputFile, bNeedUpdate =", bNeedUpdate); -		if bNeedUpdate == False: -			bNeedUpdate = check_newer_file( vDictArgs, strSwigOutputFile, strSwigInputFile ); -			dbg.dump_object( "check_newer_files strSwigInputFile than strSwigOutputFile, bNeedUpdate =", bNeedUpdate); -		if bNeedUpdate == False: -			bNeedUpdate = check_newer_file( vDictArgs, strSwigOutputFile, strSwigPythonExtensions ); -			dbg.dump_object( "check_newer_files strSwigPythonExtensions than strSwigOutputFile, bNeedUpdate =", bNeedUpdate); -		if bNeedUpdate == False: -			bNeedUpdate = check_newer_file( vDictArgs, strSwigOutputFile, strSwigPythonWrapper ); -			dbg.dump_object( "check_newer_files strSwigPythonWrapper than strSwigOutputFile, bNeedUpdate =", bNeedUpdate); -		if bNeedUpdate == False: -			bNeedUpdate = check_newer_file( vDictArgs, strSwigOutputFile, strSwigPythonTypemaps ); -			dbg.dump_object( "check_newer_files strSwigPythonTypemaps than strSwigOutputFile, bNeedUpdate =", bNeedUpdate); -		if bNeedUpdate == False: -			bNeedUpdate = check_newer_file( vDictArgs, strSwigOutputFile, strSwigPythonSwigsafecast ); -			dbg.dump_object( "check_newer_files strSwigPythonSwigsafecast than strSwigOutputFile, bNeedUpdate =", bNeedUpdate); -		 -		# Determine where to put the files -		bOk, strFrameworkPythonDir, strMsg = get_framework_python_dir( vDictArgs ); -		 -	if bOk: -		bOk, strCfgBldDir, strMsg = get_config_build_dir( vDictArgs, strFrameworkPythonDir ); -	 -	if bOk and (bNeedUpdate == False): -		strDllPath = strFrameworkPythonDir + "/_lldb.so"; -		strDllPath = os.path.normcase( strDllPath ); -		bSymbolicLink = check_file_exists( vDictArgs, strDllPath ) and os.path.islink( strDllPath ); -		bNeedUpdate = not bSymbolicLink; -		dbg.dump_object( "check_file_exists( vDictArgs, strDllPath ) and os.path.islink( strDllPath ), bNeedUpdate =", bNeedUpdate); -		 -	if bOk and (bNeedUpdate == False): -		strInitPiPath = strFrameworkPythonDir + "/__init__.py"; -		strInitPiPath = os.path.normcase( strInitPiPath ); -		print(strInitPiPath) -		bNeedUpdate = not check_file_exists( vDictArgs, strInitPiPath ); -		dbg.dump_object( "check_file_exists( vDictArgs, strInitPiPath ), bNeedUpdate =", bNeedUpdate); -		 -	if bOk:  -		if (bNeedUpdate == False): -			strMsg = strMsgNotNeedUpdate; -			return (0, strMsg ); -		else: -			print(strMsgSwigNeedRebuild); -			bOk, strMsg, nExitResult = do_swig_rebuild( vDictArgs, strSwigDepFile,  -														strCfgBldDir,  -														strSwigOutputFile, -														strSwigInputFile ); -			bGenDependencies = "-M" in vDictArgs; -			if bGenDependencies == True: -				return (nExitResult, strMsg); -				   	 -	if bOk: -		bOk, strMsg = do_modify_python_lldb( vDictArgs, strCfgBldDir ); -	 -	if bOk: -		return (0, strMsg ); -	else: -		strErrMsgProgFail += strMsg; -		return (-100, strErrMsgProgFail );	 -	 +    if (strEnvVarLLDBDisablePython != None) and \ +       (strEnvVarLLDBDisablePython == "1"): +        remove_ignore_enoent(strSwigOutputFile) +        open(strSwigOutputFile, 'w').close() # Touch the file +        if bDebug: +            strMsg = strMsgLldbDisablePythonEnv +        return (0, strMsg) + +    # If this project is being built with LLDB_DISABLE_PYTHON defined, +    # don't bother generating Python swig bindings -- we don't have +    # Python available. +    strEnvVarGccPreprocessDefs = os.getenv("GCC_PREPROCESSOR_DEFINITIONS", +                                           None) +    if (strEnvVarGccPreprocessDefs != None) or \ +       (strEnvVarLLDBDisablePython != None): +        remove_ignore_enoent(strSwigOutputFile) +        open(strSwigOutputFile, 'w').close() # Touch the file +        if bDebug: +            strMsg = strMsgLldbDisableGccEnv +        return (0, strMsg) + +    bOk = bOk and get_header_files(vDictArgs) +    bOk = bOk and get_interface_files(vDictArgs) + +    strFrameworkPythonDir = "" +    if bOk: +        bNeedUpdate = (check_file_exists(vDictArgs, strSwigOutputFile) == False) +        dbg.dump_object("check_file_exists strSwigOutputFile, bNeedUpdate =", bNeedUpdate) +        if bNeedUpdate == False: +            bNeedUpdate = check_newer_files(vDictArgs, strSwigOutputFile, vDictArgs["--headerFiles"]) +            dbg.dump_object("check_newer_files header files than strSwigOutputFile, bNeedUpdate =", bNeedUpdate) +        if bNeedUpdate == False: +            bNeedUpdate = check_newer_files(vDictArgs, strSwigOutputFile, vDictArgs["--ifaceFiles"]) +            dbg.dump_object("check_newer_files iface files than strSwigOutputFile, bNeedUpdate =", bNeedUpdate) +        if bNeedUpdate == False: +            bNeedUpdate = check_newer_file(vDictArgs, strSwigOutputFile, strSwigInputFile) +            dbg.dump_object("check_newer_files strSwigInputFile than strSwigOutputFile, bNeedUpdate =", bNeedUpdate) +        if bNeedUpdate == False: +            bNeedUpdate = check_newer_file(vDictArgs, strSwigOutputFile, strSwigPythonExtensions) +            dbg.dump_object("check_newer_files strSwigPythonExtensions than strSwigOutputFile, bNeedUpdate =", bNeedUpdate) +        if bNeedUpdate == False: +            bNeedUpdate = check_newer_file(vDictArgs, strSwigOutputFile, strSwigPythonWrapper) +            dbg.dump_object("check_newer_files strSwigPythonWrapper than strSwigOutputFile, bNeedUpdate =", bNeedUpdate) +        if bNeedUpdate == False: +            bNeedUpdate = check_newer_file(vDictArgs, strSwigOutputFile, strSwigPythonTypemaps) +            dbg.dump_object("check_newer_files strSwigPythonTypemaps than strSwigOutputFile, bNeedUpdate =", bNeedUpdate) +        if bNeedUpdate == False: +            bNeedUpdate = check_newer_file(vDictArgs, strSwigOutputFile, strSwigPythonSwigsafecast) +            dbg.dump_object("check_newer_files strSwigPythonSwigsafecast than strSwigOutputFile, bNeedUpdate =", bNeedUpdate) + +        # Determine where to put the files +        bOk, strFrameworkPythonDir, strMsg = get_framework_python_dir(vDictArgs) + +    if bOk: +        bOk, strCfgBldDir, strMsg = get_config_build_dir(vDictArgs, strFrameworkPythonDir) + +    if bOk and (bNeedUpdate == False): +        strDllPath = strFrameworkPythonDir + "/_lldb.so" +        strDllPath = os.path.normcase(strDllPath) +        bSymbolicLink = check_file_exists(vDictArgs, strDllPath) and os.path.islink(strDllPath) +        bNeedUpdate = not bSymbolicLink +        dbg.dump_object("check_file_exists(vDictArgs, strDllPath) and os.path.islink(strDllPath), bNeedUpdate =", bNeedUpdate) + +    if bOk and (bNeedUpdate == False): +        strInitPiPath = strFrameworkPythonDir + "/__init__.py" +        strInitPiPath = os.path.normcase(strInitPiPath) +        print(strInitPiPath) +        bNeedUpdate = not check_file_exists(vDictArgs, strInitPiPath) +        dbg.dump_object("check_file_exists(vDictArgs, strInitPiPath), bNeedUpdate =", bNeedUpdate) + +    if bOk: +        if bNeedUpdate == False: +            strMsg = strMsgNotNeedUpdate +            return (0, strMsg) +        else: +            print(strMsgSwigNeedRebuild) +            bOk, strMsg, nExitResult = do_swig_rebuild(vDictArgs, strSwigDepFile, +                                                       strCfgBldDir, +                                                       strSwigOutputFile, +                                                       strSwigInputFile) +            bGenDependencies = "-M" in vDictArgs +            if bGenDependencies == True: +                return (nExitResult, strMsg) + +    if bOk: +        bOk, strMsg = do_modify_python_lldb(vDictArgs, strCfgBldDir) + +    if bOk: +        return (0, strMsg) +    else: +        strErrMsgProgFail += strMsg +        return (-100, strErrMsgProgFail) +  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------  #----------------------------------------------------------------------------- -# This script can be called by another Python script by calling the main()  +# This script can be called by another Python script by calling the main()  # function directly  if __name__ == "__main__": -	print("Script cannot be called directly, called by buildSwigWrapperClasses.py"); -	 +    print("Script cannot be called directly, called by buildSwigWrapperClasses.py") diff --git a/lldb/scripts/Python/finishSwigPythonLLDB.py b/lldb/scripts/Python/finishSwigPythonLLDB.py index 45cb8b98887..46e30b6f5e9 100644 --- a/lldb/scripts/Python/finishSwigPythonLLDB.py +++ b/lldb/scripts/Python/finishSwigPythonLLDB.py @@ -38,9 +38,7 @@  # Python modules:  import os           # Provide directory and file handling, determine OS information  import sys          # System specific parameters and functions -import errno        # OS error results  import shutil       # High-level operations on files and collections of files -import subprocess   # Call external programs  import ctypes       # Invoke Windows API for creating symlinks  # Third party modules: @@ -50,28 +48,28 @@ import utilsOsType      # Determine the OS type this script is running on  import utilsDebug       # Debug Python scripts  # User facing text: -strMsgOsVersion = "The current OS is %s"; -strMsgPyVersion = "The Python version is %d.%d"; -strErrMsgProgFail = "Program failure: "; -strErrMsgLLDBPyFileNotNotFound = "Unable to locate lldb.py at path '%s'"; -strMsgCopyLLDBPy = "Copying lldb.py from '%s' to '%s'"; -strErrMsgFrameWkPyDirNotExist = "Unable to find the LLDB.framework directory '%s'"; -strMsgCreatePyPkgCopyPkgFile = "create_py_pkg: Copied file '%s' to folder '%s'"; -strMsgCreatePyPkgInitFile = "create_py_pkg: Creating pakage init file '%s'"; -strMsgCreatePyPkgMkDir = "create_py_pkg: Created folder '%s'"; -strMsgConfigBuildDir = "Configuration build directory located at '%s'"; -strMsgFoundLldbFrameWkDir = "Found '%s'"; -strMsgPyFileLocatedHere = "Python file will be put in '%s'"; -strMsgFrameWkPyExists = "Python output folder '%s' already exists"; -strMsgFrameWkPyMkDir = "Python output folder '%s' will be created"; -strErrMsgCreateFrmWkPyDirFailed = "Unable to create directory '%s' error: %s"; -strMsgSymlinkExists = "Symlink for '%s' already exists"; -strMsgSymlinkMk = "Creating symlink for %s  (%s -> %s)"; -strErrMsgCpLldbpy = "copying lldb to lldb package directory"; -strErrMsgCreatePyPkgMissingSlash = "Parameter 3 fn create_py_pkg() missing slash"; -strErrMsgMkLinkExecute = "Command mklink failed: %s"; -strErrMsgMakeSymlink = "creating symbolic link"; -strErrMsgUnexpected = "Unexpected error: %s"; +strMsgOsVersion = "The current OS is %s" +strMsgPyVersion = "The Python version is %d.%d" +strErrMsgProgFail = "Program failure: " +strErrMsgLLDBPyFileNotNotFound = "Unable to locate lldb.py at path '%s'" +strMsgCopyLLDBPy = "Copying lldb.py from '%s' to '%s'" +strErrMsgFrameWkPyDirNotExist = "Unable to find the LLDB.framework directory '%s'" +strMsgCreatePyPkgCopyPkgFile = "create_py_pkg: Copied file '%s' to folder '%s'" +strMsgCreatePyPkgInitFile = "create_py_pkg: Creating pakage init file '%s'" +strMsgCreatePyPkgMkDir = "create_py_pkg: Created folder '%s'" +strMsgConfigBuildDir = "Configuration build directory located at '%s'" +strMsgFoundLldbFrameWkDir = "Found '%s'" +strMsgPyFileLocatedHere = "Python file will be put in '%s'" +strMsgFrameWkPyExists = "Python output folder '%s' already exists" +strMsgFrameWkPyMkDir = "Python output folder '%s' will be created" +strErrMsgCreateFrmWkPyDirFailed = "Unable to create directory '%s' error: %s" +strMsgSymlinkExists = "Symlink for '%s' already exists" +strMsgSymlinkMk = "Creating symlink for %s  (%s -> %s)" +strErrMsgCpLldbpy = "copying lldb to lldb package directory" +strErrMsgCreatePyPkgMissingSlash = "Parameter 3 fn create_py_pkg() missing slash" +strErrMsgMkLinkExecute = "Command mklink failed: %s" +strErrMsgMakeSymlink = "creating symbolic link" +strErrMsgUnexpected = "Unexpected error: %s"  def is_debug_interpreter():      return hasattr(sys, 'gettotalrefcount') @@ -84,29 +82,29 @@ def is_debug_interpreter():  #           Str - Error description on task failure.  # Throws:   None.  #-- -def macosx_copy_file_for_heap( vDictArgs, vstrFrameworkPythonDir ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script macosx_copy_file_for_heap()" ); -    bOk = True; -    strMsg = ""; +def macosx_copy_file_for_heap(vDictArgs, vstrFrameworkPythonDir): +    dbg = utilsDebug.CDebugFnVerbose("Python script macosx_copy_file_for_heap()") +    bOk = True +    strMsg = "" -    eOSType = utilsOsType.determine_os_type(); +    eOSType = utilsOsType.determine_os_type()      if eOSType != utilsOsType.EnumOsType.Darwin: -        return (bOk, strMsg); +        return (bOk, strMsg) -    strHeapDir = os.path.join(vstrFrameworkPythonDir, "macosx", "heap"); -    strHeapDir = os.path.normcase( strHeapDir ); -    if (os.path.exists( strHeapDir ) and os.path.isdir( strHeapDir )): -        return (bOk, strMsg); +    strHeapDir = os.path.join(vstrFrameworkPythonDir, "macosx", "heap") +    strHeapDir = os.path.normcase(strHeapDir) +    if os.path.exists(strHeapDir) and os.path.isdir(strHeapDir): +        return (bOk, strMsg) -    os.makedirs( strHeapDir ); +    os.makedirs(strHeapDir) -    strRoot = os.path.normpath(vDictArgs[ "--srcRoot" ]); -    strSrc = os.path.join(strRoot, "examples", "darwin", "heap_find", "heap", "heap_find.cpp"); -    shutil.copy( strSrc, strHeapDir ); -    strSrc = os.path.join(strRoot, "examples", "darwin", "heap_find", "heap", "Makefile"); -    shutil.copy( strSrc, strHeapDir ); +    strRoot = os.path.normpath(vDictArgs["--srcRoot"]) +    strSrc = os.path.join(strRoot, "examples", "darwin", "heap_find", "heap", "heap_find.cpp") +    shutil.copy(strSrc, strHeapDir) +    strSrc = os.path.join(strRoot, "examples", "darwin", "heap_find", "heap", "Makefile") +    shutil.copy(strSrc, strHeapDir) -    return (bOk, strMsg); +    return (bOk, strMsg)  #++---------------------------------------------------------------------------  # Details:  Create Python packages and Python __init__ files. @@ -118,63 +116,63 @@ def macosx_copy_file_for_heap( vDictArgs, vstrFrameworkPythonDir ):  #           Str - Error description on task failure.  # Throws:   None.  #-- -def create_py_pkg( vDictArgs, vstrFrameworkPythonDir, vstrPkgDir, vListPkgFiles ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script create_py_pkg()" ); -    dbg.dump_object( "Package file(s):", vListPkgFiles ); -    bDbg = "-d" in vDictArgs; +def create_py_pkg(vDictArgs, vstrFrameworkPythonDir, vstrPkgDir, vListPkgFiles): +    dbg = utilsDebug.CDebugFnVerbose("Python script create_py_pkg()") +    dbg.dump_object("Package file(s):", vListPkgFiles) +    bDbg = "-d" in vDictArgs -    bOk = True; -    strMsg = ""; +    bOk = True +    strMsg = "" -    if vstrPkgDir.__len__() != 0 and vstrPkgDir[ 0 ] != "/": -        bOk = False; -        strMsg = strErrMsgCreatePyPkgMissingSlash; -        return (bOk, strMsg); +    if vstrPkgDir.__len__() != 0 and vstrPkgDir[0] != "/": +        bOk = False +        strMsg = strErrMsgCreatePyPkgMissingSlash +        return (bOk, strMsg) -    strPkgName = vstrPkgDir; -    strPkgName = "lldb" + strPkgName.replace( "/", "." ); +    strPkgName = vstrPkgDir +    strPkgName = "lldb" + strPkgName.replace("/", ".") -    strPkgDir = vstrFrameworkPythonDir; -    strPkgDir += vstrPkgDir; -    strPkgDir = os.path.normcase( strPkgDir ); +    strPkgDir = vstrFrameworkPythonDir +    strPkgDir += vstrPkgDir +    strPkgDir = os.path.normcase(strPkgDir) -    if not(os.path.exists( strPkgDir ) and os.path.isdir( strPkgDir )): +    if not(os.path.exists(strPkgDir) and os.path.isdir(strPkgDir)):          if bDbg: -            print((strMsgCreatePyPkgMkDir % strPkgDir)); -        os.makedirs( strPkgDir ); +            print((strMsgCreatePyPkgMkDir % strPkgDir)) +        os.makedirs(strPkgDir)      for strPkgFile in vListPkgFiles: -        if os.path.exists( strPkgFile ) and os.path.isfile( strPkgFile ): +        if os.path.exists(strPkgFile) and os.path.isfile(strPkgFile):              if bDbg: -                print((strMsgCreatePyPkgCopyPkgFile % (strPkgFile, strPkgDir))); -            shutil.copy( strPkgFile, strPkgDir ); +                print((strMsgCreatePyPkgCopyPkgFile % (strPkgFile, strPkgDir))) +            shutil.copy(strPkgFile, strPkgDir)      # Create a packet init files if there wasn't one -    strPkgIniFile = os.path.normpath(os.path.join(strPkgDir, "__init__.py")); -    if os.path.exists( strPkgIniFile ) and os.path.isfile( strPkgIniFile ): -        return (bOk, strMsg); +    strPkgIniFile = os.path.normpath(os.path.join(strPkgDir, "__init__.py")) +    if os.path.exists(strPkgIniFile) and os.path.isfile(strPkgIniFile): +        return (bOk, strMsg) -    strPyScript = "__all__ = ["; -    strDelimiter = ""; +    strPyScript = "__all__ = [" +    strDelimiter = ""      for strPkgFile in vListPkgFiles: -        if os.path.exists( strPkgFile ) and os.path.isfile( strPkgFile ): -            strBaseName = os.path.basename( strPkgFile ); -            nPos = strBaseName.find( "." ); +        if os.path.exists(strPkgFile) and os.path.isfile(strPkgFile): +            strBaseName = os.path.basename(strPkgFile) +            nPos = strBaseName.find(".")              if nPos != -1: -                strBaseName = strBaseName[ 0 : nPos ]; -            strPyScript += "%s\"%s\"" % (strDelimiter, strBaseName); -            strDelimiter = ","; -    strPyScript += "]\n"; -    strPyScript += "for x in __all__:\n"; -    strPyScript += "\t__import__('%s.' + x)" % strPkgName; +                strBaseName = strBaseName[0 : nPos] +            strPyScript += "%s\"%s\"" % (strDelimiter, strBaseName) +            strDelimiter = "," +    strPyScript += "]\n" +    strPyScript += "for x in __all__:\n" +    strPyScript += "\t__import__('%s.' + x)" % strPkgName      if bDbg: -        print((strMsgCreatePyPkgInitFile % strPkgIniFile)); -    file = open( strPkgIniFile, "w" ); -    file.write( strPyScript ); -    file.close(); +        print((strMsgCreatePyPkgInitFile % strPkgIniFile)) +    file = open(strPkgIniFile, "w") +    file.write(strPyScript) +    file.close() -    return (bOk, strMsg); +    return (bOk, strMsg)  #++---------------------------------------------------------------------------  # Details:  Copy the lldb.py file into the lldb package directory and rename @@ -186,35 +184,35 @@ def create_py_pkg( vDictArgs, vstrFrameworkPythonDir, vstrPkgDir, vListPkgFiles  #           Str - Error description on task failure.  # Throws:   None.  #-- -def copy_lldbpy_file_to_lldb_pkg_dir( vDictArgs, vstrFrameworkPythonDir, vstrCfgBldDir ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script copy_lldbpy_file_to_lldb_pkg_dir()" ); -    bOk = True; -    bDbg = "-d" in vDictArgs; -    strMsg = ""; +def copy_lldbpy_file_to_lldb_pkg_dir(vDictArgs, vstrFrameworkPythonDir, vstrCfgBldDir): +    dbg = utilsDebug.CDebugFnVerbose("Python script copy_lldbpy_file_to_lldb_pkg_dir()") +    bOk = True +    bDbg = "-d" in vDictArgs +    strMsg = "" -    strSrc = os.path.join(vstrCfgBldDir, "lldb.py"); -    strSrc = os.path.normcase( strSrc ); -    strDst = os.path.join(vstrFrameworkPythonDir, "__init__.py"); -    strDst = os.path.normcase( strDst ); +    strSrc = os.path.join(vstrCfgBldDir, "lldb.py") +    strSrc = os.path.normcase(strSrc) +    strDst = os.path.join(vstrFrameworkPythonDir, "__init__.py") +    strDst = os.path.normcase(strDst) -    if not os.path.exists( strSrc ): -        strMsg = strErrMsgLLDBPyFileNotNotFound % strSrc; -        return (bOk, strMsg); +    if not os.path.exists(strSrc): +        strMsg = strErrMsgLLDBPyFileNotNotFound % strSrc +        return (bOk, strMsg)      try:          if bDbg: -            print((strMsgCopyLLDBPy % (strSrc, strDst))); -        shutil.copyfile( strSrc, strDst ); +            print((strMsgCopyLLDBPy % (strSrc, strDst))) +        shutil.copyfile(strSrc, strDst)      except IOError as e: -        bOk = False; -        strMsg = "I/O error( %d ): %s %s" % (e.errno, e.strerror, strErrMsgCpLldbpy); +        bOk = False +        strMsg = "I/O error(%d): %s %s" % (e.errno, e.strerror, strErrMsgCpLldbpy)          if e.errno == 2: -            strMsg += " Src:'%s' Dst:'%s'" % (strSrc, strDst); +            strMsg += " Src:'%s' Dst:'%s'" % (strSrc, strDst)      except: -        bOk = False; -        strMsg = strErrMsgUnexpected % sys.exec_info()[ 0 ]; +        bOk = False +        strMsg = strErrMsgUnexpected % sys.exec_info()[0] -    return (bOk, strMsg); +    return (bOk, strMsg)  #++---------------------------------------------------------------------------  # Details:  Make the symbolic link on a Windows platform. @@ -224,11 +222,11 @@ def copy_lldbpy_file_to_lldb_pkg_dir( vDictArgs, vstrFrameworkPythonDir, vstrCfg  #           Str - Error description on task failure.  # Throws:   None.  #-- -def make_symlink_windows( vstrSrcPath, vstrTargetPath ): -    print(("Making symlink from %s to %s" % (vstrSrcPath, vstrTargetPath))); -    dbg = utilsDebug.CDebugFnVerbose( "Python script make_symlink_windows()" ); -    bOk = True; -    strErrMsg = ""; +def make_symlink_windows(vstrSrcPath, vstrTargetPath): +    print(("Making symlink from %s to %s" % (vstrSrcPath, vstrTargetPath))) +    dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_windows()") +    bOk = True +    strErrMsg = ""      try:          csl = ctypes.windll.kernel32.CreateHardLinkW @@ -238,11 +236,11 @@ def make_symlink_windows( vstrSrcPath, vstrTargetPath ):              raise ctypes.WinError()      except Exception as e:          if e.errno != 17: -            bOk = False; -            strErrMsg = "WinError( %d ): %s %s" % (e.errno, e.strerror, strErrMsgMakeSymlink); -            strErrMsg += " Src:'%s' Target:'%s'" % (vstrSrcPath, vstrTargetPath); +            bOk = False +            strErrMsg = "WinError(%d): %s %s" % (e.errno, e.strerror, strErrMsgMakeSymlink) +            strErrMsg += " Src:'%s' Target:'%s'" % (vstrSrcPath, vstrTargetPath) -    return (bOk, strErrMsg); +    return (bOk, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Make the symbolic link on a UNIX style platform. @@ -252,22 +250,22 @@ def make_symlink_windows( vstrSrcPath, vstrTargetPath ):  #           Str - Error description on task failure.  # Throws:   None.  #-- -def make_symlink_other_platforms( vstrSrcPath, vstrTargetPath ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script make_symlink_other_platforms()" ); -    bOk = True; -    strErrMsg = ""; +def make_symlink_other_platforms(vstrSrcPath, vstrTargetPath): +    dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_other_platforms()") +    bOk = True +    strErrMsg = ""      try: -        os.symlink( vstrSrcPath, vstrTargetPath ); +        os.symlink(vstrSrcPath, vstrTargetPath)      except OSError as e: -        bOk = False; -        strErrMsg = "OSError( %d ): %s %s" % (e.errno, e.strerror, strErrMsgMakeSymlink); -        strErrMsg += " Src:'%s' Target:'%s'" % (vstrSrcPath, vstrTargetPath); +        bOk = False +        strErrMsg = "OSError(%d): %s %s" % (e.errno, e.strerror, strErrMsgMakeSymlink) +        strErrMsg += " Src:'%s' Target:'%s'" % (vstrSrcPath, vstrTargetPath)      except: -        bOk = False; -        strErrMsg = strErrMsgUnexpected % sys.exec_info()[ 0 ]; +        bOk = False +        strErrMsg = strErrMsgUnexpected % sys.exec_info()[0] -    return (bOk, strErrMsg); +    return (bOk, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Make the symbolic link. @@ -279,55 +277,55 @@ def make_symlink_other_platforms( vstrSrcPath, vstrTargetPath ):  #           Str - Error description on task failure.  # Throws:   None.  #-- -def make_symlink( vDictArgs, vstrFrameworkPythonDir, vstrSrcFile, vstrTargetFile ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script make_symlink()" ); -    bOk = True; -    strErrMsg = ""; -    bDbg = "-d" in vDictArgs; -    strTarget = os.path.join(vstrFrameworkPythonDir, vstrTargetFile); -    strTarget = os.path.normcase( strTarget ); -    strSrc = ""; - -    os.chdir( vstrFrameworkPythonDir ); -    bMakeFileCalled = "-m" in vDictArgs; -    eOSType = utilsOsType.determine_os_type(); +def make_symlink(vDictArgs, vstrFrameworkPythonDir, vstrSrcFile, vstrTargetFile): +    dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink()") +    bOk = True +    strErrMsg = "" +    bDbg = "-d" in vDictArgs +    strTarget = os.path.join(vstrFrameworkPythonDir, vstrTargetFile) +    strTarget = os.path.normcase(strTarget) +    strSrc = "" + +    os.chdir(vstrFrameworkPythonDir) +    bMakeFileCalled = "-m" in vDictArgs +    eOSType = utilsOsType.determine_os_type()      if not bMakeFileCalled: -        return (bOk, strErrMsg); +        return (bOk, strErrMsg)      else:          # Resolve vstrSrcFile path relatively the build directory          if eOSType == utilsOsType.EnumOsType.Windows:              # On a Windows platform the vstrFrameworkPythonDir looks like:              # llvm\\build\\Lib\\site-packages\\lldb -            strBuildDir = os.path.join("..", "..", ".."); +            strBuildDir = os.path.join("..", "..", "..")          else:              # On a UNIX style platform the vstrFrameworkPythonDir looks like:              # llvm/build/lib/python2.7/site-packages/lldb -            strBuildDir = os.path.join("..", "..", "..", ".."); -        strSrc = os.path.normcase(os.path.join(strBuildDir, vstrSrcFile)); +            strBuildDir = os.path.join("..", "..", "..", "..") +        strSrc = os.path.normcase(os.path.join(strBuildDir, vstrSrcFile))      if eOSType == utilsOsType.EnumOsType.Unknown: -        bOk = False; -        strErrMsg = strErrMsgOsTypeUnknown; +        bOk = False +        strErrMsg = strErrMsgOsTypeUnknown      elif eOSType == utilsOsType.EnumOsType.Windows: -        if os.path.isfile( strTarget ): +        if os.path.isfile(strTarget):              if bDbg: -                print((strMsgSymlinkExists % vstrTargetFile)); -            return (bOk, strErrMsg); +                print((strMsgSymlinkExists % vstrTargetFile)) +            return (bOk, strErrMsg)          if bDbg: -            print((strMsgSymlinkMk % (vstrTargetFile, strSrc, strTarget))); -        bOk, strErrMsg = make_symlink_windows( strSrc, -                                               strTarget ); +            print((strMsgSymlinkMk % (vstrTargetFile, strSrc, strTarget))) +        bOk, strErrMsg = make_symlink_windows(strSrc, +                                              strTarget)      else: -        if os.path.islink( strTarget ): +        if os.path.islink(strTarget):              if bDbg: -                print((strMsgSymlinkExists % vstrTargetFile)); -            return (bOk, strErrMsg); +                print((strMsgSymlinkExists % vstrTargetFile)) +            return (bOk, strErrMsg)          if bDbg: -            print((strMsgSymlinkMk % (vstrTargetFile, strSrc, strTarget))); -        bOk, strErrMsg = make_symlink_other_platforms( strSrc, -                                                       strTarget ); +            print((strMsgSymlinkMk % (vstrTargetFile, strSrc, strTarget))) +        bOk, strErrMsg = make_symlink_other_platforms(strSrc, +                                                      strTarget) -    return (bOk, strErrMsg); +    return (bOk, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Make the symbolic that the script bridge for Python will need in @@ -339,41 +337,41 @@ def make_symlink( vDictArgs, vstrFrameworkPythonDir, vstrSrcFile, vstrTargetFile  #           Str - Error description on task failure.  # Throws:   None.  #-- -def make_symlink_liblldb( vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script make_symlink_liblldb()" ); -    bOk = True; -    strErrMsg = ""; -    strTarget = vstrLiblldbFileName; -    strSrc = ""; - -    eOSType = utilsOsType.determine_os_type(); +def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName): +    dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_liblldb()") +    bOk = True +    strErrMsg = "" +    strTarget = vstrLiblldbFileName +    strSrc = "" + +    eOSType = utilsOsType.determine_os_type()      if eOSType == utilsOsType.EnumOsType.Windows:          # When importing an extension module using a debug version of python, you          # write, for example, "import foo", but the interpreter searches for          # "foo_d.pyd"          if is_debug_interpreter(): -            strTarget += "_d"; -        strTarget += ".pyd"; +            strTarget += "_d" +        strTarget += ".pyd"      else: -        strTarget += ".so"; +        strTarget += ".so" -    bMakeFileCalled = "-m" in vDictArgs; +    bMakeFileCalled = "-m" in vDictArgs      if not bMakeFileCalled: -        strSrc = os.path.join("lib", "LLDB"); +        strSrc = os.path.join("lib", "LLDB")      else: -        strLibFileExtn = ""; +        strLibFileExtn = ""          if eOSType == utilsOsType.EnumOsType.Windows: -            strSrc = os.path.join("bin", "liblldb.dll"); +            strSrc = os.path.join("bin", "liblldb.dll")          else:              if eOSType == utilsOsType.EnumOsType.Darwin: -                strLibFileExtn = ".dylib"; +                strLibFileExtn = ".dylib"              else: -                strLibFileExtn = ".so"; -            strSrc = os.path.join("lib", "liblldb" + strLibFileExtn); +                strLibFileExtn = ".so" +            strSrc = os.path.join("lib", "liblldb" + strLibFileExtn) -    bOk, strErrMsg = make_symlink( vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget ); +    bOk, strErrMsg = make_symlink(vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget) -    return (bOk, strErrMsg); +    return (bOk, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Make the symbolic link to the darwin-debug. @@ -384,22 +382,22 @@ def make_symlink_liblldb( vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName  #           Str - Error description on task failure.  # Throws:   None.  #-- -def make_symlink_darwin_debug( vDictArgs, vstrFrameworkPythonDir, vstrDarwinDebugFileName ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script make_symlink_darwin_debug()" ); -    bOk = True; -    strErrMsg = ""; -    strTarget = vstrDarwinDebugFileName; -    strSrc = ""; - -    bMakeFileCalled = "-m" in vDictArgs; +def make_symlink_darwin_debug(vDictArgs, vstrFrameworkPythonDir, vstrDarwinDebugFileName): +    dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_darwin_debug()") +    bOk = True +    strErrMsg = "" +    strTarget = vstrDarwinDebugFileName +    strSrc = "" + +    bMakeFileCalled = "-m" in vDictArgs      if not bMakeFileCalled: -        return (bOk, strErrMsg); +        return (bOk, strErrMsg)      else: -        strSrc = os.path.join("bin", "lldb-launcher"); +        strSrc = os.path.join("bin", "lldb-launcher") -    bOk, strErrMsg = make_symlink( vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget ); +    bOk, strErrMsg = make_symlink(vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget) -    return (bOk, strErrMsg); +    return (bOk, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Make the symbolic link to the lldb-argdumper. @@ -410,29 +408,29 @@ def make_symlink_darwin_debug( vDictArgs, vstrFrameworkPythonDir, vstrDarwinDebu  #           Str - Error description on task failure.  # Throws:   None.  #-- -def make_symlink_lldb_argdumper( vDictArgs, vstrFrameworkPythonDir, vstrArgdumperFileName ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script make_symlink_lldb_argdumper()" ); -    bOk = True; -    strErrMsg = ""; -    strTarget = vstrArgdumperFileName; -    strSrc = ""; - -    eOSType = utilsOsType.determine_os_type(); +def make_symlink_lldb_argdumper(vDictArgs, vstrFrameworkPythonDir, vstrArgdumperFileName): +    dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_lldb_argdumper()") +    bOk = True +    strErrMsg = "" +    strTarget = vstrArgdumperFileName +    strSrc = "" + +    eOSType = utilsOsType.determine_os_type()      if eOSType == utilsOsType.EnumOsType.Windows: -        strTarget += ".exe"; +        strTarget += ".exe" -    bMakeFileCalled = "-m" in vDictArgs; +    bMakeFileCalled = "-m" in vDictArgs      if not bMakeFileCalled: -        return (bOk, strErrMsg); +        return (bOk, strErrMsg)      else: -        strExeFileExtn = ""; +        strExeFileExtn = ""          if eOSType == utilsOsType.EnumOsType.Windows: -            strExeFileExtn = ".exe"; -        strSrc = os.path.join("bin", "lldb-argdumper" + strExeFileExtn); +            strExeFileExtn = ".exe" +        strSrc = os.path.join("bin", "lldb-argdumper" + strExeFileExtn) -    bOk, strErrMsg = make_symlink( vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget ); +    bOk, strErrMsg = make_symlink(vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget) -    return (bOk, strErrMsg); +    return (bOk, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Make the symlink that the script bridge for Python will need in @@ -443,37 +441,37 @@ def make_symlink_lldb_argdumper( vDictArgs, vstrFrameworkPythonDir, vstrArgdumpe  #           strErrMsg - Error description on task failure.  # Throws:   None.  #-- -def create_symlinks( vDictArgs, vstrFrameworkPythonDir ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script create_symlinks()" ); -    bOk = True; -    strErrMsg = ""; -    eOSType = utilsOsType.determine_os_type(); +def create_symlinks(vDictArgs, vstrFrameworkPythonDir): +    dbg = utilsDebug.CDebugFnVerbose("Python script create_symlinks()") +    bOk = True +    strErrMsg = "" +    eOSType = utilsOsType.determine_os_type()      # Make symlink for _lldb -    strLibLldbFileName = "_lldb"; +    strLibLldbFileName = "_lldb"      if bOk: -        bOk, strErrMsg = make_symlink_liblldb( vDictArgs, -                                               vstrFrameworkPythonDir, -                                               strLibLldbFileName ); +        bOk, strErrMsg = make_symlink_liblldb(vDictArgs, +                                              vstrFrameworkPythonDir, +                                              strLibLldbFileName)      # Make symlink for darwin-debug on Darwin      strDarwinDebugFileName = "darwin-debug"      if bOk and eOSType == utilsOsType.EnumOsType.Darwin: -        bOk, strErrMsg = make_symlink_darwin_debug( vDictArgs, -                                                    vstrFrameworkPythonDir, -                                                    strDarwinDebugFileName ); +        bOk, strErrMsg = make_symlink_darwin_debug(vDictArgs, +                                                   vstrFrameworkPythonDir, +                                                   strDarwinDebugFileName)      # Make symlink for lldb-argdumper      strArgdumperFileName = "lldb-argdumper"      if bOk: -        bOk, strErrMsg = make_symlink_lldb_argdumper( vDictArgs, -                                                 vstrFrameworkPythonDir, -                                                 strArgdumperFileName ); +        bOk, strErrMsg = make_symlink_lldb_argdumper(vDictArgs, +                                                     vstrFrameworkPythonDir, +                                                     strArgdumperFileName) -    return (bOk, strErrMsg); +    return (bOk, strErrMsg)  #++--------------------------------------------------------------------------- -# Details:  Look for the directory in which to put the Python files; if it +# Details:  Look for the directory in which to put the Python files if it  #           does not already exist, attempt to make it.  # Args:     vDictArgs               - (R) Program input parameters.  #           vstrFrameworkPythonDir  - (R) Python framework directory. @@ -481,28 +479,28 @@ def create_symlinks( vDictArgs, vstrFrameworkPythonDir ):  #           Str - Error description on task failure.  # Throws:   None.  #-- -def find_or_create_python_dir( vDictArgs, vstrFrameworkPythonDir ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script find_or_create_python_dir()" ); -    bOk = True; -    strMsg = ""; -    bDbg = "-d" in vDictArgs; +def find_or_create_python_dir(vDictArgs, vstrFrameworkPythonDir): +    dbg = utilsDebug.CDebugFnVerbose("Python script find_or_create_python_dir()") +    bOk = True +    strMsg = "" +    bDbg = "-d" in vDictArgs -    if os.path.isdir( vstrFrameworkPythonDir ): +    if os.path.isdir(vstrFrameworkPythonDir):          if bDbg: -            print((strMsgFrameWkPyExists % vstrFrameworkPythonDir)); -        return (bOk, strMsg); +            print((strMsgFrameWkPyExists % vstrFrameworkPythonDir)) +        return (bOk, strMsg)      if bDbg: -        print((strMsgFrameWkPyMkDir % vstrFrameworkPythonDir)); +        print((strMsgFrameWkPyMkDir % vstrFrameworkPythonDir))      try: -        os.makedirs( vstrFrameworkPythonDir ); +        os.makedirs(vstrFrameworkPythonDir)      except OSError as exception: -        bOk = False; +        bOk = False          strMsg = strErrMsgCreateFrmWkPyDirFailed % (vstrFrameworkPythonDir, -                                                    os.strerror( exception.errno )); +                                                    os.strerror(exception.errno)) -    return (bOk, strMsg); +    return (bOk, strMsg)  #++---------------------------------------------------------------------------  # Details:  Retrieve the configuration build path if present and valid (using @@ -514,19 +512,19 @@ def find_or_create_python_dir( vDictArgs, vstrFrameworkPythonDir ):  #           strErrMsg - Error description on task failure.  # Throws:   None.  #-- -def get_config_build_dir( vDictArgs, vstrFrameworkPythonDir ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script get_config_build_dir()" ); -    bOk = True; -    strErrMsg = ""; +def get_config_build_dir(vDictArgs, vstrFrameworkPythonDir): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_config_build_dir()") +    bOk = True +    strErrMsg = "" -    strConfigBldDir = ""; -    bHaveConfigBldDir = "--cfgBldDir" in vDictArgs; +    strConfigBldDir = "" +    bHaveConfigBldDir = "--cfgBldDir" in vDictArgs      if bHaveConfigBldDir: -        strConfigBldDir = vDictArgs[ "--cfgBldDir" ]; +        strConfigBldDir = vDictArgs["--cfgBldDir"]      if (bHaveConfigBldDir == False) or (strConfigBldDir.__len__() == 0): -        strConfigBldDir = vstrFrameworkPythonDir; +        strConfigBldDir = vstrFrameworkPythonDir -    return (bOk, strConfigBldDir, strErrMsg); +    return (bOk, strConfigBldDir, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Determine where to put the files. Retrieve the directory path for @@ -537,32 +535,32 @@ def get_config_build_dir( vDictArgs, vstrFrameworkPythonDir ):  #           strErrMsg - Error description on task failure.  # Throws:   None.  #-- -def get_framework_python_dir_windows( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script get_framework_python_dir_windows()" ); -    bOk = True; -    strWkDir = ""; -    strErrMsg = ""; +def get_framework_python_dir_windows(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_framework_python_dir_windows()") +    bOk = True +    strWkDir = "" +    strErrMsg = ""      # We are being built by LLVM, so use the PYTHON_INSTALL_DIR argument,      # and append the python version directory to the end of it.  Depending      # on the system other stuff may need to be put here as well. -    from distutils.sysconfig import get_python_lib; -    strPythonInstallDir = ""; -    bHaveArgPrefix = "--prefix" in vDictArgs; +    from distutils.sysconfig import get_python_lib +    strPythonInstallDir = "" +    bHaveArgPrefix = "--prefix" in vDictArgs      if bHaveArgPrefix: -        strPythonInstallDir = os.path.normpath(vDictArgs[ "--prefix" ]); +        strPythonInstallDir = os.path.normpath(vDictArgs["--prefix"]) -    bHaveArgCmakeBuildConfiguration = "--cmakeBuildConfiguration" in vDictArgs; +    bHaveArgCmakeBuildConfiguration = "--cmakeBuildConfiguration" in vDictArgs      if bHaveArgCmakeBuildConfiguration: -        strPythonInstallDir = os.path.join(strPythonInstallDir, vDictArgs["--cmakeBuildConfiguration"]); +        strPythonInstallDir = os.path.join(strPythonInstallDir, vDictArgs["--cmakeBuildConfiguration"])      if strPythonInstallDir.__len__() != 0: -        strWkDir = get_python_lib( True, False, strPythonInstallDir ); +        strWkDir = get_python_lib(True, False, strPythonInstallDir)      else: -        strWkDir = get_python_lib( True, False ); -    strWkDir = os.path.normcase(os.path.join(strWkDir, "lldb")); +        strWkDir = get_python_lib(True, False) +    strWkDir = os.path.normcase(os.path.join(strWkDir, "lldb")) -    return (bOk, strWkDir, strErrMsg); +    return (bOk, strWkDir, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Retrieve the directory path for Python's dist_packages/ @@ -573,33 +571,33 @@ def get_framework_python_dir_windows( vDictArgs ):  #           strErrMsg - Error description on task failure.  # Throws:   None.  #-- -def get_framework_python_dir_other_platforms( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script get_framework_python_dir_other_platform()" ); -    bOk = True; -    strWkDir = ""; -    strErrMsg = ""; -    bDbg = "-d" in vDictArgs; - -    bMakeFileCalled = "-m" in vDictArgs; +def get_framework_python_dir_other_platforms(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_framework_python_dir_other_platform()") +    bOk = True +    strWkDir = "" +    strErrMsg = "" +    bDbg = "-d" in vDictArgs + +    bMakeFileCalled = "-m" in vDictArgs      if bMakeFileCalled: -        dbg.dump_text( "Built by LLVM" ); -        return get_framework_python_dir_windows( vDictArgs ); +        dbg.dump_text("Built by LLVM") +        return get_framework_python_dir_windows(vDictArgs)      else: -        dbg.dump_text( "Built by XCode" ); +        dbg.dump_text("Built by XCode")          # We are being built by XCode, so all the lldb Python files can go          # into the LLDB.framework/Resources/Python subdirectory. -        strWkDir = vDictArgs[ "--targetDir" ]; -        strWkDir += os.path.join(strWkDir, "LLDB.framework"); -        if os.path.exists( strWkDir ): +        strWkDir = vDictArgs["--targetDir"] +        strWkDir += os.path.join(strWkDir, "LLDB.framework") +        if os.path.exists(strWkDir):              if bDbg: -                print((strMsgFoundLldbFrameWkDir % strWkDir)); -            strWkDir = os.path.join(strWkDir, "Resources", "Python", "lldb"); -            strWkDir = os.path.normcase( strWkDir ); +                print((strMsgFoundLldbFrameWkDir % strWkDir)) +            strWkDir = os.path.join(strWkDir, "Resources", "Python", "lldb") +            strWkDir = os.path.normcase(strWkDir)          else: -            bOk = False; -            strErrMsg = strErrMsgFrameWkPyDirNotExist % strWkDir; +            bOk = False +            strErrMsg = strErrMsgFrameWkPyDirNotExist % strWkDir -    return (bOk, strWkDir, strErrMsg); +    return (bOk, strWkDir, strErrMsg)  #++---------------------------------------------------------------------------  # Details:  Retrieve the directory path for Python's dist_packages/ @@ -611,22 +609,22 @@ def get_framework_python_dir_other_platforms( vDictArgs ):  #           strErrMsg - Error description on task failure.  # Throws:   None.  #-- -def get_framework_python_dir( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script get_framework_python_dir()" ); -    bOk = True; -    strWkDir = ""; -    strErrMsg = ""; +def get_framework_python_dir(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script get_framework_python_dir()") +    bOk = True +    strWkDir = "" +    strErrMsg = "" -    eOSType = utilsOsType.determine_os_type(); +    eOSType = utilsOsType.determine_os_type()      if eOSType == utilsOsType.EnumOsType.Unknown: -        bOk = False; -        strErrMsg = strErrMsgOsTypeUnknown; +        bOk = False +        strErrMsg = strErrMsgOsTypeUnknown      elif eOSType == utilsOsType.EnumOsType.Windows: -        bOk, strWkDir, strErrMsg = get_framework_python_dir_windows( vDictArgs ); +        bOk, strWkDir, strErrMsg = get_framework_python_dir_windows(vDictArgs)      else: -        bOk, strWkDir, strErrMsg = get_framework_python_dir_other_platforms( vDictArgs ); +        bOk, strWkDir, strErrMsg = get_framework_python_dir_other_platforms(vDictArgs) -    return (bOk, strWkDir, strErrMsg); +    return (bOk, strWkDir, strErrMsg)  #-----------------------------------------------------------------------------  #----------------------------------------------------------------------------- @@ -660,92 +658,92 @@ def get_framework_python_dir( vDictArgs ):      --------------------------------------------------------------------------  """ -def main( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "Python script main()" ); -    bOk = True; -    strMsg = ""; -    strErrMsgProgFail = ""; +def main(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("Python script main()") +    bOk = True +    strMsg = "" +    strErrMsgProgFail = "" -    bDbg = "-d" in vDictArgs; +    bDbg = "-d" in vDictArgs -    eOSType = utilsOsType.determine_os_type(); +    eOSType = utilsOsType.determine_os_type()      if bDbg: -        pyVersion = sys.version_info; -        print((strMsgOsVersion % utilsOsType.EnumOsType.name_of( eOSType ))); -        print((strMsgPyVersion % (pyVersion[ 0 ], pyVersion[ 1 ]))); +        pyVersion = sys.version_info +        print((strMsgOsVersion % utilsOsType.EnumOsType.name_of(eOSType))) +        print((strMsgPyVersion % (pyVersion[0], pyVersion[1]))) -    bOk, strFrameworkPythonDir, strMsg = get_framework_python_dir( vDictArgs ); +    bOk, strFrameworkPythonDir, strMsg = get_framework_python_dir(vDictArgs)      if bOk: -        bOk, strCfgBldDir, strMsg = get_config_build_dir( vDictArgs, strFrameworkPythonDir ); +        bOk, strCfgBldDir, strMsg = get_config_build_dir(vDictArgs, strFrameworkPythonDir)      if bOk and bDbg: -        print((strMsgPyFileLocatedHere % strFrameworkPythonDir)); -        print((strMsgConfigBuildDir % strCfgBldDir)); +        print((strMsgPyFileLocatedHere % strFrameworkPythonDir)) +        print((strMsgConfigBuildDir % strCfgBldDir))      if bOk: -        bOk, strMsg = find_or_create_python_dir( vDictArgs, strFrameworkPythonDir ); +        bOk, strMsg = find_or_create_python_dir(vDictArgs, strFrameworkPythonDir)      if bOk: -        bOk, strMsg = create_symlinks( vDictArgs, strFrameworkPythonDir ); +        bOk, strMsg = create_symlinks(vDictArgs, strFrameworkPythonDir)      if bOk: -        bOk, strMsg = copy_lldbpy_file_to_lldb_pkg_dir( vDictArgs, -                                                        strFrameworkPythonDir, -                                                        strCfgBldDir ); -    strRoot = os.path.normpath(vDictArgs[ "--srcRoot" ]); +        bOk, strMsg = copy_lldbpy_file_to_lldb_pkg_dir(vDictArgs, +                                                       strFrameworkPythonDir, +                                                       strCfgBldDir) +    strRoot = os.path.normpath(vDictArgs["--srcRoot"])      if bOk:          # lldb -        listPkgFiles = [ os.path.join(strRoot, "source", "Interpreter", "embedded_interpreter.py") ]; -        bOk, strMsg = create_py_pkg( vDictArgs, strFrameworkPythonDir, "", listPkgFiles ); +        listPkgFiles = [os.path.join(strRoot, "source", "Interpreter", "embedded_interpreter.py")] +        bOk, strMsg = create_py_pkg(vDictArgs, strFrameworkPythonDir, "", listPkgFiles)      if bOk:          # lldb/formatters/cpp -        listPkgFiles = [ os.path.join(strRoot, "examples", "synthetic", "gnu_libstdcpp.py"), -                         os.path.join(strRoot, "examples", "synthetic", "libcxx.py") ]; -        bOk, strMsg = create_py_pkg( vDictArgs, strFrameworkPythonDir, "/formatters/cpp", listPkgFiles ); +        listPkgFiles = [os.path.join(strRoot, "examples", "synthetic", "gnu_libstdcpp.py"), +                        os.path.join(strRoot, "examples", "synthetic", "libcxx.py")] +        bOk, strMsg = create_py_pkg(vDictArgs, strFrameworkPythonDir, "/formatters/cpp", listPkgFiles)      if bOk:          # Make an empty __init__.py in lldb/runtime as this is required for          # Python to recognize lldb.runtime as a valid package (and hence,          # lldb.runtime.objc as a valid contained package) -        listPkgFiles = []; -        bOk, strMsg = create_py_pkg( vDictArgs, strFrameworkPythonDir, "/runtime", listPkgFiles ); +        listPkgFiles = [] +        bOk, strMsg = create_py_pkg(vDictArgs, strFrameworkPythonDir, "/runtime", listPkgFiles)      if bOk:          # lldb/formatters          # Having these files copied here ensure that lldb/formatters is a          # valid package itself -        listPkgFiles = [ os.path.join(strRoot, "examples", "summaries", "cocoa", "cache.py"), -                         os.path.join(strRoot, "examples", "summaries", "cocoa", "metrics.py"), -                         os.path.join(strRoot, "examples", "summaries", "cocoa", "attrib_fromdict.py"), -                         os.path.join(strRoot, "examples", "summaries", "cocoa", "Logger.py") ]; -        bOk, strMsg = create_py_pkg( vDictArgs, strFrameworkPythonDir, "/formatters", listPkgFiles ); +        listPkgFiles = [os.path.join(strRoot, "examples", "summaries", "cocoa", "cache.py"), +                        os.path.join(strRoot, "examples", "summaries", "cocoa", "metrics.py"), +                        os.path.join(strRoot, "examples", "summaries", "cocoa", "attrib_fromdict.py"), +                        os.path.join(strRoot, "examples", "summaries", "cocoa", "Logger.py")] +        bOk, strMsg = create_py_pkg(vDictArgs, strFrameworkPythonDir, "/formatters", listPkgFiles)      if bOk:          # lldb/utils -        listPkgFiles = [ os.path.join(strRoot, "examples", "python", "symbolication.py") ]; -        bOk, strMsg = create_py_pkg( vDictArgs, strFrameworkPythonDir, "/utils", listPkgFiles ); +        listPkgFiles = [os.path.join(strRoot, "examples", "python", "symbolication.py")] +        bOk, strMsg = create_py_pkg(vDictArgs, strFrameworkPythonDir, "/utils", listPkgFiles)      if bOk and (eOSType == utilsOsType.EnumOsType.Darwin):          # lldb/macosx -        listPkgFiles = [ os.path.join(strRoot, "examples", "python", "crashlog.py"), -                         os.path.join(strRoot, "examples", "darwin", "heap_find", "heap.py") ]; -        bOk, strMsg = create_py_pkg( vDictArgs, strFrameworkPythonDir, "/macosx", listPkgFiles ); +        listPkgFiles = [os.path.join(strRoot, "examples", "python", "crashlog.py"), +                        os.path.join(strRoot, "examples", "darwin", "heap_find", "heap.py")] +        bOk, strMsg = create_py_pkg(vDictArgs, strFrameworkPythonDir, "/macosx", listPkgFiles)      if bOk and (eOSType == utilsOsType.EnumOsType.Darwin):          # lldb/diagnose -        listPkgFiles = [ os.path.join(strRoot, "examples", "python", "diagnose_unwind.py"), -                         os.path.join(strRoot, "examples", "python", "diagnose_nsstring.py") ]; -        bOk, strMsg = create_py_pkg( vDictArgs, strFrameworkPythonDir, "/diagnose", listPkgFiles ); +        listPkgFiles = [os.path.join(strRoot, "examples", "python", "diagnose_unwind.py"), +                        os.path.join(strRoot, "examples", "python", "diagnose_nsstring.py")] +        bOk, strMsg = create_py_pkg(vDictArgs, strFrameworkPythonDir, "/diagnose", listPkgFiles)      if bOk: -        bOk, strMsg = macosx_copy_file_for_heap( vDictArgs, strFrameworkPythonDir ); +        bOk, strMsg = macosx_copy_file_for_heap(vDictArgs, strFrameworkPythonDir)      if bOk: -        return (0, strMsg ); +        return (0, strMsg)      else: -        strErrMsgProgFail += strMsg; -        return (-100, strErrMsgProgFail ); +        strErrMsgProgFail += strMsg +        return (-100, strErrMsgProgFail)  #----------------------------------------------------------------------------- @@ -755,5 +753,5 @@ def main( vDictArgs ):  # This script can be called by another Python script by calling the main()  # function directly  if __name__ == "__main__": -    print("Script cannot be called directly, called by finishSwigWrapperClasses.py"); +    print("Script cannot be called directly, called by finishSwigWrapperClasses.py") diff --git a/lldb/scripts/Python/modify-python-lldb.py b/lldb/scripts/Python/modify-python-lldb.py index 03a165c631e..7b9c26c6d80 100644 --- a/lldb/scripts/Python/modify-python-lldb.py +++ b/lldb/scripts/Python/modify-python-lldb.py @@ -27,7 +27,7 @@ if sys.version_info.major >= 3:  else:      import StringIO -if len (sys.argv) != 2: +if len(sys.argv) != 2:      output_name = "./lldb.py"  else:      output_name = sys.argv[1] + "/lldb.py" diff --git a/lldb/scripts/buildSwigWrapperClasses.py b/lldb/scripts/buildSwigWrapperClasses.py index ff5cfb737de..701bf63f476 100644 --- a/lldb/scripts/buildSwigWrapperClasses.py +++ b/lldb/scripts/buildSwigWrapperClasses.py @@ -36,27 +36,27 @@ import utilsOsType      # Determine the OS type this script is running on  import utilsDebug       # Debug Python scripts  # Instantiations: -gbDbgVerbose = False;           # True = Turn on script function tracing, False = off. -gbDbgFlag = False;              # Global debug mode flag, set by input parameter +gbDbgVerbose = False           # True = Turn on script function tracing, False = off. +gbDbgFlag = False              # Global debug mode flag, set by input parameter                                  # --dbgFlag. True = operate in debug mode. -gbMakeFileFlag = False;         # True = yes called from makefile system, False = not. -gbSwigGenDepFileFlag = False;   # True = SWIG generate a dependency file. +gbMakeFileFlag = False         # True = yes called from makefile system, False = not. +gbSwigGenDepFileFlag = False   # True = SWIG generate a dependency file.  # User facing text: -strMsgErrorNoMain = "Program called by another Python script not allowed"; -strExitMsgSuccess = "Program successful"; -strExitMsgError = "Program error: "; -strParameter = "Parameter: "; +strMsgErrorNoMain = "Program called by another Python script not allowed" +strExitMsgSuccess = "Program successful" +strExitMsgError = "Program error: " +strParameter = "Parameter: "  strMsgErrorOsTypeUnknown = "Unable to determine OS type" -strSwigFileFound = "Found the \'lldb.swig\' file\n"; +strSwigFileFound = "Found the \'lldb.swig\' file\n"  strSwigFileFoundNotFound = "Unable to locate the file \'%s\'" -strSwigExeFileNotFound = "Unable to locate the SWIG executable file \'swig\'"; -strSwigScriptDirNotFound = "Unable to locate the SWIG script directory \'/script\'"; -strSwigScriptNotFound = "Unable to locate the SWIG script file \'%s\' in \'%s\'. Is it a script directory?"; -strSwigScriptLangFound = "Found \'%s\' build script."; -strSwigScriptLangsFound = "Found the following script languages:"; -strSwigExecuteMsg = "Executing \'%s\' build script..."; -strSwigExecuteError = "Executing \'%s\' build script failed: "; +strSwigExeFileNotFound = "Unable to locate the SWIG executable file \'swig\'" +strSwigScriptDirNotFound = "Unable to locate the SWIG script directory \'/script\'" +strSwigScriptNotFound = "Unable to locate the SWIG script file \'%s\' in \'%s\'. Is it a script directory?" +strSwigScriptLangFound = "Found \'%s\' build script." +strSwigScriptLangsFound = "Found the following script languages:" +strSwigExecuteMsg = "Executing \'%s\' build script..." +strSwigExecuteError = "Executing \'%s\' build script failed: "  strHelpInfo = "\  Python script(s) to build the SWIG Python C++ Script \n\  Bridge wrapper code on various platforms.  The Python \n\ @@ -86,7 +86,7 @@ Usage:\n\      buildSwigWrapperClasses.py --srcRoot=ADirPath --targetDir=ADirPath\n\      --cfgBldDir=ADirPath --prefix=ADirPath --swigExecutable=ADirPath -m -d\n\  \n\ -"; #TAG_PROGRAM_HELP_INFO +" #TAG_PROGRAM_HELP_INFO  strHelpInfoExtraWindows = "\  On the Windows platform the PATH environmental variable needs to be \n\  extended to include the installed SWIG executable path so it can be \n\ @@ -94,7 +94,7 @@ be found by this Python script. The SWIG executable name is 'swig'."  strHelpInfoExtraNonWindows = "\  This Python script looks for the SWIG executable 'swig' in the following \n\  directories '/usr/bin', '/usr/local/bin'. If not found the script will \n\ -abort."; +abort."  #++---------------------------------------------------------------------------  # Details:  Retrieve the script -h help information based on the OS currently. @@ -103,15 +103,15 @@ abort.";  # Throws:   None.  #--  def get_help_information(): -    strHelpMsg = strHelpInfo; +    strHelpMsg = strHelpInfo -    eOSType = utilsOsType.determine_os_type(); +    eOSType = utilsOsType.determine_os_type()      if eOSType == utilsOsType.EnumOsType.Windows: -        strHelpMsg += strHelpInfoExtraWindows; +        strHelpMsg += strHelpInfoExtraWindows      else: -        strHelpMsg += strHelpInfoExtraNonWindows; +        strHelpMsg += strHelpInfoExtraNonWindows -    return strHelpMsg; +    return strHelpMsg  #++---------------------------------------------------------------------------  # Details:  Exit the program on success. Called on program successfully done @@ -121,14 +121,14 @@ def get_help_information():  # Returns:  None.  # Throws:   None.  #-- -def program_exit_success( vnResult, vMsg ): -    strMsg = ""; +def program_exit_success(vnResult, vMsg): +    strMsg = ""      if vMsg.__len__() != 0: -        strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult); -        print(strMsg); +        strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult) +        print(strMsg) -    sys.exit( vnResult ); +    sys.exit(vnResult)  #++---------------------------------------------------------------------------  # Details:  Exit the program with error. Called on exit program failed its @@ -138,9 +138,9 @@ def program_exit_success( vnResult, vMsg ):  # Returns:  None.  # Throws:   None.  #-- -def program_exit_on_failure( vnResult, vMsg ): -    print(("%s%s (%d)" % (strExitMsgError, vMsg, vnResult))); -    sys.exit( vnResult ); +def program_exit_on_failure(vnResult, vMsg): +    print(("%s%s (%d)" % (strExitMsgError, vMsg, vnResult))) +    sys.exit(vnResult)  #++---------------------------------------------------------------------------  # Details:  Exit the program return a exit result number and print a message. @@ -151,11 +151,11 @@ def program_exit_on_failure( vnResult, vMsg ):  # Returns:  None.  # Throws:   None.  #-- -def program_exit( vnResult, vMsg ): +def program_exit(vnResult, vMsg):      if vnResult >= 0: -        program_exit_success( vnResult, vMsg ); +        program_exit_success(vnResult, vMsg)      else: -        program_exit_on_failure( vnResult, vMsg ); +        program_exit_on_failure(vnResult, vMsg)  #++---------------------------------------------------------------------------  # Details:  Dump input parameters. @@ -163,14 +163,14 @@ def program_exit( vnResult, vMsg ):  # Returns:  None.  # Throws:   None.  #-- -def print_out_input_parameters( vDictArgs ): +def print_out_input_parameters(vDictArgs):      for arg, val in vDictArgs.items(): -        strEqs = ""; -        strQ = ""; +        strEqs = "" +        strQ = ""          if val.__len__() != 0: -            strEqs = " ="; -            strQ = "\""; -        print(("%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ))); +            strEqs = " =" +            strQ = "\"" +        print(("%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ)))  #++---------------------------------------------------------------------------  # Details:  Locate the lldb.swig file. No checking for path correctness is @@ -183,21 +183,21 @@ def print_out_input_parameters( vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def check_lldb_swig_file_exists( vstrSrcRoot, veOSType ): -    dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_file_exists()" ); -    bOk = True; -    strStatusMsg = ""; -    strSwigFilePathName = "/scripts/lldb.swig"; - -    strFullPath = os.path.normcase( vstrSrcRoot + strSwigFilePathName ); -    bOk = os.path.isfile( strFullPath ); +def check_lldb_swig_file_exists(vstrSrcRoot, veOSType): +    dbg = utilsDebug.CDebugFnVerbose("check_lldb_swig_file_exists()") +    bOk = True +    strStatusMsg = "" +    strSwigFilePathName = "/scripts/lldb.swig" + +    strFullPath = os.path.normcase(vstrSrcRoot + strSwigFilePathName) +    bOk = os.path.isfile(strFullPath)      if bOk:          if gbDbgFlag: -            print(strSwigFileFound); +            print(strSwigFileFound)      else: -        strStatusMsg = strSwigFileFoundNotFound % strFullPath; +        strStatusMsg = strSwigFileFoundNotFound % strFullPath -    return (bOk, strStatusMsg); +    return (bOk, strStatusMsg)  #++---------------------------------------------------------------------------  # Details:  Locate SWIG sub script language directory and the script within @@ -209,41 +209,41 @@ def check_lldb_swig_file_exists( vstrSrcRoot, veOSType ):  #           Str     - Error message.  # Throws:   None.  #-- -def run_swig( vStrScriptLang, vSwigBuildFileName, vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "run_swig()" ); -    nResult = 0; -    strStatusMsg = ""; -    strScriptFile = vSwigBuildFileName % vStrScriptLang; -    strScriptFileDir = "%s%s/%s" % (vDictArgs[ "--srcRoot" ], "/scripts", -                                    vStrScriptLang); -    strScriptFilePath = "%s/%s" % (strScriptFileDir, strScriptFile); +def run_swig(vStrScriptLang, vSwigBuildFileName, vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("run_swig()") +    nResult = 0 +    strStatusMsg = "" +    strScriptFile = vSwigBuildFileName % vStrScriptLang +    strScriptFileDir = "%s%s/%s" % (vDictArgs["--srcRoot"], "/scripts", +                                    vStrScriptLang) +    strScriptFilePath = "%s/%s" % (strScriptFileDir, strScriptFile)      # Check for the existence of the script file -    strPath = os.path.normcase( strScriptFilePath ); -    bOk = os.path.exists( strPath ); +    strPath = os.path.normcase(strScriptFilePath) +    bOk = os.path.exists(strPath)      if bOk == False: -        strDir = os.path.normcase( strScriptFileDir ); -        strStatusMsg = strSwigScriptNotFound % (strScriptFile, strDir); -        return (-9, strStatusMsg); +        strDir = os.path.normcase(strScriptFileDir) +        strStatusMsg = strSwigScriptNotFound % (strScriptFile, strDir) +        return (-9, strStatusMsg)      if gbDbgFlag: -        print((strSwigScriptLangFound % vStrScriptLang)); -        print((strSwigExecuteMsg % vStrScriptLang)); +        print((strSwigScriptLangFound % vStrScriptLang)) +        print((strSwigExecuteMsg % vStrScriptLang))      # Change where Python looks for our modules -    strDir = os.path.normcase( strScriptFileDir ); -    sys.path.append( strDir ); +    strDir = os.path.normcase(strScriptFileDir) +    sys.path.append(strDir)      # Execute the specific language script -    dictArgs = vDictArgs; # Remove any args not required before passing on -    strModuleName = strScriptFile[ : strScriptFile.__len__() - 3 ]; -    module = __import__( strModuleName ); -    nResult, strStatusMsg = module.main( dictArgs ); +    dictArgs = vDictArgs # Remove any args not required before passing on +    strModuleName = strScriptFile[: strScriptFile.__len__() - 3] +    module = __import__(strModuleName) +    nResult, strStatusMsg = module.main(dictArgs)      # Revert sys path -    sys.path.remove( strDir ); +    sys.path.remove(strDir) -    return (nResult, strStatusMsg); +    return (nResult, strStatusMsg)  #++---------------------------------------------------------------------------  # Details:  Step through each SWIG sub directory script language supported @@ -259,26 +259,26 @@ def run_swig( vStrScriptLang, vSwigBuildFileName, vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def run_swig_for_each_script_supported( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "run_swig_for_each_script_supported()" ); -    nResult = 0; -    strStatusMsg = ""; -    strSwigScriptDir = vDictArgs[ "--srcRoot" ] + "/scripts"; -    strSwigBuildFileName = "buildSwig%s.py"; +def run_swig_for_each_script_supported(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("run_swig_for_each_script_supported()") +    nResult = 0 +    strStatusMsg = "" +    strSwigScriptDir = vDictArgs["--srcRoot"] + "/scripts" +    strSwigBuildFileName = "buildSwig%s.py"      # Check for the existence of the SWIG scripts folder -    strScriptsDir = os.path.normcase( strSwigScriptDir ); -    bOk = os.path.exists( strScriptsDir ); +    strScriptsDir = os.path.normcase(strSwigScriptDir) +    bOk = os.path.exists(strScriptsDir)      if bOk == False: -        return (-8, strSwigScriptDirNotFound); +        return (-8, strSwigScriptDirNotFound)      # Look for any script language directories to build for -    listDirs = []; -    nDepth = 1; -    for strPath, listDirs, listFiles in os.walk( strSwigScriptDir ): -        nDepth = nDepth - 1; +    listDirs = [] +    nDepth = 1 +    for strPath, listDirs, listFiles in os.walk(strSwigScriptDir): +        nDepth = nDepth - 1          if nDepth == 0: -            break; +            break      # Skip the directory that contains the interface files.      listDirs.remove('interface') @@ -290,24 +290,24 @@ def run_swig_for_each_script_supported( vDictArgs ):          sys.stdout.write(strSwigScriptLangsFound)          for dir in listDirs:              sys.stdout.write(dir) -        print("\n"); +        print("\n")      # Iterate script directory find any script language directories      for scriptLang in listDirs:          # __pycache__ is a magic directory in Python 3 that holds .pyc files          if scriptLang != "__pycache__": -            dbg.dump_text( "Executing language script for \'%s\'" % scriptLang ); -            nResult, strStatusMsg = run_swig( scriptLang, strSwigBuildFileName, -                                              vDictArgs ); +            dbg.dump_text("Executing language script for \'%s\'" % scriptLang) +            nResult, strStatusMsg = run_swig(scriptLang, strSwigBuildFileName, +                                             vDictArgs)          if nResult < 0: -            break; +            break      if nResult < 0: -        strTmp = strSwigExecuteError % scriptLang; -        strTmp += strStatusMsg; -        strStatusMsg = strTmp; +        strTmp = strSwigExecuteError % scriptLang +        strTmp += strStatusMsg +        strStatusMsg = strTmp -    return (nResult, strStatusMsg); +    return (nResult, strStatusMsg)  #++---------------------------------------------------------------------------  # Details:  Dummy function - system unknown. Function should not be called. @@ -316,10 +316,10 @@ def run_swig_for_each_script_supported( vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def check_lldb_swig_executable_file_exists_Unknown( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Unknown()" ); +def check_lldb_swig_executable_file_exists_Unknown(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("check_lldb_swig_executable_file_exists_Unknown()")      # Do nothing -    return (False, strMsgErrorOsTypeUnknown); +    return (False, strMsgErrorOsTypeUnknown)  #++---------------------------------------------------------------------------  # Details:  Locate the SWIG executable file in a Windows system. Several hard @@ -331,16 +331,16 @@ def check_lldb_swig_executable_file_exists_Unknown( vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def check_lldb_swig_executable_file_exists_Windows( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Windows()" ); +def check_lldb_swig_executable_file_exists_Windows(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("check_lldb_swig_executable_file_exists_Windows()")      # Will always be true as it assumed the path to SWIG executable will be      # in the OS system environmental variable %PATH%. Easier this way as the      # user may have renamed the directory and or custom path installation. -    bExeFileFound = True; -    vDictArgs[ "--swigExePath" ] = ""; -    vDictArgs[ "--swigExeName" ] = "swig.exe"; -    return (bExeFileFound, None); +    bExeFileFound = True +    vDictArgs["--swigExePath"] = "" +    vDictArgs["--swigExeName"] = "swig.exe" +    return (bExeFileFound, None)  #++---------------------------------------------------------------------------  # Details:  Locate the SWIG executable file in a Linux system. Several hard @@ -352,28 +352,28 @@ def check_lldb_swig_executable_file_exists_Windows( vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def check_lldb_swig_executable_file_exists_Linux( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Linux()" ); -    bExeFileFound = False; - -    strSwigExe = "swig"; -    strSwigExePath = "/usr/bin"; -    strExe = os.path.normcase( "%s/%s" % (strSwigExePath, strSwigExe) ); -    if os.path.isfile( strExe ) and os.access( strExe, os.X_OK ): -        bExeFileFound = True; -        vDictArgs[ "--swigExePath" ] = os.path.normcase( strSwigExePath ); -        vDictArgs[ "--swigExeName" ] = strSwigExe; -        return (bExeFileFound, None); - -    strSwigExePath = "/usr/local/bin"; -    strExe = os.path.normcase( "%s/%s" % (strSwigExePath, strSwigExe) ); -    if os.path.isfile( strExe ) and os.access( strExe, os.X_OK ): -        bExeFileFound = True; -        vDictArgs[ "--swigExePath" ] = os.path.normcase( strSwigExePath ); -        vDictArgs[ "--swigExeName" ] = strSwigExe; -        return (bExeFileFound, None); - -    return (bExeFileFound, strSwigExeFileNotFound); +def check_lldb_swig_executable_file_exists_Linux(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("check_lldb_swig_executable_file_exists_Linux()") +    bExeFileFound = False + +    strSwigExe = "swig" +    strSwigExePath = "/usr/bin" +    strExe = os.path.normcase("%s/%s" % (strSwigExePath, strSwigExe)) +    if os.path.isfile(strExe) and os.access(strExe, os.X_OK): +        bExeFileFound = True +        vDictArgs["--swigExePath"] = os.path.normcase(strSwigExePath) +        vDictArgs["--swigExeName"] = strSwigExe +        return (bExeFileFound, None) + +    strSwigExePath = "/usr/local/bin" +    strExe = os.path.normcase("%s/%s" % (strSwigExePath, strSwigExe)) +    if os.path.isfile(strExe) and os.access(strExe, os.X_OK): +        bExeFileFound = True +        vDictArgs["--swigExePath"] = os.path.normcase(strSwigExePath) +        vDictArgs["--swigExeName"] = strSwigExe +        return (bExeFileFound, None) + +    return (bExeFileFound, strSwigExeFileNotFound)  #++---------------------------------------------------------------------------  # Details:  Locate the SWIG executable file in a OSX system. Several hard @@ -385,14 +385,14 @@ def check_lldb_swig_executable_file_exists_Linux( vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def check_lldb_swig_executable_file_exists_Darwin( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Darwin()" ); -    bExeFileFound = False; +def check_lldb_swig_executable_file_exists_Darwin(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("check_lldb_swig_executable_file_exists_Darwin()") +    bExeFileFound = False      # ToDo: Find the SWIG executable and add the path to the args dictionary -    #vDictArgs.[ "--swigExePath" ] = "/usr/bin/swig"; -    strStatusMsg = "Sorry function 'check_lldb_swig_executable_file_exists_Darwin()' is not implemented"; +    #vDictArgs.["--swigExePath"] = "/usr/bin/swig" +    strStatusMsg = "Sorry function 'check_lldb_swig_executable_file_exists_Darwin()' is not implemented" -    return (bExeFileFound, strStatusMsg); +    return (bExeFileFound, strStatusMsg)  #++---------------------------------------------------------------------------  # Details:  Locate the SWIG executable file in a OSX system. Several hard @@ -404,14 +404,14 @@ def check_lldb_swig_executable_file_exists_Darwin( vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def check_lldb_swig_executable_file_exists_FreeBSD( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_FreeBSD()" ); -    bExeFileFound = False; +def check_lldb_swig_executable_file_exists_FreeBSD(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("check_lldb_swig_executable_file_exists_FreeBSD()") +    bExeFileFound = False      # ToDo: Find the SWIG executable and add the path to the args dictionary -    #vDictArgs.[ "--swigExePath" ] = "/usr/bin/swig"; -    strStatusMsg = "Sorry function 'check_lldb_swig_executable_file_exists_FreeBSD()' is not implemented"; +    #vDictArgs.["--swigExePath"] = "/usr/bin/swig" +    strStatusMsg = "Sorry function 'check_lldb_swig_executable_file_exists_FreeBSD()' is not implemented" -    return (bExeFileFound, strStatusMsg); +    return (bExeFileFound, strStatusMsg)  #++---------------------------------------------------------------------------  # Details:  Locate the SWIG executable file. Several hard coded predetermined @@ -423,23 +423,23 @@ def check_lldb_swig_executable_file_exists_FreeBSD( vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def check_lldb_swig_executable_file_exists( vDictArgs, veOSType ): -    dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists()" ); -    bExeFileFound = False; -    strStatusMsg = ""; +def check_lldb_swig_executable_file_exists(vDictArgs, veOSType): +    dbg = utilsDebug.CDebugFnVerbose("check_lldb_swig_executable_file_exists()") +    bExeFileFound = False +    strStatusMsg = ""      if "--swigExecutable" in vDictArgs:          vDictArgs["--swigExeName"] = os.path.basename(vDictArgs["--swigExecutable"])          vDictArgs["--swigExePath"] = os.path.dirname(vDictArgs["--swigExecutable"])          bExeFileFound = True      else: -        from utilsOsType import EnumOsType; -        switch = { EnumOsType.Unknown : check_lldb_swig_executable_file_exists_Unknown, -               EnumOsType.Darwin : check_lldb_swig_executable_file_exists_Darwin, -               EnumOsType.FreeBSD : check_lldb_swig_executable_file_exists_FreeBSD, -               EnumOsType.Linux : check_lldb_swig_executable_file_exists_Linux, -               EnumOsType.Windows : check_lldb_swig_executable_file_exists_Windows } -        bExeFileFound, strStatusMsg = switch[ veOSType ]( vDictArgs ); -    return (bExeFileFound, strStatusMsg); +        from utilsOsType import EnumOsType +        switch = {EnumOsType.Unknown : check_lldb_swig_executable_file_exists_Unknown, +                  EnumOsType.Darwin : check_lldb_swig_executable_file_exists_Darwin, +                  EnumOsType.FreeBSD : check_lldb_swig_executable_file_exists_FreeBSD, +                  EnumOsType.Linux : check_lldb_swig_executable_file_exists_Linux, +                  EnumOsType.Windows : check_lldb_swig_executable_file_exists_Windows} +        bExeFileFound, strStatusMsg = switch[veOSType](vDictArgs) +    return (bExeFileFound, strStatusMsg)  #++---------------------------------------------------------------------------  # Details:  Validate the arguments passed to the program. This function exits  #           the program should error with the arguments be found. @@ -448,39 +448,39 @@ def check_lldb_swig_executable_file_exists( vDictArgs, veOSType ):  #           Dict    - Map of arguments names to argument values  # Throws:   None.  #-- -def validate_arguments( vArgv ): -    dbg = utilsDebug.CDebugFnVerbose( "validate_arguments()" ); -    strMsg = ""; -    dictArgs = {}; -    nResult = 0; -    strListArgs = "hdmM"; # Format "hiox:" = -h -i -o -x <arg> +def validate_arguments(vArgv): +    dbg = utilsDebug.CDebugFnVerbose("validate_arguments()") +    strMsg = "" +    dictArgs = {} +    nResult = 0 +    strListArgs = "hdmM" # Format "hiox:" = -h -i -o -x <arg>      listLongArgs = ["srcRoot=", "targetDir=", "cfgBldDir=", "prefix=", -            "swigExecutable=", "argsFile"]; -    dictArgReq = {  "-h": "o",          # o = optional, m = mandatory -                    "-d": "o", -                    "-m": "o", -                    "-M": "o", -                    "--srcRoot": "m", -                    "--targetDir": "m", -                    "--swigExecutable" : "o", -                    "--cfgBldDir": "o", -                    "--prefix": "o", -                    "--argsFile": "o" }; -    strHelpInfo = get_help_information(); +            "swigExecutable=", "argsFile"] +    dictArgReq = {"-h": "o",          # o = optional, m = mandatory +                  "-d": "o", +                  "-m": "o", +                  "-M": "o", +                  "--srcRoot": "m", +                  "--targetDir": "m", +                  "--swigExecutable" : "o", +                  "--cfgBldDir": "o", +                  "--prefix": "o", +                  "--argsFile": "o"} +    strHelpInfo = get_help_information()      # Check for mandatory parameters -    nResult, dictArgs, strMsg = utilsArgsParse.parse( vArgv, strListArgs, -                                                      listLongArgs, -                                                      dictArgReq, -                                                      strHelpInfo ); +    nResult, dictArgs, strMsg = utilsArgsParse.parse(vArgv, strListArgs, +                                                     listLongArgs, +                                                     dictArgReq, +                                                     strHelpInfo)      if nResult < 0: -        program_exit_on_failure( nResult, strMsg ); +        program_exit_on_failure(nResult, strMsg)      # User input -h for help      if nResult == 1: -        program_exit_success( 0, strMsg ); +        program_exit_success(0, strMsg) -    return (nResult, dictArgs); +    return (nResult, dictArgs)  #++---------------------------------------------------------------------------  # Details:  Program's main() with arguments passed in from the command line. @@ -490,45 +490,45 @@ def validate_arguments( vArgv ):  # Returns:  None  # Throws:   None.  #-- -def main( vArgv ): -    dbg = utilsDebug.CDebugFnVerbose( "main()" ); -    bOk = False; -    dictArgs = {}; -    nResult = 0; -    strMsg = ""; +def main(vArgv): +    dbg = utilsDebug.CDebugFnVerbose("main()") +    bOk = False +    dictArgs = {} +    nResult = 0 +    strMsg = ""      # The validate arguments fn will exit the program if tests fail -    nResult, dictArgs = validate_arguments( vArgv ); +    nResult, dictArgs = validate_arguments(vArgv) -    eOSType = utilsOsType.determine_os_type(); +    eOSType = utilsOsType.determine_os_type()      if eOSType == utilsOsType.EnumOsType.Unknown: -        program_exit( -4, strMsgErrorOsTypeUnknown ); +        program_exit(-4, strMsgErrorOsTypeUnknown) -    global gbDbgFlag; -    gbDbgFlag = "-d" in dictArgs; +    global gbDbgFlag +    gbDbgFlag = "-d" in dictArgs      if gbDbgFlag: -        print_out_input_parameters( dictArgs ); +        print_out_input_parameters(dictArgs)      # Check to see if we were called from the Makefile system. If we were, check      # if the caller wants SWIG to generate a dependency file.      # Not used in this program, but passed through to the language script file      # called by this program -    global gbMakeFileFlag; -    global gbSwigGenDepFileFlag; -    gbMakeFileFlag = "-m" in dictArgs; -    gbSwigGenDepFileFlag = "-M" in dictArgs; +    global gbMakeFileFlag +    global gbSwigGenDepFileFlag +    gbMakeFileFlag = "-m" in dictArgs +    gbSwigGenDepFileFlag = "-M" in dictArgs -    bOk, strMsg = check_lldb_swig_file_exists( dictArgs[ "--srcRoot" ], eOSType ); +    bOk, strMsg = check_lldb_swig_file_exists(dictArgs["--srcRoot"], eOSType)      if bOk == False: -        program_exit( -3, strMsg ); +        program_exit(-3, strMsg) -    bOk, strMsg = check_lldb_swig_executable_file_exists( dictArgs, eOSType ); +    bOk, strMsg = check_lldb_swig_executable_file_exists(dictArgs, eOSType)      if bOk == False: -        program_exit( -6, strMsg ); +        program_exit(-6, strMsg) -    nResult, strMsg = run_swig_for_each_script_supported( dictArgs ); +    nResult, strMsg = run_swig_for_each_script_supported(dictArgs) -    program_exit( nResult, strMsg ); +    program_exit(nResult, strMsg)  #-----------------------------------------------------------------------------  #----------------------------------------------------------------------------- @@ -579,8 +579,8 @@ def main( vArgv ):  # Called using "__main__" when not imported i.e. from the command line  if __name__ == "__main__": -    utilsDebug.CDebugFnVerbose.bVerboseOn = gbDbgVerbose; -    dbg = utilsDebug.CDebugFnVerbose( "__main__" ); -    main( sys.argv[ 1: ] ); +    utilsDebug.CDebugFnVerbose.bVerboseOn = gbDbgVerbose +    dbg = utilsDebug.CDebugFnVerbose("__main__") +    main(sys.argv[1:])  else: -    program_exit( -5, strMsgErrorNoMain ); +    program_exit(-5, strMsgErrorNoMain) diff --git a/lldb/scripts/finishSwigWrapperClasses.py b/lldb/scripts/finishSwigWrapperClasses.py index 3e576263562..b71fdecf933 100644 --- a/lldb/scripts/finishSwigWrapperClasses.py +++ b/lldb/scripts/finishSwigWrapperClasses.py @@ -34,25 +34,25 @@ import utilsOsType      # Determine the OS type this script is running on  import utilsDebug       # Debug Python scripts  # Instantiations: -gbDbgVerbose = False;           # True = Turn on script function tracing, False = off. -gbDbgFlag = False;              # Global debug mode flag, set by input parameter +gbDbgVerbose = False           # True = Turn on script function tracing, False = off. +gbDbgFlag = False              # Global debug mode flag, set by input parameter                                  # --dbgFlag. True = operate in debug mode. -gbMakeFileFlag = False;         # True = yes called from makefile system, False = not. +gbMakeFileFlag = False         # True = yes called from makefile system, False = not.  # User facing text: -strMsgErrorNoMain = "Program called by another Python script not allowed"; -strExitMsgSuccess = "Program successful"; -strExitMsgError = "Program error: "; -strParameter = "Parameter: "; +strMsgErrorNoMain = "Program called by another Python script not allowed" +strExitMsgSuccess = "Program successful" +strExitMsgError = "Program error: " +strParameter = "Parameter: "  strMsgErrorOsTypeUnknown = "Unable to determine OS type" -strScriptDirNotFound = "Unable to locate the script directory \'/script\'"; -strScriptLangsFound = "Found the following script languages:"; -strPostProcessError = "Executing \'%s\' post process script failed: "; -strScriptNotFound = "Unable to locate the post process script file \'%s\' in \'%s\'"; -strScriptLangFound = "Found \'%s\' build script."; -strScriptLangsFound = "Found the following script languages:"; -strExecuteMsg = "Executing \'%s\' build script..."; -strExecuteError = "Executing \'%s\' build script failed: "; +strScriptDirNotFound = "Unable to locate the script directory \'/script\'" +strScriptLangsFound = "Found the following script languages:" +strPostProcessError = "Executing \'%s\' post process script failed: " +strScriptNotFound = "Unable to locate the post process script file \'%s\' in \'%s\'" +strScriptLangFound = "Found \'%s\' build script." +strScriptLangsFound = "Found the following script languages:" +strExecuteMsg = "Executing \'%s\' build script..." +strExecuteError = "Executing \'%s\' build script failed: "  strHelpInfo = "\  Python script(s) to finish off the SWIG Python C++ Script \n\  Bridge wrapper code on the Windows/LINUX/OSX platform.  The Python \n\ @@ -82,7 +82,7 @@ Usage:\n\      finishSwigWrapperClasses.py --srcRoot=ADirPath --targetDir=ADirPath\n\      --cfgBldDir=ADirPath --prefix=ADirPath -m -d\n\  \n\ -"; #TAG_PROGRAM_HELP_INFO +" #TAG_PROGRAM_HELP_INFO  #++---------------------------------------------------------------------------  # Details:  Exit the program on success. Called on program successfully done @@ -92,14 +92,14 @@ Usage:\n\  # Returns:  None.  # Throws:   None.  #-- -def program_exit_success( vnResult, vMsg ): -    strMsg = ""; +def program_exit_success(vnResult, vMsg): +    strMsg = ""      if vMsg.__len__() != 0: -        strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult); -        print(strMsg); +        strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult) +        print(strMsg) -    sys.exit( vnResult ); +    sys.exit(vnResult)  #++---------------------------------------------------------------------------  # Details:  Exit the program with error. Called on exit program failed its @@ -109,9 +109,9 @@ def program_exit_success( vnResult, vMsg ):  # Returns:  None.  # Throws:   None.  #-- -def program_exit_on_failure( vnResult, vMsg ): -    print(("%s%s (%d)" % (strExitMsgError, vMsg, vnResult))); -    sys.exit( vnResult ); +def program_exit_on_failure(vnResult, vMsg): +    print(("%s%s (%d)" % (strExitMsgError, vMsg, vnResult))) +    sys.exit(vnResult)  #++---------------------------------------------------------------------------  # Details:  Exit the program return a exit result number and print a message. @@ -122,11 +122,11 @@ def program_exit_on_failure( vnResult, vMsg ):  # Returns:  None.  # Throws:   None.  #-- -def program_exit( vnResult, vMsg ): +def program_exit(vnResult, vMsg):      if vnResult >= 0: -        program_exit_success( vnResult, vMsg ); +        program_exit_success(vnResult, vMsg)      else: -        program_exit_on_failure( vnResult, vMsg ); +        program_exit_on_failure(vnResult, vMsg)  #++---------------------------------------------------------------------------  # Details:  Dump input parameters. @@ -134,14 +134,14 @@ def program_exit( vnResult, vMsg ):  # Returns:  None.  # Throws:   None.  #-- -def print_out_input_parameters( vDictArgs ): +def print_out_input_parameters(vDictArgs):      for arg, val in list(vDictArgs.items()): -        strEqs = ""; -        strQ = ""; +        strEqs = "" +        strQ = ""          if val.__len__() != 0: -            strEqs = " ="; -            strQ = "\""; -        print(("%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ))); +            strEqs = " =" +            strQ = "\"" +        print(("%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ)))  #++---------------------------------------------------------------------------  # Details:  Validate the arguments passed to the program. This function exits @@ -151,14 +151,14 @@ def print_out_input_parameters( vDictArgs ):  #           Dict    - Map of arguments names to argument values  # Throws:   None.  #-- -def validate_arguments( vArgv ): -    dbg = utilsDebug.CDebugFnVerbose( "validate_arguments()" ); -    strMsg = ""; -    dictArgs = {}; -    nResult = 0; -    strListArgs = "hdm"; # Format "hiox:" = -h -i -o -x <arg> +def validate_arguments(vArgv): +    dbg = utilsDebug.CDebugFnVerbose("validate_arguments()") +    strMsg = "" +    dictArgs = {} +    nResult = 0 +    strListArgs = "hdm" # Format "hiox:" = -h -i -o -x <arg>      listLongArgs = ["srcRoot=", "targetDir=", "cfgBldDir=", "prefix=", "cmakeBuildConfiguration=", -                    "argsFile"]; +                    "argsFile"]      dictArgReq = {  "-h": "o",          # o = optional, m = mandatory                      "-d": "o",                      "-m": "o", @@ -167,21 +167,21 @@ def validate_arguments( vArgv ):                      "--cfgBldDir": "o",                      "--prefix": "o",                      "--cmakeBuildConfiguration": "o", -                    "--argsFile": "o" }; +                    "--argsFile": "o" }      # Check for mandatory parameters -    nResult, dictArgs, strMsg = utilsArgsParse.parse( vArgv, strListArgs, -                                                      listLongArgs, -                                                      dictArgReq, -                                                      strHelpInfo ); +    nResult, dictArgs, strMsg = utilsArgsParse.parse(vArgv, strListArgs, +                                                     listLongArgs, +                                                     dictArgReq, +                                                     strHelpInfo)      if nResult < 0: -        program_exit_on_failure( nResult, strMsg ); +        program_exit_on_failure(nResult, strMsg)      # User input -h for help      if nResult == 1: -        program_exit_success( 0, strMsg ); +        program_exit_success(0, strMsg) -    return (nResult, dictArgs); +    return (nResult, dictArgs)  #++---------------------------------------------------------------------------  # Details:  Locate post process script language directory and the script within @@ -193,40 +193,40 @@ def validate_arguments( vArgv ):  #           Str     - Error message.  # Throws:   None.  #-- -def run_post_process( vStrScriptLang, vstrFinishFileName, vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "run_post_process()" ); -    nResult = 0; -    strStatusMsg = ""; -    strScriptFile = vstrFinishFileName % vStrScriptLang; -    strScriptFileDir = os.path.normpath(os.path.join(vDictArgs["--srcRoot"], "scripts", vStrScriptLang)); -    strScriptFilePath = os.path.join(strScriptFileDir, strScriptFile); +def run_post_process(vStrScriptLang, vstrFinishFileName, vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("run_post_process()") +    nResult = 0 +    strStatusMsg = "" +    strScriptFile = vstrFinishFileName % vStrScriptLang +    strScriptFileDir = os.path.normpath(os.path.join(vDictArgs["--srcRoot"], "scripts", vStrScriptLang)) +    strScriptFilePath = os.path.join(strScriptFileDir, strScriptFile)      # Check for the existence of the script file -    strPath = os.path.normcase( strScriptFilePath ); -    bOk = os.path.exists( strPath ); +    strPath = os.path.normcase(strScriptFilePath) +    bOk = os.path.exists(strPath)      if bOk == False: -        strDir = os.path.normcase( strScriptFileDir ); -        strStatusMsg = strScriptNotFound % (strScriptFile, strDir); -        return (-9, strStatusMsg); +        strDir = os.path.normcase(strScriptFileDir) +        strStatusMsg = strScriptNotFound % (strScriptFile, strDir) +        return (-9, strStatusMsg)      if gbDbgFlag: -        print((strScriptLangFound % vStrScriptLang)); -        print((strExecuteMsg % vStrScriptLang)); +        print((strScriptLangFound % vStrScriptLang)) +        print((strExecuteMsg % vStrScriptLang))      # Change where Python looks for our modules -    strDir = os.path.normcase( strScriptFileDir ); -    sys.path.append( strDir ); +    strDir = os.path.normcase(strScriptFileDir) +    sys.path.append(strDir)      # Execute the specific language script -    dictArgs = vDictArgs; # Remove any args not required before passing on -    strModuleName = strScriptFile[ : strScriptFile.__len__() - 3 ]; -    module = __import__( strModuleName ); -    nResult, strStatusMsg = module.main( dictArgs ); +    dictArgs = vDictArgs # Remove any args not required before passing on +    strModuleName = strScriptFile[: strScriptFile.__len__() - 3] +    module = __import__(strModuleName) +    nResult, strStatusMsg = module.main(dictArgs)      # Revert sys path -    sys.path.remove( strDir ); +    sys.path.remove(strDir) -    return (nResult, strStatusMsg); +    return (nResult, strStatusMsg)  #++---------------------------------------------------------------------------  # Details:  Step through each script language sub directory supported @@ -239,26 +239,26 @@ def run_post_process( vStrScriptLang, vstrFinishFileName, vDictArgs ):  #           Str     - Error message.  # Throws:   None.  #-- -def run_post_process_for_each_script_supported( vDictArgs ): -    dbg = utilsDebug.CDebugFnVerbose( "run_post_process_for_each_script_supported()" ); -    nResult = 0; -    strStatusMsg = ""; -    strScriptDir = os.path.normpath(os.path.join(vDictArgs["--srcRoot"], "scripts")); -    strFinishFileName = "finishSwig%sLLDB.py"; +def run_post_process_for_each_script_supported(vDictArgs): +    dbg = utilsDebug.CDebugFnVerbose("run_post_process_for_each_script_supported()") +    nResult = 0 +    strStatusMsg = "" +    strScriptDir = os.path.normpath(os.path.join(vDictArgs["--srcRoot"], "scripts")) +    strFinishFileName = "finishSwig%sLLDB.py"      # Check for the existence of the scripts folder -    strScriptsDir = os.path.normcase( strScriptDir ); -    bOk = os.path.exists( strScriptsDir ); +    strScriptsDir = os.path.normcase(strScriptDir) +    bOk = os.path.exists(strScriptsDir)      if bOk == False: -        return (-8, strScriptDirNotFound); +        return (-8, strScriptDirNotFound)      # Look for any script language directories to build for -    listDirs = []; -    nDepth = 1; -    for strPath, listDirs, listFiles in os.walk( strScriptDir ): -        nDepth = nDepth - 1; +    listDirs = [] +    nDepth = 1 +    for strPath, listDirs, listFiles in os.walk(strScriptDir): +        nDepth = nDepth - 1          if nDepth == 0: -            break; +            break      # Skip the directory that contains the interface files.      listDirs.remove('interface') @@ -276,18 +276,18 @@ def run_post_process_for_each_script_supported( vDictArgs ):      for scriptLang in listDirs:          # __pycache__ is a magic directory in Python 3 that holds .pyc files          if scriptLang != "__pycache__": -            dbg.dump_text( "Executing language script for \'%s\'" % scriptLang ); -            nResult, strStatusMsg = run_post_process( scriptLang, strFinishFileName, -                                                      vDictArgs ); +            dbg.dump_text("Executing language script for \'%s\'" % scriptLang) +            nResult, strStatusMsg = run_post_process(scriptLang, strFinishFileName, +                                                     vDictArgs)          if nResult < 0: -            break; +            break      if nResult < 0: -        strTmp = strPostProcessError % scriptLang; -        strTmp += strStatusMsg; -        strStatusMsg = strTmp; +        strTmp = strPostProcessError % scriptLang +        strTmp += strStatusMsg +        strStatusMsg = strTmp -    return (nResult, strStatusMsg); +    return (nResult, strStatusMsg)  #++---------------------------------------------------------------------------  # Details:  Program's main() with arguments passed in from the command line. @@ -297,35 +297,35 @@ def run_post_process_for_each_script_supported( vDictArgs ):  # Returns:  None  # Throws:   None.  #-- -def main( vArgv ): -    dbg = utilsDebug.CDebugFnVerbose( "main()" ); -    bOk = False; -    dictArgs = {}; -    nResult = 0; -    strMsg = ""; +def main(vArgv): +    dbg = utilsDebug.CDebugFnVerbose("main()") +    bOk = False +    dictArgs = {} +    nResult = 0 +    strMsg = ""      # The validate arguments fn will exit the program if tests fail -    nResult, dictArgs = validate_arguments( vArgv ); +    nResult, dictArgs = validate_arguments(vArgv) -    eOSType = utilsOsType.determine_os_type(); +    eOSType = utilsOsType.determine_os_type()      if eOSType == utilsOsType.EnumOsType.Unknown: -        program_exit( -4, strMsgErrorOsTypeUnknown ); +        program_exit(-4, strMsgErrorOsTypeUnknown) -    global gbDbgFlag; -    gbDbgFlag = "-d" in dictArgs; +    global gbDbgFlag +    gbDbgFlag = "-d" in dictArgs      if gbDbgFlag: -        print_out_input_parameters( dictArgs ); +        print_out_input_parameters(dictArgs)      # Check to see if we were called from the Makefile system. If we were, check      # if the caller wants SWIG to generate a dependency file.      # Not used in this program, but passed through to the language script file      # called by this program -    global gbMakeFileFlag; -    gbMakeFileFlag = "-m" in dictArgs; +    global gbMakeFileFlag +    gbMakeFileFlag = "-m" in dictArgs -    nResult, strMsg = run_post_process_for_each_script_supported( dictArgs ); +    nResult, strMsg = run_post_process_for_each_script_supported(dictArgs) -    program_exit( nResult, strMsg ); +    program_exit(nResult, strMsg)  #-----------------------------------------------------------------------------  #----------------------------------------------------------------------------- @@ -378,9 +378,8 @@ def main( vArgv ):  # Called using "__main__" when not imported i.e. from the command line  if __name__ == "__main__": -    utilsDebug.CDebugFnVerbose.bVerboseOn = gbDbgVerbose; -    dbg = utilsDebug.CDebugFnVerbose( "__main__" ); -    main( sys.argv[ 1: ] ); +    utilsDebug.CDebugFnVerbose.bVerboseOn = gbDbgVerbose +    dbg = utilsDebug.CDebugFnVerbose("__main__") +    main(sys.argv[1:])  else: -    program_exit( -5, strMsgErrorNoMain ); - +    program_exit(-5, strMsgErrorNoMain) diff --git a/lldb/scripts/utilsArgsParse.py b/lldb/scripts/utilsArgsParse.py index fa4661e45a2..e762edccc30 100644 --- a/lldb/scripts/utilsArgsParse.py +++ b/lldb/scripts/utilsArgsParse.py @@ -1,141 +1,139 @@  """ Utility module handle program args and give help -	-------------------------------------------------------------------------- -	File: 			utilsArgsParse.py - -	Overview: 		Python module to parse and validate program parameters -					against those required by the program whether mandatory -					or optional. -					Also give help information on arguments required by the -					program. -									 -	Gotchas:		None. - -	Copyright:		None. -	-------------------------------------------------------------------------- -	 +    -------------------------------------------------------------------------- +    File:     utilsArgsParse.py + +    Overview:  Python module to parse and validate program parameters +               against those required by the program whether mandatory +               or optional. +               Also give help information on arguments required by the +               program. + +    Gotchas:   None. + +    Copyright: None. +    -------------------------------------------------------------------------- +  """  # Python modules: -import sys		# Provide argument parsing -import getopt	# Parse command line arguments +import getopt # Parse command line arguments  # Third party modules:  # In-house modules: -import utilsOsType	# Determine the OS type this script is running on  # Instantiations:  # User facing text: -strMsgErrorInvalidParameters = "Invalid parameters entered, -h for help. \nYou entered:\n"; -strMsgErrorInvalidNoParams = "No parameters entered, -h for help\n"; -strMsgErrorNumberParameters = "Number of parameters entered incorrect, %d parameters required. You entered:\n"; -strMsgArgFileNotImplemented = "Sorry the --argFile is not implemented"; +strMsgErrorInvalidParameters = "Invalid parameters entered, -h for help. \nYou entered:\n" +strMsgErrorInvalidNoParams = "No parameters entered, -h for help\n" +strMsgErrorNumberParameters = "Number of parameters entered incorrect, %d parameters required. You entered:\n" +strMsgArgFileNotImplemented = "Sorry the --argFile is not implemented"  #++--------------------------------------------------------------------------- -# Details:	Validate the arguments passed in against the mandatory and -#			optional arguments specified. The argument format for the parameters -#			is required to work with the module getopt function getopt(). -#			Parameter vDictArgReq specifies which parameters are mandatory and -#			which are optional. The format is for example: -#				dictArgReq = {	"-h": "o",	# o = optional, m = mandatory -#								"-m": "m", -#								"--targetDir": "m", -#								"--cfgBldDir": "o" }; -# Args:		vArgv			- (R) List of arguments and values. -#			vstrListArgs	- (R) List of small arguments. -#			vListLongArgs	- (R) List of long arguments. -#			vDictArgReq		- (R) Map of arguments required. -#			vstrHelpInfo	- (R) Formatted help text. -# Returns:	Int		- 0 success. -#					  1 success display information, do nothing else. -#					  -1 error invalid parameters. -#					  -2 error incorrect number of mandatory parameters. -#			Dict 	- Map of arguments names to argument values -#			Str		- Error message.  -# Throws:	None. +# Details: Validate the arguments passed in against the mandatory and +#          optional arguments specified. The argument format for the parameters +#          is required to work with the module getopt function getopt(). +#          Parameter vDictArgReq specifies which parameters are mandatory and +#          which are optional. The format is for example: +#            dictArgReq = {"-h": "o", # o = optional, m = mandatory +#                          "-m": "m", +#                          "--targetDir": "m", +#                          "--cfgBldDir": "o" } +# Args:    vArgv - (R) List of arguments and values. +#          vstrListArgs - (R) List of small arguments. +#          vListLongArgs - (R) List of long arguments. +#          vDictArgReq - (R) Map of arguments required. +#          vstrHelpInfo - (R) Formatted help text. +# Returns: Int - 0 success. +#                1 success display information, do nothing else. +#                -1 error invalid parameters. +#                -2 error incorrect number of mandatory parameters. +#          Dict - Map of arguments names to argument values +#          Str - Error message. +# Throws:  None.  #-- -def parse( vArgv, vstrListArgs, vListLongArgs, vDictArgReq, vstrHelpInfo ): -	dictArgs = {}; -	dictDummy = {}; -	strDummy = ""; -			 -	# Validate parameters above and error on not recognised -	try: -		dictOptsNeeded, dictArgsLeftOver = getopt.getopt( vArgv, -														  vstrListArgs,  -														  vListLongArgs ); -	except getopt.GetoptError: -		strMsg = strMsgErrorInvalidParameters; -		strMsg += str( vArgv ); -		return (-1, dictDummy, strMsg); - -	if len( dictOptsNeeded ) == 0: -		strMsg = strMsgErrorInvalidNoParams; -		return (-1, dictDummy, strMsg); -		 -	# Look for help -h before anything else -	for opt, arg in dictOptsNeeded: -		if opt == '-h': -			return (1, dictDummy, vstrHelpInfo ); -		 -	# Look for the --argFile if found ignore other command line arguments -	for opt, arg in dictOptsNeeded: -		if opt == '--argsFile': -			return (1, dictDummy, strMsgArgFileNotImplemented); -	 -	# Count the number of mandatory args required (if any one found) -	countMandatory = 0; -	for opt, man in list(vDictArgReq.items()): -		if man == "m": -		  countMandatory = countMandatory + 1; -	 -	# Extract short args -	listArgs = []; -	for arg in vstrListArgs: -		if (arg == '-h') or (arg == ':'): -			continue; -		listArgs.append( arg ); -	 -	# Append to arg dictionary the option and its value -	bFoundNoInputValue = False; -	countMandatoryOpts = 0; -	for opt, val in dictOptsNeeded: -		match = 0; -		for arg in listArgs: -			argg = "-" + arg; -			if opt == argg: -				if "m" == vDictArgReq[ opt ]: -					countMandatoryOpts = countMandatoryOpts + 1; -				dictArgs[ opt ] = val; -				match = 1; -				break; -		if match == 0: -			for arg in vListLongArgs: -				argg = "--" + arg[:arg.__len__() - 1]; -				if opt == argg: -					if "m" == vDictArgReq[ opt ]: -						countMandatoryOpts = countMandatoryOpts + 1; -					dictArgs[ opt ] = val; -					if val.__len__() == 0: -						bFoundNoInputValue = True;	 -					break; -	 -	# Do any of the long arguments not have a value attached -	if bFoundNoInputValue: -		strMsg = strMsgErrorInvalidParameters; -		strMsg += str( vArgv ); -		return (-1, dictDummy, strMsg); - -	# Debug only -	#print countMandatoryOpts -	#print countMandatory -	 -	# Do we have the exact number of mandatory arguments -	if (countMandatoryOpts > 0) and (countMandatory != countMandatoryOpts): -		strMsg = strMsgErrorNumberParameters % countMandatory; -		strMsg += str( vArgv ); -		return (-2, dictDummy, strMsg); - -	return (0, dictArgs, strDummy); +def parse(vArgv, vstrListArgs, vListLongArgs, vDictArgReq, vstrHelpInfo): +    dictArgs = {} +    dictDummy = {} +    strDummy = "" + +    # Validate parameters above and error on not recognised +    try: +        dictOptsNeeded, dictArgsLeftOver = getopt.getopt(vArgv, +                                                         vstrListArgs, +                                                         vListLongArgs) +    except getopt.GetoptError: +        strMsg = strMsgErrorInvalidParameters +        strMsg += str(vArgv) +        return (-1, dictDummy, strMsg) + +    if len(dictOptsNeeded) == 0: +        strMsg = strMsgErrorInvalidNoParams +        return (-1, dictDummy, strMsg) + +    # Look for help -h before anything else +    for opt, arg in dictOptsNeeded: +        if opt == '-h': +            return (1, dictDummy, vstrHelpInfo) + +    # Look for the --argFile if found ignore other command line arguments +    for opt, arg in dictOptsNeeded: +        if opt == '--argsFile': +            return (1, dictDummy, strMsgArgFileNotImplemented) + +    # Count the number of mandatory args required (if any one found) +    countMandatory = 0 +    for opt, man in list(vDictArgReq.items()): +        if man == "m": +            countMandatory = countMandatory + 1 + +    # Extract short args +    listArgs = [] +    for arg in vstrListArgs: +        if (arg == '-h') or (arg == ':'): +            continue +        listArgs.append(arg) + +    # Append to arg dictionary the option and its value +    bFoundNoInputValue = False +    countMandatoryOpts = 0 +    for opt, val in dictOptsNeeded: +        match = 0 +        for arg in listArgs: +            argg = "-" + arg +            if opt == argg: +                if "m" == vDictArgReq[opt]: +                    countMandatoryOpts = countMandatoryOpts + 1 +                dictArgs[opt] = val +                match = 1 +                break +        if match == 0: +            for arg in vListLongArgs: +                argg = "--" + arg[:arg.__len__() - 1] +                if opt == argg: +                    if "m" == vDictArgReq[opt]: +                        countMandatoryOpts = countMandatoryOpts + 1 +                    dictArgs[opt] = val +                    if val.__len__() == 0: +                        bFoundNoInputValue = True +                    break + +    # Do any of the long arguments not have a value attached +    if bFoundNoInputValue: +        strMsg = strMsgErrorInvalidParameters +        strMsg += str(vArgv) +        return (-1, dictDummy, strMsg) + +    # Debug only +    #print countMandatoryOpts +    #print countMandatory + +    # Do we have the exact number of mandatory arguments +    if (countMandatoryOpts > 0) and (countMandatory != countMandatoryOpts): +        strMsg = strMsgErrorNumberParameters % countMandatory +        strMsg += str(vArgv) +        return (-2, dictDummy, strMsg) + +    return (0, dictArgs, strDummy) diff --git a/lldb/scripts/utilsDebug.py b/lldb/scripts/utilsDebug.py index 9aae22e24af..4b5eb7fa3e7 100644 --- a/lldb/scripts/utilsDebug.py +++ b/lldb/scripts/utilsDebug.py @@ -1,19 +1,17 @@  """ Utility module to help debug Python scripts -	-------------------------------------------------------------------------- -	File: 			utilsDebug.py +    -------------------------------------------------------------------------- +    File: utilsDebug.py -	Overview: 		Python module to supply functions to help debug Python -					scripts. -									 -	Gotchas:		None. - -	Copyright:		None. -	-------------------------------------------------------------------------- -	 +    Overview:  Python module to supply functions to help debug Python +               scripts. +    Gotchas:   None. +    Copyright: None. +    --------------------------------------------------------------------------  """  # Python modules: +import sys  # Third party modules: @@ -22,104 +20,101 @@  # Instantiations:  #----------------------------------------------------------------------------- -# Details:	Class to implement simple stack function trace. Instantiation the -#			class as the first function you want to trace. Example: -#				obj = utilsDebug.CDebugFnVerbose( "validate_arguments()" ); -# Gotchas:	This class will not work in properly in a multi-threaded  -#			environment. -# Authors:	Illya Rudkin 28/11/2013. -# Changes:	None. +# Details: Class to implement simple stack function trace. Instantiation the +#          class as the first function you want to trace. Example: +#          obj = utilsDebug.CDebugFnVerbose("validate_arguments()") +# Gotchas: This class will not work in properly in a multi-threaded +#          environment. +# Authors: Illya Rudkin 28/11/2013. +# Changes: None.  #-- -class CDebugFnVerbose: -	# Public static properties: -	bVerboseOn = False;	# True = turn on function tracing, False = turn off. -		 -	# Public: -	#++------------------------------------------------------------------------ -	# Details:	CDebugFnVerbose constructor. -	# Type:		Method. -	# Args:		vstrFnName	- (R) Text description i.e. a function name. -	# Return:	None. -	# Throws:	None. -	#-- -	# CDebugFnVerbose( vstrFnName ) -	 -	#++------------------------------------------------------------------------ -	# Details:	Print out information on the object specified. -	# Type:		Method. -	# Args:		vstrText	- (R) Some helper text description. -	#			vObject		- (R) Some Python type object. -	# Return:	None. -	# Throws:	None. -	#-- -	def dump_object( self, vstrText, vObject ): -		if CDebugFnVerbose.bVerboseOn == False: -			return; -		sys.stdout.write("%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(),  -								vstrText)); -		print(vObject); -	 -	#++------------------------------------------------------------------------ -	# Details:	Print out some progress text given by the client. -	# Type:		Method. -	# Args:		vstrText	- (R) Some helper text description. -	# Return:	None. -	# Throws:	None. -	#-- -	def dump_text( self, vstrText ): -		if CDebugFnVerbose.bVerboseOn == False: -			return; -		print(("%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), -								vstrText))); -				 -	# Private methods: -	def __init__( self, vstrFnName ): -		self.__indent_out( vstrFnName ); -		 -	#++------------------------------------------------------------------------ -	# Details:	Build an indentation string of dots based on the __nLevel. -	# Type:		Method. -	# Args:		None. -	# Return:	Str -	variable length string. -	# Throws:	None. -	#-- -	def __get_dots( self ): -		return "".join( "." for i in range( 0, CDebugFnVerbose.__nLevel ) ); -	 -	#++------------------------------------------------------------------------ -	# Details:	Build and print out debug verbosity text indicating the function -	#			just exited from. -	# Type:		Method. -	# Args:		None. -	# Return:	None. -	# Throws:	None. -	#-- -	def __indent_back( self ): -		if CDebugFnVerbose.bVerboseOn: -			print(("%d%s< fn: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), -									self.__strFnName))); -		CDebugFnVerbose.__nLevel -= 1; - -	#++------------------------------------------------------------------------ -	# Details:	Build and print out debug verbosity text indicating the function -	#			just entered. -	# Type:		Method. -	# Args:		vstrFnName - (R) Name of the function entered. -	# Return:	None. -	# Throws:	None. -	#-- -	def __indent_out( self, vstrFnName ): -		CDebugFnVerbose.__nLevel += 1; -		self.__strFnName = vstrFnName; -		if CDebugFnVerbose.bVerboseOn: -			print(("%d%s> fn: %s" % ( CDebugFnVerbose.__nLevel, self.__get_dots(),  -									 self.__strFnName))); - -	# Private statics attributes: -	__nLevel = 0;	# Indentation level counter -	 -	# Private attributes: -	__strFnName = ""; -	 -	 -	 +class CDebugFnVerbose(object): +    # Public static properties: +    bVerboseOn = False # True = turn on function tracing, False = turn off. + +    # Public: +    #++------------------------------------------------------------------------ +    # Details: CDebugFnVerbose constructor. +    # Type:    Method. +    # Args:    vstrFnName - (R) Text description i.e. a function name. +    # Return:  None. +    # Throws:  None. +    #-- +    # CDebugFnVerbose(vstrFnName) + +    #++------------------------------------------------------------------------ +    # Details: Print out information on the object specified. +    # Type:    Method. +    # Args:    vstrText - (R) Some helper text description. +    #          vObject - (R) Some Python type object. +    # Return:  None. +    # Throws:  None. +    #-- +    def dump_object(self, vstrText, vObject): +        if CDebugFnVerbose.bVerboseOn == False: +            return +        sys.stdout.write("%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), +                                           vstrText)) +        print(vObject) + +    #++------------------------------------------------------------------------ +    # Details: Print out some progress text given by the client. +    # Type:    Method. +    # Args:    vstrText - (R) Some helper text description. +    # Return:  None. +    # Throws:  None. +    #-- +    def dump_text(self, vstrText): +        if CDebugFnVerbose.bVerboseOn == False: +            return +        print(("%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), +                                 vstrText))) + +    # Private methods: +    def __init__(self, vstrFnName): +        self.__indent_out(vstrFnName) + +    #++------------------------------------------------------------------------ +    # Details: Build an indentation string of dots based on the __nLevel. +    # Type:    Method. +    # Args:    None. +    # Return:  Str - variable length string. +    # Throws:  None. +    #-- +    def __get_dots(self): +        return "".join("." for i in range(0, CDebugFnVerbose.__nLevel)) + +    #++------------------------------------------------------------------------ +    # Details: Build and print out debug verbosity text indicating the function +    #          just exited from. +    # Type:    Method. +    # Args:    None. +    # Return:  None. +    # Throws:  None. +    #-- +    def __indent_back(self): +        if CDebugFnVerbose.bVerboseOn: +            print(("%d%s< fn: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), +                                     self.__strFnName))) +        CDebugFnVerbose.__nLevel -= 1 + +    #++------------------------------------------------------------------------ +    # Details: Build and print out debug verbosity text indicating the function +    #          just entered. +    # Type:    Method. +    # Args:    vstrFnName - (R) Name of the function entered. +    # Return:  None. +    # Throws:  None. +    #-- +    def __indent_out(self, vstrFnName): +        CDebugFnVerbose.__nLevel += 1 +        self.__strFnName = vstrFnName +        if CDebugFnVerbose.bVerboseOn: +            print(("%d%s> fn: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), +                                     self.__strFnName))) + +    # Private statics attributes: +    __nLevel = 0 # Indentation level counter + +    # Private attributes: +    __strFnName = "" diff --git a/lldb/scripts/utilsOsType.py b/lldb/scripts/utilsOsType.py index 24dc7cad583..a2f0563bf89 100644 --- a/lldb/scripts/utilsOsType.py +++ b/lldb/scripts/utilsOsType.py @@ -3,7 +3,7 @@      --------------------------------------------------------------------------      File:         utilsOsType.py -    Overview:       Python module to supply functions and an enumeration to  +    Overview:       Python module to supply functions and an enumeration to                      help determine the platform type, bit size and OS currently                      being used.      -------------------------------------------------------------------------- @@ -36,22 +36,22 @@ if sys.version_info.major >= 3:          NetBSD = 4          Windows = 5  else: -    class EnumOsType( object ): -        values = [  "Unknown", -                    "Darwin", -                    "FreeBSD", -                    "Linux",  -                    "NetBSD", -                    "Windows" ] -        class __metaclass__( type ): +    class EnumOsType(object): +        values = ["Unknown", +                  "Darwin", +                  "FreeBSD", +                  "Linux", +                  "NetBSD", +                  "Windows"] +        class __metaclass__(type):  #++---------------------------------------------------------------------------  # Details:  Fn acts as an enumeration.  # Args:     vName - (R) Enumeration to match.  # Returns:  Int - Matching enumeration/index.  # Throws:   None.  #-- -            def __getattr__( self, vName ): -                return self.values.index( vName ); +            def __getattr__(cls, vName): +                return cls.values.index(vName)  #++---------------------------------------------------------------------------  # Details:  Reverse fast lookup of the values list. @@ -59,8 +59,8 @@ else:  # Returns:  Str - text description matching enumeration.  # Throws:   None.  #-- -            def name_of( self, vI ): -                return EnumOsType.values[ vI ]; +            def name_of(cls, vI): +                return EnumOsType.values[vI]  #-----------------------------------------------------------------------------  #----------------------------------------------------------------------------- @@ -73,18 +73,18 @@ else:  # Throws:   None.  #--  def determine_os_type(): -    eOSType = EnumOsType.Unknown; +    eOSType = EnumOsType.Unknown      strOS = sys.platform      if strOS == "darwin":          eOSType = EnumOsType.Darwin -    elif (strOS.startswith("freebsd")): +    elif strOS.startswith("freebsd"):          eOSType = EnumOsType.FreeBSD -    elif (strOS.startswith("linux")): +    elif strOS.startswith("linux"):          eOSType = EnumOsType.Linux -    elif (strOS.startswith("netbsd")): +    elif strOS.startswith("netbsd"):          eOSType = EnumOsType.NetBSD      elif strOS == "win32":          eOSType = EnumOsType.Windows -    return eOSType; +    return eOSType  | 

