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