From d6efcab9e4669b8818e6db3f17b76515fc7bf171 Mon Sep 17 00:00:00 2001 From: Daniel Moody Date: Mon, 1 Mar 2021 18:50:25 +0000 Subject: Added reinstantiatng custom cachedir --- CHANGES.txt | 3 +- RELEASE.txt | 2 + SCons/Environment.py | 5 +-- doc/user/caching.xml | 2 +- test/CacheDir/CACHEDIR_CLASS.py | 23 +++-------- test/CacheDir/CACHEDIR_CLASS_fixture/SConstruct | 12 ++++++ test/CacheDir/CACHEDIR_CLASS_fixture/file.in | 1 + test/CacheDir/CustomCacheDir.py | 18 +++------ test/CacheDir/DoubleCachedirClass.py | 47 ++++++++++++++++++++++ test/CacheDir/InvalidCustomCacheDir.py | 15 +++---- test/CacheDir/custom_cachedir/SConstruct | 5 --- test/CacheDir/custom_cachedir/file.in | 1 - test/CacheDir/custom_cachedir_fixture/SConstruct | 11 +++++ test/CacheDir/custom_cachedir_fixture/file.in | 1 + test/CacheDir/double_cachedir_fixture/SConstruct | 30 ++++++++++++++ test/CacheDir/double_cachedir_fixture/file.in | 1 + .../invalid_custom_cachedir_fixture/SConstruct | 6 +++ .../invalid_custom_cachedir_fixture/file.in | 1 + 18 files changed, 133 insertions(+), 51 deletions(-) create mode 100644 test/CacheDir/CACHEDIR_CLASS_fixture/SConstruct create mode 100644 test/CacheDir/CACHEDIR_CLASS_fixture/file.in create mode 100644 test/CacheDir/DoubleCachedirClass.py delete mode 100644 test/CacheDir/custom_cachedir/SConstruct delete mode 100644 test/CacheDir/custom_cachedir/file.in create mode 100644 test/CacheDir/custom_cachedir_fixture/SConstruct create mode 100644 test/CacheDir/custom_cachedir_fixture/file.in create mode 100644 test/CacheDir/double_cachedir_fixture/SConstruct create mode 100644 test/CacheDir/double_cachedir_fixture/file.in create mode 100644 test/CacheDir/invalid_custom_cachedir_fixture/SConstruct create mode 100644 test/CacheDir/invalid_custom_cachedir_fixture/file.in diff --git a/CHANGES.txt b/CHANGES.txt index 6e10209..186a2cf 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -28,7 +28,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER This fixes cases for shared cache where two systems write to the same cache tmpfile at the same time because the happened to get the same pid. - Added support for passing custom CacheDir derived classes to SCons to - to support MongoDB's use of a compressed CacheDir tool. + to support MongoDB's use of a compressed CacheDir tool. Moved copy_from_cache + attribute from the Environment class to CacheDir class. From Mats Wichmann: - Initial support in tests for Python 3.10 - expected bytecode and diff --git a/RELEASE.txt b/RELEASE.txt index f468e1b..a73637d 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -39,6 +39,8 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY WIN32DEFPREFIX, WIN32DEFSUFFIX, WIN32EXPPREFIX, WIN32EXPSUFFIX. All have been replaced by other names since at least 1.0. +- Moved copy_from_cache attribute from the Environment class to CacheDir class. + FIXES ----- diff --git a/SCons/Environment.py b/SCons/Environment.py index c27f94e..1227f37 100644 --- a/SCons/Environment.py +++ b/SCons/Environment.py @@ -956,8 +956,6 @@ class Base(SubstitutionEnvironment): self.decide_target = default_decide_target self.decide_source = default_decide_source - self.copy_from_cache = default_copy_from_cache - self.copy_to_cache = default_copy_to_cache self.cache_timestamp_newer = False self._dict['BUILDERS'] = BuilderDict(self._dict['BUILDERS'], self) @@ -1039,7 +1037,8 @@ class Base(SubstitutionEnvironment): except AttributeError: path = SCons.Defaults.DefaultEnvironment()._CacheDir_path try: - if path == self._last_CacheDir_path: + if (path == self._last_CacheDir_path + and self.get("CACHEDIR_CLASS", SCons.CacheDir.CacheDir) == type(self._last_CacheDir)): return self._last_CacheDir except AttributeError: pass diff --git a/doc/user/caching.xml b/doc/user/caching.xml index 4425545..c7b3842 100644 --- a/doc/user/caching.xml +++ b/doc/user/caching.xml @@ -516,7 +516,7 @@ Program('prog', - SCon's internal CacheDir class can be extended to support customization + SCons' internal CacheDir class can be extended to support customization around the details of caching behaviors, for example using compressed cache files, encrypted cache files, gathering statistics and data, or many other aspects. diff --git a/test/CacheDir/CACHEDIR_CLASS.py b/test/CacheDir/CACHEDIR_CLASS.py index ef34605..f0d6c48 100644 --- a/test/CacheDir/CACHEDIR_CLASS.py +++ b/test/CacheDir/CACHEDIR_CLASS.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -23,29 +25,14 @@ # """ -Test that a custom cache dir can be passed to scons. +Test testing the CACHEDIR_CLASS construction variable. """ import TestSCons test = TestSCons.TestSCons() -test.write(['SConstruct'], """\ -import SCons -class CustomCacheDir(SCons.CacheDir.CacheDir): - - @classmethod - def copy_to_cache(cls, env, src, dst): - print("MY_CUSTOM_CACHEDIR_CLASS") - super().copy_to_cache(env, src, dst) - -env = Environment(tools=[]) -env['CACHEDIR_CLASS'] = CustomCacheDir -env.CacheDir('cache') -env.Command('file.out', 'file.in', Copy('$TARGET', '$SOURCE')) -""") - -test.write('file.in', "file.in\n") +test.dir_fixture('CACHEDIR_CLASS_fixture') test.run() diff --git a/test/CacheDir/CACHEDIR_CLASS_fixture/SConstruct b/test/CacheDir/CACHEDIR_CLASS_fixture/SConstruct new file mode 100644 index 0000000..6ec40c6 --- /dev/null +++ b/test/CacheDir/CACHEDIR_CLASS_fixture/SConstruct @@ -0,0 +1,12 @@ +import SCons +class CustomCacheDir(SCons.CacheDir.CacheDir): + + @classmethod + def copy_to_cache(cls, env, src, dst): + print("MY_CUSTOM_CACHEDIR_CLASS") + super().copy_to_cache(env, src, dst) + +env = Environment(tools=[]) +env['CACHEDIR_CLASS'] = CustomCacheDir +env.CacheDir('cache') +env.Command('file.out', 'file.in', Copy('$TARGET', '$SOURCE')) \ No newline at end of file diff --git a/test/CacheDir/CACHEDIR_CLASS_fixture/file.in b/test/CacheDir/CACHEDIR_CLASS_fixture/file.in new file mode 100644 index 0000000..1912927 --- /dev/null +++ b/test/CacheDir/CACHEDIR_CLASS_fixture/file.in @@ -0,0 +1 @@ +file.in diff --git a/test/CacheDir/CustomCacheDir.py b/test/CacheDir/CustomCacheDir.py index 2846b28..1dac9a3 100644 --- a/test/CacheDir/CustomCacheDir.py +++ b/test/CacheDir/CustomCacheDir.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -23,24 +25,14 @@ # """ -Test that a custom cache dir can be passed to scons. +Test that a custom cache dir can be passed to SCons. """ import TestSCons test = TestSCons.TestSCons() -test.dir_fixture('custom_cachedir') - -test.write(['CustomCacheDirModule.py'], """\ -import SCons -class CustomCacheDir(SCons.CacheDir.CacheDir): - - @classmethod - def copy_to_cache(cls, env, src, dst): - print("MY_CUSTOM_CACHEDIR_CLASS") - super().copy_to_cache(env, src, dst) -""") +test.dir_fixture('custom_cachedir_fixture') test.run() diff --git a/test/CacheDir/DoubleCachedirClass.py b/test/CacheDir/DoubleCachedirClass.py new file mode 100644 index 0000000..3d06f7f --- /dev/null +++ b/test/CacheDir/DoubleCachedirClass.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# +# MIT License +# +# Copyright The SCons Foundation +# +# 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. +# + +""" +Test that a custom cache dir can be passed to SCons. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.dir_fixture('double_cachedir_fixture') + +test.run() + +test.must_contain_all_lines(test.stdout(), ["MY_CUSTOM_CACHEDIR_CLASS2"]) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/CacheDir/InvalidCustomCacheDir.py b/test/CacheDir/InvalidCustomCacheDir.py index 604ee56..cc32b48 100644 --- a/test/CacheDir/InvalidCustomCacheDir.py +++ b/test/CacheDir/InvalidCustomCacheDir.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -23,23 +25,18 @@ # """ -Test that a custom cache dir can be passed to scons. +Test to make sure invalid custom cachedir cause error. """ import TestSCons test = TestSCons.TestSCons() -test.dir_fixture('custom_cachedir') - -test.write(['CustomCacheDirModule.py'], """\ -class CustomCacheDir: - pass -""") +test.dir_fixture('invalid_custom_cachedir_fixture') test.run(status = 2, stderr = None) -test.must_contain_all_lines(test.stderr(), ["Custom CACHEDIR_CLASS not derived from CacheDir"]) +test.must_contain_all_lines(test.stderr(), ["Custom CACHEDIR_CLASS not derived from CacheDir"]) test.pass_test() diff --git a/test/CacheDir/custom_cachedir/SConstruct b/test/CacheDir/custom_cachedir/SConstruct deleted file mode 100644 index 0b24564..0000000 --- a/test/CacheDir/custom_cachedir/SConstruct +++ /dev/null @@ -1,5 +0,0 @@ -from CustomCacheDirModule import CustomCacheDir - -env = Environment(tools=[]) -env.CacheDir('cache', CustomCacheDir) -env.Command('file.out', 'file.in', Copy('$TARGET', '$SOURCE')) \ No newline at end of file diff --git a/test/CacheDir/custom_cachedir/file.in b/test/CacheDir/custom_cachedir/file.in deleted file mode 100644 index 1912927..0000000 --- a/test/CacheDir/custom_cachedir/file.in +++ /dev/null @@ -1 +0,0 @@ -file.in diff --git a/test/CacheDir/custom_cachedir_fixture/SConstruct b/test/CacheDir/custom_cachedir_fixture/SConstruct new file mode 100644 index 0000000..6389999 --- /dev/null +++ b/test/CacheDir/custom_cachedir_fixture/SConstruct @@ -0,0 +1,11 @@ +import SCons +class CustomCacheDir(SCons.CacheDir.CacheDir): + + @classmethod + def copy_to_cache(cls, env, src, dst): + print("MY_CUSTOM_CACHEDIR_CLASS") + super().copy_to_cache(env, src, dst) + +env = Environment(tools=[]) +env.CacheDir('cache', CustomCacheDir) +env.Command('file.out', 'file.in', Copy('$TARGET', '$SOURCE')) \ No newline at end of file diff --git a/test/CacheDir/custom_cachedir_fixture/file.in b/test/CacheDir/custom_cachedir_fixture/file.in new file mode 100644 index 0000000..1912927 --- /dev/null +++ b/test/CacheDir/custom_cachedir_fixture/file.in @@ -0,0 +1 @@ +file.in diff --git a/test/CacheDir/double_cachedir_fixture/SConstruct b/test/CacheDir/double_cachedir_fixture/SConstruct new file mode 100644 index 0000000..1ec442b --- /dev/null +++ b/test/CacheDir/double_cachedir_fixture/SConstruct @@ -0,0 +1,30 @@ +import SCons +class CustomCacheDir1(SCons.CacheDir.CacheDir): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + print("INSTANCIATED %s" % str(type(self))) + + @classmethod + def copy_to_cache(cls, env, src, dst): + print("MY_CUSTOM_CACHEDIR_CLASS1") + super().copy_to_cache(env, src, dst) + +class CustomCacheDir2(SCons.CacheDir.CacheDir): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + print("INSTANCIATED %s" % str(type(self))) + + @classmethod + def copy_to_cache(cls, env, src, dst): + print("MY_CUSTOM_CACHEDIR_CLASS2") + super().copy_to_cache(env, src, dst) + +env = Environment(tools=[]) +env.CacheDir('cache1', CustomCacheDir1) +env.Command('file.out', 'file.in', Copy('$TARGET', '$SOURCE')) +env.CacheDir('cache2', CustomCacheDir2) + + + diff --git a/test/CacheDir/double_cachedir_fixture/file.in b/test/CacheDir/double_cachedir_fixture/file.in new file mode 100644 index 0000000..1912927 --- /dev/null +++ b/test/CacheDir/double_cachedir_fixture/file.in @@ -0,0 +1 @@ +file.in diff --git a/test/CacheDir/invalid_custom_cachedir_fixture/SConstruct b/test/CacheDir/invalid_custom_cachedir_fixture/SConstruct new file mode 100644 index 0000000..ad467e0 --- /dev/null +++ b/test/CacheDir/invalid_custom_cachedir_fixture/SConstruct @@ -0,0 +1,6 @@ +class CustomCacheDir: + pass + +env = Environment(tools=[]) +env.CacheDir('cache', CustomCacheDir) +env.Command('file.out', 'file.in', Copy('$TARGET', '$SOURCE')) \ No newline at end of file diff --git a/test/CacheDir/invalid_custom_cachedir_fixture/file.in b/test/CacheDir/invalid_custom_cachedir_fixture/file.in new file mode 100644 index 0000000..1912927 --- /dev/null +++ b/test/CacheDir/invalid_custom_cachedir_fixture/file.in @@ -0,0 +1 @@ +file.in -- cgit v0.12