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