3 SCons platform selection.
5 This looks for modules that define a callable object that can modify a
6 construction environment as appropriate for a given platform.
8 Note that we take a more simplistic view of "platform" than Python does.
9 We're looking for a single string that determines a set of
10 tool-independent variables with which to initialize a construction
11 environment. Consequently, we'll examine both sys.platform and os.name
12 (and anything else that might come in to play) in order to return some
13 specification which is unique enough for our purposes.
15 Note that because this subsysem just *selects* a callable that can
16 modify a construction environment, it's possible for people to define
17 their own "platform specification" in an arbitrary callable function.
18 No one needs to use or tie in to this subsystem in order to roll
19 their own platform definition.
23 # Copyright (c) 2001, 2002 Steven Knight
25 # Permission is hereby granted, free of charge, to any person obtaining
26 # a copy of this software and associated documentation files (the
27 # "Software"), to deal in the Software without restriction, including
28 # without limitation the rights to use, copy, modify, merge, publish,
29 # distribute, sublicense, and/or sell copies of the Software, and to
30 # permit persons to whom the Software is furnished to do so, subject to
31 # the following conditions:
33 # The above copyright notice and this permission notice shall be included
34 # in all copies or substantial portions of the Software.
36 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
37 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
38 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
40 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
41 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
42 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
53 def platform_default():
54 """Return the platform string for our execution environment.
56 The returned value should map to one of the SCons/Platform/*.py
57 files. Since we're architecture independent, though, we don't
58 care about the machine architecture.
60 if os.name == 'posix':
61 if sys.platform == 'cygwin':
64 elif os.name == 'os2':
69 def platform_module(name = platform_default()):
70 """Return the imported module for the platform.
72 This looks for a module name that matches the specified argument.
73 If the name is unspecified, we fetch the appropriate default for
74 our execution environment.
76 full_name = 'SCons.Platform.' + name
77 if not sys.modules.has_key(full_name):
79 file, path, desc = imp.find_module(name,
80 sys.modules['SCons.Platform'].__path__)
81 imp.load_module(full_name, file, path, desc)
83 raise SCons.Errors.UserError, "No platform named '%s'" % name
86 return sys.modules[full_name]
88 def DefaultToolList(name = platform_default()):
89 """Select a default tool list for the specified platform.
91 module = platform_module(name)
92 return SCons.Tool.tool_list()
95 def __init__(self, name):
101 def Platform(name = platform_default()):
102 """Select a canned Platform specification.
104 module = platform_module(name)
105 spec = PlatformSpec(name)
106 spec.__call__ = module.generate