blob: ad3ef4e4a7e58cd9c73926416668d38de25563a6 [file] [log] [blame]
Deepak Panickal9b35cf52014-07-01 17:57:19 +00001""" SWIG creates Python C++ Script Bridge wrapper code Windows/LINUX/OSX platform
2
Ed Maste8f3c0cd2015-03-08 16:24:30 +00003 --------------------------------------------------------------------------
4 File: buildSwigWrapperClasses.py
Deepak Panickal9b35cf52014-07-01 17:57:19 +00005
Ed Maste8f3c0cd2015-03-08 16:24:30 +00006 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 Panickal9b35cf52014-07-01 17:57:19 +000018
Ed Maste8f3c0cd2015-03-08 16:24:30 +000019 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 Panickal9b35cf52014-07-01 17:57:19 +000025"""
26
27# Python modules:
Ed Maste8f3c0cd2015-03-08 16:24:30 +000028import sys # Provide argument parsing
29import os # Provide directory and file handling
Deepak Panickal9b35cf52014-07-01 17:57:19 +000030
31# Third party modules:
32
33# In-house modules:
Ed Maste8f3c0cd2015-03-08 16:24:30 +000034import utilsArgsParse # Parse and validate this script's input arguments
35import utilsOsType # Determine the OS type this script is running on
36import utilsDebug # Debug Python scripts
Deepak Panickal9b35cf52014-07-01 17:57:19 +000037
38# Instantiations:
Ed Maste8f3c0cd2015-03-08 16:24:30 +000039gbDbgVerbose = False; # True = Turn on script function tracing, False = off.
40gbDbgFlag = False; # Global debug mode flag, set by input parameter
41 # --dbgFlag. True = operate in debug mode.
42gbMakeFileFlag = False; # True = yes called from makefile system, False = not.
43gbSwigGenDepFileFlag = False; # True = SWIG generate a dependency file.
Deepak Panickal9b35cf52014-07-01 17:57:19 +000044
45# User facing text:
46strMsgErrorNoMain = "Program called by another Python script not allowed";
47strExitMsgSuccess = "Program successful";
48strExitMsgError = "Program error: ";
49strParameter = "Parameter: ";
50strMsgErrorOsTypeUnknown = "Unable to determine OS type"
51strSwigFileFound = "Found the \'lldb.swig\' file\n";
52strSwigFileFoundNotFound = "Unable to locate the file \'%s\'"
53strSwigExeFileNotFound = "Unable to locate the SWIG executable file \'swig\'";
54strSwigScriptDirNotFound = "Unable to locate the SWIG script directory \'/script\'";
55strSwigScriptNotFound = "Unable to locate the SWIG script file \'%s\' in \'%s\'. Is it a script directory?";
56strSwigScriptLangFound = "Found \'%s\' build script.";
57strSwigScriptLangsFound = "Found the following script languages:";
58strSwigExecuteMsg = "Executing \'%s\' build script...";
59strSwigExecuteError = "Executing \'%s\' build script failed: ";
60strHelpInfo = "\
61Python script(s) to build the SWIG Python C++ Script \n\
62Bridge wrapper code on various platforms. The Python \n\
63scripts are equivalent to the shell script (.sh) files \n\
64run on others platforms.\n\
Ed Maste8f3c0cd2015-03-08 16:24:30 +000065Args: -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 Panickal9b35cf52014-07-01 17:57:19 +000084\n\
85Usage:\n\
Ed Maste8f3c0cd2015-03-08 16:24:30 +000086 buildSwigWrapperClasses.py --srcRoot=ADirPath --targetDir=ADirPath\n\
87 --cfgBldDir=ADirPath --prefix=ADirPath --swigExecutable=ADirPath -m -d\n\
Deepak Panickal9b35cf52014-07-01 17:57:19 +000088\n\
89"; #TAG_PROGRAM_HELP_INFO
90strHelpInfoExtraWindows = "\
91On the Windows platform the PATH environmental variable needs to be \n\
92extended to include the installed SWIG executable path so it can be \n\
93be found by this Python script. The SWIG executable name is 'swig'."
94strHelpInfoExtraNonWindows = "\
95This Python script looks for the SWIG executable 'swig' in the following \n\
96directories '/usr/bin', '/usr/local/bin'. If not found the script will \n\
97abort.";
98
99#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000100# Details: Retrieve the script -h help information based on the OS currently.
101# Args: None.
102# Returns: Str - Help Text.
103# Throws: None.
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000104#--
105def get_help_information():
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000106 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 Panickal9b35cf52014-07-01 17:57:19 +0000115
116#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000117# 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 Panickal9b35cf52014-07-01 17:57:19 +0000123#--
124def program_exit_success( vnResult, vMsg ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000125 strMsg = "";
126
Ed Masteb933fb22015-03-20 19:59:35 +0000127 if vMsg.__len__() != 0:
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000128 strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult);
Ed Masteb933fb22015-03-20 19:59:35 +0000129 print strMsg;
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000130
131 sys.exit( vnResult );
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000132
133#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000134# 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 Panickal9b35cf52014-07-01 17:57:19 +0000140#--
141def program_exit_on_failure( vnResult, vMsg ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000142 print "%s%s (%d)" % (strExitMsgError, vMsg, vnResult);
143 sys.exit( vnResult );
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000144
145#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000146# 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 Panickal9b35cf52014-07-01 17:57:19 +0000153#--
154def program_exit( vnResult, vMsg ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000155 if vnResult >= 0:
156 program_exit_success( vnResult, vMsg );
157 else:
158 program_exit_on_failure( vnResult, vMsg );
159
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000160#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000161# Details: Dump input parameters.
162# Args: vDictArgs - (R) Map of input args to value.
163# Returns: None.
164# Throws: None.
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000165#--
166def print_out_input_parameters( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000167 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 Panickal9b35cf52014-07-01 17:57:19 +0000174
175#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000176# 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 Panickal9b35cf52014-07-01 17:57:19 +0000185#--
186def check_lldb_swig_file_exists( vstrSrcRoot, veOSType ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000187 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 Panickal9b35cf52014-07-01 17:57:19 +0000201
202#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000203# 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 Panickal9b35cf52014-07-01 17:57:19 +0000211#--
212def run_swig( vStrScriptLang, vSwigBuildFileName, vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000213 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 Panickal9b35cf52014-07-01 17:57:19 +0000247
248#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000249# 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 Panickal9b35cf52014-07-01 17:57:19 +0000261#--
262def run_swig_for_each_script_supported( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000263 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 Panickal9b35cf52014-07-01 17:57:19 +0000304#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000305# 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 Panickal9b35cf52014-07-01 17:57:19 +0000310#--
311def check_lldb_swig_executable_file_exists_Unknown( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000312 dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Unknown()" );
313 # Do nothing
314 return (False, strMsgErrorOsTypeUnknown);
315
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000316#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000317# 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 Panickal9b35cf52014-07-01 17:57:19 +0000325#--
Zachary Turnerca0c84c2014-11-17 18:38:22 +0000326def check_lldb_swig_executable_file_exists_Windows( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000327 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 Panickal9b35cf52014-07-01 17:57:19 +0000336
337#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000338# 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 Panickal9b35cf52014-07-01 17:57:19 +0000346#--
347def check_lldb_swig_executable_file_exists_Linux( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000348 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 Panickal9b35cf52014-07-01 17:57:19 +0000369
370#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000371# 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 Panickal9b35cf52014-07-01 17:57:19 +0000379#--
380def check_lldb_swig_executable_file_exists_Darwin( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000381 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 Turnerca0c84c2014-11-17 18:38:22 +0000388
389#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000390# 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 Turnerca0c84c2014-11-17 18:38:22 +0000398#--
399def check_lldb_swig_executable_file_exists_FreeBSD( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000400 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 Turnerca0c84c2014-11-17 18:38:22 +0000407
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000408#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000409# 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 Panickal9b35cf52014-07-01 17:57:19 +0000417#--
418def check_lldb_swig_executable_file_exists( vDictArgs, veOSType ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000419 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 Panickal9b35cf52014-07-01 17:57:19 +0000435#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000436# 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 Panickal9b35cf52014-07-01 17:57:19 +0000442#--
443def validate_arguments( vArgv ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000444 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 Panickal9b35cf52014-07-01 17:57:19 +0000476
477#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000478# 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 Panickal9b35cf52014-07-01 17:57:19 +0000484#--
485def main( vArgv ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000486 dbg = utilsDebug.CDebugFnVerbose( "main()" );
487 bOk = False;
488 dictArgs = {};
489 nResult = 0;
490 strMsg = "";
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000491
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000492 # The validate arguments fn will exit the program if tests fail
493 nResult, dictArgs = validate_arguments( vArgv );
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000494
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000495 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 Panickal9b35cf52014-07-01 17:57:19 +0000524
525#-----------------------------------------------------------------------------
526#-----------------------------------------------------------------------------
527#-----------------------------------------------------------------------------
528
529#TAG_PROGRAM_HELP_INFO
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000530""" Details: Program main entry point.
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000531
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000532 --------------------------------------------------------------------------
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 Panickal9b35cf52014-07-01 17:57:19 +0000570"""
571
572# Called using "__main__" when not imported i.e. from the command line
573if __name__ == "__main__":
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000574 utilsDebug.CDebugFnVerbose.bVerboseOn = gbDbgVerbose;
575 dbg = utilsDebug.CDebugFnVerbose( "__main__" );
576 main( sys.argv[ 1: ] );
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000577else:
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000578 program_exit( -5, strMsgErrorNoMain );