blob: 17e4983c1e7872cd3d61101b7e4c15239a3d85eb [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 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 Panickal9b35cf52014-07-01 17:57:19 +000023
Ed Maste8f3c0cd2015-03-08 16:24:30 +000024 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 Panickal9b35cf52014-07-01 17:57:19 +000030"""
31
32# Python modules:
Ed Maste8f3c0cd2015-03-08 16:24:30 +000033import sys # Provide argument parsing
34import os # Provide directory and file handling
Deepak Panickal9b35cf52014-07-01 17:57:19 +000035
36# Third party modules:
37
38# In-house modules:
Ed Maste8f3c0cd2015-03-08 16:24:30 +000039import utilsArgsParse # Parse and validate this script's input arguments
40import utilsOsType # Determine the OS type this script is running on
41import utilsDebug # Debug Python scripts
Deepak Panickal9b35cf52014-07-01 17:57:19 +000042
43# Instantiations:
Ed Maste8f3c0cd2015-03-08 16:24:30 +000044gbDbgVerbose = False; # True = Turn on script function tracing, False = off.
45gbDbgFlag = False; # Global debug mode flag, set by input parameter
46 # --dbgFlag. True = operate in debug mode.
47gbMakeFileFlag = False; # True = yes called from makefile system, False = not.
48gbSwigGenDepFileFlag = False; # True = SWIG generate a dependency file.
Deepak Panickal9b35cf52014-07-01 17:57:19 +000049
50# User facing text:
51strMsgErrorNoMain = "Program called by another Python script not allowed";
52strExitMsgSuccess = "Program successful";
53strExitMsgError = "Program error: ";
54strParameter = "Parameter: ";
55strMsgErrorOsTypeUnknown = "Unable to determine OS type"
56strSwigFileFound = "Found the \'lldb.swig\' file\n";
57strSwigFileFoundNotFound = "Unable to locate the file \'%s\'"
58strSwigExeFileNotFound = "Unable to locate the SWIG executable file \'swig\'";
59strSwigScriptDirNotFound = "Unable to locate the SWIG script directory \'/script\'";
60strSwigScriptNotFound = "Unable to locate the SWIG script file \'%s\' in \'%s\'. Is it a script directory?";
61strSwigScriptLangFound = "Found \'%s\' build script.";
62strSwigScriptLangsFound = "Found the following script languages:";
63strSwigExecuteMsg = "Executing \'%s\' build script...";
64strSwigExecuteError = "Executing \'%s\' build script failed: ";
65strHelpInfo = "\
66Python script(s) to build the SWIG Python C++ Script \n\
67Bridge wrapper code on various platforms. The Python \n\
68scripts are equivalent to the shell script (.sh) files \n\
69run on others platforms.\n\
Ed Maste8f3c0cd2015-03-08 16:24:30 +000070Args: -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 Panickal9b35cf52014-07-01 17:57:19 +000089\n\
90Usage:\n\
Ed Maste8f3c0cd2015-03-08 16:24:30 +000091 buildSwigWrapperClasses.py --srcRoot=ADirPath --targetDir=ADirPath\n\
92 --cfgBldDir=ADirPath --prefix=ADirPath --swigExecutable=ADirPath -m -d\n\
Deepak Panickal9b35cf52014-07-01 17:57:19 +000093\n\
94"; #TAG_PROGRAM_HELP_INFO
95strHelpInfoExtraWindows = "\
96On the Windows platform the PATH environmental variable needs to be \n\
97extended to include the installed SWIG executable path so it can be \n\
98be found by this Python script. The SWIG executable name is 'swig'."
99strHelpInfoExtraNonWindows = "\
100This Python script looks for the SWIG executable 'swig' in the following \n\
101directories '/usr/bin', '/usr/local/bin'. If not found the script will \n\
102abort.";
103
104#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000105# Details: Retrieve the script -h help information based on the OS currently.
106# Args: None.
107# Returns: Str - Help Text.
108# Throws: None.
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000109#--
110def get_help_information():
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000111 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 Panickal9b35cf52014-07-01 17:57:19 +0000120
121#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000122# 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 Panickal9b35cf52014-07-01 17:57:19 +0000128#--
129def program_exit_success( vnResult, vMsg ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000130 strMsg = "";
131
Ed Masteb933fb22015-03-20 19:59:35 +0000132 if vMsg.__len__() != 0:
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000133 strMsg = "%s: %s (%d)" % (strExitMsgSuccess, vMsg, vnResult);
Ed Masteb933fb22015-03-20 19:59:35 +0000134 print strMsg;
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000135
136 sys.exit( vnResult );
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000137
138#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000139# 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 Panickal9b35cf52014-07-01 17:57:19 +0000145#--
146def program_exit_on_failure( vnResult, vMsg ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000147 print "%s%s (%d)" % (strExitMsgError, vMsg, vnResult);
148 sys.exit( vnResult );
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000149
150#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000151# 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 Panickal9b35cf52014-07-01 17:57:19 +0000158#--
159def program_exit( vnResult, vMsg ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000160 if vnResult >= 0:
161 program_exit_success( vnResult, vMsg );
162 else:
163 program_exit_on_failure( vnResult, vMsg );
164
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000165#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000166# Details: Dump input parameters.
167# Args: vDictArgs - (R) Map of input args to value.
168# Returns: None.
169# Throws: None.
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000170#--
171def print_out_input_parameters( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000172 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 Panickal9b35cf52014-07-01 17:57:19 +0000179
180#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000181# 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 Panickal9b35cf52014-07-01 17:57:19 +0000190#--
191def check_lldb_swig_file_exists( vstrSrcRoot, veOSType ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000192 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 Panickal9b35cf52014-07-01 17:57:19 +0000206
207#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000208# 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 Panickal9b35cf52014-07-01 17:57:19 +0000216#--
217def run_swig( vStrScriptLang, vSwigBuildFileName, vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000218 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 Panickal9b35cf52014-07-01 17:57:19 +0000252
253#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000254# 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 Panickal9b35cf52014-07-01 17:57:19 +0000266#--
267def run_swig_for_each_script_supported( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000268 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 Panickal9b35cf52014-07-01 17:57:19 +0000309#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000310# 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 Panickal9b35cf52014-07-01 17:57:19 +0000315#--
316def check_lldb_swig_executable_file_exists_Unknown( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000317 dbg = utilsDebug.CDebugFnVerbose( "check_lldb_swig_executable_file_exists_Unknown()" );
318 # Do nothing
319 return (False, strMsgErrorOsTypeUnknown);
320
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000321#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000322# 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 Panickal9b35cf52014-07-01 17:57:19 +0000330#--
Zachary Turnerca0c84c2014-11-17 18:38:22 +0000331def check_lldb_swig_executable_file_exists_Windows( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000332 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 Panickal9b35cf52014-07-01 17:57:19 +0000341
342#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000343# 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 Panickal9b35cf52014-07-01 17:57:19 +0000351#--
352def check_lldb_swig_executable_file_exists_Linux( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000353 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 Panickal9b35cf52014-07-01 17:57:19 +0000374
375#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000376# 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 Panickal9b35cf52014-07-01 17:57:19 +0000384#--
385def check_lldb_swig_executable_file_exists_Darwin( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000386 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 Turnerca0c84c2014-11-17 18:38:22 +0000393
394#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000395# 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 Turnerca0c84c2014-11-17 18:38:22 +0000403#--
404def check_lldb_swig_executable_file_exists_FreeBSD( vDictArgs ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000405 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 Turnerca0c84c2014-11-17 18:38:22 +0000412
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000413#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000414# 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 Panickal9b35cf52014-07-01 17:57:19 +0000422#--
423def check_lldb_swig_executable_file_exists( vDictArgs, veOSType ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000424 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 Panickal9b35cf52014-07-01 17:57:19 +0000440#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000441# 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 Panickal9b35cf52014-07-01 17:57:19 +0000447#--
448def validate_arguments( vArgv ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000449 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 Panickal9b35cf52014-07-01 17:57:19 +0000481
482#++---------------------------------------------------------------------------
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000483# 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 Panickal9b35cf52014-07-01 17:57:19 +0000489#--
490def main( vArgv ):
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000491 dbg = utilsDebug.CDebugFnVerbose( "main()" );
492 bOk = False;
493 dictArgs = {};
494 nResult = 0;
495 strMsg = "";
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000496
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000497 # The validate arguments fn will exit the program if tests fail
498 nResult, dictArgs = validate_arguments( vArgv );
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000499
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000500 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 Panickal9b35cf52014-07-01 17:57:19 +0000529
530#-----------------------------------------------------------------------------
531#-----------------------------------------------------------------------------
532#-----------------------------------------------------------------------------
533
534#TAG_PROGRAM_HELP_INFO
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000535""" Details: Program main entry point.
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000536
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000537 --------------------------------------------------------------------------
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 Panickal9b35cf52014-07-01 17:57:19 +0000575"""
576
577# Called using "__main__" when not imported i.e. from the command line
578if __name__ == "__main__":
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000579 utilsDebug.CDebugFnVerbose.bVerboseOn = gbDbgVerbose;
580 dbg = utilsDebug.CDebugFnVerbose( "__main__" );
581 main( sys.argv[ 1: ] );
Deepak Panickal9b35cf52014-07-01 17:57:19 +0000582else:
Ed Maste8f3c0cd2015-03-08 16:24:30 +0000583 program_exit( -5, strMsgErrorNoMain );