diff options
author | Mats Wichmann <mats@linux.com> | 2018-11-10 16:41:28 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2018-12-01 16:28:01 (GMT) |
commit | 1519a7d40f5e65c1c1c896c9c96456f8364c6907 (patch) | |
tree | f418622ec8e37ac6dce1a37d99081c279a9154c1 /src/script | |
parent | b4d710b768da3f17d57ad2aade009ac8affee9e2 (diff) | |
download | SCons-1519a7d40f5e65c1c1c896c9c96456f8364c6907.zip SCons-1519a7d40f5e65c1c1c896c9c96456f8364c6907.tar.gz SCons-1519a7d40f5e65c1c1c896c9c96456f8364c6907.tar.bz2 |
Some fixes to sconsign
Two locations which attempt to directly print an item tipped over on py3,
so they now decode().
There seem to be cases where implicit dependencies do not have signatures,
so instead of looping through the dep list and indexing into the signature
list (IndexError), the two lists are now zipped, which means nothing is
printed, but sconsign does not die (the zip technique is used in FS.py
in the engine).
Minor PEP8 changes: spaces around operators; shorter lines; two-blanks
rule around classes/functions. Also unused args changed to _ to show
it was intentional.
Manpage updated slightly - the internal whichdb function explicitly
looks for the .dblite suffix, so the claim that if it's not .dbm it
is assumed to be dblite was not true.
sconsign still will not work on a dblite file which is not suffixed
.dblite, but that is an existing problem, not a newly introduced one.
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/sconsign.py | 68 |
1 files changed, 47 insertions, 21 deletions
diff --git a/src/script/sconsign.py b/src/script/sconsign.py index 2337f67..42424a2 100644 --- a/src/script/sconsign.py +++ b/src/script/sconsign.py @@ -164,7 +164,7 @@ else: 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*. @@ -195,6 +195,7 @@ import imp import SCons.SConsign + def my_whichdb(filename): if filename[-7:] == ".dblite": return "SCons.dblite" @@ -225,14 +226,18 @@ 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 = [] @@ -240,9 +245,10 @@ Print_Flags = Flagger() Verbose = 0 Readable = 0 + def default_mapper(entry, name): try: - val = eval("entry."+name) + val = eval("entry." + name) except: val = None if sys.version_info.major >= 3 and isinstance(val, bytes): @@ -252,6 +258,7 @@ def default_mapper(entry, name): val = val.decode() return str(val) + def map_action(entry, name): try: bact = entry.bact @@ -260,7 +267,7 @@ def map_action(entry, name): return None return '%s [%s]' % (bactsig, bact) -def map_timestamp(entry, name): +def map_timestamp(entry, _): try: timestamp = entry.timestamp except AttributeError: @@ -270,19 +277,20 @@ def map_timestamp(entry, name): else: return str(timestamp) -def map_bkids(entry, name): +def map_bkids(entry, _): 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], " ")) + for bkid, bkidsig in zip(bkids, bkidsigs): + result.append(nodeinfo_string(bkid, bkidsig, " ")) if not result: return None return "\n ".join(result) + map_field = { 'action' : map_action, 'timestamp' : map_timestamp, @@ -293,6 +301,7 @@ map_name = { 'implicit' : 'bkids', } + def field(name, entry, verbose=Verbose): if not Print_Flags[name]: return None @@ -303,6 +312,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. @@ -318,6 +328,7 @@ 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 @@ -325,15 +336,19 @@ def nodeinfo_cooked(name, ninfo, prefix=""): 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: @@ -347,13 +362,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 @@ -373,6 +390,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 @@ -407,15 +425,17 @@ class Do_SConsignDB(object): # 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: @@ -423,35 +443,41 @@ class Do_SConsignDB(object): 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): + 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 @@ -493,8 +519,7 @@ for o, a in opts: 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: @@ -502,6 +527,7 @@ for o, a in opts: 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') @@ -530,7 +556,6 @@ for o, a in opts: elif o in ('-v', '--verbose'): Verbose = 1 - if Do_Call: for a in args: Do_Call(a) @@ -538,11 +563,12 @@ 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') |