diff options
author | William Deegan <bill@baddogconsulting.com> | 2020-03-22 00:03:08 (GMT) |
---|---|---|
committer | William Deegan <bill@baddogconsulting.com> | 2020-04-09 20:47:32 (GMT) |
commit | 2888b4f2e8ce13dab28277552ec9fe4ea222cc61 (patch) | |
tree | 555f90ac24f06f166698433efad779b2b66d5836 | |
parent | bdc3e10c5963399badd2833a2ae74a1f87e70b36 (diff) | |
download | SCons-2888b4f2e8ce13dab28277552ec9fe4ea222cc61.zip SCons-2888b4f2e8ce13dab28277552ec9fe4ea222cc61.tar.gz SCons-2888b4f2e8ce13dab28277552ec9fe4ea222cc61.tar.bz2 |
update scripts to work from <sandbox>/scripts
-rw-r--r-- | scripts/scons-configure-cache.py | 155 | ||||
-rw-r--r-- | scripts/sconsign.py | 328 |
2 files changed, 192 insertions, 291 deletions
diff --git a/scripts/scons-configure-cache.py b/scripts/scons-configure-cache.py index 716315c..80783a9 100644 --- a/scripts/scons-configure-cache.py +++ b/scripts/scons-configure-cache.py @@ -100,78 +100,83 @@ config_entries = { } } -parser = argparse.ArgumentParser( - description='Modify the configuration of an scons cache directory', - epilog=''' - Unspecified options will not be changed unless they are not - set at all, in which case they are set to an appropriate default. - ''') - -parser.add_argument('cache-dir', help='Path to scons cache directory') -for param in config_entries: - parser.add_argument('--' + param.replace('_', '-'), - **config_entries[param]['command-line']) -parser.add_argument('--version', - action='version', - version='%(prog)s 1.0') -parser.add_argument('--show', - action="store_true", - help="show current configuration") - -# Get the command line as a dict without any of the unspecified entries. -args = dict([x for x in vars(parser.parse_args()).items() if x[1]]) - -# It seems somewhat strange to me, but positional arguments don't get the - -# in the name changed to _, whereas optional arguments do... -cache = args['cache-dir'] -if not os.path.isdir(cache): - raise RuntimeError("There is no cache directory named %s" % cache) -os.chdir(cache) -del args['cache-dir'] - -if not os.path.exists('config'): - # old config dirs did not have a 'config' file. Try to update. - # Validate the only files in the directory are directories 0-9, a-f - expected = ['{:X}'.format(x) for x in range(0, 16)] - if not set(os.listdir('.')).issubset(expected): - raise RuntimeError( - "%s does not look like a valid version 1 cache directory" % cache) - config = dict() -else: - with open('config') as conf: - config = json.load(conf) - -if args.get('show', None): - print("Current configuration in '%s':" % cache) - print(json.dumps(config, sort_keys=True, - indent=4, separators=(',', ': '))) - # in case of the show argument, emit some stats as well - file_count = 0 - for _, _, files in os.walk('.'): - file_count += len(files) - if file_count: # skip config file if it exists - file_count -= 1 - print("Cache contains %s files" % file_count) - del args['show'] - -# Find any keys that are not currently set but should be -for key in config_entries: - if key not in config: - if 'implicit' in config_entries[key]: - config[key] = config_entries[key]['implicit'] - else: - config[key] = config_entries[key]['default'] - if key not in args: - args[key] = config_entries[key]['default'] - -# Now go through each entry in args to see if it changes an existing config -# setting. -for key in args: - if args[key] != config[key]: - if 'converter' in config_entries[key]: - config_entries[key]['converter'](config[key], args[key]) - config[key] = args[key] - -# and write the updated config file -with open('config', 'w') as conf: - json.dump(config, conf) + +def main(): + parser = argparse.ArgumentParser( + description='Modify the configuration of an scons cache directory', + epilog=''' + Unspecified options will not be changed unless they are not + set at all, in which case they are set to an appropriate default. + ''') + + parser.add_argument('cache-dir', help='Path to scons cache directory') + for param in config_entries: + parser.add_argument('--' + param.replace('_', '-'), + **config_entries[param]['command-line']) + parser.add_argument('--version', + action='version', + version='%(prog)s 1.0') + parser.add_argument('--show', + action="store_true", + help="show current configuration") + + # Get the command line as a dict without any of the unspecified entries. + args = dict([x for x in vars(parser.parse_args()).items() if x[1]]) + + # It seems somewhat strange to me, but positional arguments don't get the - + # in the name changed to _, whereas optional arguments do... + cache = args['cache-dir'] + if not os.path.isdir(cache): + raise RuntimeError("There is no cache directory named %s" % cache) + os.chdir(cache) + del args['cache-dir'] + + if not os.path.exists('config'): + # old config dirs did not have a 'config' file. Try to update. + # Validate the only files in the directory are directories 0-9, a-f + expected = ['{:X}'.format(x) for x in range(0, 16)] + if not set(os.listdir('.')).issubset(expected): + raise RuntimeError( + "%s does not look like a valid version 1 cache directory" % cache) + config = dict() + else: + with open('config') as conf: + config = json.load(conf) + + if args.get('show', None): + print("Current configuration in '%s':" % cache) + print(json.dumps(config, sort_keys=True, + indent=4, separators=(',', ': '))) + # in case of the show argument, emit some stats as well + file_count = 0 + for _, _, files in os.walk('.'): + file_count += len(files) + if file_count: # skip config file if it exists + file_count -= 1 + print("Cache contains %s files" % file_count) + del args['show'] + + # Find any keys that are not currently set but should be + for key in config_entries: + if key not in config: + if 'implicit' in config_entries[key]: + config[key] = config_entries[key]['implicit'] + else: + config[key] = config_entries[key]['default'] + if key not in args: + args[key] = config_entries[key]['default'] + + # Now go through each entry in args to see if it changes an existing config + # setting. + for key in args: + if args[key] != config[key]: + if 'converter' in config_entries[key]: + config_entries[key]['converter'](config[key], args[key]) + config[key] = args[key] + + # and write the updated config file + with open('config', 'w') as conf: + json.dump(config, conf) + +if __name__ == "__main__": + main()
\ No newline at end of file diff --git a/scripts/sconsign.py b/scripts/sconsign.py index 726838c..819b9f7 100644 --- a/scripts/sconsign.py +++ b/scripts/sconsign.py @@ -35,20 +35,16 @@ __date__ = "__DATE__" __developer__ = "__DEVELOPER__" +import getopt import os import sys +from dbm import whichdb -############################################################################## -# BEGIN STANDARD SCons SCRIPT HEADER -# -# This is the cut-and-paste logic so that a self-contained script can -# interoperate correctly with different SCons versions and installation -# locations for the engine. If you modify anything in this section, you -# should also change other scripts that use this same header. -############################################################################## +import time +import pickle -# compatibility check -if sys.version_info < (3,5,0): +# python compatibility check +if sys.version_info < (3, 5, 0): msg = "scons: *** SCons version %s does not run under Python version %s.\n\ Python >= 3.5 is required.\n" sys.stderr.write(msg % (__version__, sys.version.split()[0])) @@ -68,7 +64,7 @@ if "SCONS_LIB_DIR" in os.environ: libs.append(os.environ["SCONS_LIB_DIR"]) # running from source takes 2nd priority (since 2.3.2), following SCONS_LIB_DIR -source_path = os.path.join(script_path, os.pardir, 'engine') +source_path = os.path.join(script_path, os.pardir, 'src', 'engine') if os.path.isdir(source_path): libs.append(source_path) @@ -85,94 +81,6 @@ if os.path.isdir(local): scons_version = 'scons-%s' % __version__ -# preferred order of scons lookup paths -prefs = [] - -# if we can find package information, use it -try: - import pkg_resources -except ImportError: - pass -else: - try: - d = pkg_resources.get_distribution('scons') - except pkg_resources.DistributionNotFound: - pass - else: - prefs.append(d.location) - -if sys.platform == 'win32': - # Use only sys.prefix on Windows - prefs.append(sys.prefix) - prefs.append(os.path.join(sys.prefix, 'Lib', 'site-packages')) -else: - # On other (POSIX) platforms, things are more complicated due to - # the variety of path names and library locations. - # Build up some possibilities, then transform them into candidates - temp = [] - if script_dir == 'bin': - # script_dir is `pwd`/bin; - # check `pwd`/lib/scons*. - temp.append(os.getcwd()) - else: - if script_dir in ('.', ''): - script_dir = os.getcwd() - head, tail = os.path.split(script_dir) - if tail == "bin": - # script_dir is /foo/bin; - # check /foo/lib/scons*. - temp.append(head) - - head, tail = os.path.split(sys.prefix) - if tail == "usr": - # sys.prefix is /foo/usr; - # check /foo/usr/lib/scons* first, - # then /foo/usr/local/lib/scons*. - temp.append(sys.prefix) - temp.append(os.path.join(sys.prefix, "local")) - elif tail == "local": - h, t = os.path.split(head) - if t == "usr": - # sys.prefix is /foo/usr/local; - # check /foo/usr/local/lib/scons* first, - # then /foo/usr/lib/scons*. - temp.append(sys.prefix) - temp.append(head) - else: - # sys.prefix is /foo/local; - # check only /foo/local/lib/scons*. - temp.append(sys.prefix) - else: - # sys.prefix is /foo (ends in neither /usr or /local); - # check only /foo/lib/scons*. - temp.append(sys.prefix) - - # suffix these to add to our original prefs: - prefs.extend([os.path.join(x, 'lib') for x in temp]) - prefs.extend([os.path.join(x, 'lib', 'python' + sys.version[:3], - 'site-packages') for x in temp]) - - - # Add the parent directory of the current python's library to the - # preferences. This picks up differences between, e.g., lib and lib64, - # and finds the base location in case of a non-copying virtualenv. - try: - libpath = os.__file__ - except AttributeError: - pass - else: - # Split /usr/libfoo/python*/os.py to /usr/libfoo/python*. - libpath, _ = os.path.split(libpath) - # Split /usr/libfoo/python* to /usr/libfoo - libpath, tail = os.path.split(libpath) - # Check /usr/libfoo/scons*. - prefs.append(libpath) - -# Look first for 'scons-__version__' in all of our preference libs, -# then for 'scons'. Skip paths that do not exist. -libs.extend([os.path.join(x, scons_version) for x in prefs if os.path.isdir(x)]) -libs.extend([os.path.join(x, 'scons') for x in prefs if os.path.isdir(x)]) - sys.path = libs + sys.path ############################################################################## @@ -180,17 +88,6 @@ sys.path = libs + sys.path ############################################################################## import SCons.compat - -try: - import whichdb - - whichdb = whichdb.whichdb -except ImportError as e: - from dbm import whichdb - -import time -import pickle - import SCons.SConsign @@ -202,16 +99,8 @@ def my_whichdb(filename): return "SCons.dblite" except IOError: pass - return _orig_whichdb(filename) - - -# Should work on python2 -_orig_whichdb = whichdb -whichdb = my_whichdb + return whichdb(filename) -# was changed for python3 -#_orig_whichdb = whichdb.whichdb -#dbm.whichdb = my_whichdb def my_import(mname): import imp @@ -364,8 +253,10 @@ def field(name, entry, verbose=Verbose): 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. + """ + This just formats the dictionary, which we would normally use str() + to do, except that we want the keys sorted for deterministic output. + """ d = ninfo.__getstate__() try: keys = ninfo.field_list + ['_version_id'] @@ -536,54 +427,97 @@ def Do_SConsignDir(name): ############################################################################## +def main(): + global Do_Call + + helpstr = """\ + Usage: sconsign [OPTIONS] [FILE ...] + Options: + -a, --act, --action Print build action information. + -c, --csig Print content signature information. + -d DIR, --dir=DIR Print only info about DIR. + -e ENTRY, --entry=ENTRY Print only info about ENTRY. + -f FORMAT, --format=FORMAT FILE is in the specified FORMAT. + -h, --help Print this message and exit. + -i, --implicit Print implicit dependency information. + -r, --readable Print timestamps in human-readable form. + --raw Print raw Python object representations. + -s, --size Print file sizes. + -t, --timestamp Print timestamp information. + -v, --verbose Verbose, describe each field. + """ -import getopt - -helpstr = """\ -Usage: sconsign [OPTIONS] [FILE ...] -Options: - -a, --act, --action Print build action information. - -c, --csig Print content signature information. - -d DIR, --dir=DIR Print only info about DIR. - -e ENTRY, --entry=ENTRY Print only info about ENTRY. - -f FORMAT, --format=FORMAT FILE is in the specified FORMAT. - -h, --help Print this message and exit. - -i, --implicit Print implicit dependency information. - -r, --readable Print timestamps in human-readable form. - --raw Print raw Python object representations. - -s, --size Print file sizes. - -t, --timestamp Print timestamp information. - -v, --verbose Verbose, describe each field. -""" - -try: - opts, args = getopt.getopt(sys.argv[1:], "acd:e:f:hirstv", - ['act', 'action', - 'csig', 'dir=', 'entry=', - 'format=', 'help', 'implicit', - 'raw', 'readable', - 'size', 'timestamp', 'verbose']) -except getopt.GetoptError as err: - sys.stderr.write(str(err) + '\n') - print(helpstr) - sys.exit(2) - -for o, a in opts: - if o in ('-a', '--act', '--action'): - Print_Flags['action'] = 1 - elif o in ('-c', '--csig'): - Print_Flags['csig'] = 1 - elif o in ('-d', '--dir'): - Print_Directories.append(a) - elif o in ('-e', '--entry'): - Print_Entries.append(a) - 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} - dbm_name = Module_Map.get(a, a) - if dbm_name: - try: + try: + opts, args = getopt.getopt(sys.argv[1:], "acd:e:f:hirstv", + ['act', 'action', + 'csig', 'dir=', 'entry=', + 'format=', 'help', 'implicit', + 'raw', 'readable', + 'size', 'timestamp', 'verbose']) + except getopt.GetoptError as err: + sys.stderr.write(str(err) + '\n') + print(helpstr) + sys.exit(2) + + for o, a in opts: + if o in ('-a', '--act', '--action'): + Print_Flags['action'] = 1 + elif o in ('-c', '--csig'): + Print_Flags['csig'] = 1 + elif o in ('-d', '--dir'): + Print_Directories.append(a) + elif o in ('-e', '--entry'): + Print_Entries.append(a) + 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} + 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') + # again in earlier versions... + SCons.dblite.ignore_corrupt_dbfiles = 0 + except ImportError: + sys.stderr.write("sconsign: illegal file format `%s'\n" % a) + print(helpstr) + sys.exit(2) + Do_Call = Do_SConsignDB(a, dbm) + else: + Do_Call = Do_SConsignDir + elif o in ('-h', '--help'): + print(helpstr) + sys.exit(0) + elif o in ('-i', '--implicit'): + Print_Flags['implicit'] = 1 + elif o in ('--raw',): + nodeinfo_string = nodeinfo_raw + elif o in ('-r', '--readable'): + Readable = 1 + elif o in ('-s', '--size'): + Print_Flags['size'] = 1 + elif o in ('-t', '--timestamp'): + Print_Flags['timestamp'] = 1 + elif o in ('-v', '--verbose'): + Verbose = 1 + + if Do_Call: + for a in args: + Do_Call(a) + else: + if not args: + args = [".sconsign.dblite"] + for a in args: + dbm_name = my_whichdb(a) + if dbm_name: + Map_Module = {'SCons.dblite': 'dblite'} if dbm_name != "SCons.dblite": dbm = my_import(dbm_name) else: @@ -594,56 +528,18 @@ for o, a in opts: # this was handled by calling my_import('SCons.dblite') # again in earlier versions... SCons.dblite.ignore_corrupt_dbfiles = 0 - except ImportError: - sys.stderr.write("sconsign: illegal file format `%s'\n" % a) - print(helpstr) - sys.exit(2) - Do_Call = Do_SConsignDB(a, dbm) - else: - Do_Call = Do_SConsignDir - elif o in ('-h', '--help'): - print(helpstr) - sys.exit(0) - elif o in ('-i', '--implicit'): - Print_Flags['implicit'] = 1 - elif o in ('--raw',): - nodeinfo_string = nodeinfo_raw - elif o in ('-r', '--readable'): - Readable = 1 - elif o in ('-s', '--size'): - Print_Flags['size'] = 1 - elif o in ('-t', '--timestamp'): - Print_Flags['timestamp'] = 1 - elif o in ('-v', '--verbose'): - Verbose = 1 - -if Do_Call: - for a in args: - Do_Call(a) -else: - if not args: - args = [".sconsign.dblite"] - for a in args: - dbm_name = whichdb(a) - if dbm_name: - Map_Module = {'SCons.dblite': 'dblite'} - if dbm_name != "SCons.dblite": - dbm = my_import(dbm_name) + Do_SConsignDB(Map_Module.get(dbm_name, dbm_name), dbm)(a) 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') - # again in earlier versions... - SCons.dblite.ignore_corrupt_dbfiles = 0 - Do_SConsignDB(Map_Module.get(dbm_name, dbm_name), dbm)(a) - else: - Do_SConsignDir(a) + Do_SConsignDir(a) + + if Warns: + print("NOTE: there were %d warnings, please check output" % Warns) + + - if Warns: - print("NOTE: there were %d warnings, please check output" % Warns) -sys.exit(0) +if __name__ == "__main__": + main() + sys.exit(0) # Local Variables: # tab-width:4 |