]>
git.saurik.com Git - wxWidgets.git/blob - build/tools/builder.py
6 class BuildError(Exception):
7 def __init__(self
, value
):
11 return repr(self
.value
)
13 def runInDir(command
, dir=None, verbose
=True):
18 commandStr
= " ".join(command
)
21 result
= os
.system(commandStr
)
30 Base class exposing the Builder interface.
33 def __init__(self
, formatName
="", commandName
="", programDir
=None):
35 formatName = human readable name for project format (should correspond with Bakefile names)
36 commandName = name of command line program used to invoke builder
37 programDir = directory program is located in, if not on the path
41 self
.name
= commandName
42 self
.formatName
= formatName
43 self
.programDir
= programDir
48 Do anything special needed to configure the environment to build with this builder.
53 def isAvailable(self
):
55 Run sanity checks before attempting to build with this format
57 # Make sure the builder program exists
58 programPath
= self
.getProgramPath()
59 if os
.path
.exists(programPath
):
62 # check the PATH for the program
63 # TODO: How do we check if we're in Cygwin?
64 if sys
.platform
.startswith("win"):
65 result
= os
.system(self
.name
)
68 dirs
= os
.environ
["PATH"].split(":")
71 if os
.path
.isfile(os
.path
.join(dir, self
.name
)):
75 result
= os
.system("which %s" % self
.name
)
82 def getProgramPath(self
):
84 path
= os
.path
.join(self
.programDir
, self
.name
)
85 if sys
.platform
.startswith("win"):
91 def getProjectFileArg(self
, projectFile
= None):
94 result
.append(projectFile
)
97 def clean(self
, dir=None, projectFile
=None, options
=[]):
99 dir = the directory containing the project file
100 projectFile = Some formats need to explicitly specify the project file's name
102 if self
.isAvailable():
103 args
= [self
.getProgramPath()]
104 args
.extend(self
.getProjectFileArg(projectFile
))
108 result
= runInDir(args
, dir)
113 def configure(self
, dir=None, options
=[]):
114 # if we don't have configure, just report success
117 def build(self
, dir=None, projectFile
=None, targets
=None, options
=[]):
118 if self
.isAvailable():
119 args
= [self
.getProgramPath()]
120 args
.extend(self
.getProjectFileArg(projectFile
))
123 result
= runInDir(args
, dir)
129 def install(self
, dir=None, projectFile
=None, options
=[]):
130 if self
.isAvailable():
131 args
= [self
.getProgramPath()]
132 args
.extend(self
.getProjectFileArg(projectFile
))
133 args
.append("install")
135 result
= runInDir(args
, dir)
140 # Concrete subclasses of abstract Builder interface
142 class GNUMakeBuilder(Builder
):
143 def __init__(self
, commandName
="make", formatName
="GNUMake"):
144 Builder
.__init
__(self
, commandName
=commandName
, formatName
=formatName
)
147 class XcodeBuilder(Builder
):
148 def __init__(self
, commandName
="xcodebuild", formatName
="Xcode"):
149 Builder
.__init
__(self
, commandName
=commandName
, formatName
=formatName
)
152 class AutoconfBuilder(GNUMakeBuilder
):
153 def __init__(self
, formatName
="autoconf"):
154 GNUMakeBuilder
.__init
__(self
, formatName
=formatName
)
156 def configure(self
, dir=None, options
=None):
157 #olddir = os.getcwd()
162 configdir
= os
.getcwd()
165 while os
.path
.exists(configdir
):
166 config_cmd
= os
.path
.join(configdir
, "configure")
167 if not os
.path
.exists(config_cmd
):
168 parentdir
= os
.path
.abspath(os
.path
.join(configdir
, ".."))
169 if configdir
== parentdir
:
172 configdir
= parentdir
174 configure_cmd
= config_cmd
177 if not configure_cmd
:
178 sys
.stderr
.write("Could not find configure script at %r. Have you run autoconf?\n" % dir)
181 optionsStr
= " ".join(options
) if options
else ""
182 command
= "%s %s" % (configure_cmd
, optionsStr
)
184 result
= os
.system(command
)
189 class MSVCBuilder(Builder
):
190 def __init__(self
, commandName
="nmake.exe"):
191 Builder
.__init
__(self
, commandName
=commandName
, formatName
="msvc")
193 def isAvailable(self
):
194 PATH
= os
.environ
['PATH'].split(os
.path
.pathsep
)
196 if os
.path
.exists(os
.path
.join(p
, self
.name
)):
200 def getProjectFileArg(self
, projectFile
= None):
203 result
.extend(['-f', projectFile
])
208 class MSVCProjectBuilder(Builder
):
210 Builder
.__init
__(self
, commandName
="VCExpress.exe", formatName
="msvcProject")
211 for key
in ["VS90COMNTOOLS", "VC80COMNTOOLS", "VC71COMNTOOLS"]:
212 if os
.environ
.has_key(key
):
213 self
.programDir
= os
.path
.join(os
.environ
[key
], "..", "IDE")
215 if self
.programDir
== None:
216 for version
in ["9.0", "8", ".NET 2003"]:
217 msvcDir
= "C:\\Program Files\\Microsoft Visual Studio %s\\Common7\\IDE" % version
218 if os
.path
.exists(msvcDir
):
219 self
.programDir
= msvcDir
221 def isAvailable(self
):
223 path
= os
.path
.join(self
.programDir
, self
.name
)
224 if os
.path
.exists(path
):
227 # I don't have commercial versions of MSVC so I can't test this
229 path
= os
.path
.join(self
.programDir
, name
)
230 if os
.path
.exists(path
):
231 self
.name
= "devenv.com"
236 builders
= [GNUMakeBuilder
, XcodeBuilder
, AutoconfBuilder
, MSVCBuilder
, MSVCProjectBuilder
]
238 def getAvailableBuilders():
239 availableBuilders
= {}
240 for symbol
in builders
:
241 thisBuilder
= symbol()
242 if thisBuilder
.isAvailable():
243 availableBuilders
[thisBuilder
.formatName
] = symbol
245 return availableBuilders