move -j and -mj to global config
authorTimo Savola <tsavola@movial.fi>
Tue, 8 Apr 2008 15:26:55 +0000 (18:26 +0300)
committerTimo Savola <tsavola@movial.fi>
Tue, 8 Apr 2008 15:26:55 +0000 (18:26 +0300)
matrix/build.py
matrix/config.py
matrix/matrix.py

index 84fb33c..094e7a9 100644 (file)
@@ -14,7 +14,7 @@ import log
 Error = RuntimeError
 InternalError = Exception
 
-def build(targets, build_jobs=1, make_jobs=1):
+def build(targets):
        selected = set([config.components[i] for i in targets])
        components.fill_in_depends(selected)
        components.init_rdepends(selected)
@@ -38,7 +38,7 @@ def build(targets, build_jobs=1, make_jobs=1):
 
        del flat
 
-       Builder(roots, count, build_jobs, make_jobs).run()
+       Builder(roots, count).run()
 
        unbuilt = []
        for c in selected:
@@ -96,10 +96,7 @@ def compare_weight(a, b):
        return cmp(a.weight, b.weight)
 
 class Builder(object):
-       def __init__(self, roots, count, max_jobs, max_make_jobs):
-               self.max_jobs = max_jobs
-               self.max_make_jobs = max_make_jobs
-
+       def __init__(self, roots, count):
                self.jobs = {}
 
                self.wait_build = roots
@@ -163,7 +160,7 @@ class Builder(object):
 
        def can_start_job(self):
                return (not self.error or config.keep_going) and \
-                      len(self.jobs) < self.max_jobs
+                      len(self.jobs) < config.jobs
 
        def start_build(self, c):
                if not c.repo.exists():
@@ -178,7 +175,7 @@ class Builder(object):
 
        def start_job(self, c, make_target, state):
                c.state = state
-               pid = spawn_make(c, self.max_make_jobs, make_target)
+               pid = spawn_make(c, make_target)
                self.jobs[pid] = c
 
        def wait(self):
@@ -264,14 +261,14 @@ class Progress(object):
                        str = str[index+1:]
                        self.newline = True
 
-def spawn_make(c, jobs, target):
+def spawn_make(c, target):
        board = config.boards[config.board]
 
        make = os.getenv('MAKE', 'make')
        makefile = os.path.join(config.script_dir, 'matrix.mak')
        workdir = os.path.join(config.top_dir, 'src', c.name)
        args = [make, '--no-print-directory', '-f', makefile, '-C', workdir,
-               '-j', str(jobs), target,
+               '-j', str(config.make_jobs), target,
                'MATRIX_TOPDIR='    + os.path.abspath(config.top_dir),
                'MATRIX_SCRIPTDIR=' + os.path.abspath(config.script_dir),
                'MATRIX_COMPONENT=' + c.name,
index efdef4f..2ca4f20 100644 (file)
@@ -20,6 +20,8 @@ verbose = False
 debug = False
 force = False
 keep_going = False
+jobs = 1
+make_jobs = 1
 
 class Board(object):
        def __init__(self, name, arch, gcc_march, gcc_mcpu='', gcc_mfpu='', gcc_options='', gnu_host='', flash_erase_size='65536', flash_pad_size='0'):
index 87f4b68..a4309bd 100644 (file)
@@ -48,7 +48,7 @@ def main():
                targets = all_targets
 
        if command == 'install':
-               build(targets, **params)
+               build(targets)
        elif command == 'clone':
                clone(targets)
        elif command == 'clean':
@@ -82,13 +82,13 @@ Options:
                        specified multiple times.
        -f              Build components with dirty files.
        -k              Build as much as possible after an error.
+       -j N            Execute N build jobs in parallel.
+       -mj N           Run component builds with make -j N.
        -h, --help      Print this help text.
 
 Commands and parameters:
        clone           Download the components' git repositories.
        install         Download, build and install the components.
-               -j N            Execute N build jobs in parallel.
-               -mj N           Run component builds with make -j N.
        clean           Remove all non-tracked files from the component git
                        repository directories.
        rebase          Update repositories from server by rebasing.
@@ -127,20 +127,17 @@ def parse_args(args):
                                        config.force = True
                                elif args[i] == '-k':
                                        config.keep_going = True
+                               elif args[i] == '-j':
+                                       i += 1
+                                       config.jobs = parse_jobs(args[i])
+                               elif args[i] == '-mj':
+                                       i += 1
+                                       config.make_jobs = parse_jobs(args[i])
                                elif args[i] in ('-h', '--help'):
                                        help(sys.stdout, args)
                                        sys.exit(0)
                                else:
                                        raise Error('Bad option: ' + args[i])
-                       elif command == 'install':
-                               if args[i] == '-j':
-                                       i += 1
-                                       params['build_jobs'] = parse_jobs(args[i])
-                               elif args[i] == '-mj':
-                                       i += 1
-                                       params['make_jobs'] = parse_jobs(args[i])
-                               else:
-                                       raise Error('Bad parameter: ' + args[i])
                        elif command == 'rootfs':
                                if args[i] == '-n':
                                        i += 1