summaryrefslogtreecommitdiffstats
path: root/SCons/Platform
diff options
context:
space:
mode:
Diffstat (limited to 'SCons/Platform')
-rw-r--r--SCons/Platform/PlatformTests.py255
-rw-r--r--SCons/Platform/__init__.py289
-rw-r--r--SCons/Platform/__init__.xml271
-rw-r--r--SCons/Platform/aix.py85
-rw-r--r--SCons/Platform/cygwin.py64
-rw-r--r--SCons/Platform/darwin.py73
-rw-r--r--SCons/Platform/hpux.py46
-rw-r--r--SCons/Platform/irix.py44
-rw-r--r--SCons/Platform/mingw.py39
-rw-r--r--SCons/Platform/os2.py58
-rw-r--r--SCons/Platform/posix.py131
-rw-r--r--SCons/Platform/posix.xml80
-rw-r--r--SCons/Platform/sunos.py50
-rw-r--r--SCons/Platform/sunos.xml55
-rw-r--r--SCons/Platform/virtualenv.py120
-rw-r--r--SCons/Platform/virtualenvTests.py243
-rw-r--r--SCons/Platform/win32.py449
-rw-r--r--SCons/Platform/win32.xml37
18 files changed, 2389 insertions, 0 deletions
diff --git a/SCons/Platform/PlatformTests.py b/SCons/Platform/PlatformTests.py
new file mode 100644
index 0000000..c89610f
--- /dev/null
+++ b/SCons/Platform/PlatformTests.py
@@ -0,0 +1,255 @@
+#
+# __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__"
+
+import SCons.compat
+
+import collections
+import unittest
+import os
+
+import SCons.Errors
+import SCons.Platform
+import SCons.Environment
+import SCons.Action
+
+
+class Environment(collections.UserDict):
+ def Detect(self, cmd):
+ return cmd
+
+ def AppendENVPath(self, key, value):
+ pass
+
+
+class PlatformTestCase(unittest.TestCase):
+ def test_Platform(self):
+ """Test the Platform() function"""
+ p = SCons.Platform.Platform('cygwin')
+ assert str(p) == 'cygwin', p
+ env = Environment()
+ p(env)
+ assert env['PROGSUFFIX'] == '.exe', env
+ assert env['LIBSUFFIX'] == '.a', env
+ assert env['SHELL'] == 'sh', env
+
+ p = SCons.Platform.Platform('os2')
+ assert str(p) == 'os2', p
+ env = Environment()
+ p(env)
+ assert env['PROGSUFFIX'] == '.exe', env
+ assert env['LIBSUFFIX'] == '.lib', env
+
+ p = SCons.Platform.Platform('posix')
+ assert str(p) == 'posix', p
+ env = Environment()
+ p(env)
+ assert env['PROGSUFFIX'] == '', env
+ assert env['LIBSUFFIX'] == '.a', env
+ assert env['SHELL'] == 'sh', env
+
+ p = SCons.Platform.Platform('irix')
+ assert str(p) == 'irix', p
+ env = Environment()
+ p(env)
+ assert env['PROGSUFFIX'] == '', env
+ assert env['LIBSUFFIX'] == '.a', env
+ assert env['SHELL'] == 'sh', env
+
+ p = SCons.Platform.Platform('aix')
+ assert str(p) == 'aix', p
+ env = Environment()
+ p(env)
+ assert env['PROGSUFFIX'] == '', env
+ assert env['LIBSUFFIX'] == '.a', env
+ assert env['SHELL'] == 'sh', env
+
+ p = SCons.Platform.Platform('sunos')
+ assert str(p) == 'sunos', p
+ env = Environment()
+ p(env)
+ assert env['PROGSUFFIX'] == '', env
+ assert env['LIBSUFFIX'] == '.a', env
+ assert env['SHELL'] == 'sh', env
+
+ p = SCons.Platform.Platform('hpux')
+ assert str(p) == 'hpux', p
+ env = Environment()
+ p(env)
+ assert env['PROGSUFFIX'] == '', env
+ assert env['LIBSUFFIX'] == '.a', env
+ assert env['SHELL'] == 'sh', env
+
+ p = SCons.Platform.Platform('win32')
+ assert str(p) == 'win32', p
+ env = Environment()
+ 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: # TODO pylint E0704: bare raise not inside except
+ raise
+
+ env = Environment()
+ SCons.Platform.Platform()(env)
+ assert env != {}, env
+
+
+class TempFileMungeTestCase(unittest.TestCase):
+ def test_MAXLINELENGTH(self):
+ """ Test different values for MAXLINELENGTH with the same
+ size command string to ensure that the temp file mechanism
+ kicks in only at MAXLINELENGTH+1, or higher
+ """
+ # Init class with cmd, such that the fully expanded
+ # string reads "a test command line".
+ # Note, how we're using a command string here that is
+ # actually longer than the substituted one. This is to ensure
+ # that the TempFileMunge class internally really takes the
+ # length of the expanded string into account.
+ defined_cmd = "a $VERY $OVERSIMPLIFIED line"
+ t = SCons.Platform.TempFileMunge(defined_cmd)
+ env = SCons.Environment.SubstitutionEnvironment(tools=[])
+ # Setting the line length high enough...
+ env['MAXLINELENGTH'] = 1024
+ env['VERY'] = 'test'
+ env['OVERSIMPLIFIED'] = 'command'
+ expanded_cmd = env.subst(defined_cmd)
+ # Call the tempfile munger
+ cmd = t(None, None, env, 0)
+ assert cmd == defined_cmd, cmd
+ # Let MAXLINELENGTH equal the string's length
+ env['MAXLINELENGTH'] = len(expanded_cmd)
+ cmd = t(None, None, env, 0)
+ assert cmd == defined_cmd, cmd
+ # Finally, let the actual tempfile mechanism kick in
+ # Disable printing of actions...
+ old_actions = SCons.Action.print_actions
+ SCons.Action.print_actions = 0
+ env['MAXLINELENGTH'] = len(expanded_cmd)-1
+ cmd = t(None, None, env, 0)
+ # ...and restoring its setting.
+ SCons.Action.print_actions = old_actions
+ assert cmd != defined_cmd, cmd
+
+ def test_TEMPFILEARGJOINBYTE(self):
+ """
+ Test argument join byte TEMPFILEARGJOINBYTE
+ """
+
+ # Init class with cmd, such that the fully expanded
+ # string reads "a test command line".
+ # Note, how we're using a command string here that is
+ # actually longer than the substituted one. This is to ensure
+ # that the TempFileMunge class internally really takes the
+ # length of the expanded string into account.
+ defined_cmd = "a $VERY $OVERSIMPLIFIED line"
+ t = SCons.Platform.TempFileMunge(defined_cmd)
+ env = SCons.Environment.SubstitutionEnvironment(tools=[])
+ # Setting the line length high enough...
+ env['MAXLINELENGTH'] = 1024
+ env['VERY'] = 'test'
+ env['OVERSIMPLIFIED'] = 'command'
+ env['TEMPFILEARGJOINBYTE'] = os.linesep
+ expanded_cmd = env.subst(defined_cmd)
+
+ # For tempfilemunge to operate.
+ old_actions = SCons.Action.print_actions
+ SCons.Action.print_actions = 0
+ env['MAXLINELENGTH'] = len(expanded_cmd)-1
+ cmd = t(None, None, env, 0)
+ # print("CMD is:%s"%cmd)
+
+ with open(cmd[-1],'rb') as f:
+ file_content = f.read()
+ # print("Content is:[%s]"%file_content)
+ # ...and restoring its setting.
+ SCons.Action.print_actions = old_actions
+ assert file_content != env['TEMPFILEARGJOINBYTE'].join(['test','command','line'])
+
+
+ def test_tempfilecreation_once(self):
+ # Init class with cmd, such that the fully expanded
+ # string reads "a test command line".
+ # Note, how we're using a command string here that is
+ # actually longer than the substituted one. This is to ensure
+ # that the TempFileMunge class internally really takes the
+ # length of the expanded string into account.
+ defined_cmd = "a $VERY $OVERSIMPLIFIED line"
+ t = SCons.Platform.TempFileMunge(defined_cmd)
+ env = SCons.Environment.SubstitutionEnvironment(tools=[])
+ # Setting the line length high enough...
+ env['VERY'] = 'test'
+ env['OVERSIMPLIFIED'] = 'command'
+ expanded_cmd = env.subst(defined_cmd)
+ env['MAXLINELENGTH'] = len(expanded_cmd)-1
+ # Disable printing of actions...
+ old_actions = SCons.Action.print_actions
+ SCons.Action.print_actions = 0
+ # Create an instance of object derived class to allow setattrb
+
+ class Node(object):
+ class Attrs(object):
+ pass
+
+ def __init__(self):
+ self.attributes = self.Attrs()
+ target = [Node()]
+ cmd = t(target, None, env, 0)
+ # ...and restoring its setting.
+ SCons.Action.print_actions = old_actions
+ assert cmd != defined_cmd, cmd
+ assert cmd == getattr(target[0].attributes, 'tempfile_cmdlist', None)
+
+
+class PlatformEscapeTestCase(unittest.TestCase):
+ def test_posix_escape(self):
+ """ Check that paths with parens are escaped properly
+ """
+ import SCons.Platform.posix
+
+ test_string = "/my (really) great code/main.cpp"
+ output = SCons.Platform.posix.escape(test_string)
+
+ # We expect the escape function to wrap the string
+ # in quotes, but not escape any internal characters
+ # in the test_string. (Parens doesn't require shell
+ # escaping if their quoted)
+ assert output[1:-1] == test_string
+
+
+if __name__ == "__main__":
+ unittest.main()
+
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/__init__.py b/SCons/Platform/__init__.py
new file mode 100644
index 0000000..21e63b4
--- /dev/null
+++ b/SCons/Platform/__init__.py
@@ -0,0 +1,289 @@
+"""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 subsystem 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__
+#
+# 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 SCons.compat
+
+import importlib
+import os
+import sys
+import tempfile
+
+import SCons.Errors
+import SCons.Subst
+import SCons.Tool
+
+
+def platform_default():
+ """Return the platform string for our execution environment.
+
+ The returned value should map to one of the SCons/Platform/*.py
+ files. Since we're architecture independent, though, we don't
+ care about the machine architecture.
+ """
+ osname = os.name
+ if osname == 'java':
+ osname = os._osType
+ if osname == 'posix':
+ if sys.platform == 'cygwin':
+ return 'cygwin'
+ elif sys.platform.find('irix') != -1:
+ return 'irix'
+ elif sys.platform.find('sunos') != -1:
+ return 'sunos'
+ elif sys.platform.find('hp-ux') != -1:
+ return 'hpux'
+ elif sys.platform.find('aix') != -1:
+ return 'aix'
+ elif sys.platform.find('darwin') != -1:
+ return 'darwin'
+ else:
+ return 'posix'
+ elif os.name == 'os2':
+ return 'os2'
+ else:
+ return sys.platform
+
+
+def platform_module(name = platform_default()):
+ """Return the imported module for the platform.
+
+ 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 full_name not in sys.modules:
+ if os.name == 'java':
+ eval(full_name)
+ else:
+ try:
+ # the specific platform module is a relative import
+ mod = importlib.import_module("." + name, __name__)
+ except ImportError:
+ try:
+ import zipimport
+ importer = zipimport.zipimporter( sys.modules['SCons.Platform'].__path__[0] )
+ mod = importer.load_module(full_name)
+ except ImportError:
+ raise SCons.Errors.UserError("No platform named '%s'" % name)
+ setattr(SCons.Platform, name, mod)
+ return sys.modules[full_name]
+
+
+def DefaultToolList(platform, env):
+ """Select a default tool list for the specified platform.
+ """
+ return SCons.Tool.tool_list(platform, env)
+
+
+class PlatformSpec(object):
+ def __init__(self, name, generate):
+ self.name = name
+ self.generate = generate
+
+ def __call__(self, *args, **kw):
+ return self.generate(*args, **kw)
+
+ def __str__(self):
+ return self.name
+
+
+class TempFileMunge(object):
+ """A callable class. You can set an Environment variable to this,
+ then call it with a string argument, then it will perform temporary
+ file substitution on it. This is used to circumvent the long command
+ line limitation.
+
+ Example usage:
+ env["TEMPFILE"] = TempFileMunge
+ env["LINKCOM"] = "${TEMPFILE('$LINK $TARGET $SOURCES','$LINKCOMSTR')}"
+
+ By default, the name of the temporary file used begins with a
+ prefix of '@'. This may be configured for other tool chains by
+ setting '$TEMPFILEPREFIX':
+ env["TEMPFILEPREFIX"] = '-@' # diab compiler
+ env["TEMPFILEPREFIX"] = '-via' # arm tool chain
+ env["TEMPFILEPREFIX"] = '' # (the empty string) PC Lint
+
+ You can configure the extension of the temporary file through the
+ TEMPFILESUFFIX variable, which defaults to '.lnk' (see comments
+ in the code below):
+ env["TEMPFILESUFFIX"] = '.lnt' # PC Lint
+ """
+ def __init__(self, cmd, cmdstr = None):
+ self.cmd = cmd
+ self.cmdstr = cmdstr
+
+ def __call__(self, target, source, env, for_signature):
+ if for_signature:
+ # If we're being called for signature calculation, it's
+ # because we're being called by the string expansion in
+ # Subst.py, which has the logic to strip any $( $) that
+ # may be in the command line we squirreled away. So we
+ # just return the raw command line and let the upper
+ # string substitution layers do their thing.
+ return self.cmd
+
+ # Now we're actually being called because someone is actually
+ # going to try to execute the command, so we have to do our
+ # own expansion.
+ cmd = env.subst_list(self.cmd, SCons.Subst.SUBST_CMD, target, source)[0]
+ try:
+ maxline = int(env.subst('$MAXLINELENGTH'))
+ except ValueError:
+ maxline = 2048
+
+ length = 0
+ for c in cmd:
+ length += len(c)
+ length += len(cmd) - 1
+ if length <= maxline:
+ return self.cmd
+
+ # Check if we already created the temporary file for this target
+ # It should have been previously done by Action.strfunction() call
+ node = target[0] if SCons.Util.is_List(target) else target
+ cmdlist = getattr(node.attributes, 'tempfile_cmdlist', None) \
+ if node is not None else None
+ if cmdlist is not None:
+ return cmdlist
+
+ # Default to the .lnk suffix for the benefit of the Phar Lap
+ # linkloc linker, which likes to append an .lnk suffix if
+ # none is given.
+ if 'TEMPFILESUFFIX' in env:
+ suffix = env.subst('$TEMPFILESUFFIX')
+ else:
+ suffix = '.lnk'
+
+ fd, tmp = tempfile.mkstemp(suffix, text=True)
+ native_tmp = SCons.Util.get_native_path(tmp)
+
+ if env.get('SHELL', None) == 'sh':
+ # The sh shell will try to escape the backslashes in the
+ # path, so unescape them.
+ native_tmp = native_tmp.replace('\\', r'\\\\')
+ # In Cygwin, we want to use rm to delete the temporary
+ # file, because del does not exist in the sh shell.
+ rm = env.Detect('rm') or 'del'
+ else:
+ # Don't use 'rm' if the shell is not sh, because rm won't
+ # work with the Windows shells (cmd.exe or command.com) or
+ # Windows path names.
+ rm = 'del'
+
+ prefix = env.subst('$TEMPFILEPREFIX')
+ if not prefix:
+ prefix = '@'
+
+ args = list(map(SCons.Subst.quote_spaces, cmd[1:]))
+ join_char = env.get('TEMPFILEARGJOIN',' ')
+ os.write(fd, bytearray(join_char.join(args) + "\n",'utf-8'))
+ os.close(fd)
+
+ # XXX Using the SCons.Action.print_actions value directly
+ # like this is bogus, but expedient. This class should
+ # really be rewritten as an Action that defines the
+ # __call__() and strfunction() methods and lets the
+ # normal action-execution logic handle whether or not to
+ # print/execute the action. The problem, though, is all
+ # of that is decided before we execute this method as
+ # part of expanding the $TEMPFILE construction variable.
+ # Consequently, refactoring this will have to wait until
+ # we get more flexible with allowing Actions to exist
+ # independently and get strung together arbitrarily like
+ # Ant tasks. In the meantime, it's going to be more
+ # user-friendly to not let obsession with architectural
+ # purity get in the way of just being helpful, so we'll
+ # reach into SCons.Action directly.
+ if SCons.Action.print_actions:
+ cmdstr = env.subst(self.cmdstr, SCons.Subst.SUBST_RAW, target,
+ source) if self.cmdstr is not None else ''
+ # Print our message only if XXXCOMSTR returns an empty string
+ if len(cmdstr) == 0 :
+ cmdstr = ("Using tempfile "+native_tmp+" for command line:\n"+
+ str(cmd[0]) + " " + " ".join(args))
+ self._print_cmd_str(target, source, env, cmdstr)
+
+ # Store the temporary file command list into the target Node.attributes
+ # to avoid creating two temporary files one for print and one for execute.
+ cmdlist = [ cmd[0], prefix + native_tmp + '\n' + rm, native_tmp ]
+ if node is not None:
+ try :
+ setattr(node.attributes, 'tempfile_cmdlist', cmdlist)
+ except AttributeError:
+ pass
+ return cmdlist
+
+ def _print_cmd_str(self, target, source, env, cmdstr):
+ # check if the user has specified a cmd line print function
+ print_func = None
+ try:
+ get = env.get
+ except AttributeError:
+ pass
+ else:
+ print_func = get('PRINT_CMD_LINE_FUNC')
+
+ # use the default action cmd line print if user did not supply one
+ if not print_func:
+ action = SCons.Action._ActionAction()
+ action.print_cmd_line(cmdstr, target, source, env)
+ else:
+ print_func(cmdstr, target, source, env)
+
+
+def Platform(name = platform_default()):
+ """Select a canned Platform specification.
+ """
+ module = platform_module(name)
+ spec = PlatformSpec(name, module.generate)
+ return spec
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/__init__.xml b/SCons/Platform/__init__.xml
new file mode 100644
index 0000000..4548e00
--- /dev/null
+++ b/SCons/Platform/__init__.xml
@@ -0,0 +1,271 @@
+<?xml version="1.0"?>
+<!--
+__COPYRIGHT__
+
+This file is processed by the bin/SConsDoc.py module.
+See its __doc__ string for a discussion of the format.
+-->
+
+<!DOCTYPE sconsdoc [
+<!ENTITY % scons SYSTEM '../../../../doc/scons.mod'>
+%scons;
+<!ENTITY % builders-mod SYSTEM '../../../../doc/generated/builders.mod'>
+%builders-mod;
+<!ENTITY % functions-mod SYSTEM '../../../../doc/generated/functions.mod'>
+%functions-mod;
+<!ENTITY % tools-mod SYSTEM '../../../../doc/generated/tools.mod'>
+%tools-mod;
+<!ENTITY % variables-mod SYSTEM '../../../../doc/generated/variables.mod'>
+%variables-mod;
+]>
+
+<sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
+
+<cvar name="ESCAPE">
+<summary>
+<para>
+A function that will be called to escape shell special characters in
+command lines. The function should take one argument: the command line
+string to escape; and should return the escaped command line.
+</para>
+</summary>
+</cvar>
+
+<cvar name="LIBPREFIX">
+<summary>
+<para>
+The prefix used for (static) library file names.
+A default value is set for each platform
+(posix, win32, os2, etc.),
+but the value is overridden by individual tools
+(ar, mslib, sgiar, sunar, tlib, etc.)
+to reflect the names of the libraries they create.
+</para>
+</summary>
+</cvar>
+
+<cvar name="LIBPREFIXES">
+<summary>
+<para>
+A list of all legal prefixes for library file names.
+When searching for library dependencies,
+SCons will look for files with these prefixes,
+the base library name,
+and suffixes in the &cv-LIBSUFFIXES; list.
+</para>
+</summary>
+</cvar>
+
+<cvar name="LIBSUFFIX">
+<summary>
+<para>
+The suffix used for (static) library file names.
+A default value is set for each platform
+(posix, win32, os2, etc.),
+but the value is overridden by individual tools
+(ar, mslib, sgiar, sunar, tlib, etc.)
+to reflect the names of the libraries they create.
+</para>
+</summary>
+</cvar>
+
+<cvar name="LIBSUFFIXES">
+<summary>
+<para>
+A list of all legal suffixes for library file names.
+When searching for library dependencies,
+SCons will look for files with prefixes, in the &cv-LIBPREFIXES; list,
+the base library name,
+and these suffixes.
+</para>
+</summary>
+</cvar>
+
+<cvar name="OBJPREFIX">
+<summary>
+<para>
+The prefix used for (static) object file names.
+</para>
+</summary>
+</cvar>
+
+<cvar name="OBJSUFFIX">
+<summary>
+<para>
+The suffix used for (static) object file names.
+</para>
+</summary>
+</cvar>
+
+<cvar name="PLATFORM">
+<summary>
+<para>
+The name of the platform used to create the Environment. If no platform is
+specified when the Environment is created,
+&scons;
+autodetects the platform.
+</para>
+
+<example_commands>
+env = Environment(tools = [])
+if env['PLATFORM'] == 'cygwin':
+ Tool('mingw')(env)
+else:
+ Tool('msvc')(env)
+</example_commands>
+</summary>
+</cvar>
+
+<cvar name="HOST_OS">
+ <summary>
+<para>
+ The name of the host operating system used to create the Environment.
+ If a platform is specified when creating the Environment, then
+ that Platform's logic will handle setting this value.
+ This value is immutable, and should not be changed by the user after
+ the Environment is initialized.
+ Currently only set for Win32.
+</para>
+ </summary>
+</cvar>
+
+<cvar name="HOST_ARCH">
+ <summary>
+<para>
+ The name of the host hardware architecture used to create the Environment.
+ If a platform is specified when creating the Environment, then
+ that Platform's logic will handle setting this value.
+ This value is immutable, and should not be changed by the user after
+ the Environment is initialized.
+ Currently only set for Win32.
+</para>
+ </summary>
+</cvar>
+
+<cvar name="TARGET_OS">
+ <summary>
+<para>
+ The name of the target operating system for the compiled objects
+ created by this Environment.
+ This defaults to the value of HOST_OS, and the user can override it.
+ Currently only set for Win32.
+</para>
+ </summary>
+</cvar>
+
+<cvar name="TARGET_ARCH">
+ <summary>
+<para>
+ The name of the target hardware architecture for the compiled objects
+ created by this Environment.
+ This defaults to the value of HOST_ARCH, and the user can override it.
+ Currently only set for Win32.
+</para>
+ </summary>
+</cvar>
+
+
+<cvar name="PROGPREFIX">
+<summary>
+<para>
+The prefix used for executable file names.
+</para>
+</summary>
+</cvar>
+
+<cvar name="PROGSUFFIX">
+<summary>
+<para>
+The suffix used for executable file names.
+</para>
+</summary>
+</cvar>
+
+<cvar name="SHELL">
+<summary>
+<para>
+A string naming the shell program that will be passed to the
+&cv-SPAWN;
+function.
+See the
+&cv-SPAWN;
+construction variable for more information.
+</para>
+</summary>
+</cvar>
+
+<cvar name="SHLIBPREFIX">
+<summary>
+<para>
+The prefix used for shared library file names.
+</para>
+</summary>
+</cvar>
+
+<cvar name="SHLIBSUFFIX">
+<summary>
+<para>
+The suffix used for shared library file names.
+</para>
+</summary>
+</cvar>
+
+<cvar name="SHOBJPREFIX">
+<summary>
+<para>
+The prefix used for shared object file names.
+</para>
+</summary>
+</cvar>
+
+<cvar name="SHOBJSUFFIX">
+<summary>
+<para>
+The suffix used for shared object file names.
+</para>
+</summary>
+</cvar>
+
+<cvar name="TEMPFILEPREFIX">
+<summary>
+<para>
+The prefix for a temporary file used
+to store lines lines longer than $MAXLINELENGTH
+as operations which call out to a shell will fail
+if the line is too long, which particularly
+impacts linking.
+The default is '@', which works for the Microsoft
+and GNU toolchains on Windows.
+Set this appropriately for other toolchains,
+for example '-@' for the diab compiler
+or '-via' for ARM toolchain.
+</para>
+</summary>
+</cvar>
+
+<cvar name="TEMPFILESUFFIX">
+<summary>
+<para>
+The suffix used for the temporary file name
+used for long command lines. The name should
+include the dot ('.') if one is wanted as
+it will not be added automatically.
+The default is '.lnk'.
+</para>
+</summary>
+</cvar>
+
+<cvar name="TEMPFILEARGJOIN">
+<summary>
+<para>
+The string (or character) to be used to join the arguments passed to TEMPFILE when command line exceeds the limit set by &cv-MAXLINELENGTH;.
+The default value is a space. However for MSVC, MSLINK the default is a line seperator characters as defined by os.linesep.
+Note this value is used literally and not expanded by the subst logic.
+</para>
+</summary>
+</cvar>
+
+
+</sconsdoc>
diff --git a/SCons/Platform/aix.py b/SCons/Platform/aix.py
new file mode 100644
index 0000000..0266dc6
--- /dev/null
+++ b/SCons/Platform/aix.py
@@ -0,0 +1,85 @@
+"""engine.SCons.Platform.aix
+
+Platform-specific initialization for IBM AIX 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__
+#
+# 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 os
+import subprocess
+
+from . import posix
+
+import SCons.Util
+import SCons.Action
+
+def get_xlc(env, xlc=None, packages=[]):
+ # Use the AIX package installer tool lslpp to figure out where a
+ # given xl* compiler is installed and what version it is.
+ xlcPath = None
+ xlcVersion = None
+
+ if xlc is None:
+ xlc = env.get('CC', 'xlc')
+ if SCons.Util.is_List(xlc):
+ xlc = xlc[0]
+ for package in packages:
+ # find the installed filename, which may be a symlink as well
+ pipe = SCons.Action._subproc(env, ['lslpp', '-fc', package],
+ stdin = 'devnull',
+ stderr = 'devnull',
+ stdout = subprocess.PIPE)
+ # output of lslpp is something like this:
+ # #Path:Fileset:File
+ # /usr/lib/objrepos:vac.C 6.0.0.0:/usr/vac/exe/xlCcpp
+ # /usr/lib/objrepos:vac.C 6.0.0.0:/usr/vac/bin/xlc_r -> /usr/vac/bin/xlc
+ for line in pipe.stdout:
+ if xlcPath:
+ continue # read everything to let lslpp terminate
+ fileset, filename = line.split(':')[1:3]
+ filename = filename.split()[0]
+ if ('/' in xlc and filename == xlc) \
+ or ('/' not in xlc and filename.endswith('/' + xlc)):
+ xlcVersion = fileset.split()[1]
+ xlcPath, sep, xlc = filename.rpartition('/')
+ pass
+ pass
+ return (xlcPath, xlc, xlcVersion)
+
+def generate(env):
+ posix.generate(env)
+ #Based on AIX 5.2: ARG_MAX=24576 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 21576
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/cygwin.py b/SCons/Platform/cygwin.py
new file mode 100644
index 0000000..f6c5086
--- /dev/null
+++ b/SCons/Platform/cygwin.py
@@ -0,0 +1,64 @@
+"""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__
+#
+# 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
+
+from . import posix
+from SCons.Platform import TempFileMunge
+
+CYGWIN_DEFAULT_PATHS = []
+if sys.platform == 'win32':
+ CYGWIN_DEFAULT_PATHS = [
+ r'C:\cygwin64\bin',
+ r'C:\cygwin\bin'
+ ]
+
+def generate(env):
+ posix.generate(env)
+
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = '.exe'
+ env['SHLIBPREFIX'] = ''
+ env['SHLIBSUFFIX'] = '.dll'
+ env['LIBPREFIXES'] = [ '$LIBPREFIX', '$SHLIBPREFIX', '$IMPLIBPREFIX' ]
+ env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX', '$IMPLIBSUFFIX' ]
+ env['TEMPFILE'] = TempFileMunge
+ env['TEMPFILEPREFIX'] = '@'
+ env['MAXLINELENGTH'] = 2048
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/darwin.py b/SCons/Platform/darwin.py
new file mode 100644
index 0000000..fd697f6
--- /dev/null
+++ b/SCons/Platform/darwin.py
@@ -0,0 +1,73 @@
+"""engine.SCons.Platform.darwin
+
+Platform-specific initialization for Mac OS X 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__
+#
+# 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__"
+
+from . import posix
+import os
+
+def generate(env):
+ posix.generate(env)
+ env['SHLIBSUFFIX'] = '.dylib'
+ # put macports paths at front to override Apple's versions, fink path is after
+ # For now let people who want Macports or Fink tools specify it!
+ # env['ENV']['PATH'] = '/opt/local/bin:/opt/local/sbin:' + env['ENV']['PATH'] + ':/sw/bin'
+
+ # Store extra system paths in env['ENV']['PATHOSX']
+
+ filelist = ['/etc/paths',]
+ # make sure this works on Macs with Tiger or earlier
+ try:
+ dirlist = os.listdir('/etc/paths.d')
+ except:
+ dirlist = []
+
+ for file in dirlist:
+ filelist.append('/etc/paths.d/'+file)
+
+ for file in filelist:
+ if os.path.isfile(file):
+ with open(file, 'r') as f:
+ lines = f.readlines()
+ for line in lines:
+ if line:
+ env.AppendENVPath('PATHOSX', line.strip('\n'))
+
+ # Not sure why this wasn't the case all along?
+ if env['ENV'].get('PATHOSX', False) and os.environ.get('SCONS_USE_MAC_PATHS', False):
+ env.AppendENVPath('PATH',env['ENV']['PATHOSX'])
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/hpux.py b/SCons/Platform/hpux.py
new file mode 100644
index 0000000..0e0bbcf
--- /dev/null
+++ b/SCons/Platform/hpux.py
@@ -0,0 +1,46 @@
+"""engine.SCons.Platform.hpux
+
+Platform-specific initialization for HP-UX 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__
+#
+# 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__"
+
+from . import posix
+
+def generate(env):
+ posix.generate(env)
+ #Based on HP-UX11i: ARG_MAX=2048000 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 2045000
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/irix.py b/SCons/Platform/irix.py
new file mode 100644
index 0000000..2e5f217
--- /dev/null
+++ b/SCons/Platform/irix.py
@@ -0,0 +1,44 @@
+"""SCons.Platform.irix
+
+Platform-specific initialization for SGI IRIX 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__
+#
+# 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__"
+
+from . import posix
+
+def generate(env):
+ posix.generate(env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/mingw.py b/SCons/Platform/mingw.py
new file mode 100644
index 0000000..73633d7
--- /dev/null
+++ b/SCons/Platform/mingw.py
@@ -0,0 +1,39 @@
+"""SCons.Platform.mingw
+
+Platform-specific initialization for the MinGW system.
+
+"""
+
+#
+# __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__"
+
+import sys
+
+MINGW_DEFAULT_PATHS = []
+if sys.platform == 'win32':
+ MINGW_DEFAULT_PATHS = [
+ r'C:\msys64',
+ r'C:\msys'
+ ] \ No newline at end of file
diff --git a/SCons/Platform/os2.py b/SCons/Platform/os2.py
new file mode 100644
index 0000000..5ca26bc
--- /dev/null
+++ b/SCons/Platform/os2.py
@@ -0,0 +1,58 @@
+"""SCons.Platform.os2
+
+Platform-specific initialization for OS/2 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__
+#
+# 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__"
+from . import win32
+
+def generate(env):
+ if 'ENV' not in env:
+ env['ENV'] = {}
+ env['OBJPREFIX'] = ''
+ env['OBJSUFFIX'] = '.obj'
+ env['SHOBJPREFIX'] = '$OBJPREFIX'
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = '.exe'
+ env['LIBPREFIX'] = ''
+ env['LIBSUFFIX'] = '.lib'
+ env['SHLIBPREFIX'] = ''
+ env['SHLIBSUFFIX'] = '.dll'
+ env['LIBPREFIXES'] = '$LIBPREFIX'
+ env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
+ env['HOST_OS'] = 'os2'
+ env['HOST_ARCH'] = win32.get_architecture().arch
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/posix.py b/SCons/Platform/posix.py
new file mode 100644
index 0000000..ad4e859
--- /dev/null
+++ b/SCons/Platform/posix.py
@@ -0,0 +1,131 @@
+"""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__
+#
+# 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 errno
+import os
+import os.path
+import subprocess
+import sys
+import select
+
+import SCons.Util
+from SCons.Platform import TempFileMunge
+from SCons.Platform.virtualenv import ImportVirtualenv
+from SCons.Platform.virtualenv import ignore_virtualenv, enable_virtualenv
+
+exitvalmap = {
+ 2 : 127,
+ 13 : 126,
+}
+
+def escape(arg):
+ """escape shell special characters"""
+ slash = '\\'
+ special = '"$'
+
+ arg = arg.replace(slash, slash+slash)
+ for c in special:
+ arg = arg.replace(c, slash+c)
+
+ # print("ESCAPE RESULT: %s" % arg)
+ return '"' + arg + '"'
+
+
+def exec_subprocess(l, env):
+ proc = subprocess.Popen(l, env = env, close_fds = True)
+ return proc.wait()
+
+def subprocess_spawn(sh, escape, cmd, args, env):
+ return exec_subprocess([sh, '-c', ' '.join(args)], env)
+
+def exec_popen3(l, env, stdout, stderr):
+ proc = subprocess.Popen(l, env = env, close_fds = True,
+ stdout = stdout,
+ stderr = stderr)
+ return proc.wait()
+
+def piped_env_spawn(sh, escape, cmd, args, env, stdout, stderr):
+ # spawn using Popen3 combined with the env command
+ # the command name and the command's stdout is written to stdout
+ # the command's stderr is written to stderr
+ return exec_popen3([sh, '-c', ' '.join(args)],
+ env, stdout, stderr)
+
+
+def generate(env):
+ # Bearing in mind we have python 2.4 as a baseline, we can just do this:
+ spawn = subprocess_spawn
+ pspawn = piped_env_spawn
+ # Note that this means that 'escape' is no longer used
+
+ if 'ENV' not in env:
+ env['ENV'] = {}
+ env['ENV']['PATH'] = '/usr/local/bin:/opt/bin:/bin:/usr/bin'
+ env['OBJPREFIX'] = ''
+ env['OBJSUFFIX'] = '.o'
+ env['SHOBJPREFIX'] = '$OBJPREFIX'
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = ''
+ env['LIBPREFIX'] = 'lib'
+ env['LIBSUFFIX'] = '.a'
+ env['SHLIBPREFIX'] = '$LIBPREFIX'
+ env['SHLIBSUFFIX'] = '.so'
+ env['LIBPREFIXES'] = [ '$LIBPREFIX' ]
+ env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
+ env['PSPAWN'] = pspawn
+ env['SPAWN'] = spawn
+ env['SHELL'] = 'sh'
+ env['ESCAPE'] = escape
+ env['TEMPFILE'] = TempFileMunge
+ env['TEMPFILEPREFIX'] = '@'
+ #Based on LINUX: ARG_MAX=ARG_MAX=131072 - 3000 for environment expansion
+ #Note: specific platforms might rise or lower this value
+ env['MAXLINELENGTH'] = 128072
+
+ # This platform supports RPATH specifications.
+ env['__RPATH'] = '$_RPATH'
+
+ # GDC is GCC family, but DMD and LDC have different options.
+ # Must be able to have GCC and DMD work in the same build, so:
+ env['__DRPATH'] = '$_DRPATH'
+
+ if enable_virtualenv and not ignore_virtualenv:
+ ImportVirtualenv(env)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/posix.xml b/SCons/Platform/posix.xml
new file mode 100644
index 0000000..4b2e0cd
--- /dev/null
+++ b/SCons/Platform/posix.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0"?>
+<!--
+__COPYRIGHT__
+
+This file is processed by the bin/SConsDoc.py module.
+See its __doc__ string for a discussion of the format.
+-->
+
+<!DOCTYPE sconsdoc [
+<!ENTITY % scons SYSTEM '../../../../doc/scons.mod'>
+%scons;
+<!ENTITY % builders-mod SYSTEM '../../../../doc/generated/builders.mod'>
+%builders-mod;
+<!ENTITY % functions-mod SYSTEM '../../../../doc/generated/functions.mod'>
+%functions-mod;
+<!ENTITY % tools-mod SYSTEM '../../../../doc/generated/tools.mod'>
+%tools-mod;
+<!ENTITY % variables-mod SYSTEM '../../../../doc/generated/variables.mod'>
+%variables-mod;
+]>
+
+<sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
+
+<cvar name="RPATH">
+<summary>
+<para>
+A list of paths to search for shared libraries when running programs.
+Currently only used in the GNU (gnulink),
+IRIX (sgilink) and Sun (sunlink) linkers.
+Ignored on platforms and toolchains that don't support it.
+Note that the paths added to RPATH
+are not transformed by
+&scons;
+in any way: if you want an absolute
+path, you must make it absolute yourself.
+</para>
+</summary>
+</cvar>
+
+<cvar name="_RPATH">
+<summary>
+<para>
+An automatically-generated construction variable
+containing the rpath flags to be used when linking
+a program with shared libraries.
+The value of &cv-_RPATH; is created
+by respectively prepending &cv-RPATHPREFIX; and appending &cv-RPATHSUFFIX;
+to the beginning and end
+of each directory in &cv-RPATH;.
+</para>
+</summary>
+</cvar>
+
+<cvar name="RPATHPREFIX">
+<summary>
+<para>
+The prefix used to specify a directory to be searched for
+shared libraries when running programs.
+This will be prepended to the beginning of each directory
+in the &cv-RPATH; construction variable
+when the &cv-_RPATH; variable is automatically generated.
+</para>
+</summary>
+</cvar>
+
+<cvar name="RPATHSUFFIX">
+<summary>
+<para>
+The suffix used to specify a directory to be searched for
+shared libraries when running programs.
+This will be appended to the end of each directory
+in the &cv-RPATH; construction variable
+when the &cv-_RPATH; variable is automatically generated.
+</para>
+</summary>
+</cvar>
+
+</sconsdoc>
diff --git a/SCons/Platform/sunos.py b/SCons/Platform/sunos.py
new file mode 100644
index 0000000..057fddf
--- /dev/null
+++ b/SCons/Platform/sunos.py
@@ -0,0 +1,50 @@
+"""engine.SCons.Platform.sunos
+
+Platform-specific initialization for Sun 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__
+#
+# 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__"
+
+from . import posix
+
+def generate(env):
+ posix.generate(env)
+ # Based on sunSparc 8:32bit
+ # ARG_MAX=1048320 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 1045320
+ env['PKGINFO'] = 'pkginfo'
+ env['PKGCHK'] = '/usr/sbin/pkgchk'
+ env['ENV']['PATH'] = env['ENV']['PATH'] + ':/opt/SUNWspro/bin:/usr/ccs/bin'
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/sunos.xml b/SCons/Platform/sunos.xml
new file mode 100644
index 0000000..6f912e3
--- /dev/null
+++ b/SCons/Platform/sunos.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+<!--
+__COPYRIGHT__
+
+This file is processed by the bin/SConsDoc.py module.
+See its __doc__ string for a discussion of the format.
+-->
+
+<!DOCTYPE sconsdoc [
+<!ENTITY % scons SYSTEM '../../../../doc/scons.mod'>
+%scons;
+<!ENTITY % builders-mod SYSTEM '../../../../doc/generated/builders.mod'>
+%builders-mod;
+<!ENTITY % functions-mod SYSTEM '../../../../doc/generated/functions.mod'>
+%functions-mod;
+<!ENTITY % tools-mod SYSTEM '../../../../doc/generated/tools.mod'>
+%tools-mod;
+<!ENTITY % variables-mod SYSTEM '../../../../doc/generated/variables.mod'>
+%variables-mod;
+]>
+
+<sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
+
+
+<cvar name="PKGCHK">
+<summary>
+<para>
+On Solaris systems,
+the package-checking program that will
+be used (along with &cv-PKGINFO;)
+to look for installed versions of
+the Sun PRO C++ compiler.
+The default is
+<filename>/usr/sbin/pgkchk</filename>.
+</para>
+</summary>
+</cvar>
+
+<cvar name="PKGINFO">
+<summary>
+<para>
+On Solaris systems,
+the package information program that will
+be used (along with &cv-PKGCHK;)
+to look for installed versions of
+the Sun PRO C++ compiler.
+The default is
+<filename>pkginfo</filename>.
+</para>
+</summary>
+</cvar>
+
+</sconsdoc>
diff --git a/SCons/Platform/virtualenv.py b/SCons/Platform/virtualenv.py
new file mode 100644
index 0000000..4708cb2
--- /dev/null
+++ b/SCons/Platform/virtualenv.py
@@ -0,0 +1,120 @@
+"""SCons.Platform.virtualenv
+
+Support for virtualenv.
+"""
+
+#
+# __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__"
+
+import os
+import sys
+import SCons.Util
+
+
+virtualenv_enabled_by_default = False
+
+
+def _enable_virtualenv_default():
+ return SCons.Util.get_os_env_bool('SCONS_ENABLE_VIRTUALENV', virtualenv_enabled_by_default)
+
+
+def _ignore_virtualenv_default():
+ return SCons.Util.get_os_env_bool('SCONS_IGNORE_VIRTUALENV', False)
+
+
+enable_virtualenv = _enable_virtualenv_default()
+ignore_virtualenv = _ignore_virtualenv_default()
+virtualenv_variables = ['VIRTUAL_ENV', 'PIPENV_ACTIVE']
+
+
+def _running_in_virtualenv():
+ """Returns True, if scons is executed within a virtualenv"""
+ # see https://stackoverflow.com/a/42580137
+ return (hasattr(sys, 'real_prefix') or
+ (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
+
+
+def _is_path_in(path, base):
+ """Returns true, if **path** is located under the **base** directory."""
+ if not path or not base: # empty path may happen, base too
+ return False
+ rp = os.path.relpath(path, base)
+ return (not rp.startswith(os.path.pardir)) and (not rp == os.path.curdir)
+
+
+def _inject_venv_variables(env):
+ if 'ENV' not in env:
+ env['ENV'] = {}
+ ENV = env['ENV']
+ for name in virtualenv_variables:
+ try:
+ ENV[name] = os.environ[name]
+ except KeyError:
+ pass
+
+def _inject_venv_path(env, path_list=None):
+ """Modify environment such that SCons will take into account its virtualenv
+ when running external tools."""
+ if path_list is None:
+ path_list = os.getenv('PATH')
+ env.PrependENVPath('PATH', select_paths_in_venv(path_list))
+
+
+def select_paths_in_venv(path_list):
+ """Returns a list of paths from **path_list** which are under virtualenv's
+ home directory."""
+ if SCons.Util.is_String(path_list):
+ path_list = path_list.split(os.path.pathsep)
+ # Find in path_list the paths under the virtualenv's home
+ return [path for path in path_list if IsInVirtualenv(path)]
+
+
+def ImportVirtualenv(env):
+ """Copies virtualenv-related environment variables from OS environment
+ to ``env['ENV']`` and prepends virtualenv's PATH to ``env['ENV']['PATH']``.
+ """
+ _inject_venv_variables(env)
+ _inject_venv_path(env)
+
+
+def Virtualenv():
+ """Returns path to the virtualenv home if scons is executing within a
+ virtualenv or None, if not."""
+ if _running_in_virtualenv():
+ return sys.prefix
+ return None
+
+
+def IsInVirtualenv(path):
+ """Returns True, if **path** is under virtualenv's home directory. If not,
+ or if we don't use virtualenv, returns False."""
+ return _is_path_in(path, Virtualenv())
+
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/virtualenvTests.py b/SCons/Platform/virtualenvTests.py
new file mode 100644
index 0000000..02b37ab
--- /dev/null
+++ b/SCons/Platform/virtualenvTests.py
@@ -0,0 +1,243 @@
+#
+# __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__"
+
+import SCons.compat
+
+import collections
+import unittest
+import os
+import sys
+
+import SCons.Platform.virtualenv
+import SCons.Util
+
+class Environment(collections.UserDict):
+ def Detect(self, cmd):
+ return cmd
+
+ def AppendENVPath(self, key, value):
+ if SCons.Util.is_List(value):
+ value = os.path.pathsep.join(value)
+ if 'ENV' not in self:
+ self['ENV'] = {}
+ current = self['ENV'].get(key)
+ if not current:
+ self['ENV'][key] = value
+ else:
+ self['ENV'][key] = os.path.pathsep.join([current, value])
+
+ def PrependENVPath(self, key, value):
+ if SCons.Util.is_List(value):
+ value = os.path.pathsep.join(value)
+ if 'ENV' not in self:
+ self['ENV'] = {}
+ current = self['ENV'].get(key)
+ if not current:
+ self['ENV'][key] = value
+ else:
+ self['ENV'][key] = os.path.pathsep.join([value, current])
+
+class SysPrefixes(object):
+ """Used to temporarily mock sys.prefix, sys.real_prefix and sys.base_prefix"""
+ def __init__(self, prefix, real_prefix=None, base_prefix=None):
+ self._prefix = prefix
+ self._real_prefix = real_prefix
+ self._base_prefix = base_prefix
+
+ def start(self):
+ self._store()
+ sys.prefix = self._prefix
+ if self._real_prefix is None:
+ if hasattr(sys, 'real_prefix'):
+ del sys.real_prefix
+ else:
+ sys.real_prefix = self._real_prefix
+ if self._base_prefix is None:
+ if hasattr(sys, 'base_prefix'):
+ del sys.base_prefix
+ else:
+ sys.base_prefix = self._base_prefix
+
+ def stop(self):
+ self._restore()
+
+ def __enter__(self):
+ self.start()
+ attrs = ('prefix', 'real_prefix', 'base_prefix')
+ return {k: getattr(sys, k) for k in attrs if hasattr(sys, k)}
+
+ def __exit__(self, *args):
+ self.stop()
+
+ def _store(self):
+ s = dict()
+ if hasattr(sys, 'real_prefix'):
+ s['real_prefix'] = sys.real_prefix
+ if hasattr(sys, 'base_prefix'):
+ s['base_prefix'] = sys.base_prefix
+ s['prefix'] = sys.prefix
+ self._stored = s
+
+ def _restore(self):
+ s = self._stored
+ if 'real_prefix' in s:
+ sys.real_prefix = s['real_prefix']
+ if 'base_prefix' in s:
+ sys.base_prefix = s['base_prefix']
+ if 'prefix' in s:
+ sys.prefix = s['prefix']
+ del self._stored
+
+def _p(p):
+ """Converts path string **p** from posix format to os-specific format."""
+ drive = []
+ if p.startswith('/') and sys.platform == 'win32':
+ drive = ['C:']
+ pieces = p.split('/')
+ return os.path.sep.join(drive + pieces)
+
+
+class _is_path_in_TestCase(unittest.TestCase):
+ def test_false(self):
+ for args in [ ('',''),
+ ('', _p('/foo/bar')),
+ (_p('/foo/bar'), ''),
+ (_p('/foo/bar'), _p('/foo/bar')),
+ (_p('/foo/bar'), _p('/foo/bar/geez')),
+ (_p('/'), _p('/foo')),
+ (_p('foo'), _p('foo/bar')) ]:
+ assert SCons.Platform.virtualenv._is_path_in(*args) is False, "_is_path_in(%r, %r) should be False" % args
+
+ def test__true(self):
+ for args in [ (_p('/foo'), _p('/')),
+ (_p('/foo/bar'), _p('/foo')),
+ (_p('/foo/bar/geez'), _p('/foo/bar')),
+ (_p('/foo//bar//geez'), _p('/foo/bar')),
+ (_p('/foo/bar/geez'), _p('/foo//bar')),
+ (_p('/foo/bar/geez'), _p('//foo//bar')) ]:
+ assert SCons.Platform.virtualenv._is_path_in(*args) is True, "_is_path_in(%r, %r) should be True" % args
+
+class IsInVirtualenvTestCase(unittest.TestCase):
+ def test_false(self):
+ # "without wirtualenv" - always false
+ with SysPrefixes(_p('/prefix')):
+ for p in [ _p(''),
+ _p('/foo'),
+ _p('/prefix'),
+ _p('/prefix/foo') ]:
+ assert SCons.Platform.virtualenv.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p
+
+ # "with virtualenv"
+ with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')):
+ for p in [ _p(''),
+ _p('/real/prefix/foo'),
+ _p('/virtualenv/prefix'),
+ _p('/virtualenv/prefix/bar/..'),
+ _p('/virtualenv/prefix/bar/../../bleah'),
+ _p('/virtualenv/bleah') ]:
+ assert SCons.Platform.virtualenv.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p
+
+ # "with venv"
+ with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')):
+ for p in [ _p(''),
+ _p('/base/prefix/foo'),
+ _p('/virtualenv/prefix'),
+ _p('/virtualenv/prefix/bar/..'),
+ _p('/virtualenv/prefix/bar/../../bleah'),
+ _p('/virtualenv/bleah') ]:
+ assert SCons.Platform.virtualenv.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p
+
+ def test_true(self):
+ # "with virtualenv"
+ with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')):
+ for p in [ _p('/virtualenv/prefix/foo'),
+ _p('/virtualenv/prefix/foo/bar') ]:
+ assert SCons.Platform.virtualenv.IsInVirtualenv(p) is True, "IsInVirtualenv(%r) should be True" % p
+
+ # "with venv"
+ with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')):
+ for p in [ _p('/virtualenv/prefix/foo'),
+ _p('/virtualenv/prefix/foo/bar') ]:
+ assert SCons.Platform.virtualenv.IsInVirtualenv(p) is True, "IsInVirtualenv(%r) should be True" % p
+
+class _inject_venv_pathTestCase(unittest.TestCase):
+ def path_list(self):
+ return [
+ _p('/virtualenv/prefix/bin'),
+ _p('/virtualenv/prefix'),
+ _p('/virtualenv/prefix/../bar'),
+ _p('/home/user/.local/bin'),
+ _p('/usr/bin'),
+ _p('/opt/bin')
+ ]
+ def test_with_path_string(self):
+ env = Environment()
+ path_string = os.path.pathsep.join(self.path_list())
+ with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')):
+ SCons.Platform.virtualenv._inject_venv_path(env, path_string)
+ assert env['ENV']['PATH'] == _p('/virtualenv/prefix/bin'), env['ENV']['PATH']
+
+ def test_with_path_list(self):
+ env = Environment()
+ with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')):
+ SCons.Platform.virtualenv._inject_venv_path(env, self.path_list())
+ assert env['ENV']['PATH'] == _p('/virtualenv/prefix/bin'), env['ENV']['PATH']
+
+class VirtualenvTestCase(unittest.TestCase):
+ def test_none(self):
+ def _msg(given):
+ return "Virtualenv() should be None, not %s" % repr(given)
+
+ with SysPrefixes(_p('/prefix')):
+ ve = SCons.Platform.virtualenv.Virtualenv()
+ assert ve is None , _msg(ve)
+ with SysPrefixes(_p('/base/prefix'), base_prefix=_p('/base/prefix')):
+ ve = SCons.Platform.virtualenv.Virtualenv()
+ assert ve is None, _msg(ve)
+
+ def test_not_none(self):
+ def _msg(expected, given):
+ return "Virtualenv() should == %r, not %s" % (_p(expected), repr(given))
+
+ with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')):
+ ve = SCons.Platform.virtualenv.Virtualenv()
+ assert ve == _p('/virtualenv/prefix'), _msg('/virtualenv/prefix', ve)
+ with SysPrefixes(_p('/same/prefix'), real_prefix=_p('/same/prefix')):
+ ve = SCons.Platform.virtualenv.Virtualenv()
+ assert ve == _p('/same/prefix'), _msg('/same/prefix', ve)
+ with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')):
+ ve = SCons.Platform.virtualenv.Virtualenv()
+ assert ve == _p('/virtualenv/prefix'), _msg('/virtualenv/prefix', ve)
+
+
+if __name__ == "__main__":
+ unittest.main()
+
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/win32.py b/SCons/Platform/win32.py
new file mode 100644
index 0000000..afe2df9
--- /dev/null
+++ b/SCons/Platform/win32.py
@@ -0,0 +1,449 @@
+"""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__
+#
+# 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 os
+import os.path
+import sys
+import tempfile
+
+from SCons.Platform.posix import exitvalmap
+from SCons.Platform import TempFileMunge
+from SCons.Platform.virtualenv import ImportVirtualenv
+from SCons.Platform.virtualenv import ignore_virtualenv, enable_virtualenv
+import SCons.Util
+
+CHOCO_DEFAULT_PATH = [
+ r'C:\ProgramData\chocolatey\bin'
+]
+
+try:
+ import msvcrt
+ import win32api
+ import win32con
+except ImportError:
+ parallel_msg = \
+ "you do not seem to have the pywin32 extensions installed;\n" + \
+ "\tparallel (-j) builds may not work reliably with open Python files."
+except AttributeError:
+ parallel_msg = \
+ "your pywin32 extensions do not support file handle operations;\n" + \
+ "\tparallel (-j) builds may not work reliably with open Python files."
+else:
+ parallel_msg = None
+
+
+if False:
+ # Now swap out shutil.filecopy and filecopy2 for win32 api native CopyFile
+ try:
+ from ctypes import windll
+ import shutil
+
+ CopyFile = windll.kernel32.CopyFileA
+ SetFileTime = windll.kernel32.SetFileTime
+
+ _shutil_copy = shutil.copy
+ _shutil_copy2 = shutil.copy2
+
+ shutil.copy2 = CopyFile
+
+ def win_api_copyfile(src,dst):
+ CopyFile(src,dst)
+ os.utime(dst)
+
+ shutil.copy = win_api_copyfile
+
+ except AttributeError:
+ parallel_msg = \
+ "Couldn't override shutil.copy or shutil.copy2 falling back to shutil defaults"
+
+
+
+
+
+
+
+try:
+ import threading
+ spawn_lock = threading.Lock()
+
+ # This locked version of spawnve works around a Windows
+ # MSVCRT bug, because its spawnve is not thread-safe.
+ # Without this, python can randomly crash while using -jN.
+ # See the python bug at http://bugs.python.org/issue6476
+ # and SCons issue at
+ # https://github.com/SCons/scons/issues/2449
+ def spawnve(mode, file, args, env):
+ spawn_lock.acquire()
+ try:
+ if mode == os.P_WAIT:
+ ret = os.spawnve(os.P_NOWAIT, file, args, env)
+ else:
+ ret = os.spawnve(mode, file, args, env)
+ finally:
+ spawn_lock.release()
+ if mode == os.P_WAIT:
+ pid, status = os.waitpid(ret, 0)
+ ret = status >> 8
+ return ret
+except ImportError:
+ # Use the unsafe method of spawnve.
+ # Please, don't try to optimize this try-except block
+ # away by assuming that the threading module is always present.
+ # In the test test/option-j.py we intentionally call SCons with
+ # a fake threading.py that raises an import exception right away,
+ # simulating a non-existent package.
+ def spawnve(mode, file, args, env):
+ return os.spawnve(mode, file, args, env)
+
+# The upshot of all this is that, if you are using Python 1.5.2,
+# you had better have cmd or command.com in your PATH when you run
+# scons.
+
+
+def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
+ # There is no direct way to do that in python. What we do
+ # here should work for most cases:
+ # In case stdout (stderr) is not redirected to a file,
+ # we redirect it into a temporary file tmpFileStdout
+ # (tmpFileStderr) and copy the contents of this file
+ # to stdout (stderr) given in the argument
+ # Note that because this will paste shell redirection syntax
+ # into the cmdline, we have to call a shell to run the command,
+ # even though that's a bit of a performance hit.
+ if not sh:
+ sys.stderr.write("scons: Could not find command interpreter, is it in your PATH?\n")
+ return 127
+
+ # one temporary file for stdout and stderr
+ tmpFileStdout, tmpFileStdoutName = tempfile.mkstemp(text=True)
+ os.close(tmpFileStdout) # don't need open until the subproc is done
+ tmpFileStderr, tmpFileStderrName = tempfile.mkstemp(text=True)
+ os.close(tmpFileStderr)
+
+ # check if output is redirected
+ stdoutRedirected = False
+ stderrRedirected = False
+ for arg in args:
+ # are there more possibilities to redirect stdout ?
+ if arg.find(">", 0, 1) != -1 or arg.find("1>", 0, 2) != -1:
+ stdoutRedirected = True
+ # are there more possibilities to redirect stderr ?
+ if arg.find("2>", 0, 2) != -1:
+ stderrRedirected = True
+
+ # redirect output of non-redirected streams to our tempfiles
+ if not stdoutRedirected:
+ args.append(">" + tmpFileStdoutName)
+ if not stderrRedirected:
+ args.append("2>" + tmpFileStderrName)
+
+ # actually do the spawn
+ try:
+ args = [sh, '/C', escape(' '.join(args))]
+ ret = spawnve(os.P_WAIT, sh, args, env)
+ except OSError as e:
+ # catch any error
+ try:
+ ret = exitvalmap[e.errno]
+ except KeyError:
+ sys.stderr.write("scons: unknown OSError exception code %d - %s: %s\n" % (e.errno, cmd, e.strerror))
+ if stderr is not None:
+ stderr.write("scons: %s: %s\n" % (cmd, e.strerror))
+
+ # copy child output from tempfiles to our streams
+ # and do clean up stuff
+ if stdout is not None and not stdoutRedirected:
+ try:
+ with open(tmpFileStdoutName, "r") as tmpFileStdout:
+ stdout.write(tmpFileStdout.read())
+ os.remove(tmpFileStdoutName)
+ except (IOError, OSError):
+ pass
+
+ if stderr is not None and not stderrRedirected:
+ try:
+ with open(tmpFileStderrName, "r") as tmpFileStderr:
+ stderr.write(tmpFileStderr.read())
+ os.remove(tmpFileStderrName)
+ except (IOError, OSError):
+ pass
+
+ return ret
+
+
+def exec_spawn(l, env):
+ try:
+ result = spawnve(os.P_WAIT, l[0], l, env)
+ except (OSError, EnvironmentError) as e:
+ try:
+ result = exitvalmap[e.errno]
+ sys.stderr.write("scons: %s: %s\n" % (l[0], e.strerror))
+ except KeyError:
+ result = 127
+ if len(l) > 2:
+ if len(l[2]) < 1000:
+ command = ' '.join(l[0:3])
+ else:
+ command = l[0]
+ else:
+ command = l[0]
+ sys.stderr.write("scons: unknown OSError exception code %d - '%s': %s\n" % (e.errno, command, e.strerror))
+ return result
+
+
+def spawn(sh, escape, cmd, args, env):
+ if not sh:
+ sys.stderr.write("scons: Could not find command interpreter, is it in your PATH?\n")
+ return 127
+ return exec_spawn([sh, '/C', escape(' '.join(args))], env)
+
+# Windows does not allow special characters in file names anyway, so no
+# need for a complex escape function, we will just quote the arg, except
+# that "cmd /c" requires that if an argument ends with a backslash it
+# needs to be escaped so as not to interfere with closing double quote
+# that we add.
+def escape(x):
+ if x[-1] == '\\':
+ x = x + '\\'
+ return '"' + x + '"'
+
+# Get the windows system directory name
+_system_root = None
+
+
+def get_system_root():
+ global _system_root
+ if _system_root is not None:
+ return _system_root
+
+ # A resonable default if we can't read the registry
+ val = os.environ.get('SystemRoot', "C:\\WINDOWS")
+
+ if SCons.Util.can_read_reg:
+ try:
+ # Look for Windows NT system root
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows NT\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+ except SCons.Util.RegError:
+ try:
+ # Okay, try the Windows 9x system root
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+ except KeyboardInterrupt:
+ raise
+ except:
+ pass
+
+ _system_root = val
+ return val
+
+
+def get_program_files_dir():
+ """
+ Get the location of the program files directory
+ Returns
+ -------
+
+ """
+ # Now see if we can look in the registry...
+ val = ''
+ if SCons.Util.can_read_reg:
+ try:
+ # Look for Windows Program Files directory
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'ProgramFilesDir')
+ except SCons.Util.RegError:
+ val = ''
+ pass
+
+ if val == '':
+ # A reasonable default if we can't read the registry
+ # (Actually, it's pretty reasonable even if we can :-)
+ val = os.path.join(os.path.dirname(get_system_root()),"Program Files")
+
+ return val
+
+
+class ArchDefinition(object):
+ """
+ Determine which windows CPU were running on.
+ A class for defining architecture-specific settings and logic.
+ """
+ def __init__(self, arch, synonyms=[]):
+ self.arch = arch
+ self.synonyms = synonyms
+
+SupportedArchitectureList = [
+ ArchDefinition(
+ 'x86',
+ ['i386', 'i486', 'i586', 'i686'],
+ ),
+
+ ArchDefinition(
+ 'x86_64',
+ ['AMD64', 'amd64', 'em64t', 'EM64T', 'x86_64'],
+ ),
+
+ ArchDefinition(
+ 'ia64',
+ ['IA64'],
+ ),
+]
+
+SupportedArchitectureMap = {}
+for a in SupportedArchitectureList:
+ SupportedArchitectureMap[a.arch] = a
+ for s in a.synonyms:
+ SupportedArchitectureMap[s] = a
+
+
+def get_architecture(arch=None):
+ """Returns the definition for the specified architecture string.
+
+ If no string is specified, the system default is returned (as defined
+ by the PROCESSOR_ARCHITEW6432 or PROCESSOR_ARCHITECTURE environment
+ variables).
+ """
+ if arch is None:
+ arch = os.environ.get('PROCESSOR_ARCHITEW6432')
+ if not arch:
+ arch = os.environ.get('PROCESSOR_ARCHITECTURE')
+ return SupportedArchitectureMap.get(arch, ArchDefinition('', ['']))
+
+
+def generate(env):
+ # Attempt to find cmd.exe (for WinNT/2k/XP) or
+ # command.com for Win9x
+ cmd_interp = ''
+ # First see if we can look in the registry...
+ if SCons.Util.can_read_reg:
+ try:
+ # Look for Windows NT system root
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows NT\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+ cmd_interp = os.path.join(val, 'System32\\cmd.exe')
+ except SCons.Util.RegError:
+ try:
+ # Okay, try the Windows 9x system root
+ k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+ 'Software\\Microsoft\\Windows\\CurrentVersion')
+ val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+ cmd_interp = os.path.join(val, 'command.com')
+ except KeyboardInterrupt:
+ raise
+ except:
+ pass
+
+ # For the special case of not having access to the registry, we
+ # use a temporary path and pathext to attempt to find the command
+ # interpreter. If we fail, we try to find the interpreter through
+ # the env's PATH. The problem with that is that it might not
+ # contain an ENV and a PATH.
+ if not cmd_interp:
+ systemroot = get_system_root()
+ tmp_path = systemroot + os.pathsep + \
+ os.path.join(systemroot,'System32')
+ tmp_pathext = '.com;.exe;.bat;.cmd'
+ if 'PATHEXT' in os.environ:
+ tmp_pathext = os.environ['PATHEXT']
+ cmd_interp = SCons.Util.WhereIs('cmd', tmp_path, tmp_pathext)
+ if not cmd_interp:
+ cmd_interp = SCons.Util.WhereIs('command', tmp_path, tmp_pathext)
+
+ if not cmd_interp:
+ cmd_interp = env.Detect('cmd')
+ if not cmd_interp:
+ cmd_interp = env.Detect('command')
+
+ if 'ENV' not in env:
+ env['ENV'] = {}
+
+ # Import things from the external environment to the construction
+ # environment's ENV. This is a potential slippery slope, because we
+ # *don't* want to make builds dependent on the user's environment by
+ # default. We're doing this for SystemRoot, though, because it's
+ # needed for anything that uses sockets, and seldom changes, and
+ # for SystemDrive because it's related.
+ #
+ # Weigh the impact carefully before adding other variables to this list.
+ import_env = ['SystemDrive', 'SystemRoot', 'TEMP', 'TMP' ]
+ for var in import_env:
+ v = os.environ.get(var)
+ if v:
+ env['ENV'][var] = v
+
+ if 'COMSPEC' not in env['ENV']:
+ v = os.environ.get("COMSPEC")
+ if v:
+ env['ENV']['COMSPEC'] = v
+
+ env.AppendENVPath('PATH', get_system_root() + '\\System32')
+
+ env['ENV']['PATHEXT'] = '.COM;.EXE;.BAT;.CMD'
+ env['OBJPREFIX'] = ''
+ env['OBJSUFFIX'] = '.obj'
+ env['SHOBJPREFIX'] = '$OBJPREFIX'
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = '.exe'
+ env['LIBPREFIX'] = ''
+ env['LIBSUFFIX'] = '.lib'
+ env['SHLIBPREFIX'] = ''
+ env['SHLIBSUFFIX'] = '.dll'
+ env['LIBPREFIXES'] = [ '$LIBPREFIX' ]
+ env['LIBSUFFIXES'] = [ '$LIBSUFFIX' ]
+ env['PSPAWN'] = piped_spawn
+ env['SPAWN'] = spawn
+ env['SHELL'] = cmd_interp
+ env['TEMPFILE'] = TempFileMunge
+ env['TEMPFILEPREFIX'] = '@'
+ env['MAXLINELENGTH'] = 2048
+ env['ESCAPE'] = escape
+
+ env['HOST_OS'] = 'win32'
+ env['HOST_ARCH'] = get_architecture().arch
+
+ if enable_virtualenv and not ignore_virtualenv:
+ ImportVirtualenv(env)
+
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/SCons/Platform/win32.xml b/SCons/Platform/win32.xml
new file mode 100644
index 0000000..6face5f
--- /dev/null
+++ b/SCons/Platform/win32.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<!--
+__COPYRIGHT__
+
+This file is processed by the bin/SConsDoc.py module.
+See its __doc__ string for a discussion of the format.
+-->
+
+<!DOCTYPE sconsdoc [
+<!ENTITY % scons SYSTEM '../../../../doc/scons.mod'>
+%scons;
+<!ENTITY % builders-mod SYSTEM '../../../../doc/generated/builders.mod'>
+%builders-mod;
+<!ENTITY % functions-mod SYSTEM '../../../../doc/generated/functions.mod'>
+%functions-mod;
+<!ENTITY % tools-mod SYSTEM '../../../../doc/generated/tools.mod'>
+%tools-mod;
+<!ENTITY % variables-mod SYSTEM '../../../../doc/generated/variables.mod'>
+%variables-mod;
+]>
+
+<sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
+
+<cvar name="MAXLINELENGTH">
+<summary>
+<para>
+The maximum number of characters allowed on an external command line.
+On Win32 systems,
+link lines longer than this many characters
+are linked via a temporary file name.
+</para>
+</summary>
+</cvar>
+
+</sconsdoc>