Skip to content

Commit

Permalink
Merge 1c7b5c0 into b4d710b
Browse files Browse the repository at this point in the history
  • Loading branch information
mwichmann committed Dec 1, 2018
2 parents b4d710b + 1c7b5c0 commit 39a9854
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 30 deletions.
18 changes: 11 additions & 7 deletions doc/man/sconsign.xml
Expand Up @@ -25,7 +25,7 @@
-->

<!-- lifted from troff+man by doclifter -->
<refentry id='sconsign1'
<refentry id='sconsign1'
xmlns="http://www.scons.org/dbxsd/v1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
Expand All @@ -42,7 +42,7 @@
<!-- body begins here -->
<refsynopsisdiv id='synopsis'>
<cmdsynopsis>
<command>sconsign</command>
<command>sconsign</command>
<arg choice='opt' rep='repeat'><replaceable>options</replaceable></arg>
<arg choice='plain'><replaceable>file</replaceable></arg>
<arg choice='opt'><replaceable>...</replaceable></arg>
Expand All @@ -51,7 +51,7 @@


<refsect1 id='description'><title>DESCRIPTION</title>
<para>The
<para>The
<command>sconsign</command>
command
displays the contents of one or more
Expand Down Expand Up @@ -94,17 +94,21 @@ was specified by the
function).
Any
<emphasis>file</emphasis>
argument that does not end in
<markup>.dbm</markup>
argument that ends in
<markup>.dblite</markup>
is assumed to be a traditional
<markup>.sconsign</markup>
file containing the signature entries
for a single directory.
An explicit format
If neither of those is true,
<command>sconsign</command>
attempts to guess the format.
If that does not work,
an explicit format
may be specified using the
<option>-f</option>
or
<option>--file=</option>
<option>--format=</option>
options.</para>

</refsect1>
Expand Down
2 changes: 2 additions & 0 deletions src/CHANGES.txt
Expand Up @@ -176,6 +176,8 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE
- Update (pep8) configure-cache script, add a --show option.
- Fix for a couple of "what if tool not found" exceptions in framework.
- Add Textfile/Substfile to default environment. (issue #3147)
- sconsign: a couple of python3 fixes; be more tolerant of implicit
entries which have no signatures; minor PEP8 changes.

From Bernhard M. Wiedemann:
- Update SCons' internal scons build logic to allow overriding build date
Expand Down
127 changes: 104 additions & 23 deletions src/script/sconsign.py
Expand Up @@ -164,7 +164,7 @@
pass
else:
# Split /usr/libfoo/python*/os.py to /usr/libfoo/python*.
libpath, tail = os.path.split(libpath)
libpath, _ = os.path.split(libpath)
# Split /usr/libfoo/python* to /usr/libfoo
libpath, tail = os.path.split(libpath)
# Check /usr/libfoo/scons*.
Expand Down Expand Up @@ -195,6 +195,7 @@

import SCons.SConsign


def my_whichdb(filename):
if filename[-7:] == ".dblite":
return "SCons.dblite"
Expand Down Expand Up @@ -225,24 +226,41 @@ def my_import(mname):
fp, pathname, description = imp.find_module(mname)
return imp.load_module(mname, fp, pathname, description)


class Flagger(object):
default_value = 1

def __setitem__(self, item, value):
self.__dict__[item] = value
self.default_value = 0

def __getitem__(self, item):
return self.__dict__.get(item, self.default_value)


Do_Call = None
Print_Directories = []
Print_Entries = []
Print_Flags = Flagger()
Verbose = 0
Readable = 0
Warns = 0



def default_mapper(entry, name):
'''
Stringify an entry that doesn't have an explicit mapping.
Args:
entry: entry
name: field name
Returns: str
'''
try:
val = eval("entry."+name)
val = eval("entry." + name)
except:
val = None
if sys.version_info.major >= 3 and isinstance(val, bytes):
Expand All @@ -252,15 +270,36 @@ def default_mapper(entry, name):
val = val.decode()
return str(val)

def map_action(entry, name):

def map_action(entry, _):
'''
Stringify an action entry and signature.
Args:
entry: action entry
second argument is not used
Returns: str
'''
try:
bact = entry.bact
bactsig = entry.bactsig
except AttributeError:
return None
return '%s [%s]' % (bactsig, bact)

def map_timestamp(entry, name):
def map_timestamp(entry, _):
'''
Stringify a timestamp entry.
Args:
entry: timestamp entry
second argument is not used
Returns: str
'''
try:
timestamp = entry.timestamp
except AttributeError:
Expand All @@ -270,19 +309,38 @@ def map_timestamp(entry, name):
else:
return str(timestamp)

def map_bkids(entry, name):
def map_bkids(entry, _):
'''
Stringify an implicit entry.
Args:
entry:
second argument is not used
Returns: str
'''
try:
bkids = entry.bsources + entry.bdepends + entry.bimplicit
bkidsigs = entry.bsourcesigs + entry.bdependsigs + entry.bimplicitsigs
except AttributeError:
return None
result = []
for i in range(len(bkids)):
result.append(nodeinfo_string(bkids[i], bkidsigs[i], " "))

if len(bkids) != len(bkidsigs):
global Warns
Warns += 1
# add warning to result rather than direct print so it will line up
msg = "Warning: missing information, {} ids but {} sigs"
result = [msg.format(len(bkids), len(bkidsigs))]
else:
result = []
result += [nodeinfo_string(bkid, bkidsig, " ")
for bkid, bkidsig in zip(bkids, bkidsigs)]
if not result:
return None
return "\n ".join(result)


map_field = {
'action' : map_action,
'timestamp' : map_timestamp,
Expand All @@ -293,6 +351,7 @@ def map_bkids(entry, name):
'implicit' : 'bkids',
}


def field(name, entry, verbose=Verbose):
if not Print_Flags[name]:
return None
Expand All @@ -303,6 +362,7 @@ def field(name, entry, verbose=Verbose):
val = name + ": " + val
return val


def nodeinfo_raw(name, ninfo, prefix=""):
# This just formats the dictionary, which we would normally use str()
# to do, except that we want the keys sorted for deterministic output.
Expand All @@ -318,22 +378,27 @@ def nodeinfo_raw(name, ninfo, prefix=""):
name = repr(name)
return name + ': {' + ', '.join(l) + '}'


def nodeinfo_cooked(name, ninfo, prefix=""):
try:
field_list = ninfo.field_list
except AttributeError:
field_list = []
if '\n' in name:
name = repr(name)
outlist = [name+':'] + [_f for _f in [field(x, ninfo, Verbose) for x in field_list] if _f]
outlist = [name + ':'] + [
f for f in [field(x, ninfo, Verbose) for x in field_list] if f
]
if Verbose:
sep = '\n ' + prefix
else:
sep = ' '
return sep.join(outlist)


nodeinfo_string = nodeinfo_cooked


def printfield(name, entry, prefix=""):
outlist = field("implicit", entry, 0)
if outlist:
Expand All @@ -347,13 +412,15 @@ def printfield(name, entry, prefix=""):
else:
print(" " + outact)


def printentries(entries, location):
if Print_Entries:
for name in Print_Entries:
try:
entry = entries[name]
except KeyError:
sys.stderr.write("sconsign: no entry `%s' in `%s'\n" % (name, location))
err = "sconsign: no entry `%s' in `%s'\n" % (name, location)
sys.stderr.write(err)
else:
try:
ninfo = entry.ninfo
Expand All @@ -373,6 +440,7 @@ def printentries(entries, location):
print(nodeinfo_string(name, entry.ninfo))
printfield(name, entry.binfo)


class Do_SConsignDB(object):
def __init__(self, dbm_name, dbm):
self.dbm_name = dbm_name
Expand Down Expand Up @@ -407,51 +475,62 @@ def __call__(self, fname):
# Nope, that file doesn't even exist, so report that
# fact back.
print_e = e
sys.stderr.write("sconsign: %s\n" % (print_e))
sys.stderr.write("sconsign: %s\n" % print_e)
return
except KeyboardInterrupt:
raise
except pickle.UnpicklingError:
sys.stderr.write("sconsign: ignoring invalid `%s' file `%s'\n" % (self.dbm_name, fname))
sys.stderr.write("sconsign: ignoring invalid `%s' file `%s'\n"
% (self.dbm_name, fname))
return
except Exception as e:
sys.stderr.write("sconsign: ignoring invalid `%s' file `%s': %s\n" % (self.dbm_name, fname, e))
sys.stderr.write("sconsign: ignoring invalid `%s' file `%s': %s\n"
% (self.dbm_name, fname, e))
return

if Print_Directories:
for dir in Print_Directories:
try:
val = db[dir]
except KeyError:
sys.stderr.write("sconsign: no dir `%s' in `%s'\n" % (dir, args[0]))
err = "sconsign: no dir `%s' in `%s'\n" % (dir, args[0])
sys.stderr.write(err)
else:
self.printentries(dir, val)
else:
for dir in sorted(db.keys()):
self.printentries(dir, db[dir])

def printentries(self, dir, val):
print('=== ' + dir + ':')
@staticmethod
def printentries(dir, val):
try:
print('=== ' + dir + ':')
except TypeError:
print('=== ' + dir.decode() + ':')
printentries(pickle.loads(val), dir)


def Do_SConsignDir(name):
try:
fp = open(name, 'rb')
except (IOError, OSError) as e:
sys.stderr.write("sconsign: %s\n" % (e))
sys.stderr.write("sconsign: %s\n" % e)
return
try:
sconsign = SCons.SConsign.Dir(fp)
except KeyboardInterrupt:
raise
except pickle.UnpicklingError:
sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s'\n" % (name))
err = "sconsign: ignoring invalid .sconsign file `%s'\n" % (name)
sys.stderr.write(err)
return
except Exception as e:
sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s': %s\n" % (name, e))
err = "sconsign: ignoring invalid .sconsign file `%s': %s\n" % (name, e)
sys.stderr.write(err)
return
printentries(sconsign.entries, args[0])


##############################################################################

import getopt
Expand Down Expand Up @@ -493,15 +572,15 @@ def Do_SConsignDir(name):
elif o in ('-f', '--format'):
# Try to map the given DB format to a known module
# name, that we can then try to import...
Module_Map = {'dblite' : 'SCons.dblite',
'sconsign' : None}
Module_Map = {'dblite': 'SCons.dblite', 'sconsign': None}
dbm_name = Module_Map.get(a, a)
if dbm_name:
try:
if dbm_name != "SCons.dblite":
dbm = my_import(dbm_name)
else:
import SCons.dblite

dbm = SCons.dblite
# Ensure that we don't ignore corrupt DB files,
# this was handled by calling my_import('SCons.dblite')
Expand Down Expand Up @@ -530,19 +609,19 @@ def Do_SConsignDir(name):
elif o in ('-v', '--verbose'):
Verbose = 1


if Do_Call:
for a in args:
Do_Call(a)
else:
for a in args:
dbm_name = whichdb(a)
if dbm_name:
Map_Module = {'SCons.dblite' : 'dblite'}
Map_Module = {'SCons.dblite': 'dblite'}
if dbm_name != "SCons.dblite":
dbm = my_import(dbm_name)
else:
import SCons.dblite

dbm = SCons.dblite
# Ensure that we don't ignore corrupt DB files,
# this was handled by calling my_import('SCons.dblite')
Expand All @@ -552,6 +631,8 @@ def Do_SConsignDir(name):
else:
Do_SConsignDir(a)

if Warns:
print("NOTE: there were %d warnings, please check output" % Warns)
sys.exit(0)

# Local Variables:
Expand Down

0 comments on commit 39a9854

Please sign in to comment.