diff options
author | Steven Knight <knight@baldmt.com> | 2002-05-09 18:58:15 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-05-09 18:58:15 (GMT) |
commit | 3155d672bfd0eeaf3089c21d002c114b99c1b777 (patch) | |
tree | 8521a026810bd6cac8633e7658386204b70c47ba /src | |
parent | 7f2e1de1e8ec624d8061f84b0aef9ef7f75bfb49 (diff) | |
download | SCons-3155d672bfd0eeaf3089c21d002c114b99c1b777.zip SCons-3155d672bfd0eeaf3089c21d002c114b99c1b777.tar.gz SCons-3155d672bfd0eeaf3089c21d002c114b99c1b777.tar.bz2 |
Add a Platform() method.
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 6 | ||||
-rw-r--r-- | src/engine/MANIFEST.in | 4 | ||||
-rw-r--r-- | src/engine/SCons/Action.py | 9 | ||||
-rw-r--r-- | src/engine/SCons/Defaults.py | 24 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 7 | ||||
-rw-r--r-- | src/engine/SCons/Platform/.aeignore | 5 | ||||
-rw-r--r-- | src/engine/SCons/Platform/PlatformTests.py | 72 | ||||
-rw-r--r-- | src/engine/SCons/Platform/__init__.py | 92 | ||||
-rw-r--r-- | src/engine/SCons/Platform/cygwin.py | 48 | ||||
-rw-r--r-- | src/engine/SCons/Platform/posix.py | 48 | ||||
-rw-r--r-- | src/engine/SCons/Platform/win32.py | 48 | ||||
-rw-r--r-- | src/engine/SCons/Script/SConscript.py | 2 | ||||
-rw-r--r-- | src/setup.py | 1 |
14 files changed, 345 insertions, 26 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 3797327..965b7a6 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,12 @@ RELEASE 0.08 - + From Steven Knight: + + - Add a "platform=" keyword argument to Environment instantiation, + and a separate Platform() method, for more flexible specification + of platform-specific environment changes. + From Anthony Roach: - Add a "multi" keyword argument to Builder creation that specifies diff --git a/src/engine/MANIFEST.in b/src/engine/MANIFEST.in index e86d601..9194557 100644 --- a/src/engine/MANIFEST.in +++ b/src/engine/MANIFEST.in @@ -9,6 +9,10 @@ SCons/exitfuncs.py SCons/Node/__init__.py SCons/Node/Alias.py SCons/Node/FS.py +SCons/Platform/__init__.py +SCons/Platform/cygwin.py +SCons/Platform/posix.py +SCons/Platform/win32.py SCons/Scanner/__init__.py SCons/Scanner/C.py SCons/Scanner/Prog.py diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 94af6bd..f8d37ee 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -48,6 +48,8 @@ exitvalmap = { 13 : 126, } +default_ENV = None + if os.name == 'posix': def defaultSpawn(cmd, args, env): @@ -356,8 +358,11 @@ class CommandAction(ActionBase): try: ENV = kw['env']['ENV'] except: - import SCons.Defaults - ENV = SCons.Defaults.ConstructionEnvironment['ENV'] + global default_ENV + if not default_ENV: + import SCons.Environment + default_ENV = SCons.Environment.Environment()['ENV'] + ENV = default_ENV ret = spawn(cmd_line[0], cmd_line, ENV) if ret: return ret diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 7597169..a7b0dc0 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -47,6 +47,7 @@ import SCons.Builder import SCons.Errors import SCons.Node.Alias import SCons.Node.FS +import SCons.Platform import SCons.Scanner.C import SCons.Scanner.Prog import SCons.Util @@ -452,8 +453,6 @@ def make_win32_env_from_paths(include, lib, path): 'AR' : 'lib', 'ARFLAGS' : '/nologo', 'ARCOM' : '$AR $ARFLAGS /OUT:$TARGET $SOURCES', - 'SHLIBPREFIX': '', - 'SHLIBSUFFIX': '.dll', 'LEX' : 'lex', 'LEXFLAGS' : '', 'LEXCOM' : '$LEX $LEXFLAGS -t $SOURCES > $TARGET', @@ -485,14 +484,6 @@ def make_win32_env_from_paths(include, lib, path): 'BUILDERS' : [Alias, CFile, CXXFile, DVI, Library, Object, PDF, PostScript, Program], 'SCANNERS' : [CScan], - 'OBJPREFIX' : '', - 'OBJSUFFIX' : '.obj', - 'PROGPREFIX' : '', - 'PROGSUFFIX' : '.exe', - 'LIBPREFIX' : '', - 'LIBPREFIXES': '$LIBPREFIX', - 'LIBSUFFIX' : '.lib', - 'LIBSUFFIXES': '$LIBSUFFIX', 'LIBDIRPREFIX' : '/LIBPATH:', 'LIBDIRSUFFIX' : '', 'LIBLINKPREFIX' : '', @@ -509,7 +500,6 @@ def make_win32_env_from_paths(include, lib, path): 'INCLUDE' : include, 'LIB' : lib, 'PATH' : path, - 'PATHEXT' : '.COM;.EXE;.BAT;.CMD', }, } @@ -567,8 +557,6 @@ if os.name == 'posix': 'RANLIB' : ranlib, 'RANLIBFLAGS' : '', 'ARCOM' : arcom, - 'SHLIBPREFIX': '$LIBPREFIX', - 'SHLIBSUFFIX': '.so', 'LEX' : 'lex', 'LEXFLAGS' : '', 'LEXCOM' : '$LEX $LEXFLAGS -t $SOURCES > $TARGET', @@ -598,21 +586,12 @@ if os.name == 'posix': 'BUILDERS' : [Alias, CFile, CXXFile, DVI, Library, Object, PDF, PostScript, Program], 'SCANNERS' : [CScan], - 'OBJPREFIX' : '', - 'OBJSUFFIX' : '.o', - 'PROGPREFIX' : '', - 'PROGSUFFIX' : (sys.platform == 'cygwin') and '.exe' or '', - 'LIBPREFIX' : 'lib', - 'LIBPREFIXES': '$LIBPREFIX', - 'LIBSUFFIX' : '.a', - 'LIBSUFFIXES': [ '$LIBSUFFIX', '$SHLIBSUFFIX' ], 'LIBDIRPREFIX' : '-L', 'LIBDIRSUFFIX' : '', 'LIBLINKPREFIX' : '-l', 'LIBLINKSUFFIX' : '', 'INCPREFIX' : '-I', 'INCSUFFIX' : '', - 'ENV' : { 'PATH' : '/usr/local/bin:/bin:/usr/bin' }, } elif os.name == 'nt': @@ -662,4 +641,3 @@ elif os.name == 'nt': include_path, lib_path, exe_path) - diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index c5f3407..8c61ceb 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -92,9 +92,12 @@ class Environment: Environment. """ - def __init__(self, **kw): + def __init__(self, platform=SCons.Platform.Platform(), **kw): self.fs = SCons.Node.FS.default_fs self._dict = our_deepcopy(SCons.Defaults.ConstructionEnvironment) + if SCons.Util.is_String(platform): + platform = SCons.Platform.Platform(platform) + platform(self) apply(self.Replace, (), kw) # diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index f16632d..3066fc2 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -403,6 +403,13 @@ class EnvironmentTestCase(unittest.TestCase): assert len(dict['_INCFLAGS']) == 0, dict['_INCFLAGS'] assert len(dict['_LIBDIRFLAGS']) == 0, dict['_LIBDIRFLAGS'] + def test_platform(self): + """Test specifying a platform callable when instantiating.""" + def p(env): + env['XYZZY'] = 777 + env = Environment(platform = p) + assert env['XYZZY'] == 777, env + if __name__ == "__main__": diff --git a/src/engine/SCons/Platform/.aeignore b/src/engine/SCons/Platform/.aeignore new file mode 100644 index 0000000..22ebd62 --- /dev/null +++ b/src/engine/SCons/Platform/.aeignore @@ -0,0 +1,5 @@ +*,D +*.pyc +.*.swp +.consign +.sconsign diff --git a/src/engine/SCons/Platform/PlatformTests.py b/src/engine/SCons/Platform/PlatformTests.py new file mode 100644 index 0000000..e3f5966 --- /dev/null +++ b/src/engine/SCons/Platform/PlatformTests.py @@ -0,0 +1,72 @@ +# +# Copyright (c) 2001, 2002 Steven Knight +# +# 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 sys +import unittest + +import SCons.Errors +import SCons.Platform + +class PlatformTestCase(unittest.TestCase): + def test_Platform(self): + """Test the Platform() function""" + p = SCons.Platform.Platform('cygwin') + assert str(p) == 'cygwin', p + env = {} + p(env) + assert env['PROGSUFFIX'] == '.exe', env + assert env['LIBSUFFIX'] == '.a', env + + p = SCons.Platform.Platform('posix') + assert str(p) == 'posix', p + env = {} + p(env) + assert env['PROGSUFFIX'] == '', env + assert env['LIBSUFFIX'] == '.a', env + + p = SCons.Platform.Platform('win32') + assert str(p) == 'win32', p + env = {} + p(env) + assert env['PROGSUFFIX'] == '.exe', env + assert env['LIBSUFFIX'] == '.lib', env + assert str + + try: + p = SCons.Platform.Platform('_does_not_exist_') + except SCons.Errors.UserError: + pass + else: + raise + + env = {} + SCons.Platform.Platform()(env) + assert env != {}, env + + +if __name__ == "__main__": + suite = unittest.makeSuite(PlatformTestCase, 'test_') + if not unittest.TextTestRunner().run(suite).wasSuccessful(): + sys.exit(1) diff --git a/src/engine/SCons/Platform/__init__.py b/src/engine/SCons/Platform/__init__.py new file mode 100644 index 0000000..201a1b9 --- /dev/null +++ b/src/engine/SCons/Platform/__init__.py @@ -0,0 +1,92 @@ +"""SCons.Platform + +SCons platform selection. + +This looks for modules that define a callable object that can modify a +construction environment as appropriate for a given platform. + +Note that we take a more simplistic view of "platform" than Python does. +We're looking for a single string that determines a set of +tool-independent variables with which to initialize a construction +environment. Consequently, we'll examine both sys.platform and os.name +(and anything else that might come in to play) in order to return some +specification which is unique enough for our purposes. + +Note that because this subsysem just *selects* a callable that can +modify a construction environment, it's possible for people to define +their own "platform specification" in an arbitrary callable function. +No one needs to use or tie in to this subsystem in order to roll +their own platform definition. +""" + +# +# Copyright (c) 2001, 2002 Steven Knight +# +# 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__" + +__version__ = "__VERSION__" + +import imp +import os +import sys + +import SCons.Errors + +def platform_default(): + """Return the platform string for our execution environment. + """ + if sys.platform == 'win32': + return 'win32' + if os.name == 'cygwin': + return 'cygwin' + if os.name == 'posix': + return 'posix' + return None + +class PlatformSpec: + def __init__(self, name): + self.name = name + + def __str__(self): + return self.name + +def Platform(name = platform_default()): + """Select a canned Platform specification. + + This looks for a module name that matches the specified argument. + If the name is unspecified, we fetch the appropriate default for + our execution environment. + """ + full_name = 'SCons.Platform.' + name + if not sys.modules.has_key(full_name): + try: + file, path, desc = imp.find_module(name, + sys.modules['SCons.Platform'].__path__) + imp.load_module(full_name, file, path, desc) + except ImportError: + raise SCons.Errors.UserError, "No platform named '%s'" % name + if file: + file.close() + spec = PlatformSpec(name) + spec.__call__ = sys.modules[full_name].generate + return spec diff --git a/src/engine/SCons/Platform/cygwin.py b/src/engine/SCons/Platform/cygwin.py new file mode 100644 index 0000000..7faafd8 --- /dev/null +++ b/src/engine/SCons/Platform/cygwin.py @@ -0,0 +1,48 @@ +"""SCons.Platform.cygwin + +Platform-specific initialization for Cygwin systems. + +There normally shouldn't be any need to import this module directly. It +will usually be imported through the generic SCons.Platform.Platform() +selection method. +""" + +# +# Copyright (c) 2001, 2002 Steven Knight +# +# 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__" + +def generate(env): + if not env.has_key('ENV'): + env['ENV'] = {} + env['ENV']['PATH'] = '/usr/local/bin:/bin:/usr/bin' + env['OBJPREFIX'] = '' + env['OBJSUFFIX'] = '.o' + env['PROGPREFIX'] = '' + env['PROGSUFFIX'] = '.exe' + env['LIBPREFIX'] = 'lib' + env['LIBSUFFIX'] = '.a' + env['SHLIBPREFIX'] = '$LIBPREFIX' + env['SHLIBSUFFIX'] = '.so' + env['LIBPREFIXES'] = '$LIBPREFIX' + env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ] diff --git a/src/engine/SCons/Platform/posix.py b/src/engine/SCons/Platform/posix.py new file mode 100644 index 0000000..4de68f6 --- /dev/null +++ b/src/engine/SCons/Platform/posix.py @@ -0,0 +1,48 @@ +"""SCons.Platform.posix + +Platform-specific initialization for POSIX (Linux, UNIX, etc.) systems. + +There normally shouldn't be any need to import this module directly. It +will usually be imported through the generic SCons.Platform.Platform() +selection method. +""" + +# +# Copyright (c) 2001, 2002 Steven Knight +# +# 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__" + +def generate(env): + if not env.has_key('ENV'): + env['ENV'] = {} + env['ENV']['PATH'] = '/usr/local/bin:/bin:/usr/bin' + env['OBJPREFIX'] = '' + env['OBJSUFFIX'] = '.o' + env['PROGPREFIX'] = '' + env['PROGSUFFIX'] = '' + env['LIBPREFIX'] = 'lib' + env['LIBSUFFIX'] = '.a' + env['SHLIBPREFIX'] = '$LIBPREFIX' + env['SHLIBSUFFIX'] = '.so' + env['LIBPREFIXES'] = '$LIBPREFIX' + env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ] diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py new file mode 100644 index 0000000..aa9a75f --- /dev/null +++ b/src/engine/SCons/Platform/win32.py @@ -0,0 +1,48 @@ +"""SCons.Platform.win32 + +Platform-specific initialization for Win32 systems. + +There normally shouldn't be any need to import this module directly. It +will usually be imported through the generic SCons.Platform.Platform() +selection method. +""" + +# +# Copyright (c) 2001, 2002 Steven Knight +# +# 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__" + +def generate(env): + if not env.has_key('ENV'): + env['ENV'] = {} + env['ENV']['PATHEXT'] = '.COM;.EXE;.BAT;.CMD' + env['OBJPREFIX'] = '' + env['OBJSUFFIX'] = '.obj' + env['PROGPREFIX'] = '' + env['PROGSUFFIX'] = '.exe' + env['LIBPREFIX'] = '' + env['LIBSUFFIX'] = '.lib' + env['SHLIBPREFIX'] = '' + env['SHLIBSUFFIX'] = '.dll' + env['LIBPREFIXES'] = '$LIBPREFIX' + env['LIBSUFFIXES'] = '$LIBSUFFIX' diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 606be08..44ec7ce 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -36,6 +36,7 @@ import SCons.Environment import SCons.Errors import SCons.Node import SCons.Node.FS +import SCons.Platform import SCons.Util import os @@ -260,6 +261,7 @@ def BuildDefaultGlobals(): globals['Import'] = Import globals['Library'] = SCons.Defaults.Library globals['Object'] = SCons.Defaults.Object + globals['Platform'] = SCons.Platform.Platform globals['Program'] = SCons.Defaults.Program globals['Return'] = Return globals['Scanner'] = SCons.Scanner.Base diff --git a/src/setup.py b/src/setup.py index 73abe19..b84f41a 100644 --- a/src/setup.py +++ b/src/setup.py @@ -66,6 +66,7 @@ arguments = { 'version' : "__VERSION__", 'packages' : ["SCons", "SCons.Node", + "SCons.Platform", "SCons.Scanner", "SCons.Sig", "SCons.Script"], |