Package SCons :: Package Scanner :: Module Prog
[hide private]
[frames] | no frames]

Source Code for Module SCons.Scanner.Prog

  1  # 
  2  # Copyright (c) 2001 - 2019 The SCons Foundation 
  3  # 
  4  # Permission is hereby granted, free of charge, to any person obtaining 
  5  # a copy of this software and associated documentation files (the 
  6  # "Software"), to deal in the Software without restriction, including 
  7  # without limitation the rights to use, copy, modify, merge, publish, 
  8  # distribute, sublicense, and/or sell copies of the Software, and to 
  9  # permit persons to whom the Software is furnished to do so, subject to 
 10  # the following conditions: 
 11  # 
 12  # The above copyright notice and this permission notice shall be included 
 13  # in all copies or substantial portions of the Software. 
 14  # 
 15  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
 16  # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
 17  # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 18  # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
 19  # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
 20  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
 21  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 22  # 
 23   
 24  __revision__ = "src/engine/SCons/Scanner/Prog.py 3a41ed6b288cee8d085373ad7fa02894e1903864 2019-01-23 17:30:35 bdeegan" 
 25   
 26  import SCons.Node 
 27  import SCons.Node.FS 
 28  import SCons.Scanner 
 29  import SCons.Util 
 30   
 31  # global, set by --debug=findlibs 
 32  print_find_libs = None 
 33   
34 -def ProgramScanner(**kw):
35 """Return a prototype Scanner instance for scanning executable 36 files for static-lib dependencies""" 37 kw['path_function'] = SCons.Scanner.FindPathDirs('LIBPATH') 38 ps = SCons.Scanner.Base(scan, "ProgramScanner", **kw) 39 return ps
40
41 -def _subst_libs(env, libs):
42 """ 43 Substitute environment variables and split into list. 44 """ 45 if SCons.Util.is_String(libs): 46 libs = env.subst(libs) 47 if SCons.Util.is_String(libs): 48 libs = libs.split() 49 elif SCons.Util.is_Sequence(libs): 50 _libs = [] 51 for l in libs: 52 _libs += _subst_libs(env, l) 53 libs = _libs 54 else: 55 # libs is an object (Node, for example) 56 libs = [libs] 57 return libs
58
59 -def scan(node, env, libpath = ()):
60 """ 61 This scanner scans program files for static-library 62 dependencies. It will search the LIBPATH environment variable 63 for libraries specified in the LIBS variable, returning any 64 files it finds as dependencies. 65 """ 66 try: 67 libs = env['LIBS'] 68 except KeyError: 69 # There are no LIBS in this environment, so just return a null list: 70 return [] 71 72 libs = _subst_libs(env, libs) 73 74 try: 75 prefix = env['LIBPREFIXES'] 76 if not SCons.Util.is_List(prefix): 77 prefix = [ prefix ] 78 except KeyError: 79 prefix = [ '' ] 80 81 try: 82 suffix = env['LIBSUFFIXES'] 83 if not SCons.Util.is_List(suffix): 84 suffix = [ suffix ] 85 except KeyError: 86 suffix = [ '' ] 87 88 pairs = [] 89 for suf in map(env.subst, suffix): 90 for pref in map(env.subst, prefix): 91 pairs.append((pref, suf)) 92 93 result = [] 94 95 if callable(libpath): 96 libpath = libpath() 97 98 find_file = SCons.Node.FS.find_file 99 adjustixes = SCons.Util.adjustixes 100 for lib in libs: 101 if SCons.Util.is_String(lib): 102 for pref, suf in pairs: 103 l = adjustixes(lib, pref, suf) 104 l = find_file(l, libpath, verbose=print_find_libs) 105 if l: 106 result.append(l) 107 else: 108 result.append(lib) 109 110 return result
111 112 # Local Variables: 113 # tab-width:4 114 # indent-tabs-mode:nil 115 # End: 116 # vim: set expandtab tabstop=4 shiftwidth=4: 117