]>
git.saurik.com Git - wxWidgets.git/blob - build/tools/builder.py
a61ca3d2b28fad226021feb770ba335a13bbc8cb
7 class BuildError(Exception):
8 def __init__(self
, value
):
12 return repr(self
.value
)
14 def runInDir(command
, dir=None, verbose
=True):
19 commandStr
= " ".join(command
)
22 result
= os
.system(commandStr
)
31 Base class exposing the Builder interface.
34 def __init__(self
, formatName
="", commandName
="", programDir
=None):
36 formatName = human readable name for project format (should correspond with Bakefile names)
37 commandName = name of command line program used to invoke builder
38 programDir = directory program is located in, if not on the path
42 self
.name
= commandName
43 self
.formatName
= formatName
44 self
.programDir
= programDir
49 Do anything special needed to configure the environment to build with this builder.
54 def isAvailable(self
):
56 Run sanity checks before attempting to build with this format
58 # Make sure the builder program exists
59 programPath
= self
.getProgramPath()
60 if os
.path
.exists(programPath
):
63 # check the PATH for the program
64 # TODO: How do we check if we're in Cygwin?
65 if sys
.platform
.startswith("win"):
66 result
= os
.system(self
.name
)
69 dirs
= os
.environ
["PATH"].split(":")
72 if os
.path
.isfile(os
.path
.join(dir, self
.name
)):
76 result
= os
.system("which %s" % self
.name
)
83 def getProgramPath(self
):
85 path
= os
.path
.join(self
.programDir
, self
.name
)
86 if sys
.platform
.startswith("win"):
92 def clean(self
, dir=None, projectFile
=None, options
=None):
94 dir = the directory containing the project file
95 projectFile = Some formats need to explicitly specify the project file's name
97 if self
.isAvailable():
99 optionList
= list(options
)
103 optionList
.insert(0, self
.getProgramPath())
104 optionList
.append("clean")
106 result
= runInDir(optionList
, dir)
111 def configure(self
, options
=None):
112 # if we don't have configure, just report success
115 def build(self
, dir=None, projectFile
=None, targets
=None, options
=None):
116 if self
.isAvailable():
118 optionList
= list(options
)
122 optionList
.insert(0, self
.getProgramPath())
124 result
= runInDir(optionList
, dir)
130 def install(self
, dir=None, options
=None):
131 if self
.isAvailable():
133 args
= ["make", "install"]
136 result
= runInDir(args
, dir)
141 # Concrete subclasses of abstract Builder interface
143 class GNUMakeBuilder(Builder
):
144 def __init__(self
, commandName
="make", formatName
="GNUMake"):
145 Builder
.__init
__(self
, commandName
=commandName
, formatName
=formatName
)
148 class XcodeBuilder(Builder
):
149 def __init__(self
, commandName
="xcodebuild", formatName
="Xcode"):
150 Builder
.__init
__(self
, commandName
=commandName
, formatName
=formatName
)
153 class AutoconfBuilder(GNUMakeBuilder
):
154 def __init__(self
, formatName
="autoconf"):
155 GNUMakeBuilder
.__init
__(self
, formatName
=formatName
)
157 def configure(self
, dir=None, options
=None):
158 #olddir = os.getcwd()
163 configdir
= os
.getcwd()
166 while os
.path
.exists(configdir
):
167 config_cmd
= os
.path
.join(configdir
, "configure")
168 if not os
.path
.exists(config_cmd
):
169 parentdir
= os
.path
.abspath(os
.path
.join(configdir
, ".."))
170 if configdir
== parentdir
:
173 configdir
= parentdir
175 configure_cmd
= config_cmd
178 if not configure_cmd
:
179 sys
.stderr
.write("Could not find configure script at %r. Have you run autoconf?\n" % dir)
182 optionsStr
= string
.join(options
, " ") if options
else ""
183 command
= "%s %s" % (configure_cmd
, optionsStr
)
185 result
= os
.system(command
)
190 class MSVCBuilder(Builder
):
192 Builder
.__init
__(self
, commandName
="nmake.exe", formatName
="msvc")
194 def isAvailable(self
):
195 PATH
= os
.environ
['PATH'].split(os
.path
.pathsep
)
197 if os
.path
.exists(os
.path
.join(p
, self
.name
)):
202 class MSVCProjectBuilder(Builder
):
204 Builder
.__init
__(self
, commandName
="VCExpress.exe", formatName
="msvcProject")
205 for key
in ["VS90COMNTOOLS", "VC80COMNTOOLS", "VC71COMNTOOLS"]:
206 if os
.environ
.has_key(key
):
207 self
.programDir
= os
.path
.join(os
.environ
[key
], "..", "IDE")
209 if self
.programDir
== None:
210 for version
in ["9.0", "8", ".NET 2003"]:
211 msvcDir
= "C:\\Program Files\\Microsoft Visual Studio %s\\Common7\\IDE" % version
212 if os
.path
.exists(msvcDir
):
213 self
.programDir
= msvcDir
215 def isAvailable(self
):
217 path
= os
.path
.join(self
.programDir
, self
.name
)
218 if os
.path
.exists(path
):
221 # I don't have commercial versions of MSVC so I can't test this
223 path
= os
.path
.join(self
.programDir
, name
)
224 if os
.path
.exists(path
):
225 self
.name
= "devenv.com"
230 builders
= [GNUMakeBuilder
, XcodeBuilder
, AutoconfBuilder
, MSVCBuilder
, MSVCProjectBuilder
]
232 def getAvailableBuilders():
233 availableBuilders
= {}
234 for symbol
in builders
:
235 thisBuilder
= symbol()
236 if thisBuilder
.isAvailable():
237 availableBuilders
[thisBuilder
.formatName
] = symbol
239 return availableBuilders