blob: e9d78486c8e17ec22cd105bf52b8cbea5e2d73aa [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:
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +000033 cmd_args.extend(arglist.render(arch))
Daniel Dunbara5677512009-01-05 19:53:30 +000034 if isinstance(output, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +000035 cmd_args.extend(['-o', '-'])
Daniel Dunbara5677512009-01-05 19:53:30 +000036 elif output is None:
Daniel Dunbardb439902009-01-07 18:40:45 +000037 cmd_args.append('-fsyntax-only')
Daniel Dunbara5677512009-01-05 19:53:30 +000038 else:
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +000039 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +000040
Daniel Dunbardb439902009-01-07 18:40:45 +000041 cmd_args.extend(['-x', input.type.name])
Daniel Dunbara5677512009-01-05 19:53:30 +000042 if isinstance(input.source, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +000043 cmd_args.append('-')
Daniel Dunbara5677512009-01-05 19:53:30 +000044 else:
Daniel Dunbardb439902009-01-07 18:40:45 +000045 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +000046
47 jobs.addJob(Jobs.Command('gcc', cmd_args))
48
49class GCC_PreprocessTool(GCC_Common_Tool):
50 def __init__(self):
51 super(GCC_PreprocessTool, self).__init__('gcc',
52 (Tool.eFlagsPipedInput |
53 Tool.eFlagsPipedOutput))
54
55 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000056 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000057 return super(GCC_PreprocessTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000058 output, outputType, args, arglist,
59 ['-E'])
Daniel Dunbara5677512009-01-05 19:53:30 +000060
61class GCC_CompileTool(GCC_Common_Tool):
62 def __init__(self):
63 super(GCC_CompileTool, self).__init__('gcc',
64 (Tool.eFlagsPipedInput |
65 Tool.eFlagsPipedOutput |
66 Tool.eFlagsIntegratedCPP))
67
68 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000069 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000070 return super(GCC_CompileTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000071 output, outputType, args, arglist,
72 ['-S'])
Daniel Dunbara5677512009-01-05 19:53:30 +000073
74class GCC_PrecompileTool(GCC_Common_Tool):
75 def __init__(self):
76 super(GCC_PrecompileTool, self).__init__('gcc',
77 (Tool.eFlagsPipedInput |
78 Tool.eFlagsIntegratedCPP))
79
80 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000081 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000082 return super(GCC_PrecompileTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000083 output, outputType, args, arglist,
Daniel Dunbara5677512009-01-05 19:53:30 +000084 [])
85
86class DarwinAssemblerTool(Tool):
87 def __init__(self):
88 super(DarwinAssemblerTool, self).__init__('as',
89 Tool.eFlagsPipedInput)
90
91 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000092 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000093 assert len(inputs) == 1
94 assert outputType is Types.ObjectType
95
96 input = inputs[0]
97
98 cmd_args = []
99 if arch:
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000100 cmd_args.extend(arglist.render(arch))
Daniel Dunbardb439902009-01-07 18:40:45 +0000101 cmd_args.append('-force_cpusubtype_ALL')
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000102 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000103 if isinstance(input.source, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +0000104 cmd_args.append('-')
Daniel Dunbara5677512009-01-05 19:53:30 +0000105 else:
Daniel Dunbardb439902009-01-07 18:40:45 +0000106 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000107 jobs.addJob(Jobs.Command('as', cmd_args))
108
109class Collect2Tool(Tool):
110 kCollect2Path = '/usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2'
111 def __init__(self):
112 super(Collect2Tool, self).__init__('collect2')
113
114 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000115 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000116 assert outputType is Types.ImageType
117
118 cmd_args = []
119 for arg in args:
Daniel Dunbara75ea3d2009-01-09 22:21:24 +0000120 if arg.opt.name in ('-framework',):
121 cmd_args.extend(arglist.render(arg))
Daniel Dunbara5677512009-01-05 19:53:30 +0000122 for input in inputs:
Daniel Dunbardb439902009-01-07 18:40:45 +0000123 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000124 cmd_args.extend(arglist.render(output))
Daniel Dunbardb439902009-01-07 18:40:45 +0000125 cmd_args.extend(['-L/usr/lib/gcc/i686-apple-darwin10/4.2.1',
126 '-lcrt1.10.5.o',
127 '-lgcc_s.10.5',
128 '-lgcc',
129 '-lSystem'])
Daniel Dunbara5677512009-01-05 19:53:30 +0000130 jobs.addJob(Jobs.Command(self.kCollect2Path, cmd_args))
131
132class LipoTool(Tool):
133 def __init__(self):
134 super(LipoTool, self).__init__('lipo')
135
136 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000137 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000138 assert outputType is Types.ImageType
139
Daniel Dunbardb439902009-01-07 18:40:45 +0000140 cmd_args = ['-create']
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000141 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000142 for input in inputs:
Daniel Dunbardb439902009-01-07 18:40:45 +0000143 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000144 jobs.addJob(Jobs.Command('lipo', cmd_args))