]>
git.saurik.com Git - wxWidgets.git/blob - build/tools/builder.py
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):
94 dir = the directory containing the project file
95 projectFile = Some formats need to explicitly specify the project file's name
98 args
= [self
.getProgramPath(), "clean"]
101 if self
.isAvailable():
102 result
= runInDir(args
)
107 def configure(self
, options
=None):
108 # if we don't have configure, just report success
111 def build(self
, dir=None, projectFile
=None, targets
=None, options
=None):
112 if self
.isAvailable():
114 optionList
= list(options
)
118 optionList
.insert(0, self
.getProgramPath())
120 result
= runInDir(optionList
, dir)
126 def install(self
, dir=None, options
=None):
127 if self
.isAvailable():
129 args
= ["make", "install"]
132 result
= runInDir(args
, dir)
137 # Concrete subclasses of abstract Builder interface
139 class GNUMakeBuilder(Builder
):
140 def __init__(self
, commandName
="make", formatName
="GNUMake"):
141 Builder
.__init
__(self
, commandName
=commandName
, formatName
=formatName
)
144 class XcodeBuilder(Builder
):
145 def __init__(self
, commandName
="xcodebuild", formatName
="Xcode"):
146 Builder
.__init
__(self
, commandName
=commandName
, formatName
=formatName
)
149 class AutoconfBuilder(GNUMakeBuilder
):
150 def __init__(self
, formatName
="autoconf"):
151 GNUMakeBuilder
.__init
__(self
, formatName
=formatName
)
153 def configure(self
, dir=None, options
=None):
154 #olddir = os.getcwd()
159 configdir
= os
.getcwd()
162 while os
.path
.exists(configdir
):
163 config_cmd
= os
.path
.join(configdir
, "configure")
164 if not os
.path
.exists(config_cmd
):
165 parentdir
= os
.path
.abspath(os
.path
.join(configdir
, ".."))
166 if configdir
== parentdir
:
169 configdir
= parentdir
171 configure_cmd
= config_cmd
174 if not configure_cmd
:
175 sys
.stderr
.write("Could not find configure script at %r. Have you run autoconf?\n" % dir)
178 optionsStr
= string
.join(options
, " ") if options
else ""
179 command
= "%s %s" % (configure_cmd
, optionsStr
)
181 result
= os
.system(command
)
186 class MSVCBuilder(Builder
):
188 Builder
.__init
__(self
, commandName
="nmake.exe", formatName
="msvc")
190 def isAvailable(self
):
191 PATH
= os
.environ
['PATH'].split(os
.path
.pathsep
)
193 if os
.path
.exists(os
.path
.join(p
, self
.name
)):
198 class MSVCProjectBuilder(Builder
):
200 Builder
.__init
__(self
, commandName
="VCExpress.exe", formatName
="msvcProject")
201 for key
in ["VS90COMNTOOLS", "VC80COMNTOOLS", "VC71COMNTOOLS"]:
202 if os
.environ
.has_key(key
):
203 self
.prgoramDir
= os
.path
.join(os
.environ
[key
], "..", "IDE")
205 if self
.programDir
== None:
206 for version
in ["9.0", "8", ".NET 2003"]:
207 msvcDir
= "C:\\Program Files\\Microsoft Visual Studio %s\\Common7\\IDE" % version
208 if os
.path
.exists(msvcDir
):
209 self
.programDir
= msvcDir
211 def isAvailable(self
):
213 path
= os
.path
.join(self
.programDir
, self
.name
)
214 if os
.path
.exists(path
):
217 # I don't have commercial versions of MSVC so I can't test this
219 path
= os
.path
.join(self
.programDir
, name
)
220 if os
.path
.exists(path
):
221 self
.name
= "devenv.com"
226 builders
= [GNUMakeBuilder
, XcodeBuilder
, AutoconfBuilder
, MSVCBuilder
, MSVCProjectBuilder
]
228 def getAvailableBuilders():
229 availableBuilders
= {}
230 for symbol
in builders
:
231 thisBuilder
= symbol()
232 if thisBuilder
.isAvailable():
233 availableBuilders
[thisBuilder
.formatName
] = symbol
235 return availableBuilders