build.py'yi biraz düzenledim.

This commit is contained in:
Barış Metin
2005-07-04 15:57:40 +00:00
parent 58ba460834
commit 27f3486386
+69 -80
View File
@@ -66,6 +66,12 @@ class PisiBuild:
self.spec = self.ctx.spec self.spec = self.ctx.spec
self.sourceArchive = SourceArchive(self.ctx) self.sourceArchive = SourceArchive(self.ctx)
self.setEnvorinmentVars()
self.actionLocals = None
self.actionGlobals = None
self.srcDir = None
def build(self): def build(self):
"""Build the package in one shot.""" """Build the package in one shot."""
ui.info("Building PISI source package: %s\n" % self.spec.source.name) ui.info("Building PISI source package: %s\n" % self.spec.source.name)
@@ -81,7 +87,43 @@ class PisiBuild:
self.sourceArchive.unpack() self.sourceArchive.unpack()
ui.info(" unpacked (%s)\n" % self.ctx.pkg_work_dir()) ui.info(" unpacked (%s)\n" % self.ctx.pkg_work_dir())
# Compile actions.py self.compileActionScript()
self.srcDir = self.pkgSrcDir()
self.applyPatches()
# we'll need our working directory after actionscript
# finished its work in the archive source directory.
curDir = os.getcwd()
os.chdir(self.srcDir)
# Run configure, build and install phase
ui.info("Setting up source...\n")
self.runActionFunction(const.setup_func)
ui.info("Building source...\n")
self.runActionFunction(const.build_func)
ui.info("Intalling...\n")
# install function is mandatory!
self.runActionFunction(const.install_func, True)
os.chdir(curDir)
# after all, we are ready to build/prepare the packages
self.buildPackages()
def setEnvorinmentVars(self):
"""Sets the environment variables for actions API to use"""
evn = {
"PKG_DIR": self.ctx.pkg_dir(),
"WORK_DIR": self.ctx.pkg_work_dir(),
"INSTALL_DIR": self.ctx.pkg_install_dir(),
"SRC_NAME": self.spec.source.name,
"SRC_VERSION": self.spec.source.version,
"SRC_RELEASE": self.spec.source.release
}
os.environ.update(evn)
def compileActionScript(self):
try: try:
specdir = os.path.dirname(self.ctx.pspecfile) specdir = os.path.dirname(self.ctx.pspecfile)
self.actionScript = open("/".join([specdir, \ self.actionScript = open("/".join([specdir, \
@@ -91,33 +133,40 @@ class PisiBuild:
return return
localSymbols = globalSymbols = {} localSymbols = globalSymbols = {}
# Set needed evironment variables for actions API
self.setEnvorinment()
try: try:
exec compile(self.actionScript , "error", "exec") in localSymbols, \ exec compile(self.actionScript , "error", "exec") in \
globalSymbols localSymbols, globalSymbols
except SyntaxError, e: except SyntaxError, e:
ui.error ("Error : %s\n" % e) ui.error ("Error : %s\n" % e)
return return
# Get the source directory self.actionLocals = localSymbols
self.srcDir = self.pkgSrcDir(globalSymbols) self.actionGlobals = globalSymbols
# apply patches from specfile def pkgSrcDir(self):
self.applyPatches() """Returns the real path of WorkDir for an unpacked archive."""
if 'WorkDir' in self.actionGlobals:
path = os.path.join(self.ctx.pkg_work_dir(),
self.actionGlobals['WorkDir'])
else:
path = os.path.join(self.ctx.pkg_work_dir(),
self.spec.source.name + "-" + \
self.spec.source.version)
#we'll need this our working directory after actionscript if not os.path.exists(path):
#finished its work in the work_dir ui.error ("No such file or directory: %s\n" % e)
curDir = os.getcwd() sys.exit(1)
os.chdir(self.srcDir) return path
# Run configure, build and install phase def runActionFunction(self, func, mandatory=False):
self.configureSource(localSymbols) """Calls the corresponding function in actions.py.
self.buildSource(localSymbols)
self.installSource(localSymbols)
os.chdir(curDir) If mandatory parameter is True, and function is not present in
# after all, we are ready to build/prepare the packages actionLocals PisiBuildError will be raised."""
self.buildPackages() if func in self.actionLocals:
self.actionLocals[func]()
else:
if mandatory:
PisiBuildError, "unable to call function from actions: %s" %func
def solveBuildDependencies(self): def solveBuildDependencies(self):
"""pre-alpha: fail if dependencies not satisfied""" """pre-alpha: fail if dependencies not satisfied"""
@@ -137,66 +186,6 @@ class PisiBuild:
ui.info("Applying patch: %s\n" % patch.filename) ui.info("Applying patch: %s\n" % patch.filename)
util.do_patch(self.srcDir, patchFile, level=patch.level) util.do_patch(self.srcDir, patchFile, level=patch.level)
def setEnvorinment(self):
"""Sets the environment variables for actions API to use"""
evn = {
"PKG_DIR": self.ctx.pkg_dir(),
"WORK_DIR": self.ctx.pkg_work_dir(),
"INSTALL_DIR": self.ctx.pkg_install_dir(),
"SRC_NAME": self.spec.source.name,
"SRC_VERSION": self.spec.source.version,
"SRC_RELEASE": self.spec.source.release
}
os.environ.update(evn)
def pkgSrcDir(self, globalSymbols):
"""Returns the real path of WorkDir for an unpacked archive."""
if 'WorkDir' in globalSymbols:
path = os.path.join(self.ctx.pkg_work_dir(), globalSymbols['WorkDir'])
else:
path = os.path.join(self.ctx.pkg_work_dir(), self.spec.source.name \
+ "-" + self.spec.source.version)
if not os.path.exists(path):
ui.error ("No such file or directory: %s\n" % e)
sys.exit(1)
return path
def configureSource(self, localSymbols):
"""Calls the corresponding function in actions.py. This time its
const.setup_func which sets up the source tree for building.
setup_func is optional in actions.py. If its present it will
be called, if not nothing will be done."""
func = const.setup_func
if func in localSymbols:
ui.info("Configuring %s...\n" % self.spec.source.name)
localSymbols[func]()
def buildSource(self, localSymbols):
"""Calls the corresponding function in actions.py. This time its
const.build_func which builds the source.
build_func is optional in actions.py. If its present it will
be called, if not nothing will be done."""
func = const.build_func
if func in localSymbols:
ui.info("Building %s...\n" % self.spec.source.name)
localSymbols[func]()
def installSource(self, localSymbols):
"""Calls the corresponding function in actions.py. This time its
const.install_func which will install the build source.
install_func is _mandatory_ in actions.py. If its present it will
be called, if not package building process will _fail_."""
func = const.install_func
ui.info("Installing %s...\n" % self.spec.source.name)
if func in localSymbols:
localSymbols[func]()
else:
raise PisiBuildError, "install function is not defined in actions.py!"
def genMetaDataXml(self, package): def genMetaDataXml(self, package):
"""Generate the metadata.xml file for build source. """Generate the metadata.xml file for build source.