blob: f48aec9d56fa56d33e3453b811b73b6a935796bc [file] [log] [blame]
Daniel Dunbara5677512009-01-05 19:53:30 +00001import Arguments
2import Jobs
3import Types
4
5class Tool(object):
Daniel Dunbarba6e3232009-01-06 06:12:13 +00006 """Tool - A concrete implementation of an action."""
Daniel Dunbara5677512009-01-05 19:53:30 +00007
8 eFlagsPipedInput = 1 << 0
9 eFlagsPipedOutput = 1 << 1
10 eFlagsIntegratedCPP = 1 << 2
11
12 def __init__(self, name, flags = 0):
13 self.name = name
14 self.flags = flags
15
16 def acceptsPipedInput(self):
17 return not not (self.flags & Tool.eFlagsPipedInput)
18 def canPipeOutput(self):
19 return not not (self.flags & Tool.eFlagsPipedOutput)
20 def hasIntegratedCPP(self):
21 return not not (self.flags & Tool.eFlagsIntegratedCPP)
22
23class GCC_Common_Tool(Tool):
24 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000025 output, outputType, args, arglist,
Daniel Dunbara5677512009-01-05 19:53:30 +000026 extraArgs):
27 assert len(inputs) == 1
28
29 input = inputs[0]
30
Daniel Dunbardb439902009-01-07 18:40:45 +000031 cmd_args = sum(map(arglist.render, args),[]) + extraArgs
Daniel Dunbara5677512009-01-05 19:53:30 +000032 if arch:
33 # FIXME: Clean this up.
34 if isinstance(arch, Arguments.DerivedArg):
Daniel Dunbardb439902009-01-07 18:40:45 +000035 cmd_args.extend(['-arch', arglist.getValue(arch)])
Daniel Dunbara5677512009-01-05 19:53:30 +000036 else:
Daniel Dunbardb439902009-01-07 18:40:45 +000037 cmd_args.extend(arglist.render(arch))
Daniel Dunbara5677512009-01-05 19:53:30 +000038 if isinstance(output, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +000039 cmd_args.extend(['-o', '-'])
Daniel Dunbara5677512009-01-05 19:53:30 +000040 elif output is None:
Daniel Dunbardb439902009-01-07 18:40:45 +000041 cmd_args.append('-fsyntax-only')
Daniel Dunbara5677512009-01-05 19:53:30 +000042 else:
43 # FIXME: Ditch this hack.
44 if isinstance(output, Arguments.DerivedArg):
Daniel Dunbardb439902009-01-07 18:40:45 +000045 cmd_args.extend(['-o', arglist.getValue(output)])
Daniel Dunbara5677512009-01-05 19:53:30 +000046 else:
Daniel Dunbardb439902009-01-07 18:40:45 +000047 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +000048
Daniel Dunbardb439902009-01-07 18:40:45 +000049 cmd_args.extend(['-x', input.type.name])
Daniel Dunbara5677512009-01-05 19:53:30 +000050 if isinstance(input.source, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +000051 cmd_args.append('-')
Daniel Dunbara5677512009-01-05 19:53:30 +000052 else:
Daniel Dunbardb439902009-01-07 18:40:45 +000053 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +000054
55 jobs.addJob(Jobs.Command('gcc', cmd_args))
56
57class GCC_PreprocessTool(GCC_Common_Tool):
58 def __init__(self):
59 super(GCC_PreprocessTool, self).__init__('gcc',
60 (Tool.eFlagsPipedInput |
61 Tool.eFlagsPipedOutput))
62
63 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000064 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000065 return super(GCC_PreprocessTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000066 output, outputType, args, arglist,
67 ['-E'])
Daniel Dunbara5677512009-01-05 19:53:30 +000068
69class GCC_CompileTool(GCC_Common_Tool):
70 def __init__(self):
71 super(GCC_CompileTool, self).__init__('gcc',
72 (Tool.eFlagsPipedInput |
73 Tool.eFlagsPipedOutput |
74 Tool.eFlagsIntegratedCPP))
75
76 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000077 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000078 return super(GCC_CompileTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000079 output, outputType, args, arglist,
80 ['-S'])
Daniel Dunbara5677512009-01-05 19:53:30 +000081
82class GCC_PrecompileTool(GCC_Common_Tool):
83 def __init__(self):
84 super(GCC_PrecompileTool, self).__init__('gcc',
85 (Tool.eFlagsPipedInput |
86 Tool.eFlagsIntegratedCPP))
87
88 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000089 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000090 return super(GCC_PrecompileTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000091 output, outputType, args, arglist,
Daniel Dunbara5677512009-01-05 19:53:30 +000092 [])
93
94class DarwinAssemblerTool(Tool):
95 def __init__(self):
96 super(DarwinAssemblerTool, self).__init__('as',
97 Tool.eFlagsPipedInput)
98
99 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000100 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000101 assert len(inputs) == 1
102 assert outputType is Types.ObjectType
103
104 input = inputs[0]
105
106 cmd_args = []
107 if arch:
108 # FIXME: Clean this up.
109 if isinstance(arch, Arguments.DerivedArg):
Daniel Dunbardb439902009-01-07 18:40:45 +0000110 cmd_args.extend(['-arch',
111 arglist.getValue(arch)])
Daniel Dunbara5677512009-01-05 19:53:30 +0000112 else:
Daniel Dunbardb439902009-01-07 18:40:45 +0000113 cmd_args.extend(arglist.render(arch))
114 cmd_args.append('-force_cpusubtype_ALL')
Daniel Dunbara5677512009-01-05 19:53:30 +0000115 if isinstance(output, Arguments.DerivedArg):
Daniel Dunbardb439902009-01-07 18:40:45 +0000116 cmd_args.extend(['-o', arglist.getValue(output)])
Daniel Dunbara5677512009-01-05 19:53:30 +0000117 else:
Daniel Dunbardb439902009-01-07 18:40:45 +0000118 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000119 if isinstance(input.source, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +0000120 cmd_args.append('-')
Daniel Dunbara5677512009-01-05 19:53:30 +0000121 else:
Daniel Dunbardb439902009-01-07 18:40:45 +0000122 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000123 jobs.addJob(Jobs.Command('as', cmd_args))
124
125class Collect2Tool(Tool):
126 kCollect2Path = '/usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2'
127 def __init__(self):
128 super(Collect2Tool, self).__init__('collect2')
129
130 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000131 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000132 assert outputType is Types.ImageType
133
134 cmd_args = []
135 for arg in args:
136 if arg.opt:
137 if arg.opt.name in ('-framework',):
Daniel Dunbardb439902009-01-07 18:40:45 +0000138 cmd_args.extend(arglist.render(arg))
Daniel Dunbara5677512009-01-05 19:53:30 +0000139 for input in inputs:
Daniel Dunbardb439902009-01-07 18:40:45 +0000140 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000141 if isinstance(output, Arguments.DerivedArg):
Daniel Dunbardb439902009-01-07 18:40:45 +0000142 cmd_args.extend(['-o', arglist.getValue(output)])
Daniel Dunbara5677512009-01-05 19:53:30 +0000143 else:
Daniel Dunbardb439902009-01-07 18:40:45 +0000144 cmd_args.extend(arglist.render(output))
145 cmd_args.extend(['-L/usr/lib/gcc/i686-apple-darwin10/4.2.1',
146 '-lcrt1.10.5.o',
147 '-lgcc_s.10.5',
148 '-lgcc',
149 '-lSystem'])
Daniel Dunbara5677512009-01-05 19:53:30 +0000150 jobs.addJob(Jobs.Command(self.kCollect2Path, cmd_args))
151
152class LipoTool(Tool):
153 def __init__(self):
154 super(LipoTool, self).__init__('lipo')
155
156 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000157 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000158 assert outputType is Types.ImageType
159
Daniel Dunbardb439902009-01-07 18:40:45 +0000160 cmd_args = ['-create']
Daniel Dunbara5677512009-01-05 19:53:30 +0000161 if isinstance(output, Arguments.DerivedArg):
Daniel Dunbardb439902009-01-07 18:40:45 +0000162 cmd_args.extend(['-o', arglist.getValue(output)])
Daniel Dunbara5677512009-01-05 19:53:30 +0000163 else:
Daniel Dunbardb439902009-01-07 18:40:45 +0000164 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000165 for input in inputs:
Daniel Dunbardb439902009-01-07 18:40:45 +0000166 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000167 jobs.addJob(Jobs.Command('lipo', cmd_args))