diff options
Diffstat (limited to 'test/implicit')
-rw-r--r-- | test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py | 125 | ||||
-rw-r--r-- | test/implicit/asynchronous-modification.py | 89 | ||||
-rw-r--r-- | test/implicit/changed-node.py | 142 |
3 files changed, 356 insertions, 0 deletions
diff --git a/test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py b/test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py new file mode 100644 index 0000000..47acc2f --- /dev/null +++ b/test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py @@ -0,0 +1,125 @@ +#!/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__" + +""" +Verify that the $IMPLICIT_COMMAND_DEPENDENCIES variable controls +whether or not the implicit dependency on executed commands +is added to targets. +""" + +import TestSCons + +python = TestSCons.python +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +generate_build_py_py_contents = """\ +#!%(python)s +import os +import sys + +open(sys.argv[1], 'w').write('''\ +#!/usr/bin/env %(python)s +import os.path +import string +import sys +fp = open(sys.argv[1], 'wb') +args = [os.path.split(sys.argv[0])[1]] + sys.argv[1:] +fp.write(string.join(args) + '\\\\n' + '%(extra)s') +for infile in sys.argv[2:]: + fp.write(open(infile, 'rb').read()) +fp.close() +''') +os.chmod(sys.argv[1], 0755) + +""" + +extra = '' +test.write('generate_build_py.py', generate_build_py_py_contents % locals()) + +test.write('SConstruct', """ +generate = Builder(action = r'%(_python_)s $GENERATE $TARGET') +build = Builder(action = r'$BUILD_PY $TARGET $SOURCES') +env = Environment(BUILDERS = { + 'GenerateBuild' : generate, + 'BuildFile' : build, + }, + GENERATE = 'generate_build_py.py', + BUILD_PY = 'build.py', + ) +env.PrependENVPath('PATH', '.') +env.PrependENVPath('PATHEXT', '.PY') +env0 = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0) +env1 = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 1) +envNone = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = None) +envFalse = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = False) +envTrue = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = True) + +build_py = env.GenerateBuild('${BUILD_PY}', []) +AlwaysBuild(build_py) + +env.BuildFile('file.out', 'file.in') +env0.BuildFile('file0.out', 'file.in') +env1.BuildFile('file1.out', 'file.in') +envNone.BuildFile('fileNone.out', 'file.in') +envFalse.BuildFile('fileFalse.out', 'file.in') +envTrue.BuildFile('fileTrue.out', 'file.in') +""" % locals()) + + + +test.write('file.in', "file.in\n") + +test.run(arguments = '--tree=all .') + +expect_none = 'build.py %s file.in\nfile.in\n' + +test.must_match('file.out', expect_none % 'file.out') +test.must_match('file0.out', expect_none % 'file0.out') +test.must_match('file1.out', expect_none % 'file1.out') +test.must_match('fileNone.out', expect_none % 'fileNone.out') +test.must_match('fileFalse.out', expect_none % 'fileFalse.out') +test.must_match('fileTrue.out', expect_none % 'fileTrue.out') + + + +extra = 'xyzzy\\\\n' +test.write('generate_build_py.py', generate_build_py_py_contents % locals()) + +test.run(arguments = '--tree=all .') + +expect_extra = 'build.py %s file.in\nxyzzy\nfile.in\n' + +test.must_match('file.out', expect_extra % 'file.out') +test.must_match('file0.out', expect_none % 'file0.out') +test.must_match('file1.out', expect_extra % 'file1.out') +test.must_match('fileNone.out', expect_none % 'fileNone.out') +test.must_match('fileFalse.out', expect_none % 'fileFalse.out') +test.must_match('fileTrue.out', expect_extra % 'fileTrue.out') + + +test.pass_test() diff --git a/test/implicit/asynchronous-modification.py b/test/implicit/asynchronous-modification.py new file mode 100644 index 0000000..d10f823 --- /dev/null +++ b/test/implicit/asynchronous-modification.py @@ -0,0 +1,89 @@ +#!/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__" + +""" +Verify expected behavior when an implicit dependency is modified +asynchronously (that is, mid-build and without our knowledge). + +Test case courtesy Greg Noel. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.write(['SConstruct'], """\ +import SCons.Defaults +env = Environment() +env['BUILDERS']['C'] = Builder(action = Copy('$TARGET', '$SOURCE'), + source_scanner = SCons.Defaults.CScan) +env['BUILDERS']['Mod'] = Builder(action = r'%(_python_)s mod.py') +Alias('seq', env.C('one.c')) +Alias('seq', env.Mod('mod', 'mod.py')) +Alias('seq', env.C('two.c')) +Default('seq') +""" % locals()) + +test.write(['hdr.h'], """\ +/* empty header */ +""") + +test.write(['mod.py'], """\ +open('mod', 'w').write(open('mod.py', 'r').read()) +open('hdr.h', 'w').write("/* modified */\\n") +""") + +test.write(['one.c'], """\ +#include "hdr.h" +""") + +test.write(['two.c'], """\ +#include "hdr.h" +""") + +# The first run builds the file 'one', then runs the 'mod' script +# (which update modifies the 'hdr.h' file) then builds the file 'two'. +test.run(arguments = 'seq') + +# The 'hdr.h' file had its original contents when 'one' was built, +# and modified contents when 'two' was built. Because we took a +# look at 'hdr.h' once, up front, we think both files are out of +# date and will rebuild both (even though 'two' is really up to date). +# +# A future enhancement might add some sort of verification mode that +# would examine 'hdr.h' again when 'two' was built, thereby avoiding +# the unnecessary rebuild. In that case, the second line below +# will need to change to "test.up_to_date(...)". +test.not_up_to_date(arguments = 'one') +test.not_up_to_date(arguments = 'two') + +# Regardless of what happened on the middle run(s), both files should +# be up to date now. +test.up_to_date(arguments = 'seq') + +test.pass_test() diff --git a/test/implicit/changed-node.py b/test/implicit/changed-node.py new file mode 100644 index 0000000..99a16ac --- /dev/null +++ b/test/implicit/changed-node.py @@ -0,0 +1,142 @@ +#!/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__" + +""" +Verify that we don't throw an exception if a stored implicit +dependency has changed +""" + +import TestSCons + +test = TestSCons.TestSCons() + + + +test.subdir('d', + ['d', '1'], + ['d', '2'], + ['d', '3']) + +test.write('SConstruct', """\ +SetOption('implicit_cache', 1) +SetOption('max_drift', 1) +SourceCode('.', None) + +def lister(target, source, env): + import os + fp = open(str(target[0]), 'w') + s = str(source[0]) + if os.path.isdir(s): + for l in os.listdir(str(source[0])): + fp.write(l + '\\n') + else: + fp.write(s + '\\n') + fp.close() + +builder = Builder(action=lister, + source_factory=Dir, + source_scanner=DirScanner) +env = Environment(tools=[]) +env['BUILDERS']['builder'] = builder +env.builder('d/xfactor', 'd/1') +env.builder('a', 'd') +""") + +test.write(['d', '1', 'x'], "d/1/x\n") +test.write(['d', '1', 'y'], "d/1/y\n") +test.write(['d', '1', 'z'], "d/1/z\n") +test.write(['d', '2', 'x'], "d/2/x\n") +test.write(['d', '2', 'y'], "d/2/y\n") +test.write(['d', '2', 'z'], "d/2/x\n") +test.write(['d', '3', 'x'], "d/3/x\n") +test.write(['d', '3', 'y'], "d/3/y\n") +test.write(['d', '3', 'z'], "d/3/z\n") + +test.run('--debug=stacktrace') + + + +test.write('SConstruct', """\ +SetOption('implicit_cache', 1) +SetOption('max_drift', 1) +SourceCode('.', None) + +def lister(target, source, env): + import os.path + fp = open(str(target[0]), 'w') + s = str(source[0]) + if os.path.isdir(s): + for l in os.listdir(str(source[0])): + fp.write(l + '\\n') + else: + fp.write(s + '\\n') + fp.close() + +builder = Builder(action=lister, + source_factory=File) +env = Environment(tools=[]) +env['BUILDERS']['builder'] = builder + +env.builder('a', 'SConstruct') +""") + +test.run('--debug=stacktrace') + +test.pass_test() + + + + +#from os import system, rmdir, remove, mkdir, listdir +#from os.path import exists, isdir +#import sys +# +# +#def setfile(f, content): +# f = open(f, 'w') +# try: f.write(content) +# finally: f.close() +# +#def checkfile(f, content): +# assert open(f).read().strip() == content +# +#def rm(f): +# if exists(f): +# if isdir(f): +# for name in listdir(f): +# rm(f+'/'+name) +# rmdir(f) +# else: remove(f) +#def clean(full=0): +# for f in ('d','b','a','SConstruct'): +# rm(f) +# if full: +# for f in ('.sconsign.dblite', 'build.py'): +# rm(f) +# +#clean(1) +# +#clean(1) |