diff options
-rwxr-xr-x | commands/build | 23 | ||||
-rw-r--r-- | commands/common.py | 4 | ||||
-rwxr-xr-x | commands/helpers/build | 18 | ||||
-rw-r--r-- | devbot/build.py | 28 | ||||
-rw-r--r-- | devbot/command.py | 15 | ||||
-rwxr-xr-x | tools/log-command | 11 |
6 files changed, 56 insertions, 43 deletions
diff --git a/commands/build b/commands/build index 71c69be..a8405c8 100755 --- a/commands/build +++ b/commands/build @@ -1,15 +1,18 @@ -#!/bin/bash +#!/usr/bin/python -u -commandsdir=`dirname "$0"` -rootdir=`dirname "$commandsdir"` -logsdir=$rootdir/logs -helpersdir=$commandsdir/helpers +import argparse -timestamp=`date +%Y%m%d-%H%M%S` -logfile=$logsdir/build-$timestamp.log +import common -mkdir -p $logsdir +from devbot import build -PYTHONPATH=$commandsdir $helpersdir/build $@ | tee -a $logfile +parser = argparse.ArgumentParser() +parser.add_argument("module", nargs="?", help="name of the module to build") +args = parser.parse_args() -exit ${PIPESTATUS[0]} +common.setup() + +if args.module: + build.build_one(args.module) +else: + build.build() diff --git a/commands/common.py b/commands/common.py index b26e192..9a8ef41 100644 --- a/commands/common.py +++ b/commands/common.py @@ -9,6 +9,7 @@ sys.path.append(base_dir) from devbot import system from devbot import config from devbot import distro +from devbot import command def setup(): config.load_plugins() @@ -16,6 +17,7 @@ def setup(): relocatable = "SUGAR_BUILDBOT" in os.environ logs_dir = os.path.join(base_dir, "logs") install_dir = os.path.join(base_dir, "install") + tools_dir = os.path.join(base_dir, "tools") config.set_devbot_dir(os.path.join(base_dir, "devbot")) config.set_config_dir(os.path.join(base_dir, "config")) @@ -52,3 +54,5 @@ def setup(): package_files.append("buildslave") config.set_package_files(package_files) + + command.set_logger(os.path.join(tools_dir, "log-command")) diff --git a/commands/helpers/build b/commands/helpers/build deleted file mode 100755 index a8405c8..0000000 --- a/commands/helpers/build +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python -u - -import argparse - -import common - -from devbot import build - -parser = argparse.ArgumentParser() -parser.add_argument("module", nargs="?", help="name of the module to build") -args = parser.parse_args() - -common.setup() - -if args.module: - build.build_one(args.module) -else: - build.build() diff --git a/devbot/build.py b/devbot/build.py index 29c886d..c22449b 100644 --- a/devbot/build.py +++ b/devbot/build.py @@ -4,6 +4,7 @@ import multiprocessing import shutil import sys import subprocess +import time from devbot import command from devbot import config @@ -56,7 +57,8 @@ def build(): state.remove_built_commit_id(module) for module in modules: - if not _build_module(module): + log = "build-%s" % time.strftime("%Y%m%d-%H%M%S") + if not _build_module(module, log): break def clean(): @@ -99,10 +101,10 @@ def _pull_module(module): except subprocess.CalledProcessError: sys.exit(1) -def _build_make(module): - command.run(["make"]) +def _build_make(module, log): + command.run(["make"], log) -def _build_autotools(module): +def _build_autotools(module, log): makefile_path = os.path.join(module.get_build_dir(), "Makefile") if not os.path.exists(makefile_path): @@ -113,19 +115,19 @@ def _build_autotools(module): "--libdir", config.lib_dir] args.extend(module.options) - command.run(args) + command.run(args, log) jobs = multiprocessing.cpu_count() * 2 - command.run(["make", "-j", "%d" % jobs]) - command.run(["make", "install"]) + command.run(["make", "-j", "%d" % jobs], log) + command.run(["make", "install"], log) _unlink_libtool_files() -def _build_activity(module): - command.run(["./setup.py", "install", "--prefix", config.prefix_dir]) +def _build_activity(module, log): + command.run(["./setup.py", "install", "--prefix", config.prefix_dir], log) -def _build_module(module): +def _build_module(module, log): print "\n=== Building %s ===\n" % module.name source_dir = module.get_source_dir() @@ -147,11 +149,11 @@ def _build_module(module): try: if os.path.exists(os.path.join(source_dir, "setup.py")): - _build_activity(module) + _build_activity(module, log) elif os.path.exists(os.path.join(source_dir, "autogen.sh")): - _build_autotools(module) + _build_autotools(module, log) elif os.path.exists(os.path.join(source_dir, "Makefile")): - _build_make(module) + _build_make(module, log) else: print "The source directory has unexpected content, please " \ "delete it and pull\nthe source again." diff --git a/devbot/command.py b/devbot/command.py index 9a8b5e2..aaef58f 100644 --- a/devbot/command.py +++ b/devbot/command.py @@ -1,16 +1,27 @@ import subprocess import time -def run(args, test=False, retry=0): +_logger = None + +def set_logger(logger): + global _logger + _logger = logger + +def run(args, log=None, test=False, retry=0): print " ".join(args) if test: return + full_args = args[:] + if log is not None: + full_args.insert(0, _logger) + full_args.append(log) + tries = 0 while tries < retry + 1: try: tries = tries + 1 - subprocess.check_call(args) + subprocess.check_call(full_args) return except subprocess.CalledProcessError, e: if tries < retry + 1: diff --git a/tools/log-command b/tools/log-command new file mode 100755 index 0000000..3def5f9 --- /dev/null +++ b/tools/log-command @@ -0,0 +1,11 @@ +#!/bin/bash + +toolsdir=`dirname "$0"` +rootdir=`dirname "$toolsdir"` +logsdir=$rootdir/logs + +mkdir -p $logsdir + +${@:(-$#):($#-1)} | tee -a $logsdir/${@: -1:1}.log + +exit ${PIPESTATUS[0]} |