aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slave/TODO1
-rw-r--r--slave/autotua/__init__.py32
-rw-r--r--slave/autotua/bin/jobuild-functions.sh104
-rwxr-xr-xslave/autotua/bin/jobuild.sh13
-rw-r--r--slave/autotua/chroot/__init__.py6
-rw-r--r--slave/autotua/const.py2
-rw-r--r--slave/autotua/jobuild/__init__.py18
-rwxr-xr-xslave/test_modules.py3
8 files changed, 157 insertions, 22 deletions
diff --git a/slave/TODO b/slave/TODO
index 45a8efe..c7a0bd3 100644
--- a/slave/TODO
+++ b/slave/TODO
@@ -5,4 +5,5 @@
Do:
-----
[~] Atom parsing, jobuild searching, etc etc
+[ ] Implement daemonisation of jobuild.sh instead of repeated calling
[ ] Auto-detect SCM of source jobtage repo for syncer.Sync().sync()
diff --git a/slave/autotua/__init__.py b/slave/autotua/__init__.py
index 15d68a4..bdcd56b 100644
--- a/slave/autotua/__init__.py
+++ b/slave/autotua/__init__.py
@@ -84,18 +84,32 @@ class Job:
stage = fetch.Fetchable(uri=uri)
return stage
- # - Get jobuild SRC_URI -> tarball dir
- def _fetch_src(self):
+ # Get jobuild SRC_URI -> $tmpdir/jobfiles
+ # jobfile -(link)-> $chroot_tmpdir/jobfiles
+ def _setup_jobfiles(self):
job_src = []
+ action = 'link'
fetcher = fetch.Fetcher(const.JOBFILE_DIR)
processor = jobuild.Processor(None, self.chroot)
- for one in self.jobuilds:
- processor.jobuild = one
+ for jbld in self.jobuilds:
+ processor.jobuild = jbld
src_uri = processor.get_var('SRC_URI').split()
for i in src_uri:
job_src.append(fetch.Fetchable(uri=[i]))
+ src = fetcher.tarballdir+'/%s'
+ dest = self.chroot.chrootdir+const.CHAUTOTUA_DIR+'/jobfiles/%s'
for fetchable in job_src:
fetcher.fetch(fetchable)
+ src = src % fetchable.filename
+ dest = dest % fetchable.filename
+ if action == 'link':
+ try:
+ os.link(src, dest)
+ except OSError:
+ print "Chroot and Jobfiles are on different devices. Falling back to copying..."
+ action = 'copy'
+ if action == 'copy':
+ shutil.copyfile(src, dest)
def fetch(self):
# Job metadata stuff
@@ -121,11 +135,15 @@ class Job:
# Create jobuild objects for parsing
for atom in self.atoms:
self.jobuilds.append(jobuild.Jobuild(self.jobdir, atom))
- print 'Fetch jobuild SRC_URI...'
- self._fetch_src()
+ print 'Fetch jobuild SRC_URI and hardlink/copy into chroot'
+ self._setup_jobfiles()
def run(self):
- print "Rheeet, it's running!~ NOT."
+ processor = jobuild.Processor(None, self.chroot)
+ for jbld in self.jobuilds:
+ processor.jobuild = jbld
+ print 'Running jobuild "%s"' % jbld.name
+ processor.run_phase('all')
def tidy(self):
print 'Tidying up..'
diff --git a/slave/autotua/bin/jobuild-functions.sh b/slave/autotua/bin/jobuild-functions.sh
index 6dfda9e..c146a1b 100644
--- a/slave/autotua/bin/jobuild-functions.sh
+++ b/slave/autotua/bin/jobuild-functions.sh
@@ -23,15 +23,109 @@ has() {
return 1
}
+# Lifted shamelessly from pkgcore
+unpack() {
+ local x y myfail srcdir taropts tar_subdir
+ taropts='--no-same-owner'
+
+ [ -z "$*" ] && die "Nothing passed to the 'unpack' command"
+
+ for x in "$@"; do
+ echo ">>> Unpacking ${x} to ${PWD}"
+ myfail="failure unpacking ${x}"
+ y="${x%.*}"
+ y="${y##*.}"
+ if [ "${x:0:2}" == "./" ]; then
+ srcdir=''
+ else
+ srcdir="${JOBFILES_DIR}"
+ fi
+
+ [ ! -s "${srcdir}${x}" ] && die "$myfail: empty file"
+ [ "${x/${JOBFILES_DIR}}" != "${x}" ] && \
+ die "Arguments to unpack() should not begin with \${DISTDIR}."
+
+ case "${x}" in
+ *.tar)
+ tar xf "${srcdir}${x}" ${taropts} || die "$myfail"
+ ;;
+ *.tar.gz|*.tgz|*.tar.Z)
+ tar xzf "${srcdir}${x}" ${taropts} || die "$myfail"
+ ;;
+ *.tar.bz2|*.tbz2|*.tbz)
+ bzip2 -dc "${srcdir}${x}" | tar xf - ${taropts}
+ assert "$myfail"
+ ;;
+ *.ZIP|*.zip|*.jar)
+ unzip -qo "${srcdir}${x}" || die "$myfail"
+ ;;
+ *.gz|*.Z|*.z)
+ gzip -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
+ ;;
+ *.bz2|*.bz)
+ bzip2 -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
+ ;;
+ *.7Z|*.7z)
+ local my_output
+ my_output="$(7z x -y "${srcdir}/${x}")"
+ if [ $? -ne 0 ]; then
+ echo "${my_output}" >&2
+ die "$myfail"
+ fi
+ ;;
+ *.RAR|*.rar)
+ unrar x -idq -o+ "${srcdir}/${x}" || die "$myfail"
+ ;;
+ *.LHa|*.LHA|*.lha|*.lzh)
+ lha xfq "${srcdir}/${x}" || die "$myfail"
+ ;;
+ *.a|*.deb)
+ ar x "${srcdir}/${x}" || die "$myfail"
+ ;;
+ *.lzma)
+ if [ "${y}" == "tar" ]; then
+ lzma -dc "${srcdir}${x}" | tar xof - ${taropts}
+ assert "$myfail"
+ else
+ lzma -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
+ fi
+ ;;
+ *)
+ echo "unpack ${x}: file format not recognized. Ignoring."
+ ;;
+ esac
+ done
+ find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
+ xargs -0 chmod -fR a+rX,u+w,g-w,o-w
+
+}
+
+src_unpack() {
+ :
+}
+
get_param() {
- # Param to extract
- local param="${1}"
- local jobuild="${2}"
+ # Param to extract
+ local param="${1}"
+ local jobuild="${2}"
- source "${jobuild}" &>/dev/null
- eval echo \$${param}
+ if ! source "${jobuild}"; then
+ die "Unable to source ${jobuild}"
+ fi
+ eval echo \$${param}
}
get_jobuild_path() {
echo "${AUTOTUA_DIR}/jobtage/${1}"
}
+
+run_all_phases() {
+ local jobuild="${1}"
+
+ if ! source "${jobuild}"; then
+ die "Unable to source ${jobuild}"
+ fi
+ src_unpack
+ do_work
+ cleanup
+}
diff --git a/slave/autotua/bin/jobuild.sh b/slave/autotua/bin/jobuild.sh
index c75e4ee..81a657a 100755
--- a/slave/autotua/bin/jobuild.sh
+++ b/slave/autotua/bin/jobuild.sh
@@ -37,8 +37,17 @@ get_var() {
}
run_phase() {
- echo "Placeholder phase \"runner\""
- echo "Running phase \"${1}\" from \"${2}\""
+ phase="${1}"
+ jobuild="${2}"
+ echo "Running phase \"${phase}\" from \"${jobuild}\""
+ case "${phase}" in
+ all)
+ run_all_phases "${jobuild}" || die "Running all phases failed."
+ ;;
+ *)
+ die "Unknown phase ${phase}"
+ ;;
+ esac
}
case "${1}" in
diff --git a/slave/autotua/chroot/__init__.py b/slave/autotua/chroot/__init__.py
index d30c29b..8899181 100644
--- a/slave/autotua/chroot/__init__.py
+++ b/slave/autotua/chroot/__init__.py
@@ -6,7 +6,7 @@
# Immortal lh!
#
-import os, sys, shutil, subprocess, re
+import os, shutil, subprocess, re
import os.path as osp
from .. import const, sync
from time import strftime
@@ -136,8 +136,8 @@ class WorkChroot(object):
self.tidy()
# self.pristine.dir/ => rsync *contents* to self.chrootdir
sync.Syncer(uri=self.pristine.dir+"/", destdir=self.chrootdir, scheme='rsync-nc').sync()
- os.makedirs('%s/tmp/autotua/bin' % self.chrootdir)
- os.makedirs('%s/tmp/autotua/jobtage' % self.chrootdir)
+ for dir in ['bin', 'jobfiles', 'jobtage', 'src']:
+ os.makedirs('%s/tmp/autotua/%s' % (self.chrootdir, dir))
self._setup_mounts()
print "Work Chroot ready."
diff --git a/slave/autotua/const.py b/slave/autotua/const.py
index de7920c..eea287e 100644
--- a/slave/autotua/const.py
+++ b/slave/autotua/const.py
@@ -51,7 +51,7 @@ job_list = [
'stage': 'gentoo://stage3',
'arch': 'i686',
'type': '',
- 'release': '2008.0_beta2',
+ 'release': '2008.0',
'jobtagerev': '',
#'overlays': ['overlays/bheekling/tag1', 'overlays/bonsaikitten/tag2']
# These are in order of running
diff --git a/slave/autotua/jobuild/__init__.py b/slave/autotua/jobuild/__init__.py
index f435a77..b2d254f 100644
--- a/slave/autotua/jobuild/__init__.py
+++ b/slave/autotua/jobuild/__init__.py
@@ -93,11 +93,11 @@ class Jobuild(object):
return '%(maint)s/%(pn)s/%(pn)s-%(pv)s.jobuild' % data
class Processor(object):
- """Jobuild processor"""
+ """Generic Jobuild processor"""
def __init__(self, jobuild, chroot):
"""
- @param jobuild: Jobuild to process
+ @param jobuild: Jobuild to process. Can be changed anytime
@type jobuild: L{autotua.jobuild.Jobuild}
@param chroot: Chroot to use for processing the jobuild
@@ -107,7 +107,13 @@ class Processor(object):
self.chroot = chroot
def run_phase(self, phase):
- """Run the specified phase of the jobuild"""
+ """
+ Run the specified phase of the jobuild
+ all: Run all the phases
+ unpack: src_unpack()
+ work: do_work()
+ cleanup: cleanup()
+ """
args = {'phase': phase,
'jobuild': self.jobuild.where,
'chroot': self.chroot.chrootdir,}
@@ -124,5 +130,11 @@ class Processor(object):
def _msg(self, msg):
proc = daemon.Spawn(self.chroot.chrootdir, '\"%s\"/bin/jobuild.sh %s' % (const.CHAUTOTUA_DIR, msg))
+ # XXX: This waits for process to close stderr.
+ # Replace with a loop during daemonisation
response = proc.process.stderr.read()[:-1] # Remove trailing newline
+ returncode = proc.process.returncode
+ if returncode and returncode < 0:
+ # FIXME: Custom exceptions
+ raise 'Daemon died with exit code \'%s\'' % -returncode
return response
diff --git a/slave/test_modules.py b/slave/test_modules.py
index db3238d..8b4a21e 100755
--- a/slave/test_modules.py
+++ b/slave/test_modules.py
@@ -35,6 +35,7 @@ if 'job' in modules:
job.fetch()
if os.getuid() == 0:
job.prepare()
+ job.run()
job.tidy()
else:
- print 'You need to be root to run job.prepare()'
+ print 'You need to be root to run job.prepare(), job.run() and job.tidy()'