You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.1 KiB

6 years ago
  1. """SCons.Platform.posix
  2. Platform-specific initialization for POSIX (Linux, UNIX, etc.) systems.
  3. There normally shouldn't be any need to import this module directly. It
  4. will usually be imported through the generic SCons.Platform.Platform()
  5. selection method.
  6. """
  7. #
  8. # Copyright (c) 2001 - 2017 The SCons Foundation
  9. #
  10. # Permission is hereby granted, free of charge, to any person obtaining
  11. # a copy of this software and associated documentation files (the
  12. # "Software"), to deal in the Software without restriction, including
  13. # without limitation the rights to use, copy, modify, merge, publish,
  14. # distribute, sublicense, and/or sell copies of the Software, and to
  15. # permit persons to whom the Software is furnished to do so, subject to
  16. # the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included
  19. # in all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  22. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  23. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. #
  29. __revision__ = "src/engine/SCons/Platform/posix.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  30. import errno
  31. import os
  32. import os.path
  33. import subprocess
  34. import sys
  35. import select
  36. import SCons.Util
  37. from SCons.Platform import TempFileMunge
  38. exitvalmap = {
  39. 2 : 127,
  40. 13 : 126,
  41. }
  42. def escape(arg):
  43. "escape shell special characters"
  44. slash = '\\'
  45. special = '"$'
  46. arg = arg.replace(slash, slash+slash)
  47. for c in special:
  48. arg = arg.replace(c, slash+c)
  49. # print("ESCAPE RESULT: %s" % arg)
  50. return '"' + arg + '"'
  51. def exec_subprocess(l, env):
  52. proc = subprocess.Popen(l, env = env, close_fds = True)
  53. return proc.wait()
  54. def subprocess_spawn(sh, escape, cmd, args, env):
  55. return exec_subprocess([sh, '-c', ' '.join(args)], env)
  56. def exec_popen3(l, env, stdout, stderr):
  57. proc = subprocess.Popen(l, env = env, close_fds = True,
  58. stdout = stdout,
  59. stderr = stderr)
  60. return proc.wait()
  61. def piped_env_spawn(sh, escape, cmd, args, env, stdout, stderr):
  62. # spawn using Popen3 combined with the env command
  63. # the command name and the command's stdout is written to stdout
  64. # the command's stderr is written to stderr
  65. return exec_popen3([sh, '-c', ' '.join(args)],
  66. env, stdout, stderr)
  67. def generate(env):
  68. # Bearing in mind we have python 2.4 as a baseline, we can just do this:
  69. spawn = subprocess_spawn
  70. pspawn = piped_env_spawn
  71. # Note that this means that 'escape' is no longer used
  72. if 'ENV' not in env:
  73. env['ENV'] = {}
  74. env['ENV']['PATH'] = '/usr/local/bin:/opt/bin:/bin:/usr/bin'
  75. env['OBJPREFIX'] = ''
  76. env['OBJSUFFIX'] = '.o'
  77. env['SHOBJPREFIX'] = '$OBJPREFIX'
  78. env['SHOBJSUFFIX'] = '$OBJSUFFIX'
  79. env['PROGPREFIX'] = ''
  80. env['PROGSUFFIX'] = ''
  81. env['LIBPREFIX'] = 'lib'
  82. env['LIBSUFFIX'] = '.a'
  83. env['SHLIBPREFIX'] = '$LIBPREFIX'
  84. env['SHLIBSUFFIX'] = '.so'
  85. env['LIBPREFIXES'] = [ '$LIBPREFIX' ]
  86. env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
  87. env['PSPAWN'] = pspawn
  88. env['SPAWN'] = spawn
  89. env['SHELL'] = 'sh'
  90. env['ESCAPE'] = escape
  91. env['TEMPFILE'] = TempFileMunge
  92. env['TEMPFILEPREFIX'] = '@'
  93. #Based on LINUX: ARG_MAX=ARG_MAX=131072 - 3000 for environment expansion
  94. #Note: specific platforms might rise or lower this value
  95. env['MAXLINELENGTH'] = 128072
  96. # This platform supports RPATH specifications.
  97. env['__RPATH'] = '$_RPATH'
  98. # GDC is GCC family, but DMD and LDC have different options.
  99. # Must be able to have GCC and DMD work in the same build, so:
  100. env['__DRPATH'] = '$_DRPATH'
  101. # Local Variables:
  102. # tab-width:4
  103. # indent-tabs-mode:nil
  104. # End:
  105. # vim: set expandtab tabstop=4 shiftwidth=4: