Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 1 | import os |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 2 | import platform |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 3 | import sys |
| 4 | import tempfile |
| 5 | from pprint import pprint |
| 6 | |
| 7 | ### |
| 8 | |
| 9 | import Arguments |
| 10 | import Jobs |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 11 | import HostInfo |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 12 | import Phases |
| 13 | import Tools |
| 14 | import Types |
| 15 | import Util |
| 16 | |
| 17 | # FIXME: Clean up naming of options and arguments. Decide whether to |
| 18 | # rename Option and be consistent about use of Option/Arg. |
| 19 | |
| 20 | #### |
| 21 | |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 22 | class Driver(object): |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 23 | def __init__(self, driverName, driverDir): |
| 24 | self.driverName = driverName |
| 25 | self.driverDir = driverDir |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 26 | self.hostInfo = None |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 27 | self.parser = Arguments.OptionParser() |
Daniel Dunbar | 7c2f91b | 2009-01-14 01:03:36 +0000 | [diff] [blame] | 28 | self.cccHostBits = self.cccHostMachine = None |
| 29 | self.cccHostSystem = self.cccHostRelease = None |
| 30 | self.cccCXX = False |
| 31 | self.cccClang = False |
Daniel Dunbar | 4c751dc | 2009-01-14 01:32:05 +0000 | [diff] [blame] | 32 | self.cccEcho = False |
Daniel Dunbar | 7c2f91b | 2009-01-14 01:03:36 +0000 | [diff] [blame] | 33 | self.cccFallback = False |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 34 | |
Daniel Dunbar | dbc9ee9 | 2009-01-09 22:21:24 +0000 | [diff] [blame] | 35 | # Host queries which can be forcibly over-riden by the user for |
| 36 | # testing purposes. |
| 37 | # |
| 38 | # FIXME: We should make sure these are drawn from a fixed set so |
| 39 | # that nothing downstream ever plays a guessing game. |
| 40 | |
| 41 | def getHostBits(self): |
| 42 | if self.cccHostBits: |
| 43 | return self.cccHostBits |
| 44 | |
| 45 | return platform.architecture()[0].replace('bit','') |
| 46 | |
| 47 | def getHostMachine(self): |
| 48 | if self.cccHostMachine: |
| 49 | return self.cccHostMachine |
| 50 | |
| 51 | machine = platform.machine() |
| 52 | # Normalize names. |
| 53 | if machine == 'Power Macintosh': |
| 54 | return 'ppc' |
| 55 | return machine |
| 56 | |
| 57 | def getHostSystemName(self): |
| 58 | if self.cccHostSystem: |
| 59 | return self.cccHostSystem |
| 60 | |
| 61 | return platform.system().lower() |
| 62 | |
Daniel Dunbar | c214856 | 2009-01-12 04:21:12 +0000 | [diff] [blame] | 63 | def getHostReleaseName(self): |
| 64 | if self.cccHostRelease: |
| 65 | return self.cccHostRelease |
| 66 | |
| 67 | return platform.release() |
| 68 | |
Daniel Dunbar | 4c751dc | 2009-01-14 01:32:05 +0000 | [diff] [blame] | 69 | def getenvBool(self, name): |
| 70 | var = os.getenv(name) |
| 71 | if not var: |
| 72 | return False |
| 73 | |
| 74 | try: |
| 75 | return bool(int(var)) |
| 76 | except: |
| 77 | return False |
| 78 | |
Daniel Dunbar | dbc9ee9 | 2009-01-09 22:21:24 +0000 | [diff] [blame] | 79 | ### |
| 80 | |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 81 | def getFilePath(self, name, toolChain=None): |
| 82 | tc = toolChain or self.toolChain |
| 83 | for p in tc.filePathPrefixes: |
| 84 | path = os.path.join(p, name) |
| 85 | if os.path.exists(path): |
| 86 | return path |
| 87 | return name |
| 88 | |
| 89 | def getProgramPath(self, name, toolChain=None): |
| 90 | tc = toolChain or self.toolChain |
| 91 | for p in tc.programPathPrefixes: |
| 92 | path = os.path.join(p, name) |
| 93 | if os.path.exists(path): |
| 94 | return path |
| 95 | return name |
| 96 | |
| 97 | ### |
| 98 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 99 | def run(self, argv): |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 100 | # FIXME: Things to support from environment: GCC_EXEC_PREFIX, |
| 101 | # COMPILER_PATH, LIBRARY_PATH, LPATH, CC_PRINT_OPTIONS, |
| 102 | # QA_OVERRIDE_GCC3_OPTIONS, ...? |
| 103 | |
| 104 | # FIXME: -V and -b processing |
| 105 | |
| 106 | # Handle some special -ccc- options used for testing which are |
| 107 | # only allowed at the beginning of the command line. |
| 108 | cccPrintOptions = False |
| 109 | cccPrintPhases = False |
Daniel Dunbar | dbc9ee9 | 2009-01-09 22:21:24 +0000 | [diff] [blame] | 110 | |
| 111 | # FIXME: How to handle override of host? ccc specific options? |
| 112 | # Abuse -b? |
Daniel Dunbar | 4c751dc | 2009-01-14 01:32:05 +0000 | [diff] [blame] | 113 | if self.getenvBool('CCC_CLANG'): |
| 114 | self.cccClang = True |
| 115 | if self.getenvBool('CCC_ECHO'): |
| 116 | self.cccEcho = True |
| 117 | if self.getenvBool('CCC_FALLBACK'): |
| 118 | self.cccFallback = True |
| 119 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 120 | while argv and argv[0].startswith('-ccc-'): |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 121 | fullOpt,argv = argv[0],argv[1:] |
| 122 | opt = fullOpt[5:] |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 123 | |
| 124 | if opt == 'print-options': |
| 125 | cccPrintOptions = True |
| 126 | elif opt == 'print-phases': |
| 127 | cccPrintPhases = True |
Daniel Dunbar | 7c2f91b | 2009-01-14 01:03:36 +0000 | [diff] [blame] | 128 | elif opt == 'cxx': |
| 129 | self.cccCXX = True |
| 130 | elif opt == 'clang': |
| 131 | self.cccClang = True |
Daniel Dunbar | 4c751dc | 2009-01-14 01:32:05 +0000 | [diff] [blame] | 132 | elif opt == 'echo': |
| 133 | self.cccEcho = True |
Daniel Dunbar | 7c2f91b | 2009-01-14 01:03:36 +0000 | [diff] [blame] | 134 | elif opt == 'fallback': |
| 135 | self.cccFallback = True |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 136 | elif opt == 'host-bits': |
Daniel Dunbar | dbc9ee9 | 2009-01-09 22:21:24 +0000 | [diff] [blame] | 137 | self.cccHostBits,argv = argv[0],argv[1:] |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 138 | elif opt == 'host-machine': |
Daniel Dunbar | dbc9ee9 | 2009-01-09 22:21:24 +0000 | [diff] [blame] | 139 | self.cccHostMachine,argv = argv[0],argv[1:] |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 140 | elif opt == 'host-system': |
Daniel Dunbar | dbc9ee9 | 2009-01-09 22:21:24 +0000 | [diff] [blame] | 141 | self.cccHostSystem,argv = argv[0],argv[1:] |
Daniel Dunbar | c214856 | 2009-01-12 04:21:12 +0000 | [diff] [blame] | 142 | elif opt == 'host-release': |
| 143 | self.cccHostRelease,argv = argv[0],argv[1:] |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 144 | else: |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 145 | raise Arguments.InvalidArgumentsError("invalid option: %r" % fullOpt) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 146 | |
Daniel Dunbar | dbc9ee9 | 2009-01-09 22:21:24 +0000 | [diff] [blame] | 147 | self.hostInfo = HostInfo.getHostInfo(self) |
Daniel Dunbar | 08dea46 | 2009-01-10 02:07:54 +0000 | [diff] [blame] | 148 | self.toolChain = self.hostInfo.getToolChain() |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 149 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 150 | args = self.parser.parseArgs(argv) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 151 | |
| 152 | # FIXME: Ho hum I have just realized -Xarch_ is broken. We really |
| 153 | # need to reparse the Arguments after they have been expanded by |
| 154 | # -Xarch. How is this going to work? |
| 155 | # |
| 156 | # Scratch that, we aren't going to do that; it really disrupts the |
| 157 | # organization, doesn't consistently work with gcc-dd, and is |
| 158 | # confusing. Instead we are going to enforce that -Xarch_ is only |
| 159 | # used with options which do not alter the driver behavior. Let's |
| 160 | # hope this is ok, because the current architecture is a little |
| 161 | # tied to it. |
| 162 | |
| 163 | if cccPrintOptions: |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 164 | self.printOptions(args) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 165 | sys.exit(0) |
| 166 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 167 | self.handleImmediateOptions(args) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 168 | |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 169 | if self.hostInfo.useDriverDriver(): |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 170 | phases = self.buildPipeline(args) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 171 | else: |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 172 | phases = self.buildNormalPipeline(args) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 173 | |
| 174 | if cccPrintPhases: |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 175 | self.printPhases(phases, args) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 176 | sys.exit(0) |
Daniel Dunbar | 4ed45ea | 2009-01-09 01:00:40 +0000 | [diff] [blame] | 177 | |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 178 | if 0: |
| 179 | print Util.pprint(phases) |
| 180 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 181 | jobs = self.bindPhases(phases, args) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 182 | |
| 183 | # FIXME: We should provide some basic sanity checking of the |
| 184 | # pipeline as a "verification" sort of stage. For example, the |
| 185 | # pipeline should never end up writing to an output file in two |
| 186 | # places (I think). The pipeline should also never end up writing |
| 187 | # to an output file that is an input. |
| 188 | # |
| 189 | # This is intended to just be a "verify" step, not a functionality |
| 190 | # step. It should catch things like the driver driver not |
| 191 | # preventing -save-temps, but it shouldn't change behavior (so we |
| 192 | # can turn it off in Release-Asserts builds). |
| 193 | |
| 194 | # Print in -### syntax. |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 195 | hasHashHashHash = args.getLastArg(self.parser.hashHashHashOption) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 196 | if hasHashHashHash: |
| 197 | self.claim(hasHashHashHash) |
| 198 | for j in jobs.iterjobs(): |
| 199 | if isinstance(j, Jobs.Command): |
Daniel Dunbar | d87b6ec | 2009-01-12 19:36:35 +0000 | [diff] [blame] | 200 | print >>sys.stderr, ' "%s"' % '" "'.join(j.getArgv()) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 201 | elif isinstance(j, Jobs.PipedJob): |
| 202 | for c in j.commands: |
Daniel Dunbar | d87b6ec | 2009-01-12 19:36:35 +0000 | [diff] [blame] | 203 | print >>sys.stderr, ' "%s" %c' % ('" "'.join(c.getArgv()), |
| 204 | "| "[c is j.commands[-1]]) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 205 | elif not isinstance(j, JobList): |
| 206 | raise ValueError,'Encountered unknown job.' |
| 207 | sys.exit(0) |
| 208 | |
| 209 | for j in jobs.iterjobs(): |
| 210 | if isinstance(j, Jobs.Command): |
Daniel Dunbar | 4c751dc | 2009-01-14 01:32:05 +0000 | [diff] [blame] | 211 | if self.cccEcho: |
Anders Carlsson | 76613bf | 2009-01-18 02:54:17 +0000 | [diff] [blame] | 212 | print >>sys.stderr, ' '.join(map(repr,j.getArgv())) |
| 213 | sys.stderr.flush() |
Daniel Dunbar | b421dba | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 214 | res = os.spawnvp(os.P_WAIT, j.executable, j.getArgv()) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 215 | if res: |
| 216 | sys.exit(res) |
| 217 | elif isinstance(j, Jobs.PipedJob): |
Daniel Dunbar | e19ed8e | 2009-01-17 02:02:35 +0000 | [diff] [blame] | 218 | import subprocess |
| 219 | procs = [] |
| 220 | for sj in j.commands: |
| 221 | if self.cccEcho: |
Anders Carlsson | 76613bf | 2009-01-18 02:54:17 +0000 | [diff] [blame] | 222 | print >> sys.stderr, ' '.join(map(repr,sj.getArgv())) |
Daniel Dunbar | e19ed8e | 2009-01-17 02:02:35 +0000 | [diff] [blame] | 223 | sys.stdout.flush() |
| 224 | |
| 225 | if not procs: |
| 226 | stdin = None |
| 227 | else: |
| 228 | stdin = procs[-1].stdout |
| 229 | if sj is j.commands[-1]: |
| 230 | stdout = None |
| 231 | else: |
| 232 | stdout = subprocess.PIPE |
| 233 | procs.append(subprocess.Popen(sj.getArgv(), |
| 234 | executable=sj.executable, |
| 235 | stdin=stdin, |
| 236 | stdout=stdout)) |
| 237 | for proc in procs: |
| 238 | res = proc.wait() |
| 239 | if res: |
| 240 | sys.exit(res) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 241 | else: |
| 242 | raise ValueError,'Encountered unknown job.' |
| 243 | |
| 244 | def claim(self, option): |
| 245 | # FIXME: Move to OptionList once introduced and implement. |
| 246 | pass |
| 247 | |
| 248 | def warning(self, message): |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 249 | print >>sys.stderr,'%s: %s' % (self.driverName, message) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 250 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 251 | def printOptions(self, args): |
| 252 | for i,arg in enumerate(args): |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 253 | if isinstance(arg, Arguments.MultipleValuesArg): |
| 254 | values = list(args.getValues(arg)) |
| 255 | elif isinstance(arg, Arguments.ValueArg): |
| 256 | values = [args.getValue(arg)] |
| 257 | elif isinstance(arg, Arguments.JoinedAndSeparateValuesArg): |
| 258 | values = [args.getJoinedValue(arg), args.getSeparateValue(arg)] |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 259 | else: |
| 260 | values = [] |
Daniel Dunbar | 927a509 | 2009-01-06 02:30:10 +0000 | [diff] [blame] | 261 | print 'Option %d - Name: "%s", Values: {%s}' % (i, arg.opt.name, |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 262 | ', '.join(['"%s"' % v |
| 263 | for v in values])) |
| 264 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 265 | def printPhases(self, phases, args): |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 266 | def printPhase(p, f, steps, arch=None): |
| 267 | if p in steps: |
| 268 | return steps[p] |
| 269 | elif isinstance(p, Phases.BindArchAction): |
| 270 | for kid in p.inputs: |
| 271 | printPhase(kid, f, steps, p.arch) |
| 272 | steps[p] = len(steps) |
| 273 | return |
| 274 | |
| 275 | if isinstance(p, Phases.InputAction): |
| 276 | phaseName = 'input' |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 277 | inputStr = '"%s"' % args.getValue(p.filename) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 278 | else: |
| 279 | phaseName = p.phase.name |
| 280 | inputs = [printPhase(i, f, steps, arch) |
| 281 | for i in p.inputs] |
| 282 | inputStr = '{%s}' % ', '.join(map(str, inputs)) |
| 283 | if arch is not None: |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 284 | phaseName += '-' + args.getValue(arch) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 285 | steps[p] = index = len(steps) |
| 286 | print "%d: %s, %s, %s" % (index,phaseName,inputStr,p.type.name) |
| 287 | return index |
| 288 | steps = {} |
| 289 | for phase in phases: |
| 290 | printPhase(phase, sys.stdout, steps) |
| 291 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 292 | def handleImmediateOptions(self, args): |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 293 | # FIXME: Some driver Arguments are consumed right off the bat, |
| 294 | # like -dumpversion. Currently the gcc-dd handles these |
| 295 | # poorly, so we should be ok handling them upfront instead of |
| 296 | # after driver-driver level dispatching. |
| 297 | # |
| 298 | # FIXME: The actual order of these options in gcc is all over the |
| 299 | # place. The -dump ones seem to be first and in specification |
| 300 | # order, but there are other levels of precedence. For example, |
| 301 | # -print-search-dirs is evaluated before -print-prog-name=, |
| 302 | # regardless of order (and the last instance of -print-prog-name= |
| 303 | # wins verse itself). |
| 304 | # |
| 305 | # FIXME: Do we want to report "argument unused" type errors in the |
| 306 | # presence of things like -dumpmachine and -print-search-dirs? |
| 307 | # Probably not. |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 308 | arg = (args.getLastArg(self.parser.dumpmachineOption) or |
| 309 | args.getLastArg(self.parser.dumpversionOption) or |
| 310 | args.getLastArg(self.parser.printSearchDirsOption)) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 311 | if arg: |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 312 | raise NotImplementedError('%s unsupported' % arg.opt.name) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 313 | |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 314 | arg = (args.getLastArg(self.parser.dumpspecsOption) or |
| 315 | args.getLastArg(self.parser.printMultiDirectoryOption) or |
| 316 | args.getLastArg(self.parser.printMultiLibOption)) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 317 | if arg: |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 318 | raise Arguments.InvalidArgumentsError('%s unsupported by this driver' % arg.opt.name) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 319 | |
| 320 | arg = args.getLastArg(self.parser.printFileNameOption) |
| 321 | if arg: |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 322 | print self.getFilePath(args.getValue(arg)) |
| 323 | sys.exit(0) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 324 | |
| 325 | arg = args.getLastArg(self.parser.printProgNameOption) |
| 326 | if arg: |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 327 | print self.getProgramPath(args.getValue(arg)) |
| 328 | sys.exit(0) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 329 | |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 330 | arg = args.getLastArg(self.parser.printLibgccFileNameOption) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 331 | if arg: |
Daniel Dunbar | f677a60 | 2009-01-21 02:03:52 +0000 | [diff] [blame] | 332 | print self.getFilePath('libgcc.a') |
| 333 | sys.exit(0) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 334 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 335 | def buildNormalPipeline(self, args): |
Daniel Dunbar | 90c72cd | 2009-01-21 01:07:49 +0000 | [diff] [blame] | 336 | hasAnalyze = args.getLastArg(self.parser.analyzeOption) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 337 | hasCombine = args.getLastArg(self.parser.combineOption) |
| 338 | hasSyntaxOnly = args.getLastArg(self.parser.syntaxOnlyOption) |
| 339 | hasDashC = args.getLastArg(self.parser.cOption) |
| 340 | hasDashE = args.getLastArg(self.parser.EOption) |
| 341 | hasDashS = args.getLastArg(self.parser.SOption) |
Daniel Dunbar | 445c46d | 2009-01-20 01:53:54 +0000 | [diff] [blame] | 342 | hasDashM = args.getLastArg(self.parser.MOption) |
| 343 | hasDashMM = args.getLastArg(self.parser.MMOption) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 344 | |
| 345 | inputType = None |
| 346 | inputTypeOpt = None |
| 347 | inputs = [] |
| 348 | for a in args: |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 349 | if a.opt is self.parser.inputOption: |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 350 | inputValue = args.getValue(a) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 351 | if inputType is None: |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 352 | base,ext = os.path.splitext(inputValue) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 353 | if ext and ext in Types.kTypeSuffixMap: |
| 354 | klass = Types.kTypeSuffixMap[ext] |
| 355 | else: |
| 356 | # FIXME: Its not clear why we shouldn't just |
| 357 | # revert to unknown. I think this is more likely a |
| 358 | # bug / unintended behavior in gcc. Not very |
| 359 | # important though. |
| 360 | klass = Types.ObjectType |
| 361 | else: |
| 362 | assert inputTypeOpt is not None |
| 363 | self.claim(inputTypeOpt) |
| 364 | klass = inputType |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 365 | |
| 366 | # Check that the file exists. It isn't clear this is |
| 367 | # worth doing, since the tool presumably does this |
| 368 | # anyway, and this just adds an extra stat to the |
| 369 | # equation, but this is gcc compatible. |
| 370 | if not os.path.exists(inputValue): |
| 371 | self.warning("%s: No such file or directory" % inputValue) |
| 372 | else: |
| 373 | inputs.append((klass, a)) |
Daniel Dunbar | fc2ad02 | 2009-01-12 03:33:58 +0000 | [diff] [blame] | 374 | elif a.opt.isLinkerInput: |
| 375 | # Treat as a linker input. |
Daniel Dunbar | 927a509 | 2009-01-06 02:30:10 +0000 | [diff] [blame] | 376 | # |
| 377 | # FIXME: This might not be good enough. We may |
| 378 | # need to introduce another type for this case, so |
| 379 | # that other code which needs to know the inputs |
| 380 | # handles this properly. Best not to try and lipo |
| 381 | # this, for example. |
| 382 | inputs.append((Types.ObjectType, a)) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 383 | elif a.opt is self.parser.xOption: |
Daniel Dunbar | 927a509 | 2009-01-06 02:30:10 +0000 | [diff] [blame] | 384 | inputTypeOpt = a |
| 385 | value = args.getValue(a) |
| 386 | if value in Types.kTypeSpecifierMap: |
| 387 | inputType = Types.kTypeSpecifierMap[value] |
| 388 | else: |
| 389 | # FIXME: How are we going to handle diagnostics. |
| 390 | self.warning("language %s not recognized" % value) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 391 | |
Daniel Dunbar | 927a509 | 2009-01-06 02:30:10 +0000 | [diff] [blame] | 392 | # FIXME: Its not clear why we shouldn't just |
| 393 | # revert to unknown. I think this is more likely a |
| 394 | # bug / unintended behavior in gcc. Not very |
| 395 | # important though. |
Daniel Dunbar | 6cb4205 | 2009-01-13 21:07:43 +0000 | [diff] [blame] | 396 | inputType = Types.ObjectType |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 397 | |
| 398 | # We claim things here so that options for which we silently allow |
| 399 | # override only ever claim the used option. |
| 400 | if hasCombine: |
| 401 | self.claim(hasCombine) |
| 402 | |
| 403 | finalPhase = Phases.Phase.eOrderPostAssemble |
| 404 | finalPhaseOpt = None |
| 405 | |
| 406 | # Determine what compilation mode we are in. |
Daniel Dunbar | 445c46d | 2009-01-20 01:53:54 +0000 | [diff] [blame] | 407 | if hasDashE or hasDashM or hasDashMM: |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 408 | finalPhase = Phases.Phase.eOrderPreprocess |
| 409 | finalPhaseOpt = hasDashE |
Daniel Dunbar | 90c72cd | 2009-01-21 01:07:49 +0000 | [diff] [blame] | 410 | elif hasAnalyze: |
| 411 | finalPhase = Phases.Phase.eOrderCompile |
| 412 | finalPhaseOpt = hasAnalyze |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 413 | elif hasSyntaxOnly: |
| 414 | finalPhase = Phases.Phase.eOrderCompile |
| 415 | finalPhaseOpt = hasSyntaxOnly |
| 416 | elif hasDashS: |
| 417 | finalPhase = Phases.Phase.eOrderCompile |
| 418 | finalPhaseOpt = hasDashS |
| 419 | elif hasDashC: |
| 420 | finalPhase = Phases.Phase.eOrderAssemble |
| 421 | finalPhaseOpt = hasDashC |
| 422 | |
| 423 | if finalPhaseOpt: |
| 424 | self.claim(finalPhaseOpt) |
| 425 | |
| 426 | # FIXME: Support -combine. |
| 427 | if hasCombine: |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 428 | raise NotImplementedError,"-combine is not yet supported" |
| 429 | |
Daniel Dunbar | 80e48b7 | 2009-01-17 00:53:19 +0000 | [diff] [blame] | 430 | # Reject -Z* at the top level for now. |
| 431 | arg = args.getLastArg(self.parser.ZOption) |
| 432 | if arg: |
| 433 | raise Arguments.InvalidArgumentsError("%s: unsupported use of internal gcc option" % ' '.join(args.render(arg))) |
| 434 | |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 435 | if (not inputs and |
| 436 | not args.getLastArg(self.parser.hashHashHashOption)): |
| 437 | raise Arguments.InvalidArgumentsError("no input files") |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 438 | |
| 439 | actions = [] |
| 440 | linkerInputs = [] |
| 441 | # FIXME: This is gross. |
| 442 | linkPhase = Phases.LinkPhase() |
| 443 | for klass,input in inputs: |
| 444 | # Figure out what step to start at. |
| 445 | |
| 446 | # FIXME: This should be part of the input class probably? |
| 447 | # Altough it doesn't quite fit there either, things like |
| 448 | # asm-with-preprocess don't easily fit into a linear scheme. |
| 449 | |
| 450 | # FIXME: I think we are going to end up wanting to just build |
| 451 | # a simple FSA which we run the inputs down. |
| 452 | sequence = [] |
| 453 | if klass.preprocess: |
| 454 | sequence.append(Phases.PreprocessPhase()) |
| 455 | if klass == Types.ObjectType: |
| 456 | sequence.append(linkPhase) |
| 457 | elif klass.onlyAssemble: |
| 458 | sequence.extend([Phases.AssemblePhase(), |
| 459 | linkPhase]) |
| 460 | elif klass.onlyPrecompile: |
| 461 | sequence.append(Phases.PrecompilePhase()) |
Daniel Dunbar | 90c72cd | 2009-01-21 01:07:49 +0000 | [diff] [blame] | 462 | elif hasAnalyze: |
| 463 | sequence.append(Phases.AnalyzePhase()) |
| 464 | elif hasSyntaxOnly: |
| 465 | sequence.append(Phases.SyntaxOnlyPhase()) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 466 | else: |
| 467 | sequence.extend([Phases.CompilePhase(), |
| 468 | Phases.AssemblePhase(), |
| 469 | linkPhase]) |
| 470 | |
| 471 | if sequence[0].order > finalPhase: |
| 472 | assert finalPhaseOpt and finalPhaseOpt.opt |
| 473 | # FIXME: Explain what type of input file is. Or just match |
| 474 | # gcc warning. |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 475 | self.warning("%s: %s input file unused when %s is present" % (args.getValue(input), |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 476 | sequence[0].name, |
| 477 | finalPhaseOpt.opt.name)) |
| 478 | else: |
| 479 | # Build the pipeline for this file. |
| 480 | |
| 481 | current = Phases.InputAction(input, klass) |
| 482 | for transition in sequence: |
| 483 | # If the current action produces no output, or we are |
| 484 | # past what the user requested, we are done. |
| 485 | if (current.type is Types.NothingType or |
| 486 | transition.order > finalPhase): |
| 487 | break |
| 488 | else: |
| 489 | if isinstance(transition, Phases.PreprocessPhase): |
| 490 | assert isinstance(klass.preprocess, Types.InputType) |
| 491 | current = Phases.JobAction(transition, |
| 492 | [current], |
| 493 | klass.preprocess) |
| 494 | elif isinstance(transition, Phases.PrecompilePhase): |
| 495 | current = Phases.JobAction(transition, |
| 496 | [current], |
| 497 | Types.PCHType) |
Daniel Dunbar | 90c72cd | 2009-01-21 01:07:49 +0000 | [diff] [blame] | 498 | elif isinstance(transition, Phases.AnalyzePhase): |
| 499 | output = Types.PlistType |
| 500 | current = Phases.JobAction(transition, |
| 501 | [current], |
| 502 | output) |
| 503 | elif isinstance(transition, Phases.SyntaxOnlyPhase): |
| 504 | output = Types.NothingType |
| 505 | current = Phases.JobAction(transition, |
| 506 | [current], |
| 507 | output) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 508 | elif isinstance(transition, Phases.CompilePhase): |
Daniel Dunbar | 90c72cd | 2009-01-21 01:07:49 +0000 | [diff] [blame] | 509 | output = Types.AsmTypeNoPP |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 510 | current = Phases.JobAction(transition, |
| 511 | [current], |
| 512 | output) |
| 513 | elif isinstance(transition, Phases.AssemblePhase): |
| 514 | current = Phases.JobAction(transition, |
| 515 | [current], |
| 516 | Types.ObjectType) |
| 517 | elif transition is linkPhase: |
| 518 | linkerInputs.append(current) |
| 519 | current = None |
| 520 | break |
| 521 | else: |
| 522 | raise RuntimeError,'Unrecognized transition: %s.' % transition |
| 523 | pass |
| 524 | |
| 525 | if current is not None: |
| 526 | assert not isinstance(current, Phases.InputAction) |
| 527 | actions.append(current) |
| 528 | |
| 529 | if linkerInputs: |
| 530 | actions.append(Phases.JobAction(linkPhase, |
| 531 | linkerInputs, |
| 532 | Types.ImageType)) |
| 533 | |
| 534 | return actions |
| 535 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 536 | def buildPipeline(self, args): |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 537 | # FIXME: We need to handle canonicalization of the specified arch. |
| 538 | |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 539 | archs = {} |
Daniel Dunbar | 445c46d | 2009-01-20 01:53:54 +0000 | [diff] [blame] | 540 | hasDashM = args.getLastArg(self.parser.MGroup) |
Daniel Dunbar | a33176f | 2009-01-21 18:49:34 +0000 | [diff] [blame^] | 541 | hasSaveTemps = args.getLastArg(self.parser.saveTempsOption) |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 542 | for arg in args: |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 543 | if arg.opt is self.parser.archOption: |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 544 | # FIXME: Canonicalize this. |
| 545 | archName = args.getValue(arg) |
| 546 | archs[archName] = arg |
| 547 | |
| 548 | archs = archs.values() |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 549 | if not archs: |
Daniel Dunbar | f3d5ca0 | 2009-01-13 04:05:40 +0000 | [diff] [blame] | 550 | archs.append(args.makeSeparateArg(self.hostInfo.getArchName(args), |
Daniel Dunbar | 1ba9098 | 2009-01-07 18:54:26 +0000 | [diff] [blame] | 551 | self.parser.archOption)) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 552 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 553 | actions = self.buildNormalPipeline(args) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 554 | |
| 555 | # FIXME: Use custom exception for this. |
| 556 | # |
| 557 | # FIXME: We killed off some others but these aren't yet detected in |
| 558 | # a functional manner. If we added information to jobs about which |
| 559 | # "auxiliary" files they wrote then we could detect the conflict |
| 560 | # these cause downstream. |
| 561 | if len(archs) > 1: |
| 562 | if hasDashM: |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 563 | raise Arguments.InvalidArgumentsError("Cannot use -M options with multiple arch flags.") |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 564 | elif hasSaveTemps: |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 565 | raise Arguments.InvalidArgumentsError("Cannot use -save-temps with multiple arch flags.") |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 566 | |
| 567 | # Execute once per arch. |
| 568 | finalActions = [] |
| 569 | for p in actions: |
| 570 | # Make sure we can lipo this kind of output. If not (and it |
| 571 | # is an actual output) then we disallow, since we can't |
| 572 | # create an output file with the right name without |
| 573 | # overwriting it. We could remove this oddity by just |
| 574 | # changing the output names to include the arch, which would |
| 575 | # also fix -save-temps. Compatibility wins for now. |
| 576 | # |
| 577 | # FIXME: Is this error substantially less useful than |
| 578 | # gcc-dd's? The main problem is that "Cannot use compiler |
| 579 | # output with multiple arch flags" won't make sense to most |
| 580 | # developers. |
| 581 | if (len(archs) > 1 and |
| 582 | p.type not in (Types.NothingType,Types.ObjectType,Types.ImageType)): |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 583 | raise Arguments.InvalidArgumentsError('Cannot use %s output with multiple arch flags.' % p.type.name) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 584 | |
| 585 | inputs = [] |
| 586 | for arch in archs: |
| 587 | inputs.append(Phases.BindArchAction(p, arch)) |
| 588 | |
| 589 | # Lipo if necessary. We do it this way because we need to set |
| 590 | # the arch flag so that -Xarch_ gets rewritten. |
| 591 | if len(inputs) == 1 or p.type == Types.NothingType: |
| 592 | finalActions.extend(inputs) |
| 593 | else: |
| 594 | finalActions.append(Phases.JobAction(Phases.LipoPhase(), |
| 595 | inputs, |
| 596 | p.type)) |
| 597 | |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 598 | return finalActions |
| 599 | |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 600 | def bindPhases(self, phases, args): |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 601 | jobs = Jobs.JobList() |
| 602 | |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 603 | finalOutput = args.getLastArg(self.parser.oOption) |
Daniel Dunbar | a33176f | 2009-01-21 18:49:34 +0000 | [diff] [blame^] | 604 | hasSaveTemps = args.getLastArg(self.parser.saveTempsOption) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 605 | hasNoIntegratedCPP = args.getLastArg(self.parser.noIntegratedCPPOption) |
Daniel Dunbar | f86e98a | 2009-01-12 09:23:15 +0000 | [diff] [blame] | 606 | hasTraditionalCPP = args.getLastArg(self.parser.traditionalCPPOption) |
Daniel Dunbar | e9f1a69 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 607 | hasPipe = args.getLastArg(self.parser.pipeOption) |
Daniel Dunbar | fc2ad02 | 2009-01-12 03:33:58 +0000 | [diff] [blame] | 608 | |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 609 | # We claim things here so that options for which we silently allow |
| 610 | # override only ever claim the used option. |
| 611 | if hasPipe: |
| 612 | self.claim(hasPipe) |
| 613 | # FIXME: Hack, override -pipe till we support it. |
Daniel Dunbar | e19ed8e | 2009-01-17 02:02:35 +0000 | [diff] [blame] | 614 | if hasSaveTemps: |
| 615 | self.warning('-pipe ignored because -save-temps specified') |
| 616 | hasPipe = None |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 617 | # Claim these here. Its not completely accurate but any warnings |
| 618 | # about these being unused are likely to be noise anyway. |
| 619 | if hasSaveTemps: |
| 620 | self.claim(hasSaveTemps) |
Daniel Dunbar | f86e98a | 2009-01-12 09:23:15 +0000 | [diff] [blame] | 621 | |
| 622 | if hasTraditionalCPP: |
| 623 | self.claim(hasTraditionalCPP) |
| 624 | elif hasNoIntegratedCPP: |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 625 | self.claim(hasNoIntegratedCPP) |
Daniel Dunbar | f86e98a | 2009-01-12 09:23:15 +0000 | [diff] [blame] | 626 | |
Daniel Dunbar | e5fb679 | 2009-01-13 06:25:31 +0000 | [diff] [blame] | 627 | # FIXME: Move to... somewhere else. |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 628 | class InputInfo: |
| 629 | def __init__(self, source, type, baseInput): |
| 630 | self.source = source |
| 631 | self.type = type |
| 632 | self.baseInput = baseInput |
| 633 | |
| 634 | def __repr__(self): |
| 635 | return '%s(%r, %r, %r)' % (self.__class__.__name__, |
| 636 | self.source, self.type, self.baseInput) |
Daniel Dunbar | e5fb679 | 2009-01-13 06:25:31 +0000 | [diff] [blame] | 637 | |
| 638 | def isOriginalInput(self): |
| 639 | return self.source is self.baseInput |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 640 | |
Daniel Dunbar | b349276 | 2009-01-13 18:51:26 +0000 | [diff] [blame] | 641 | def createJobs(tc, phase, |
| 642 | canAcceptPipe=False, atTopLevel=False, arch=None, |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 643 | tcArgs=None, linkingOutput=None): |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 644 | if isinstance(phase, Phases.InputAction): |
| 645 | return InputInfo(phase.filename, phase.type, phase.filename) |
| 646 | elif isinstance(phase, Phases.BindArchAction): |
Daniel Dunbar | 7472787 | 2009-01-06 01:35:44 +0000 | [diff] [blame] | 647 | archName = args.getValue(phase.arch) |
Daniel Dunbar | 758cf64 | 2009-01-11 22:06:22 +0000 | [diff] [blame] | 648 | tc = self.hostInfo.getToolChainForArch(archName) |
Daniel Dunbar | b349276 | 2009-01-13 18:51:26 +0000 | [diff] [blame] | 649 | return createJobs(tc, phase.inputs[0], |
| 650 | canAcceptPipe, atTopLevel, phase.arch, |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 651 | None, linkingOutput) |
Daniel Dunbar | b349276 | 2009-01-13 18:51:26 +0000 | [diff] [blame] | 652 | |
| 653 | if tcArgs is None: |
| 654 | tcArgs = tc.translateArgs(args, arch) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 655 | |
| 656 | assert isinstance(phase, Phases.JobAction) |
Daniel Dunbar | 758cf64 | 2009-01-11 22:06:22 +0000 | [diff] [blame] | 657 | tool = tc.selectTool(phase) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 658 | |
| 659 | # See if we should use an integrated CPP. We only use an |
| 660 | # integrated cpp when we have exactly one input, since this is |
| 661 | # the only use case we care about. |
| 662 | useIntegratedCPP = False |
| 663 | inputList = phase.inputs |
| 664 | if (not hasNoIntegratedCPP and |
Daniel Dunbar | f86e98a | 2009-01-12 09:23:15 +0000 | [diff] [blame] | 665 | not hasTraditionalCPP and |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 666 | not hasSaveTemps and |
| 667 | tool.hasIntegratedCPP()): |
| 668 | if (len(phase.inputs) == 1 and |
Daniel Dunbar | 7d49409 | 2009-01-20 00:47:24 +0000 | [diff] [blame] | 669 | isinstance(phase.inputs[0], Phases.JobAction) and |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 670 | isinstance(phase.inputs[0].phase, Phases.PreprocessPhase)): |
| 671 | useIntegratedCPP = True |
| 672 | inputList = phase.inputs[0].inputs |
| 673 | |
| 674 | # Only try to use pipes when exactly one input. |
| 675 | canAcceptPipe = len(inputList) == 1 and tool.acceptsPipedInput() |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 676 | inputs = [createJobs(tc, p, canAcceptPipe, False, |
| 677 | arch, tcArgs, linkingOutput) |
Daniel Dunbar | 758cf64 | 2009-01-11 22:06:22 +0000 | [diff] [blame] | 678 | for p in inputList] |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 679 | |
| 680 | # Determine if we should output to a pipe. |
| 681 | canOutputToPipe = canAcceptPipe and tool.canPipeOutput() |
| 682 | outputToPipe = False |
| 683 | if canOutputToPipe: |
| 684 | # Some things default to writing to a pipe if the final |
| 685 | # phase and there was no user override. |
| 686 | # |
| 687 | # FIXME: What is the best way to handle this? |
Daniel Dunbar | 1b39127 | 2009-01-18 21:35:24 +0000 | [diff] [blame] | 688 | if atTopLevel: |
| 689 | if (isinstance(phase.phase, Phases.PreprocessPhase) and |
| 690 | not finalOutput): |
| 691 | outputToPipe = True |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 692 | elif hasPipe: |
| 693 | outputToPipe = True |
| 694 | |
| 695 | # Figure out where to put the job (pipes). |
| 696 | jobList = jobs |
| 697 | if canAcceptPipe and isinstance(inputs[0].source, Jobs.PipedJob): |
| 698 | jobList = inputs[0].source |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 699 | |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 700 | baseInput = inputs[0].baseInput |
Daniel Dunbar | d9b7a74 | 2009-01-21 00:05:15 +0000 | [diff] [blame] | 701 | output,jobList = self.getOutputName(phase, outputToPipe, jobs, jobList, baseInput, |
| 702 | args, atTopLevel, hasSaveTemps, finalOutput) |
Daniel Dunbar | b421dba | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 703 | tool.constructJob(phase, arch, jobList, inputs, output, phase.type, |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 704 | tcArgs, linkingOutput) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 705 | |
| 706 | return InputInfo(output, phase.type, baseInput) |
| 707 | |
| 708 | # It is an error to provide a -o option if we are making multiple |
| 709 | # output files. |
| 710 | if finalOutput and len([a for a in phases if a.type is not Types.NothingType]) > 1: |
Daniel Dunbar | a0026f2 | 2009-01-16 23:12:12 +0000 | [diff] [blame] | 711 | raise Arguments.InvalidArgumentsError("cannot specify -o when generating multiple files") |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 712 | |
| 713 | for phase in phases: |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 714 | # If we are linking an image for multiple archs then the |
| 715 | # linker wants -arch_multiple and -final_output <final image |
| 716 | # name>. Unfortunately this requires some gross contortions. |
| 717 | # |
| 718 | # FIXME: This is a hack; find a cleaner way to integrate this |
| 719 | # into the process. |
| 720 | linkingOutput = None |
| 721 | if (isinstance(phase, Phases.JobAction) and |
| 722 | isinstance(phase.phase, Phases.LipoPhase)): |
| 723 | finalOutput = args.getLastArg(self.parser.oOption) |
| 724 | if finalOutput: |
| 725 | linkingOutput = finalOutput |
| 726 | else: |
| 727 | linkingOutput = args.makeSeparateArg('a.out', |
| 728 | self.parser.oOption) |
| 729 | |
Daniel Dunbar | b349276 | 2009-01-13 18:51:26 +0000 | [diff] [blame] | 730 | createJobs(self.toolChain, phase, |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 731 | canAcceptPipe=True, atTopLevel=True, |
| 732 | linkingOutput=linkingOutput) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 733 | |
| 734 | return jobs |
Daniel Dunbar | 31c8081 | 2009-01-20 21:29:14 +0000 | [diff] [blame] | 735 | |
| 736 | def getOutputName(self, phase, outputToPipe, jobs, jobList, baseInput, |
| 737 | args, atTopLevel, hasSaveTemps, finalOutput): |
| 738 | # Figure out where to put the output. |
| 739 | if phase.type == Types.NothingType: |
| 740 | output = None |
| 741 | elif outputToPipe: |
| 742 | if isinstance(jobList, Jobs.PipedJob): |
| 743 | output = jobList |
| 744 | else: |
| 745 | jobList = output = Jobs.PipedJob([]) |
| 746 | jobs.addJob(output) |
| 747 | else: |
| 748 | # Figure out what the derived output location would be. |
| 749 | # |
| 750 | # FIXME: gcc has some special case in here so that it doesn't |
| 751 | # create output files if they would conflict with an input. |
| 752 | if phase.type is Types.ImageType: |
| 753 | namedOutput = "a.out" |
| 754 | else: |
| 755 | inputName = args.getValue(baseInput) |
| 756 | base,_ = os.path.splitext(inputName) |
| 757 | assert phase.type.tempSuffix is not None |
| 758 | namedOutput = base + '.' + phase.type.tempSuffix |
| 759 | |
| 760 | # Output to user requested destination? |
| 761 | if atTopLevel and finalOutput: |
| 762 | output = finalOutput |
| 763 | # Contruct a named destination? |
| 764 | elif atTopLevel or hasSaveTemps: |
| 765 | # As an annoying special case, pch generation |
| 766 | # doesn't strip the pathname. |
| 767 | if phase.type is Types.PCHType: |
| 768 | outputName = namedOutput |
| 769 | else: |
| 770 | outputName = os.path.basename(namedOutput) |
| 771 | output = args.makeSeparateArg(outputName, |
| 772 | self.parser.oOption) |
| 773 | else: |
| 774 | # Output to temp file... |
| 775 | fd,filename = tempfile.mkstemp(suffix='.'+phase.type.tempSuffix) |
| 776 | output = args.makeSeparateArg(filename, |
| 777 | self.parser.oOption) |
Daniel Dunbar | d9b7a74 | 2009-01-21 00:05:15 +0000 | [diff] [blame] | 778 | return output,jobList |