Home | Trees | Indices | Help |
|
---|
|
1 """SCons.Platform 2 3 SCons platform selection. 4 5 This looks for modules that define a callable object that can modify a 6 construction environment as appropriate for a given platform. 7 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. 14 15 Note that because this subsystem 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. 20 """ 21 22 # 23 # Copyright (c) 2001 - 2018 The SCons Foundation 24 # 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: 32 # 33 # The above copyright notice and this permission notice shall be included 34 # in all copies or substantial portions of the Software. 35 # 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. 43 # 44 from __future__ import print_function 45 46 __revision__ = "src/engine/SCons/Platform/__init__.py 425375072d7b582a2df0db815c8eaeaa489468ab 2019-01-01 18:32:02 bdbaddog" 47 48 import SCons.compat 49 50 import imp 51 import os 52 import sys 53 import tempfile 54 55 import SCons.Errors 56 import SCons.Subst 57 import SCons.Tool 58 5961 """Return the platform string for our execution environment. 62 63 The returned value should map to one of the SCons/Platform/*.py 64 files. Since we're architecture independent, though, we don't 65 care about the machine architecture. 66 """ 67 osname = os.name 68 if osname == 'java': 69 osname = os._osType 70 if osname == 'posix': 71 if sys.platform == 'cygwin': 72 return 'cygwin' 73 elif sys.platform.find('irix') != -1: 74 return 'irix' 75 elif sys.platform.find('sunos') != -1: 76 return 'sunos' 77 elif sys.platform.find('hp-ux') != -1: 78 return 'hpux' 79 elif sys.platform.find('aix') != -1: 80 return 'aix' 81 elif sys.platform.find('darwin') != -1: 82 return 'darwin' 83 else: 84 return 'posix' 85 elif os.name == 'os2': 86 return 'os2' 87 else: 88 return sys.platform89 9092 """Return the imported module for the platform. 93 94 This looks for a module name that matches the specified argument. 95 If the name is unspecified, we fetch the appropriate default for 96 our execution environment. 97 """ 98 full_name = 'SCons.Platform.' + name 99 if full_name not in sys.modules: 100 if os.name == 'java': 101 eval(full_name) 102 else: 103 try: 104 file, path, desc = imp.find_module(name, 105 sys.modules['SCons.Platform'].__path__) 106 try: 107 mod = imp.load_module(full_name, file, path, desc) 108 finally: 109 if file: 110 file.close() 111 except ImportError: 112 try: 113 import zipimport 114 importer = zipimport.zipimporter( sys.modules['SCons.Platform'].__path__[0] ) 115 mod = importer.load_module(full_name) 116 except ImportError: 117 raise SCons.Errors.UserError("No platform named '%s'" % name) 118 setattr(SCons.Platform, name, mod) 119 return sys.modules[full_name]120 121123 """Select a default tool list for the specified platform. 124 """ 125 return SCons.Tool.tool_list(platform, env)126 127 138 139141 """A callable class. You can set an Environment variable to this, 142 then call it with a string argument, then it will perform temporary 143 file substitution on it. This is used to circumvent the long command 144 line limitation. 145 146 Example usage: 147 env["TEMPFILE"] = TempFileMunge 148 env["LINKCOM"] = "${TEMPFILE('$LINK $TARGET $SOURCES','$LINKCOMSTR')}" 149 150 By default, the name of the temporary file used begins with a 151 prefix of '@'. This may be configred for other tool chains by 152 setting '$TEMPFILEPREFIX'. 153 154 env["TEMPFILEPREFIX"] = '-@' # diab compiler 155 env["TEMPFILEPREFIX"] = '-via' # arm tool chain 156 """ 160258 259162 if for_signature: 163 # If we're being called for signature calculation, it's 164 # because we're being called by the string expansion in 165 # Subst.py, which has the logic to strip any $( $) that 166 # may be in the command line we squirreled away. So we 167 # just return the raw command line and let the upper 168 # string substitution layers do their thing. 169 return self.cmd 170 171 # Now we're actually being called because someone is actually 172 # going to try to execute the command, so we have to do our 173 # own expansion. 174 cmd = env.subst_list(self.cmd, SCons.Subst.SUBST_CMD, target, source)[0] 175 try: 176 maxline = int(env.subst('$MAXLINELENGTH')) 177 except ValueError: 178 maxline = 2048 179 180 length = 0 181 for c in cmd: 182 length += len(c) 183 length += len(cmd) - 1 184 if length <= maxline: 185 return self.cmd 186 187 # Check if we already created the temporary file for this target 188 # It should have been previously done by Action.strfunction() call 189 node = target[0] if SCons.Util.is_List(target) else target 190 cmdlist = getattr(node.attributes, 'tempfile_cmdlist', None) \ 191 if node is not None else None 192 if cmdlist is not None : 193 return cmdlist 194 195 # We do a normpath because mktemp() has what appears to be 196 # a bug in Windows that will use a forward slash as a path 197 # delimiter. Windows's link mistakes that for a command line 198 # switch and barfs. 199 # 200 # We use the .lnk suffix for the benefit of the Phar Lap 201 # linkloc linker, which likes to append an .lnk suffix if 202 # none is given. 203 (fd, tmp) = tempfile.mkstemp('.lnk', text=True) 204 native_tmp = SCons.Util.get_native_path(os.path.normpath(tmp)) 205 206 if env.get('SHELL',None) == 'sh': 207 # The sh shell will try to escape the backslashes in the 208 # path, so unescape them. 209 native_tmp = native_tmp.replace('\\', r'\\\\') 210 # In Cygwin, we want to use rm to delete the temporary 211 # file, because del does not exist in the sh shell. 212 rm = env.Detect('rm') or 'del' 213 else: 214 # Don't use 'rm' if the shell is not sh, because rm won't 215 # work with the Windows shells (cmd.exe or command.com) or 216 # Windows path names. 217 rm = 'del' 218 219 prefix = env.subst('$TEMPFILEPREFIX') 220 if not prefix: 221 prefix = '@' 222 223 args = list(map(SCons.Subst.quote_spaces, cmd[1:])) 224 os.write(fd, bytearray(" ".join(args) + "\n",'utf-8')) 225 os.close(fd) 226 # XXX Using the SCons.Action.print_actions value directly 227 # like this is bogus, but expedient. This class should 228 # really be rewritten as an Action that defines the 229 # __call__() and strfunction() methods and lets the 230 # normal action-execution logic handle whether or not to 231 # print/execute the action. The problem, though, is all 232 # of that is decided before we execute this method as 233 # part of expanding the $TEMPFILE construction variable. 234 # Consequently, refactoring this will have to wait until 235 # we get more flexible with allowing Actions to exist 236 # independently and get strung together arbitrarily like 237 # Ant tasks. In the meantime, it's going to be more 238 # user-friendly to not let obsession with architectural 239 # purity get in the way of just being helpful, so we'll 240 # reach into SCons.Action directly. 241 if SCons.Action.print_actions: 242 cmdstr = env.subst(self.cmdstr, SCons.Subst.SUBST_RAW, target, 243 source) if self.cmdstr is not None else '' 244 # Print our message only if XXXCOMSTR returns an empty string 245 if len(cmdstr) == 0 : 246 print("Using tempfile "+native_tmp+" for command line:\n"+ 247 str(cmd[0]) + " " + " ".join(args)) 248 249 # Store the temporary file command list into the target Node.attributes 250 # to avoid creating two temporary files one for print and one for execute. 251 cmdlist = [ cmd[0], prefix + native_tmp + '\n' + rm, native_tmp ] 252 if node is not None: 253 try : 254 setattr(node.attributes, 'tempfile_cmdlist', cmdlist) 255 except AttributeError: 256 pass 257 return cmdlist261 """Select a canned Platform specification. 262 """ 263 module = platform_module(name) 264 spec = PlatformSpec(name, module.generate) 265 return spec266 267 # Local Variables: 268 # tab-width:4 269 # indent-tabs-mode:nil 270 # End: 271 # vim: set expandtab tabstop=4 shiftwidth=4: 272
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Jan 1 10:36:39 2019 | http://epydoc.sourceforge.net |