From 726f4a0214cd69aae4b5ca5104bcac483cd9e6f0 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Fri, 11 Jan 2002 00:02:51 +0000 Subject: Add the InstallAs() method (Charles Crain). --- doc/man/scons.1 | 25 +++++++++++++++++++++++++ src/CHANGES.txt | 4 ++++ src/engine/SCons/Environment.py | 11 +++++++++++ src/engine/SCons/EnvironmentTests.py | 11 ++++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index c19641b..c249162 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -582,6 +582,31 @@ env.Depends('foo.c', 'foo.h') .PP .fi +Additional methods include: + +.IP Install +Installs one or more files in a destination directory. +The file names remain the same. +.IP +.nf +env.Install(dir = '/usr/local/bin', source = 'foo bar') +.PP +.fi + +.IP InstallAs +Installs one or more files as specific file names. +This allows changing a file name as part of the +installation: +.IP +.nf +env.Install(dir = '/usr/local/bin/foo', source = 'foo_debug') +env.Install(target = '../lib/libfoo.a ../lib/libbar.a', + source = 'libFOO.a libBAR.a') +.PP +.fi +It is an error if the target and source +list different numbers of files. + .SS Construction Variables A construction environment has an associated dictionary of construction diff --git a/src/CHANGES.txt b/src/CHANGES.txt index e739fea..43860f1 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -14,6 +14,8 @@ RELEASE 0.03 - - Performance improvements in the Node.FS and Sig.Calculator classes. + - Add the InstallAs() method. + From Steven Knight: - Search both /usr/lib and /usr/local/lib for scons directories by @@ -45,6 +47,8 @@ RELEASE 0.03 - - Use one CPlusPlusAction in the Object Builder's action dictionary, instead of letting it create multiple identical instances. + - Document the Install() and InstallAs() methods. + From Steve Leblanc: - Require that a Builder be given a name argument, supplying a diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 6f77354..612ae9a 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -204,6 +204,17 @@ class Environment: tgt = tgt[0] return tgt + def InstallAs(self, target, source): + """Install sources as targets.""" + sources = SCons.Util.scons_str2nodes(source) + targets = SCons.Util.scons_str2nodes(target) + ret = [] + for src, tgt in map(lambda x, y: (x, y), sources, targets): + ret.append(InstallBuilder(self, tgt, src)) + if len(ret) == 1: + ret = ret[0] + return ret + def subst(self, string): """Recursively interpolates construction variables from the Environment into the specified string, returning the expanded diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 878e736..a65cc33 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -215,7 +215,7 @@ class EnvironmentTestCase(unittest.TestCase): assert env1 == env2 def test_Install(self): - """Test Install method""" + """Test Install and InstallAs methods""" env=Environment() tgt = env.Install('export', [ 'build/foo1', 'build/foo2' ]) paths = map(str, tgt) @@ -225,6 +225,15 @@ class EnvironmentTestCase(unittest.TestCase): for tnode in tgt: assert tnode.builder == InstallBuilder + tgt = env.InstallAs(target='foo1 foo2', source='bar1 bar2') + assert len(tgt) == 2, len(tgt) + paths = map(lambda x: str(x.sources[0]), tgt) + paths.sort() + expect = map(os.path.normpath, [ 'bar1', 'bar2' ]) + assert paths == expect, paths + for tnode in tgt: + assert tnode.builder == InstallBuilder + def test_InstallAs(self): pass # XXX -- cgit v0.12