self.addOption(JoinedOrSeparateOption('-idirafter', self.iGroup))
self.addOption(JoinedOrSeparateOption('-iquote', self.iGroup))
self.isysrootOption = self.addOption(JoinedOrSeparateOption('-isysroot', self.iGroup))
- self.addOption(JoinedOrSeparateOption('-include', self.iGroup))
+ self.includeOption = self.addOption(JoinedOrSeparateOption('-include', self.iGroup))
self.addOption(JoinedOption('-i', self.iGroup))
self.keep_private_externsOption = self.addOption(JoinedOrSeparateOption('-keep_private_externs'))
def selectTool(self, action):
assert isinstance(action, Phases.JobAction)
- if (self.driver.cccClang and
- self.archName == 'i386' and
- action.inputs[0].type in (Types.CType, Types.CTypeNoPP,
- Types.ObjCType, Types.ObjCTypeNoPP) and
- isinstance(action.phase, Phases.CompilePhase)):
- return self.clangTool
+ if self.driver.cccClang and self.archName == 'i386':
+ if (action.inputs[0].type in (Types.CType, Types.CTypeNoPP,
+ Types.ObjCType, Types.ObjCTypeNoPP) and
+ isinstance(action.phase, Phases.CompilePhase)):
+ return self.clangTool
+ elif (action.inputs[0].type in (Types.CHeaderType, Types.CHeaderNoPPType,
+ Types.ObjCHeaderType, Types.ObjCHeaderNoPPType) and
+ isinstance(action.phase, Phases.PrecompilePhase)):
+ return self.clangTool
return self.toolMap[action.phase.__class__]
output, outputType, arglist):
cmd_args = []
+ patchOutputNameForPTH = False
if output is None:
cmd_args.append('-fsyntax-only')
elif outputType is Types.AsmTypeNoPP:
cmd_args.append('-S')
+ elif outputType is Types.PCHType:
+ # No special option needed, driven by -x. However, we
+ # patch the output name to try and not conflict with gcc.
+ patchOutputNameForPTH = True
+
+ # FIXME: This is a total hack. Copy the input header file
+ # to the output, so that it can be -include'd by clang.
+ assert len(inputs) == 1
+ assert not isinstance(output, Jobs.PipedJob)
+ assert not isinstance(inputs[0].source, Jobs.PipedJob)
+ inputPath = arglist.getValue(inputs[0].source)
+ outputPath = os.path.join(os.path.dirname(arglist.getValue(output)),
+ os.path.basename(inputPath))
+ # Only do copy when the output doesn't exist.
+ if not os.path.exists(outputPath):
+ import shutil
+ shutil.copyfile(inputPath, outputPath)
else:
raise ValueError,"Unexpected output type for clang tool."
# FIXME: Clang isn't going to accept just anything here.
arglist.addAllArgs(cmd_args, arglist.parser.iGroup)
+ # Automatically load .pth files which match -include options.
+ for arg in arglist.getArgs(arglist.parser.includeOption):
+ pthPath = arglist.getValue(arg) + '.pth'
+ if os.path.exists(pthPath):
+ cmd_args.append('-token-cache')
+ cmd_args.append(pthPath)
+
# FIXME: Dehardcode this.
cmd_args.append('-fblocks')
if arch is not None:
cmd_args.extend(arglist.render(arch))
- cmd_args.extend(arglist.render(output))
+ if isinstance(output, Jobs.PipedJob):
+ cmd_args.extend(['-o', '-'])
+ else:
+ if patchOutputNameForPTH:
+ base,suffix = os.path.splitext(arglist.getValue(output))
+ if suffix == '.gch':
+ suffix = '.pth'
+ cmd_args.append('-o')
+ cmd_args.append(base + suffix)
+ else:
+ cmd_args.extend(arglist.render(output))
for input in inputs:
cmd_args.append('-x')