From e34bbde475e832fcafbb08744d857c19939750a9 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Tue, 17 Feb 2004 03:35:08 +0000 Subject: [PATCH] Update the __env__ variable when making a Copy() or Override() of an Environment. git-svn-id: http://scons.tigris.org/svn/scons/trunk@901 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Environment.py | 2 + src/engine/SCons/EnvironmentTests.py | 26 ++++++++---- test/QT.py | 62 +++++++++++++++++++++------- 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 900b1e1f..5f8575eb 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -489,6 +489,7 @@ class Base: """ clone = copy.copy(self) clone._dict = our_deepcopy(self._dict) + clone['__env__'] = clone try: cbd = clone._dict['BUILDERS'] clone._dict['BUILDERS'] = BuilderDict(cbd, clone) @@ -553,6 +554,7 @@ class Base: if overrides: env = copy.copy(self) env._dict = copy.copy(self._dict) + env['__env__'] = env env._dict.update(overrides) return env else: diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 0887ae33..3a0e79ea 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -117,14 +117,17 @@ class Scanner: class EnvironmentTestCase(unittest.TestCase): def test___init__(self): - """Test construction Environments creation - - Create two with identical arguments and check that - they compare the same. - """ - env1 = Environment(XXX = 'x', YYY = 'y') - env2 = Environment(XXX = 'x', YYY = 'y') - assert env1 == env2, diff_env(env1, env2) + """Test construction Environment creation + + Create two with identical arguments and check that + they compare the same. + """ + env1 = Environment(XXX = 'x', YYY = 'y') + env2 = Environment(XXX = 'x', YYY = 'y') + assert env1 == env2, diff_env(env1, env2) + + assert env1['__env__'] is env1, env1['__env__'] + assert env2['__env__'] is env2, env2['__env__'] def test_get(self): """Test the get() method.""" @@ -947,6 +950,10 @@ class EnvironmentTestCase(unittest.TestCase): assert env3.Dictionary('ZZZ') == 'z3' assert env1 == env1copy + assert env1['__env__'] is env1, env1['__env__'] + assert env2['__env__'] is env2, env2['__env__'] + assert env3['__env__'] is env3, env3['__env__'] + # Ensure that lists and dictionaries are # deep copied, but not instances. class TestA: @@ -1106,6 +1113,9 @@ class EnvironmentTestCase(unittest.TestCase): assert env2['ONE'] == "won" assert env['ONE'] == 1 + assert env['__env__'] is env, env['__env__'] + assert env2['__env__'] is env2, env2['__env__'] + def test_ParseConfig(self): """Test the ParseConfig() method""" env = Environment(COMMAND='command', diff --git a/test/QT.py b/test/QT.py index 3eb5af46..a46d3ef6 100644 --- a/test/QT.py +++ b/test/QT.py @@ -148,7 +148,7 @@ Export("env") SConscript( sconscript ) """ % (QT, QT_LIB, QT_MOC, QT_UIC)) -test.subdir( 'work1', 'work2', 'work3', 'work4', 'work5', 'work6' ) +test.subdir( 'work1', 'work2', 'work3', 'work4', 'work5', 'work6', 'work7' ) ############################################################################## # 1. create a moc file from a header file. @@ -336,13 +336,14 @@ if not MYLIB_IMPL: test.fail_test() ############################################################################## -# 5. Test creation from a copied environment. +# 5. Test creation from a copied environment that already has QT variables. +# This makes sure the tool initialization is re-entrant. createSConstruct(test, ['work5', 'SConstruct']) test.write( ['work5', 'SConscript'], """ Import("env") env = env.Copy(tools=['qt']) -env.Program('main', 'main.cpp', CXXFLAGS=['-g']) +env.Program('main', 'main.cpp', CXXFLAGS=['-g'], LIBS=[]) """) test.write(['work5', 'main.cpp'], r""" @@ -366,14 +367,47 @@ test.run(program = test.workpath('work5', main_exe), stdout = 'qt/include/foo5.h\n') ############################################################################## -# 6. look if qt is installed, and try out all builders +# 6. Test creation from a copied empty environment. + +test.write(['work6', 'SConstruct'], """\ +orig = Environment() +env = orig.Copy(QTDIR = r'%s', + QT_LIB = r'%s', + QT_MOC = r'%s', + QT_UIC = r'%s', + tools=['qt']) +env.Program('main', 'main.cpp', CXXFLAGS=['-g'], LIBS=[]) +""" % (QT, QT_LIB, QT_MOC, QT_UIC)) + +test.write(['work6', 'main.cpp'], r""" +#include "foo6.h" +int main() { foo6(); return 0; } +""") + +test.write(['qt', 'include', 'foo6.h'], """\ +#include +void +foo6(void) +{ + printf("qt/include/foo6.h\\n"); +} +""") + +test.run(chdir='work6') + +main_exe = 'main' + _exe +test.run(program = test.workpath('work6', main_exe), + stdout = 'qt/include/foo6.h\n') + +############################################################################## +# 7. look if qt is installed, and try out all builders if os.environ.get('QTDIR', None): QTDIR=os.environ['QTDIR'] - test.write( ['work6', 'SConstruct'],""" + test.write( ['work7', 'SConstruct'],""" import os dummy_env = Environment() ENV = dummy_env['ENV'] @@ -409,11 +443,11 @@ env.Program('test_realqt', ['mocFromCpp.cpp', 'main.cpp']) """) - test.write( ['work6', 'mocFromCpp.h'],""" + test.write( ['work7', 'mocFromCpp.h'],""" void mocFromCpp(); """) - test.write( ['work6', 'mocFromCpp.cpp'],""" + test.write( ['work7', 'mocFromCpp.cpp'],""" #include #include "mocFromCpp.h" class MyClass1 : public QObject { @@ -429,7 +463,7 @@ void mocFromCpp() { #include "moc_mocFromCpp.cpp" """) - test.write( ['work6', 'mocFromH.h'],""" + test.write( ['work7', 'mocFromH.h'],""" #include class MyClass2 : public QObject { Q_OBJECT; @@ -441,7 +475,7 @@ class MyClass2 : public QObject { void mocFromH(); """) - test.write( ['work6', 'mocFromH.cpp'],""" + test.write( ['work7', 'mocFromH.cpp'],""" #include "mocFromH.h" MyClass2::MyClass2() : QObject() {} @@ -451,7 +485,7 @@ void mocFromH() { } """) - test.write( ['work6', 'anUiFile.ui'],""" + test.write( ['work7', 'anUiFile.ui'],""" MyWidget @@ -467,7 +501,7 @@ void mocFromH() { """) - test.write( ['work6', 'main.cpp'], """ + test.write( ['work7', 'main.cpp'], """ #include "mocFromCpp.h" #include "mocFromH.h" #include "anUiFile.h" @@ -478,13 +512,13 @@ int main() { } """) - test.run(chdir='work6', arguments="test_realqt" + _exe) + test.run(chdir='work7', arguments="test_realqt" + _exe) QTDIR=os.environ['QTDIR'] del os.environ['QTDIR'] - test.run(chdir='work6', arguments="-c test_realqt" + _exe) - test.run(chdir='work6', arguments="PATH=%s/bin test_realqt%s"%(QTDIR,_exe)) + test.run(chdir='work7', arguments="-c test_realqt" + _exe) + test.run(chdir='work7', arguments="PATH=%s/bin test_realqt%s"%(QTDIR,_exe)) else: print "Could not find QT, skipping test(s)." -- 2.26.2