Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 1 | """ SWIG creates Python C++ Script Bridge wrapper code Windows/LINUX/OSX platform |
| 2 | |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 3 | -------------------------------------------------------------------------- |
| 4 | File: buildSwigWrapperClasses.py |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 5 | |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 6 | Overview: Python script(s) to build the SWIG Python C++ Script |
| 7 | Bridge wrapper code on the Windows/LINUX/OSX platform. |
| 8 | The Python scripts are equivalent to the shell script (.sh) |
| 9 | files. |
| 10 | For each scripting language lib lldb supports, we need to |
| 11 | create the appropriate Script Bridge wrapper classes for |
| 12 | that language so that users can call Script Bridge |
| 13 | functions from within the script interpreter. |
| 14 | We use SWIG to help create the appropriate wrapper |
| 15 | classes/functions for the scripting language. In some |
| 16 | cases the file generated by SWIG may need some tweaking |
| 17 | before it is completely ready to use. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 18 | |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 19 | Gotchas: For Windows OS it is assumed the SWIG executable can be |
| 20 | found in the %PATH% environmental variable. |
| 21 | |
| 22 | Copyright: None. |
| 23 | -------------------------------------------------------------------------- |
| 24 | |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 25 | """ |
| 26 | |
| 27 | # Python modules: |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 28 | import sys # Provide argument parsing |
| 29 | import os # Provide directory and file handling |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 30 | |
| 31 | # Third party modules: |
| 32 | |
| 33 | # In-house modules: |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 34 | import utilsArgsParse # Parse and validate this script's input arguments |
| 35 | import utilsOsType # Determine the OS type this script is running on |
| 36 | import utilsDebug # Debug Python scripts |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 37 | |
| 38 | # Instantiations: |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 39 | gbDbgVerbose = False; # True = Turn on script function tracing, False = off. |
| 40 | gbDbgFlag = False; # Global debug mode flag, set by input parameter |
| 41 | # --dbgFlag. True = operate in debug mode. |
| 42 | gbMakeFileFlag = False; # True = yes called from makefile system, False = not. |
| 43 | gbSwigGenDepFileFlag = False; # True = SWIG generate a dependency file. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 44 | |
| 45 | # User facing text: |
| 46 | strMsgErrorNoMain = "Program called by another Python script not allowed"; |
| 47 | strExitMsgSuccess = "Program successful"; |
| 48 | strExitMsgError = "Program error: "; |
| 49 | strParameter = "Parameter: "; |
| 50 | strMsgErrorOsTypeUnknown = "Unable to determine OS type" |
| 51 | strSwigFileFound = "Found the \'lldb.swig\' file\n"; |
| 52 | strSwigFileFoundNotFound = "Unable to locate the file \'%s\'" |
| 53 | strSwigExeFileNotFound = "Unable to locate the SWIG executable file \'swig\'"; |
| 54 | strSwigScriptDirNotFound = "Unable to locate the SWIG script directory \'/script\'"; |
| 55 | strSwigScriptNotFound = "Unable to locate the SWIG script file \'%s\' in \'%s\'. Is it a script directory?"; |
| 56 | strSwigScriptLangFound = "Found \'%s\' build script."; |
| 57 | strSwigScriptLangsFound = "Found the following script languages:"; |
| 58 | strSwigExecuteMsg = "Executing \'%s\' build script..."; |
| 59 | strSwigExecuteError = "Executing \'%s\' build script failed: "; |
| 60 | strHelpInfo = "\ |
| 61 | Python script(s) to build the SWIG Python C++ Script \n\ |
| 62 | Bridge wrapper code on various platforms. The Python \n\ |
| 63 | scripts are equivalent to the shell script (.sh) files \n\ |
| 64 | run on others platforms.\n\ |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 65 | Args: -h (optional) Print help information on this program.\n\ |
| 66 | -d (optional) Determines whether or not this script\n\ |
| 67 | outputs additional information when running.\n\ |
| 68 | -m (optional) Specify called from Makefile system.\n\ |
| 69 | -M (optional) Specify want SWIG to generate a dependency \n\ |
| 70 | file.\n\ |
| 71 | --srcRoot= The root of the lldb source tree.\n\ |
| 72 | --targetDir= Where the lldb framework/shared library gets put.\n\ |
| 73 | --cfgBldDir= (optional) Where the build-swig-Python-LLDB.py program \n\ |
| 74 | will put the lldb.py file it generated from running\n\ |
| 75 | SWIG.\n\ |
| 76 | --prefix= (optional) Is the root directory used to determine where\n\ |
| 77 | third-party modules for scripting languages should\n\ |
| 78 | be installed. Where non-Darwin systems want to put\n\ |
| 79 | the .py and .so files so that Python can find them\n\ |
| 80 | automatically. Python install directory.\n\ |
| 81 | --argsFile= The args are read from a file instead of the\n\ |
| 82 | command line. Other command line args are ignored.\n\ |
| 83 | --swigExecutable= (optional) Full path of swig executable.\n\ |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 84 | \n\ |
| 85 | Usage:\n\ |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 86 | buildSwigWrapperClasses.py --srcRoot=ADirPath --targetDir=ADirPath\n\ |
| 87 | --cfgBldDir=ADirPath --prefix=ADirPath --swigExecutable=ADirPath -m -d\n\ |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 88 | \n\ |
| 89 | "; #TAG_PROGRAM_HELP_INFO |
| 90 | strHelpInfoExtraWindows = "\ |
| 91 | On the Windows platform the PATH environmental variable needs to be \n\ |
| 92 | extended to include the installed SWIG executable path so it can be \n\ |
| 93 | be found by this Python script. The SWIG executable name is 'swig'." |
| 94 | strHelpInfoExtraNonWindows = "\ |
| 95 | This Python script looks for the SWIG executable 'swig' in the following \n\ |
| 96 | directories '/usr/bin', '/usr/local/bin'. If not found the script will \n\ |
| 97 | abort."; |
| 98 | |
| 99 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 100 | # Details: Retrieve the script -h help information based on the OS currently. |
| 101 | # Args: None. |
| 102 | # Returns: Str - Help Text. |
| 103 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 104 | #-- |
| 105 | def get_help_information(): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 106 | strHelpMsg = strHelpInfo; |
| 107 | |
| 108 | eOSType = utilsOsType.determine_os_type(); |
| 109 | if eOSType == utilsOsType.EnumOsType.Windows: |
| 110 | strHelpMsg += strHelpInfoExtraWindows; |
| 111 | else: |
| 112 | strHelpMsg += strHelpInfoExtraNonWindows; |
| 113 | |
| 114 | return strHelpMsg; |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 115 | |
| 116 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 117 | # Details: Exit the program on success. Called on program successfully done |
| 118 | # its work. Returns a status result to the caller. |
| 119 | # Args: vnResult - (R) 0 or greater indicating success. |
| 120 | # vMsg - (R) Success message if any to show success to user. |
| 121 | # Returns: None. |
| 122 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 123 | #-- |
| 124 | def program_exit_success( vnResult, vMsg ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 125 | strMsg = ""; |
| 126 | |
Ed Maste | b933fb2 | 2015-03-20 19:59:35 +0000 | [diff] [blame] | 127 | if vMsg.__len__() != 0: |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 128 | strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult); |
Ed Maste | b933fb2 | 2015-03-20 19:59:35 +0000 | [diff] [blame] | 129 | print strMsg; |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 130 | |
| 131 | sys.exit( vnResult ); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 132 | |
| 133 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 134 | # Details: Exit the program with error. Called on exit program failed its |
| 135 | # task. Returns a status result to the caller. |
| 136 | # Args: vnResult - (R) A negative number indicating error condition. |
| 137 | # vMsg - (R) Error message to show to user. |
| 138 | # Returns: None. |
| 139 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 140 | #-- |
| 141 | def program_exit_on_failure( vnResult, vMsg ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 142 | print "%s%s (%d)" % (strExitMsgError, vMsg, vnResult); |
| 143 | sys.exit( vnResult ); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 144 | |
| 145 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 146 | # Details: Exit the program return a exit result number and print a message. |
| 147 | # Positive numbers and zero are returned for success other error |
| 148 | # occurred. |
| 149 | # Args: vnResult - (R) A -ve (an error), 0 or +ve number (ok or status). |
| 150 | # vMsg - (R) Error message to show to user. |
| 151 | # Returns: None. |
| 152 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 153 | #-- |
| 154 | def program_exit( vnResult, vMsg ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 155 | if vnResult >= 0: |
| 156 | program_exit_success( vnResult, vMsg ); |
| 157 | else: |
| 158 | program_exit_on_failure( vnResult, vMsg ); |
| 159 | |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 160 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 161 | # Details: Dump input parameters. |
| 162 | # Args: vDictArgs - (R) Map of input args to value. |
| 163 | # Returns: None. |
| 164 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 165 | #-- |
| 166 | def print_out_input_parameters( vDictArgs ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 167 | for arg, val in vDictArgs.iteritems(): |
| 168 | strEqs = ""; |
| 169 | strQ = ""; |
| 170 | if val.__len__() != 0: |
| 171 | strEqs = " ="; |
| 172 | strQ = "\""; |
| 173 | print "%s%s%s %s%s%s\n" % (strParameter, arg, strEqs, strQ, val, strQ); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 174 | |
| 175 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 176 | # Details: Locate the lldb.swig file. No checking for path correctness is |
| 177 | # done here as assumed all values checked already. Path is adapted |
| 178 | # to be compatible with the platform file system. |
| 179 | # Args: vstrSrcRoot - (R) Directory path to the lldb source root. |
| 180 | # veOSType - (R) Current OS type enumeration. |
| 181 | # Returns: Bool - True = Success. |
| 182 | # - False = Failure file not found. |
| 183 | # Str - Error message. |
| 184 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 185 | #-- |
| 186 | def check_lldb_swig_file_exists( vstrSrcRoot, veOSType ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 187 | dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_file_exists()" ); |
| 188 | bOk = True; |
| 189 | strStatusMsg = ""; |
| 190 | strSwigFilePathName = "/scripts/lldb.swig"; |
| 191 | |
| 192 | strFullPath = os.path.normcase( vstrSrcRoot + strSwigFilePathName ); |
| 193 | bOk = os.path.isfile( strFullPath ); |
| 194 | if bOk: |
| 195 | if gbDbgFlag: |
| 196 | print strSwigFileFound; |
| 197 | else: |
| 198 | strStatusMsg = strSwigFileFoundNotFound % strFullPath; |
| 199 | |
| 200 | return (bOk, strStatusMsg); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 201 | |
| 202 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 203 | # Details: Locate SWIG sub script language directory and the script within |
| 204 | # and execute SWIG for that script language. |
| 205 | # Args: vStrScriptLang - (R) Name of the script language to build. |
| 206 | # vSwigBuildFileName - (R) Prefix file name to build full name. |
| 207 | # vDictArgs - (R) Program input parameters. |
| 208 | # Returns: Int - 0 = Success, < 0 some error condition. |
| 209 | # Str - Error message. |
| 210 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 211 | #-- |
| 212 | def run_swig( vStrScriptLang, vSwigBuildFileName, vDictArgs ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 213 | dbg = utilsDebug.CDebugFnVerbose( "run_swig()" ); |
| 214 | nResult = 0; |
| 215 | strStatusMsg = ""; |
| 216 | strScriptFile = vSwigBuildFileName % vStrScriptLang; |
| 217 | strScriptFileDir = "%s%s/%s" % (vDictArgs[ "--srcRoot" ], "/scripts", |
| 218 | vStrScriptLang); |
| 219 | strScriptFilePath = "%s/%s" % (strScriptFileDir, strScriptFile); |
| 220 | |
| 221 | # Check for the existence of the script file |
| 222 | strPath = os.path.normcase( strScriptFilePath ); |
| 223 | bOk = os.path.exists( strPath ); |
| 224 | if bOk == False: |
| 225 | strDir = os.path.normcase( strScriptFileDir ); |
| 226 | strStatusMsg = strSwigScriptNotFound % (strScriptFile, strDir); |
| 227 | return (-9, strStatusMsg); |
| 228 | |
| 229 | if gbDbgFlag: |
| 230 | print strSwigScriptLangFound % vStrScriptLang; |
| 231 | print strSwigExecuteMsg % vStrScriptLang; |
| 232 | |
| 233 | # Change where Python looks for our modules |
| 234 | strDir = os.path.normcase( strScriptFileDir ); |
| 235 | sys.path.append( strDir ); |
| 236 | |
| 237 | # Execute the specific language script |
| 238 | dictArgs = vDictArgs; # Remove any args not required before passing on |
| 239 | strModuleName = strScriptFile[ : strScriptFile.__len__() - 3 ]; |
| 240 | module = __import__( strModuleName ); |
| 241 | nResult, strStatusMsg = module.main( dictArgs ); |
| 242 | |
| 243 | # Revert sys path |
| 244 | sys.path.remove( strDir ); |
| 245 | |
| 246 | return (nResult, strStatusMsg); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 247 | |
| 248 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 249 | # Details: Step through each SWIG sub directory script language supported |
| 250 | # type and execute SWIG to build wrapper code based on that language. |
| 251 | # If an error occurs for a build this function will return with an |
| 252 | # error and not continue with proceed script builds. |
| 253 | # For each scripting language, make sure the build script for that |
| 254 | # language exists. |
| 255 | # For now the only language we support is Python, but we expect this |
| 256 | # to change. |
| 257 | # Args: vDictArgs - (R) Program input parameters. |
| 258 | # Returns: Int - 0 = Success, < 0 some error condition. |
| 259 | # Str - Error message. |
| 260 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 261 | #-- |
| 262 | def run_swig_for_each_script_supported( vDictArgs ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 263 | dbg = utilsDebug.CDebugFnVerbose( "run_swig_for_each_script_supported()" ); |
| 264 | nResult = 0; |
| 265 | strStatusMsg = ""; |
| 266 | strSwigScriptDir = vDictArgs[ "--srcRoot" ] + "/scripts"; |
| 267 | strSwigBuildFileName = "buildSwig%s.py"; |
| 268 | |
| 269 | # Check for the existence of the SWIG scripts folder |
| 270 | strScriptsDir = os.path.normcase( strSwigScriptDir ); |
| 271 | bOk = os.path.exists( strScriptsDir ); |
| 272 | if bOk == False: |
| 273 | return (-8, strSwigScriptDirNotFound); |
| 274 | |
| 275 | # Look for any script language directories to build for |
| 276 | listDirs = []; |
| 277 | nDepth = 1; |
| 278 | for strPath, listDirs, listFiles in os.walk( strSwigScriptDir ): |
| 279 | nDepth = nDepth - 1; |
| 280 | if nDepth == 0: |
| 281 | break; |
| 282 | |
| 283 | if gbDbgFlag: |
| 284 | print strSwigScriptLangsFound, |
| 285 | for dir in listDirs: |
| 286 | print dir, |
| 287 | print "\n"; |
| 288 | |
| 289 | # Iterate script directory find any script language directories |
| 290 | for scriptLang in listDirs: |
| 291 | dbg.dump_text( "Executing language script for \'%s\'" % scriptLang ); |
| 292 | nResult, strStatusMsg = run_swig( scriptLang, strSwigBuildFileName, |
| 293 | vDictArgs ); |
| 294 | if nResult < 0: |
| 295 | break; |
| 296 | |
| 297 | if nResult < 0: |
| 298 | strTmp = strSwigExecuteError % scriptLang; |
| 299 | strTmp += strStatusMsg; |
| 300 | strStatusMsg = strTmp; |
| 301 | |
| 302 | return (nResult, strStatusMsg); |
| 303 | |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 304 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 305 | # Details: Dummy function - system unknown. Function should not be called. |
| 306 | # Args: vDictArgs - (R) Program input parameters. |
| 307 | # Returns: Bool - False = Program logic error. |
| 308 | # Str - Error message. |
| 309 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 310 | #-- |
| 311 | def check_lldb_swig_executable_file_exists_Unknown( vDictArgs ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 312 | dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Unknown()" ); |
| 313 | # Do nothing |
| 314 | return (False, strMsgErrorOsTypeUnknown); |
| 315 | |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 316 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 317 | # Details: Locate the SWIG executable file in a Windows system. Several hard |
| 318 | # coded predetermined possible file path locations are searched. |
| 319 | # (This is good candidate for a derived class object) |
| 320 | # Args: vDictArgs - (W) Program input parameters. |
| 321 | # Returns: Bool - True = Success. |
| 322 | # - False = Failure file not found. |
| 323 | # Str - Error message. |
| 324 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 325 | #-- |
Zachary Turner | ca0c84c | 2014-11-17 18:38:22 +0000 | [diff] [blame] | 326 | def check_lldb_swig_executable_file_exists_Windows( vDictArgs ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 327 | dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Windows()" ); |
| 328 | |
| 329 | # Will always be true as it assumed the path to SWIG executable will be |
| 330 | # in the OS system environmental variable %PATH%. Easier this way as the |
| 331 | # user may have renamed the directory and or custom path installation. |
| 332 | bExeFileFound = True; |
| 333 | vDictArgs[ "--swigExePath" ] = ""; |
| 334 | vDictArgs[ "--swigExeName" ] = "swig.exe"; |
| 335 | return (bExeFileFound, None); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 336 | |
| 337 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 338 | # Details: Locate the SWIG executable file in a Linux system. Several hard |
| 339 | # coded predetermined possible file path locations are searched. |
| 340 | # (This is good candidate for a derived class object) |
| 341 | # Args: vDictArgs - (W) Program input parameters. |
| 342 | # Returns: Bool - True = Success. |
| 343 | # - False = Failure file not found. |
| 344 | # Str - Error message. |
| 345 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 346 | #-- |
| 347 | def check_lldb_swig_executable_file_exists_Linux( vDictArgs ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 348 | dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Linux()" ); |
| 349 | bExeFileFound = False; |
| 350 | |
| 351 | strSwigExe = "swig"; |
| 352 | strSwigExePath = "/usr/bin"; |
| 353 | strExe = os.path.normcase( "%s/%s" % (strSwigExePath, strSwigExe) ); |
| 354 | if os.path.isfile( strExe ) and os.access( strExe, os.X_OK ): |
| 355 | bExeFileFound = True; |
| 356 | vDictArgs[ "--swigExePath" ] = os.path.normcase( strSwigExePath ); |
| 357 | vDictArgs[ "--swigExeName" ] = strSwigExe; |
| 358 | return (bExeFileFound, None); |
| 359 | |
| 360 | strSwigExePath = "/usr/local/bin"; |
| 361 | strExe = os.path.normcase( "%s/%s" % (strSwigExePath, strSwigExe) ); |
| 362 | if os.path.isfile( strExe ) and os.access( strExe, os.X_OK ): |
| 363 | bExeFileFound = True; |
| 364 | vDictArgs[ "--swigExePath" ] = os.path.normcase( strSwigExePath ); |
| 365 | vDictArgs[ "--swigExeName" ] = strSwigExe; |
| 366 | return (bExeFileFound, None); |
| 367 | |
| 368 | return (bExeFileFound, strSwigExeFileNotFound); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 369 | |
| 370 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 371 | # Details: Locate the SWIG executable file in a OSX system. Several hard |
| 372 | # coded predetermined possible file path locations are searched. |
| 373 | # (This is good candidate for a derived class object) |
| 374 | # Args: vDictArgs - (W) Program input parameters. |
| 375 | # Returns: Bool - True = Success. |
| 376 | # - False = Failure file not found. |
| 377 | # Str - Error message. |
| 378 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 379 | #-- |
| 380 | def check_lldb_swig_executable_file_exists_Darwin( vDictArgs ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 381 | dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Darwin()" ); |
| 382 | bExeFileFound = False; |
| 383 | # ToDo: Find the SWIG executable and add the path to the args dictionary |
| 384 | #vDictArgs.[ "--swigExePath" ] = "/usr/bin/swig"; |
| 385 | strStatusMsg = "Sorry function 'check_lldb_swig_executable_file_exists_Darwin()' is not implemented"; |
| 386 | |
| 387 | return (bExeFileFound, strStatusMsg); |
Zachary Turner | ca0c84c | 2014-11-17 18:38:22 +0000 | [diff] [blame] | 388 | |
| 389 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 390 | # Details: Locate the SWIG executable file in a OSX system. Several hard |
| 391 | # coded predetermined possible file path locations are searched. |
| 392 | # (This is good candidate for a derived class object) |
| 393 | # Args: vDictArgs - (W) Program input parameters. |
| 394 | # Returns: Bool - True = Success. |
| 395 | # - False = Failure file not found. |
| 396 | # Str - Error message. |
| 397 | # Throws: None. |
Zachary Turner | ca0c84c | 2014-11-17 18:38:22 +0000 | [diff] [blame] | 398 | #-- |
| 399 | def check_lldb_swig_executable_file_exists_FreeBSD( vDictArgs ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 400 | dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_FreeBSD()" ); |
| 401 | bExeFileFound = False; |
| 402 | # ToDo: Find the SWIG executable and add the path to the args dictionary |
| 403 | #vDictArgs.[ "--swigExePath" ] = "/usr/bin/swig"; |
| 404 | strStatusMsg = "Sorry function 'check_lldb_swig_executable_file_exists_FreeBSD()' is not implemented"; |
| 405 | |
| 406 | return (bExeFileFound, strStatusMsg); |
Zachary Turner | ca0c84c | 2014-11-17 18:38:22 +0000 | [diff] [blame] | 407 | |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 408 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 409 | # Details: Locate the SWIG executable file. Several hard coded predetermined |
| 410 | # possible file path locations are searched. |
| 411 | # Args: vDictArgs - (RW) Program input parameters. |
| 412 | # veOSType - (R) Current OS type enumeration. |
| 413 | # Returns: Bool - True = Success. |
| 414 | # - False = Failure file not found. |
| 415 | # Str - Error message. |
| 416 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 417 | #-- |
| 418 | def check_lldb_swig_executable_file_exists( vDictArgs, veOSType ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 419 | dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists()" ); |
| 420 | bExeFileFound = False; |
| 421 | strStatusMsg = ""; |
| 422 | if "--swigExecutable" in vDictArgs: |
| 423 | vDictArgs["--swigExeName"] = os.path.basename(vDictArgs["--swigExecutable"]) |
| 424 | vDictArgs["--swigExePath"] = os.path.dirname(vDictArgs["--swigExecutable"]) |
| 425 | bExeFileFound = True |
| 426 | else: |
| 427 | from utilsOsType import EnumOsType; |
| 428 | switch = { EnumOsType.Unknown : check_lldb_swig_executable_file_exists_Unknown, |
| 429 | EnumOsType.Darwin : check_lldb_swig_executable_file_exists_Darwin, |
| 430 | EnumOsType.FreeBSD : check_lldb_swig_executable_file_exists_FreeBSD, |
| 431 | EnumOsType.Linux : check_lldb_swig_executable_file_exists_Linux, |
| 432 | EnumOsType.Windows : check_lldb_swig_executable_file_exists_Windows } |
| 433 | bExeFileFound, strStatusMsg = switch[ veOSType ]( vDictArgs ); |
| 434 | return (bExeFileFound, strStatusMsg); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 435 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 436 | # Details: Validate the arguments passed to the program. This function exits |
| 437 | # the program should error with the arguments be found. |
| 438 | # Args: vArgv - (R) List of arguments and values. |
| 439 | # Returns: Int - 0 = success, -ve = some failure. |
| 440 | # Dict - Map of arguments names to argument values |
| 441 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 442 | #-- |
| 443 | def validate_arguments( vArgv ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 444 | dbg = utilsDebug.CDebugFnVerbose( "validate_arguments()" ); |
| 445 | strMsg = ""; |
| 446 | dictArgs = {}; |
| 447 | nResult = 0; |
| 448 | strListArgs = "hdmM"; # Format "hiox:" = -h -i -o -x <arg> |
| 449 | listLongArgs = ["srcRoot=", "targetDir=", "cfgBldDir=", "prefix=", |
| 450 | "swigExecutable=", "argsFile"]; |
| 451 | dictArgReq = { "-h": "o", # o = optional, m = mandatory |
| 452 | "-d": "o", |
| 453 | "-m": "o", |
| 454 | "-M": "o", |
| 455 | "--srcRoot": "m", |
| 456 | "--targetDir": "m", |
| 457 | "--swigExecutable" : "o", |
| 458 | "--cfgBldDir": "o", |
| 459 | "--prefix": "o", |
| 460 | "--argsFile": "o" }; |
| 461 | strHelpInfo = get_help_information(); |
| 462 | |
| 463 | # Check for mandatory parameters |
| 464 | nResult, dictArgs, strMsg = utilsArgsParse.parse( vArgv, strListArgs, |
| 465 | listLongArgs, |
| 466 | dictArgReq, |
| 467 | strHelpInfo ); |
| 468 | if nResult < 0: |
| 469 | program_exit_on_failure( nResult, strMsg ); |
| 470 | |
| 471 | # User input -h for help |
| 472 | if nResult == 1: |
| 473 | program_exit_success( 0, strMsg ); |
| 474 | |
| 475 | return (nResult, dictArgs); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 476 | |
| 477 | #++--------------------------------------------------------------------------- |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 478 | # Details: Program's main() with arguments passed in from the command line. |
| 479 | # Program either exits normally or with error from this function - |
| 480 | # top most level function. |
| 481 | # Args: vArgv - (R) List of arguments and values. |
| 482 | # Returns: None |
| 483 | # Throws: None. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 484 | #-- |
| 485 | def main( vArgv ): |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 486 | dbg = utilsDebug.CDebugFnVerbose( "main()" ); |
| 487 | bOk = False; |
| 488 | dictArgs = {}; |
| 489 | nResult = 0; |
| 490 | strMsg = ""; |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 491 | |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 492 | # The validate arguments fn will exit the program if tests fail |
| 493 | nResult, dictArgs = validate_arguments( vArgv ); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 494 | |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 495 | eOSType = utilsOsType.determine_os_type(); |
| 496 | if eOSType == utilsOsType.EnumOsType.Unknown: |
| 497 | program_exit( -4, strMsgErrorOsTypeUnknown ); |
| 498 | |
| 499 | global gbDbgFlag; |
| 500 | gbDbgFlag = dictArgs.has_key( "-d" ); |
| 501 | if gbDbgFlag: |
| 502 | print_out_input_parameters( dictArgs ); |
| 503 | |
| 504 | # Check to see if we were called from the Makefile system. If we were, check |
| 505 | # if the caller wants SWIG to generate a dependency file. |
| 506 | # Not used in this program, but passed through to the language script file |
| 507 | # called by this program |
| 508 | global gbMakeFileFlag; |
| 509 | global gbSwigGenDepFileFlag; |
| 510 | gbMakeFileFlag = dictArgs.has_key( "-m" ); |
| 511 | gbSwigGenDepFileFlag = dictArgs.has_key( "-M" ); |
| 512 | |
| 513 | bOk, strMsg = check_lldb_swig_file_exists( dictArgs[ "--srcRoot" ], eOSType ); |
| 514 | if bOk == False: |
| 515 | program_exit( -3, strMsg ); |
| 516 | |
| 517 | bOk, strMsg = check_lldb_swig_executable_file_exists( dictArgs, eOSType ); |
| 518 | if bOk == False: |
| 519 | program_exit( -6, strMsg ); |
| 520 | |
| 521 | nResult, strMsg = run_swig_for_each_script_supported( dictArgs ); |
| 522 | |
| 523 | program_exit( nResult, strMsg ); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 524 | |
| 525 | #----------------------------------------------------------------------------- |
| 526 | #----------------------------------------------------------------------------- |
| 527 | #----------------------------------------------------------------------------- |
| 528 | |
| 529 | #TAG_PROGRAM_HELP_INFO |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 530 | """ Details: Program main entry point. |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 531 | |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 532 | -------------------------------------------------------------------------- |
| 533 | Args: -h (optional) Print help information on this program. |
| 534 | -d (optional) Determines whether or not this script |
| 535 | outputs additional information when running. |
| 536 | -m (optional) Specify called from Makefile system. If given locate |
| 537 | the LLDBWrapPython.cpp in --srcRoot/source folder |
| 538 | else in the --targetDir folder. |
| 539 | -M (optional) Specify want SWIG to generate a dependency file. |
| 540 | --srcRoot= The root of the lldb source tree. |
| 541 | --targetDir= Where the lldb framework/shared library gets put. |
| 542 | --cfgBldDir= Where the buildSwigPythonLLDB.py program will |
| 543 | (optional) put the lldb.py file it generated from running |
| 544 | SWIG. |
| 545 | --prefix= Is the root directory used to determine where |
| 546 | (optional) third-party modules for scripting languages should |
| 547 | be installed. Where non-Darwin systems want to put |
| 548 | the .py and .so files so that Python can find them |
| 549 | automatically. Python install directory. |
| 550 | --argsFile= The args are read from a file instead of the |
| 551 | command line. Other command line args are ignored. |
| 552 | Usage: |
| 553 | buildSwigWrapperClasses.py --srcRoot=ADirPath --targetDir=ADirPath |
| 554 | --cfgBldDir=ADirPath --prefix=ADirPath --swigExecutable=ADirPath -m -d |
| 555 | |
| 556 | Results: 0 Success |
| 557 | -1 Error - invalid parameters passed. |
| 558 | -2 Error - incorrect number of mandatory parameters passed. |
| 559 | -3 Error - unable to locate lldb.swig file. |
| 560 | -4 Error - unable to determine OS type. |
| 561 | -5 Error - program called by another Python script not allowed. |
| 562 | -6 Error - unable to locate the swig executable file. |
| 563 | -7 Error - SWIG script execution failed. |
| 564 | -8 Error - unable to locate the SWIG scripts folder. |
| 565 | -9 Error - unable to locate the SWIG language script file. |
| 566 | -100+ - Error messages from the SWIG language script file. |
| 567 | -200+ - 200 +- the SWIG exit result. |
| 568 | -------------------------------------------------------------------------- |
| 569 | |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 570 | """ |
| 571 | |
| 572 | # Called using "__main__" when not imported i.e. from the command line |
| 573 | if __name__ == "__main__": |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 574 | utilsDebug.CDebugFnVerbose.bVerboseOn = gbDbgVerbose; |
| 575 | dbg = utilsDebug.CDebugFnVerbose( "__main__" ); |
| 576 | main( sys.argv[ 1: ] ); |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 577 | else: |
Ed Maste | 8f3c0cd | 2015-03-08 16:24:30 +0000 | [diff] [blame] | 578 | program_exit( -5, strMsgErrorNoMain ); |