3 # SCons - a Software Constructor
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
28 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
30 __version__ = "__VERSION__"
32 __build__ = "__BUILD__"
34 __buildsys__ = "__BUILDSYS__"
38 __developer__ = "__DEVELOPER__"
45 ##############################################################################
46 # BEGIN STANDARD SCons SCRIPT HEADER
48 # This is the cut-and-paste logic so that a self-contained script can
49 # interoperate correctly with different SCons versions and installation
50 # locations for the engine. If you modify anything in this section, you
51 # should also change other scripts that use this same header.
52 ##############################################################################
54 # Strip the script directory from sys.path() so on case-insensitive
55 # (WIN32) systems Python doesn't think that the "scons" script is the
56 # "SCons" package. Replace it with our own library directories
57 # (version-specific first, in case they installed by hand there,
58 # followed by generic) so we pick up the right version of the build
59 # engine modules if they're in either directory.
61 script_dir = sys.path[0]
63 if script_dir in sys.path:
64 sys.path.remove(script_dir)
68 if "SCONS_LIB_DIR" in os.environ:
69 libs.append(os.environ["SCONS_LIB_DIR"])
71 local_version = 'scons-local-' + __version__
74 local_version = os.path.join(script_dir, local_version)
75 local = os.path.join(script_dir, local)
76 libs.append(os.path.abspath(local_version))
77 libs.append(os.path.abspath(local))
79 scons_version = 'scons-%s' % __version__
83 if sys.platform == 'win32':
84 # sys.prefix is (likely) C:\Python*;
85 # check only C:\Python*.
86 prefs.append(sys.prefix)
87 prefs.append(os.path.join(sys.prefix, 'Lib', 'site-packages'))
89 # On other (POSIX) platforms, things are more complicated due to
90 # the variety of path names and library locations. Try to be smart
92 if script_dir == 'bin':
93 # script_dir is `pwd`/bin;
94 # check `pwd`/lib/scons*.
95 prefs.append(os.getcwd())
97 if script_dir == '.' or script_dir == '':
98 script_dir = os.getcwd()
99 head, tail = os.path.split(script_dir)
101 # script_dir is /foo/bin;
102 # check /foo/lib/scons*.
105 head, tail = os.path.split(sys.prefix)
107 # sys.prefix is /foo/usr;
108 # check /foo/usr/lib/scons* first,
109 # then /foo/usr/local/lib/scons*.
110 prefs.append(sys.prefix)
111 prefs.append(os.path.join(sys.prefix, "local"))
112 elif tail == "local":
113 h, t = os.path.split(head)
115 # sys.prefix is /foo/usr/local;
116 # check /foo/usr/local/lib/scons* first,
117 # then /foo/usr/lib/scons*.
118 prefs.append(sys.prefix)
121 # sys.prefix is /foo/local;
122 # check only /foo/local/lib/scons*.
123 prefs.append(sys.prefix)
125 # sys.prefix is /foo (ends in neither /usr or /local);
126 # check only /foo/lib/scons*.
127 prefs.append(sys.prefix)
129 temp = [os.path.join(x, 'lib') for x in prefs]
130 temp.extend([os.path.join(x,
132 'python' + sys.version[:3],
133 'site-packages') for x in prefs])
136 # Add the parent directory of the current python's library to the
137 # preferences. On SuSE-91/AMD64, for example, this is /usr/lib64,
140 libpath = os.__file__
141 except AttributeError:
144 # Split /usr/libfoo/python*/os.py to /usr/libfoo/python*.
145 libpath, tail = os.path.split(libpath)
146 # Split /usr/libfoo/python* to /usr/libfoo
147 libpath, tail = os.path.split(libpath)
148 # Check /usr/libfoo/scons*.
149 prefs.append(libpath)
156 # when running from an egg add the egg's directory
158 d = pkg_resources.get_distribution('scons')
159 except pkg_resources.DistributionNotFound:
162 prefs.append(d.location)
164 # Look first for 'scons-__version__' in all of our preference libs,
166 libs.extend([os.path.join(x, scons_version) for x in prefs])
167 libs.extend([os.path.join(x, 'scons') for x in prefs])
169 sys.path = libs + sys.path
171 ##############################################################################
172 # END STANDARD SCons SCRIPT HEADER
173 ##############################################################################
181 import SCons.SConsign
183 # Monkey-patch in a whichdb()-like function so any use of dbm.whichdb()
184 # can detect our internal .dblite format,
185 def my_whichdb(filename):
186 if filename[-7:] == ".dblite":
187 return "SCons.dblite"
189 f = open(filename + ".dblite", "rb")
191 return "SCons.dblite"
194 return _orig_whichdb(filename)
196 _orig_whichdb = dbm.whichdb
197 dbm.whichdb = my_whichdb
199 def my_import(mname):
202 parent = my_import(mname[:i])
203 fp, pathname, description = imp.find_module(mname[i+1:],
206 fp, pathname, description = imp.find_module(mname)
207 return imp.load_module(mname, fp, pathname, description)
211 def __setitem__(self, item, value):
212 self.__dict__[item] = value
213 self.default_value = 0
214 def __getitem__(self, item):
215 return self.__dict__.get(item, self.default_value)
218 Print_Directories = []
220 Print_Flags = Flagger()
224 def default_mapper(entry, name):
226 val = eval("entry."+name)
231 def map_action(entry, name):
234 bactsig = entry.bactsig
235 except AttributeError:
237 return '%s [%s]' % (bactsig, bact)
239 def map_timestamp(entry, name):
241 timestamp = entry.timestamp
242 except AttributeError:
244 if Readable and timestamp:
245 return "'" + time.ctime(timestamp) + "'"
247 return str(timestamp)
249 def map_bkids(entry, name):
251 bkids = entry.bsources + entry.bdepends + entry.bimplicit
252 bkidsigs = entry.bsourcesigs + entry.bdependsigs + entry.bimplicitsigs
253 except AttributeError:
256 for i in range(len(bkids)):
257 result.append(nodeinfo_string(bkids[i], bkidsigs[i], " "))
260 return "\n ".join(result)
263 'action' : map_action,
264 'timestamp' : map_timestamp,
269 'implicit' : 'bkids',
272 def field(name, entry, verbose=Verbose):
273 if not Print_Flags[name]:
275 fieldname = map_name.get(name, name)
276 mapper = map_field.get(fieldname, default_mapper)
277 val = mapper(entry, name)
279 val = name + ": " + val
282 def nodeinfo_raw(name, ninfo, prefix=""):
283 # This just formats the dictionary, which we would normally use str()
284 # to do, except that we want the keys sorted for deterministic output.
287 keys = ninfo.field_list + ['_version_id']
288 except AttributeError:
289 keys = sorted(d.keys())
292 l.append('%s: %s' % (repr(k), repr(d.get(k))))
295 return name + ': {' + ', '.join(l) + '}'
297 def nodeinfo_cooked(name, ninfo, prefix=""):
299 field_list = ninfo.field_list
300 except AttributeError:
304 outlist = [name+':'] + [_f for _f in [field(x, ninfo, Verbose) for x in field_list] if _f]
309 return sep.join(outlist)
311 nodeinfo_string = nodeinfo_cooked
313 def printfield(name, entry, prefix=""):
314 outlist = field("implicit", entry, 0)
319 outact = field("action", entry, 0)
322 print " action: " + outact
326 def printentries(entries, location):
328 for name in Print_Entries:
330 entry = entries[name]
332 sys.stderr.write("sconsign: no entry `%s' in `%s'\n" % (name, location))
336 except AttributeError:
339 print nodeinfo_string(name, entry.ninfo)
340 printfield(name, entry.binfo)
342 for name in sorted(entries.keys()):
343 entry = entries[name]
346 except AttributeError:
349 print nodeinfo_string(name, entry.ninfo)
350 printfield(name, entry.binfo)
353 def __init__(self, dbm_name, dbm):
354 self.dbm_name = dbm_name
357 def __call__(self, fname):
358 # The *dbm modules stick their own file suffixes on the names
359 # that are passed in. This is causes us to jump through some
360 # hoops here to be able to allow the user
362 # Try opening the specified file name. Example:
363 # SPECIFIED OPENED BY self.dbm.open()
364 # --------- -------------------------
365 # .sconsign => .sconsign.dblite
366 # .sconsign.dblite => .sconsign.dblite.dblite
367 db = self.dbm.open(fname, "r")
368 except (IOError, OSError), e:
371 # That didn't work, so try opening the base name,
372 # so that if the actually passed in 'sconsign.dblite'
373 # (for example), the dbm module will put the suffix back
374 # on for us and open it anyway.
375 db = self.dbm.open(os.path.splitext(fname)[0], "r")
376 except (IOError, OSError):
377 # That didn't work either. See if the file name
378 # they specified just exists (independent of the dbm
382 except (IOError, OSError), e:
383 # Nope, that file doesn't even exist, so report that
386 sys.stderr.write("sconsign: %s\n" % (print_e))
388 except KeyboardInterrupt:
390 except pickle.UnpicklingError:
391 sys.stderr.write("sconsign: ignoring invalid `%s' file `%s'\n" % (self.dbm_name, fname))
394 sys.stderr.write("sconsign: ignoring invalid `%s' file `%s': %s\n" % (self.dbm_name, fname, e))
397 if Print_Directories:
398 for dir in Print_Directories:
402 sys.stderr.write("sconsign: no dir `%s' in `%s'\n" % (dir, args[0]))
404 self.printentries(dir, val)
406 for dir in sorted(db.keys()):
407 self.printentries(dir, db[dir])
409 def printentries(self, dir, val):
410 print '=== ' + dir + ':'
411 printentries(pickle.loads(val), dir)
413 def Do_SConsignDir(name):
415 fp = open(name, 'rb')
416 except (IOError, OSError), e:
417 sys.stderr.write("sconsign: %s\n" % (e))
420 sconsign = SCons.SConsign.Dir(fp)
421 except KeyboardInterrupt:
423 except pickle.UnpicklingError:
424 sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s'\n" % (name))
427 sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s': %s\n" % (name, e))
429 printentries(sconsign.entries, args[0])
431 ##############################################################################
436 Usage: sconsign [OPTIONS] FILE [...]
438 -a, --act, --action Print build action information.
439 -c, --csig Print content signature information.
440 -d DIR, --dir=DIR Print only info about DIR.
441 -e ENTRY, --entry=ENTRY Print only info about ENTRY.
442 -f FORMAT, --format=FORMAT FILE is in the specified FORMAT.
443 -h, --help Print this message and exit.
444 -i, --implicit Print implicit dependency information.
445 -r, --readable Print timestamps in human-readable form.
446 --raw Print raw Python object representations.
447 -s, --size Print file sizes.
448 -t, --timestamp Print timestamp information.
449 -v, --verbose Verbose, describe each field.
452 opts, args = getopt.getopt(sys.argv[1:], "acd:e:f:hirstv",
454 'csig', 'dir=', 'entry=',
455 'format=', 'help', 'implicit',
457 'size', 'timestamp', 'verbose'])
461 if o in ('-a', '--act', '--action'):
462 Print_Flags['action'] = 1
463 elif o in ('-c', '--csig'):
464 Print_Flags['csig'] = 1
465 elif o in ('-d', '--dir'):
466 Print_Directories.append(a)
467 elif o in ('-e', '--entry'):
468 Print_Entries.append(a)
469 elif o in ('-f', '--format'):
470 Module_Map = {'dblite' : 'SCons.dblite',
472 dbm_name = Module_Map.get(a, a)
475 dbm = my_import(dbm_name)
477 sys.stderr.write("sconsign: illegal file format `%s'\n" % a)
480 Do_Call = Do_SConsignDB(a, dbm)
482 Do_Call = Do_SConsignDir
483 elif o in ('-h', '--help'):
486 elif o in ('-i', '--implicit'):
487 Print_Flags['implicit'] = 1
488 elif o in ('--raw',):
489 nodeinfo_string = nodeinfo_raw
490 elif o in ('-r', '--readable'):
492 elif o in ('-s', '--size'):
493 Print_Flags['size'] = 1
494 elif o in ('-t', '--timestamp'):
495 Print_Flags['timestamp'] = 1
496 elif o in ('-v', '--verbose'):
504 dbm_name = dbm.whichdb(a)
506 Map_Module = {'SCons.dblite' : 'dblite'}
507 dbm = my_import(dbm_name)
508 Do_SConsignDB(Map_Module.get(dbm_name, dbm_name), dbm)(a)
516 # indent-tabs-mode:nil
518 # vim: set expandtab tabstop=4 shiftwidth=4: