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 ##############################################################################
179 import SCons.SConsign
181 def my_whichdb(filename):
182 if filename[-7:] == ".dblite":
183 return "SCons.dblite"
185 f = open(filename + ".dblite", "rb")
187 return "SCons.dblite"
190 return _orig_whichdb(filename)
192 _orig_whichdb = whichdb.whichdb
193 whichdb.whichdb = my_whichdb
195 def my_import(mname):
198 parent = my_import(mname[:i])
199 fp, pathname, description = imp.find_module(mname[i+1:],
202 fp, pathname, description = imp.find_module(mname)
203 return imp.load_module(mname, fp, pathname, description)
207 def __setitem__(self, item, value):
208 self.__dict__[item] = value
209 self.default_value = 0
210 def __getitem__(self, item):
211 return self.__dict__.get(item, self.default_value)
214 Print_Directories = []
216 Print_Flags = Flagger()
220 def default_mapper(entry, name):
222 val = eval("entry."+name)
227 def map_action(entry, name):
230 bactsig = entry.bactsig
231 except AttributeError:
233 return '%s [%s]' % (bactsig, bact)
235 def map_timestamp(entry, name):
237 timestamp = entry.timestamp
238 except AttributeError:
240 if Readable and timestamp:
241 return "'" + time.ctime(timestamp) + "'"
243 return str(timestamp)
245 def map_bkids(entry, name):
247 bkids = entry.bsources + entry.bdepends + entry.bimplicit
248 bkidsigs = entry.bsourcesigs + entry.bdependsigs + entry.bimplicitsigs
249 except AttributeError:
252 for i in xrange(len(bkids)):
253 result.append(nodeinfo_string(bkids[i], bkidsigs[i], " "))
256 return "\n ".join(result)
259 'action' : map_action,
260 'timestamp' : map_timestamp,
265 'implicit' : 'bkids',
268 def field(name, entry, verbose=Verbose):
269 if not Print_Flags[name]:
271 fieldname = map_name.get(name, name)
272 mapper = map_field.get(fieldname, default_mapper)
273 val = mapper(entry, name)
275 val = name + ": " + val
278 def nodeinfo_raw(name, ninfo, prefix=""):
279 # This just formats the dictionary, which we would normally use str()
280 # to do, except that we want the keys sorted for deterministic output.
283 keys = ninfo.field_list + ['_version_id']
284 except AttributeError:
285 keys = sorted(d.keys())
288 l.append('%s: %s' % (repr(k), repr(d.get(k))))
291 return name + ': {' + ', '.join(l) + '}'
293 def nodeinfo_cooked(name, ninfo, prefix=""):
295 field_list = ninfo.field_list
296 except AttributeError:
300 outlist = [name+':'] + [_f for _f in [field(x, ninfo, Verbose) for x in field_list] if _f]
305 return sep.join(outlist)
307 nodeinfo_string = nodeinfo_cooked
309 def printfield(name, entry, prefix=""):
310 outlist = field("implicit", entry, 0)
315 outact = field("action", entry, 0)
318 print " action: " + outact
322 def printentries(entries, location):
324 for name in Print_Entries:
326 entry = entries[name]
328 sys.stderr.write("sconsign: no entry `%s' in `%s'\n" % (name, location))
332 except AttributeError:
335 print nodeinfo_string(name, entry.ninfo)
336 printfield(name, entry.binfo)
338 for name in sorted(entries.keys()):
339 entry = entries[name]
342 except AttributeError:
345 print nodeinfo_string(name, entry.ninfo)
346 printfield(name, entry.binfo)
349 def __init__(self, dbm_name, dbm):
350 self.dbm_name = dbm_name
353 def __call__(self, fname):
354 # The *dbm modules stick their own file suffixes on the names
355 # that are passed in. This is causes us to jump through some
356 # hoops here to be able to allow the user
358 # Try opening the specified file name. Example:
359 # SPECIFIED OPENED BY self.dbm.open()
360 # --------- -------------------------
361 # .sconsign => .sconsign.dblite
362 # .sconsign.dblite => .sconsign.dblite.dblite
363 db = self.dbm.open(fname, "r")
364 except (IOError, OSError), e:
367 # That didn't work, so try opening the base name,
368 # so that if the actually passed in 'sconsign.dblite'
369 # (for example), the dbm module will put the suffix back
370 # on for us and open it anyway.
371 db = self.dbm.open(os.path.splitext(fname)[0], "r")
372 except (IOError, OSError):
373 # That didn't work either. See if the file name
374 # they specified just exists (independent of the dbm
378 except (IOError, OSError), e:
379 # Nope, that file doesn't even exist, so report that
382 sys.stderr.write("sconsign: %s\n" % (print_e))
384 except KeyboardInterrupt:
386 except cPickle.UnpicklingError:
387 sys.stderr.write("sconsign: ignoring invalid `%s' file `%s'\n" % (self.dbm_name, fname))
390 sys.stderr.write("sconsign: ignoring invalid `%s' file `%s': %s\n" % (self.dbm_name, fname, e))
393 if Print_Directories:
394 for dir in Print_Directories:
398 sys.stderr.write("sconsign: no dir `%s' in `%s'\n" % (dir, args[0]))
400 self.printentries(dir, val)
402 for dir in sorted(db.keys()):
403 self.printentries(dir, db[dir])
405 def printentries(self, dir, val):
406 print '=== ' + dir + ':'
407 printentries(cPickle.loads(val), dir)
409 def Do_SConsignDir(name):
411 fp = open(name, 'rb')
412 except (IOError, OSError), e:
413 sys.stderr.write("sconsign: %s\n" % (e))
416 sconsign = SCons.SConsign.Dir(fp)
417 except KeyboardInterrupt:
419 except cPickle.UnpicklingError:
420 sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s'\n" % (name))
423 sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s': %s\n" % (name, e))
425 printentries(sconsign.entries, args[0])
427 ##############################################################################
432 Usage: sconsign [OPTIONS] FILE [...]
434 -a, --act, --action Print build action information.
435 -c, --csig Print content signature information.
436 -d DIR, --dir=DIR Print only info about DIR.
437 -e ENTRY, --entry=ENTRY Print only info about ENTRY.
438 -f FORMAT, --format=FORMAT FILE is in the specified FORMAT.
439 -h, --help Print this message and exit.
440 -i, --implicit Print implicit dependency information.
441 -r, --readable Print timestamps in human-readable form.
442 --raw Print raw Python object representations.
443 -s, --size Print file sizes.
444 -t, --timestamp Print timestamp information.
445 -v, --verbose Verbose, describe each field.
448 opts, args = getopt.getopt(sys.argv[1:], "acd:e:f:hirstv",
450 'csig', 'dir=', 'entry=',
451 'format=', 'help', 'implicit',
453 'size', 'timestamp', 'verbose'])
457 if o in ('-a', '--act', '--action'):
458 Print_Flags['action'] = 1
459 elif o in ('-c', '--csig'):
460 Print_Flags['csig'] = 1
461 elif o in ('-d', '--dir'):
462 Print_Directories.append(a)
463 elif o in ('-e', '--entry'):
464 Print_Entries.append(a)
465 elif o in ('-f', '--format'):
466 Module_Map = {'dblite' : 'SCons.dblite',
468 dbm_name = Module_Map.get(a, a)
471 dbm = my_import(dbm_name)
473 sys.stderr.write("sconsign: illegal file format `%s'\n" % a)
476 Do_Call = Do_SConsignDB(a, dbm)
478 Do_Call = Do_SConsignDir
479 elif o in ('-h', '--help'):
482 elif o in ('-i', '--implicit'):
483 Print_Flags['implicit'] = 1
484 elif o in ('--raw',):
485 nodeinfo_string = nodeinfo_raw
486 elif o in ('-r', '--readable'):
488 elif o in ('-s', '--size'):
489 Print_Flags['size'] = 1
490 elif o in ('-t', '--timestamp'):
491 Print_Flags['timestamp'] = 1
492 elif o in ('-v', '--verbose'):
500 dbm_name = whichdb.whichdb(a)
502 Map_Module = {'SCons.dblite' : 'dblite'}
503 dbm = my_import(dbm_name)
504 Do_SConsignDB(Map_Module.get(dbm_name, dbm_name), dbm)(a)
512 # indent-tabs-mode:nil
514 # vim: set expandtab tabstop=4 shiftwidth=4: