diff options
author | Adam Gross <grossag@vmware.com> | 2020-06-22 19:10:43 (GMT) |
---|---|---|
committer | Adam Gross <grossag@vmware.com> | 2020-08-04 13:07:42 (GMT) |
commit | 1fa19ef5eeb2b37c54d291a5aa5858b7b91bbb5d (patch) | |
tree | 34f1d076367301728471aa896e4a14e8082d5910 /test/option | |
parent | 05e2dc91e95507b3c0f1bd42b93f41c0c8733371 (diff) | |
download | SCons-1fa19ef5eeb2b37c54d291a5aa5858b7b91bbb5d.zip SCons-1fa19ef5eeb2b37c54d291a5aa5858b7b91bbb5d.tar.gz SCons-1fa19ef5eeb2b37c54d291a5aa5858b7b91bbb5d.tar.bz2 |
Add support for overriding the default hash format
This change adds support for a new --hash-format parameter that can be used to
override the default hash format used by SCons. The default remains MD5, but
this allows consumers to opt into SHA1, SHA256, or any other hash algorithm
offered by their implementation of hashlib.
Diffstat (limited to 'test/option')
-rw-r--r-- | test/option/hash-format.py | 49 | ||||
-rw-r--r-- | test/option/hash-format/.exclude_tests | 1 | ||||
-rw-r--r-- | test/option/hash-format/SConstruct | 27 | ||||
-rw-r--r-- | test/option/hash-format/build.py | 3 | ||||
-rw-r--r-- | test/option/hash-format/f1.in | 1 |
5 files changed, 81 insertions, 0 deletions
diff --git a/test/option/hash-format.py b/test/option/hash-format.py new file mode 100644 index 0000000..5dfa45d --- /dev/null +++ b/test/option/hash-format.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons + +test = TestSCons.TestSCons() + +test.dir_fixture('hash-format') +test.write('f1.in', str(list(range(10)))) +test.write('f2.in', str(list(range(100000)))) + +# Test passing the hash format by command-line. +for algorithm in ['md5', 'sha1', 'sha256']: + test.run('--hash-format=%s .' % algorithm) + +# In this case, the SConstruct file will use SetOption to override the hash +# format. +test.run() + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/option/hash-format/.exclude_tests b/test/option/hash-format/.exclude_tests new file mode 100644 index 0000000..3fb299e --- /dev/null +++ b/test/option/hash-format/.exclude_tests @@ -0,0 +1 @@ +build.py diff --git a/test/option/hash-format/SConstruct b/test/option/hash-format/SConstruct new file mode 100644 index 0000000..07713ac --- /dev/null +++ b/test/option/hash-format/SConstruct @@ -0,0 +1,27 @@ +import atexit +import sys + +hash_format = GetOption('hash_format') +if not hash_format: + # Override to SHA-256 to validate that override is effective + hash_format = 'sha256' + SetOption('hash_format', hash_format) + +DefaultEnvironment(tools=[]) +B = Builder(action = r'$PYTHON build.py $TARGETS $SOURCES') +env = Environment(tools=[], BUILDERS = { 'B' : B }) +env['PYTHON'] = sys.executable +f1 = env.B(target = 'f1.out', source = 'f1.in') + +def VerifyCsig(): + csig = f1[0].get_csig() + if hash_format == 'md5': + assert csig == 'fe06ae4170d4fead2c958439c738859e', csig + elif hash_format == 'sha1': + assert csig == 'efe5c6daa743540e9561934e3e18628b336013f7', csig + elif hash_format == 'sha256': + assert csig == 'a28bb79aa5ca8a5eb2dc5910a103d1a6312e79d73ed8054787cee78cc532a6aa', csig + else: + raise Exception('Hash format %s is not supported in ' + 'test/option/hash-format/SConstruct' % hash_format) +atexit.register(VerifyCsig)
\ No newline at end of file diff --git a/test/option/hash-format/build.py b/test/option/hash-format/build.py new file mode 100644 index 0000000..6b6baad --- /dev/null +++ b/test/option/hash-format/build.py @@ -0,0 +1,3 @@ +import sys +with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as infp: + f.write(infp.read())
\ No newline at end of file diff --git a/test/option/hash-format/f1.in b/test/option/hash-format/f1.in new file mode 100644 index 0000000..eafc800 --- /dev/null +++ b/test/option/hash-format/f1.in @@ -0,0 +1 @@ +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
\ No newline at end of file |