summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Gross <grossag@vmware.com>2020-12-15 13:58:33 (GMT)
committerAdam Gross <grossag@vmware.com>2020-12-15 13:58:33 (GMT)
commit7dde534c55a58c4b49f5a1dc843ab19866ed426a (patch)
tree356811b1b8d30e6ed545b0851b65f058b6afce40
parent6ee0fc53dbe8a59085d4228891e5542c3f1187bb (diff)
downloadSCons-7dde534c55a58c4b49f5a1dc843ab19866ed426a.zip
SCons-7dde534c55a58c4b49f5a1dc843ab19866ed426a.tar.gz
SCons-7dde534c55a58c4b49f5a1dc843ab19866ed426a.tar.bz2
More improvements
1. Fix failure finding UserError. 2. Fix bad string formatting. 3. Add test case covering passing an invalid hash format. 4. Remove blake2b, as I haven't tested it. We can add it some day if people want it.
-rwxr-xr-xCHANGES.txt2
-rw-r--r--SCons/Script/SConsOptions.py2
-rw-r--r--SCons/Util.py13
-rw-r--r--doc/man/scons.xml2
-rw-r--r--test/option/hash-format.py27
-rw-r--r--test/option/hash-format/SConstruct2
6 files changed, 32 insertions, 16 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 4803ab3..4dd0fd7 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -40,7 +40,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
when running multiple tests with multiple jobs.
- Added support for a new command-line parameter `--hash-format` to override the default
hash format that SCons uses. It can also be set via `SetOption('hash_format')`. Supported
- values include `md5`, `sha1`, `sha256`, and `blake2b`. For all hash formats other than
+ values are: `md5`, `sha1`, and `sha256`. For all hash formats other than
the default of `md5`, the SConsign database will include the name of the hash format.
In addition, the default Decider is now called `content` instead of `MD5`.
- Fix incorrect cache hits and/or misses when running in interactive mode by having
diff --git a/SCons/Script/SConsOptions.py b/SCons/Script/SConsOptions.py
index ae1cac5..c72f670 100644
--- a/SCons/Script/SConsOptions.py
+++ b/SCons/Script/SConsOptions.py
@@ -729,7 +729,7 @@ def Parser(version):
op.add_option('--hash-format',
dest='hash_format',
action='store',
- help='Hash format (e.g. md5, sha1, sha256, or blake2b).')
+ help='Hash format (e.g. md5, sha1, or sha256).')
op.add_option('-i', '--ignore-errors',
dest='ignore_errors', default=False,
diff --git a/SCons/Util.py b/SCons/Util.py
index d341709..d2a7e48 100644
--- a/SCons/Util.py
+++ b/SCons/Util.py
@@ -1500,16 +1500,17 @@ def set_hash_format(hash_format):
_hash_format = hash_format
if hash_format:
hash_format_lower = hash_format.lower()
- allowed_hash_formats = ['md5', 'sha1', 'sha256', 'blake2b']
+ allowed_hash_formats = ['md5', 'sha1', 'sha256']
if hash_format_lower not in allowed_hash_formats:
- from SCons.Warnings import UserError
+ from SCons.Errors import UserError
raise UserError('Hash format "%s" is not supported by SCons. Only '
- 'the following hash formats are supported.' %
- allowed_hash_formats)
+ 'the following hash formats are supported: %s' %
+ (hash_format_lower,
+ ', '.join(allowed_hash_formats)))
_hash_function = getattr(hashlib, hash_format_lower, None)
if _hash_function is None:
- from SCons.Warnings import UserError
+ from SCons.Errors import UserError
raise UserError(
'Hash format "%s" is not available in your Python '
'interpreter.' % hash_format_lower)
@@ -1526,7 +1527,7 @@ def set_hash_format(hash_format):
pass
else:
# This is not expected to happen in practice.
- from SCons.Warnings import UserError
+ from SCons.Errors import UserError
raise UserError(
'Your Python interpreter does not have MD5, SHA1, or SHA256. '
'SCons requires at least one.')
diff --git a/doc/man/scons.xml b/doc/man/scons.xml
index f077735..f4333a0 100644
--- a/doc/man/scons.xml
+++ b/doc/man/scons.xml
@@ -1125,7 +1125,7 @@ the help message not to be displayed.
This value determines the hashing algorithm used in generating content signatures
or &f-link-CacheDir; keys.</para>
-<para>The supported list of values are: md5, sha1, sha256, and blake2b.
+<para>The supported list of values are: md5, sha1, and sha256.
However, the Python interpreter used to run SCons must have the corresponding
support available in hashlib to use the specified algorithm.</para>
</listitem>
diff --git a/test/option/hash-format.py b/test/option/hash-format.py
index 43e5ad7..9fa10ee 100644
--- a/test/option/hash-format.py
+++ b/test/option/hash-format.py
@@ -29,19 +29,26 @@ import os
import TestSCons
# Test passing the hash format by command-line.
-for algorithm in ['md5', 'sha1', 'sha256', 'blake2b', None]:
+INVALID_ALGORITHM = 'testfailure'
+for algorithm in ['md5', 'sha1', 'sha256', INVALID_ALGORITHM, None]:
test = TestSCons.TestSCons()
test.dir_fixture('hash-format')
- if algorithm is not None:
+ if algorithm == INVALID_ALGORITHM:
+ # Expect failure due to an unsupported/invalid algorithm.
+ test.run('--hash-format=%s .' % algorithm, stderr=r"""
+scons: \*\*\* Hash format "{}" is not supported by SCons. Only the following hash formats are supported: md5, sha1, sha256
+File "[^"]+", line \d+, in \S+
+""".format(algorithm), status=2, match=TestSCons.match_re)
+ continue
+ elif algorithm is not None:
# Skip any algorithm that the Python interpreter doesn't have.
if hasattr(hashlib, algorithm):
expected_dblite = test.workpath('.sconsign_%s.dblite' % algorithm)
test.run('--hash-format=%s .' % algorithm)
else:
- test.skip_test('Skipping test with --hash-format=%s because that '
- 'algorithm is not available.' % algorithm)
- continue
+ print('Skipping test with --hash-format=%s because that '
+ 'algorithm is not available.' % algorithm)
else:
# The SConsign file in the hash-format folder has logic to call
# SCons.Util.set_hash_format('sha256') if the default algorithm is
@@ -56,7 +63,15 @@ for algorithm in ['md5', 'sha1', 'sha256', 'blake2b', None]:
assert os.path.isfile(expected_dblite), \
"%s does not exist when running algorithm %s" % (expected_dblite,
algorithm)
- test.pass_test()
+
+ test.run('-C .')
+ os.unlink(expected_dblite)
+
+# In this case, the SConstruct file will use SetOption to override the hash
+# format.
+test.run()
+
+test.pass_test()
# Local Variables:
# tab-width:4
diff --git a/test/option/hash-format/SConstruct b/test/option/hash-format/SConstruct
index 8d600d7..de76e1b 100644
--- a/test/option/hash-format/SConstruct
+++ b/test/option/hash-format/SConstruct
@@ -21,7 +21,7 @@ def VerifyCsig():
assert csig == 'efe5c6daa743540e9561934e3e18628b336013f7', csig
elif hash_format == 'sha256':
assert csig == 'a28bb79aa5ca8a5eb2dc5910a103d1a6312e79d73ed8054787cee78cc532a6aa', csig
- else:
+ elif hash_format != 'testfailure':
raise Exception('Hash format %s is not supported in '
'test/option/hash-format/SConstruct' % hash_format)
atexit.register(VerifyCsig)