matrix-rootfs: add jffs2_extra_args
[matrix.git] / matrix / config.py
index 45d1c82..2b926fa 100644 (file)
@@ -1,8 +1,64 @@
-# Copyright (C) 2007-2008 Movial Oy
-# Authors: Timo Savola <tsavola@movial.fi>
-#          Kalle Vahlman <kalle.vahlman@movial.fi>
+# Copyright (C) 2007-2009 Movial Creative Technologies Inc.
+# Authors: Timo Savola
+#          Kalle Vahlman <kalle.vahlman@movial.com>
+#          Daniel Bainton <daniel.bainton@movial.com>
 
-import os
+import re
+from glob import glob
+from os import getenv
+from os.path import basename, exists, isabs, isdir, join
+from sets import Set as set
+
+Error = RuntimeError
+
+exclude = re.compile(r'^[.#].*|.*[~#]$')
+
+def _make_list(arg):
+       if arg is None:
+               return []
+
+       if isinstance(arg, basestring):
+               return arg.split()
+
+       return list(arg)
+
+def config_dir(path=None, url=None, branch='master', optional=False):
+       from repositories import Repository
+
+       if not path:
+               if not url:
+                       raise Error('No path or URL specified')
+
+               path = basename(url)
+               if path.endswith('.git'):
+                       path = path[:-4]
+
+       if optional and path not in config.initial_config_dirs:
+               if config.debug:
+                       print 'Skipping', path
+               return
+
+       if url:
+               name = basename(path)
+               repo = Repository(name=name, path=path, url=url, branch=branch)
+
+               if repo.exists():
+                       if config.pull_config_dirs:
+                               repo.pull()
+               else:
+                       repo.clone()
+       else:
+               if not isdir(path):
+                       raise Error('Config dir does not exist: %s' % path)
+
+       if path not in config.initial_config_dirs:
+               config.config_dirs.append(path)
+
+def pull_config_dirs(flag):
+       config.pull_config_dirs = flag
+
+def root(url, branch='master'):
+       config.roots.append((url, branch))
 
 class Board(object):
        def __init__(self, name, arch, gcc_march,
@@ -11,78 +67,211 @@ class Board(object):
                     gcc_options=None,
                     gnu_host=None,
                     flash_erase_size=65536,
-                    flash_pad_size=0):
+                    flash_pad_size=0,
+                    flash_compression=None,
+                    ubifs_leb_size=0,
+                    ubifs_max_leb_count=0,
+                    ubifs_min_io_size=0,
+                    ubinize_config_vol_size=0,
+                    cleanmarkers="unknown",
+                    jffs2_extra_args="",
+                    flags=[]):
+
                self.name = name
                self.arch = arch
                self.gcc_march = gcc_march
                self.gcc_mcpu = gcc_mcpu or ''
                self.gcc_mfpu = gcc_mfpu or ''
-               self.gcc_options = gcc_options or ''
+               self.gcc_options = _make_list(gcc_options)
                self.gnu_host = gnu_host or ''
                self.flash_erase_size = flash_erase_size
                self.flash_pad_size = flash_pad_size
+               self.flash_compression = flash_compression or ''
+               self.ubifs_leb_size = ubifs_leb_size
+               self.ubifs_max_leb_count = ubifs_max_leb_count
+               self.ubifs_min_io_size = ubifs_min_io_size
+               self.ubinize_config_vol_size = ubinize_config_vol_size
+               self.cleanmarkers = cleanmarkers
+               self.jffs2_extra_args = jffs2_extra_args
+               self.flags = flags
 
                config.boards[name] = self
 
-def Component(*args, **kwargs):
+def component(*args, **kwargs):
        import components
 
        c = components.Component(*args, **kwargs)
        config.components[c.name] = c
        return c
 
-def PlatformProvidedComponent(*args, **kwargs):
-       import components
-
-       c = components.PlatformProvidedComponent(*args, **kwargs)
-       config.components[c.name] = c
+def provide_component(name):
+       c = config.components.get(name)
+       if not c:
+               c = component(name)
+       c.cached = True
        return c
 
-def parse(name, required=False):
-       if os.path.isabs(name):
-               path = os.path.join(config.top_dir, name)
+def parse(pattern, require=True):
+       if isabs(pattern):
+               dirs = [None]
        else:
-               path = name
+               config_dirs = config.config_dirs + config.initial_config_dirs
+               dirs = [join(config.top_dir, dir) for dir in config_dirs]
+               dirs.append(config.top_dir)
 
-       if os.path.exists(path):
-               if config.debug:
-                       print 'Parsing', path
+       found = False
 
-               execfile(path, actions, config.__dict__)
-       else:
-               msg = 'Config file not found: %s' % name
-               if required:
-                       raise RuntimeError(msg)
+       for dir in dirs:
+               for path in glob(join(dir, pattern)):
+                       if exclude.match(basename(path)):
+                               continue
+
+                       found = True
+
+                       if config.debug:
+                               print 'Parsing', path
+
+                       execfile(path, actions.copy(), {})
+
+       if not found:
+               msg = 'Config file(s) not found: %s' % pattern
+               if require:
+                       raise Error(msg)
                elif config.debug:
                        print msg
 
-actions = dict(
-       Board = Board,
-       Component = Component,
-       PlatformProvidedComponent = PlatformProvidedComponent,
-       parse = parse,
-)
+def set_flag(name):
+       config.flags.add(name)
 
-class Config(object):
+def clear_flag(name):
+       config.flags.discard(name)
+
+def use_board(name):
+       config.board = name
+
+def cache_dir(path):
+       config.cache_dir = path
+
+def sb2_target(name):
+       config.sb2_target = name
+
+def sb2_compiler(path):
+       config.sb2_compiler = path
+
+def sb2_init_options(args):
+       config.sb2_init_options = list(args)
+
+def get_variables():
+       return config
+
+def rootfs_root(path, target = None):
+       rootfs.path = path
+       rootfs.target = target
+
+def include_paths(paths):
+       rootfs.include_paths.extend(paths)
+
+def include_files(files):
+       rootfs.include_files.extend(files)
+
+def exclude_paths(paths):
+       rootfs.exclude_paths.extend(paths)
+
+def exclude_files(files):
+       rootfs.exclude_files.extend(files)
+
+def exclude_expressions(expressions):
+       rootfs.exclude_expressions.extend(expressions)
+
+def created_paths(paths):
+       rootfs.created_paths.extend(paths)
+
+def file_modes(modes):
+       rootfs.file_modes.update(modes)
+
+def directory_owners(owners):
+       rootfs.directory_owners.update(owners)
+
+def device_nodes(devices):
+       rootfs.devices.update(devices)
+
+def remove_account(uid=None, gid=None):
+       rootfs.remove_uid = uid
+       rootfs.remove_gid = gid
+
+class RootFS(object):
        def __init__(self):
-               self.top_dir = os.environ.get('MATRIX_TOPDIR', '')
+               self.path = None
+               self.target = None
+               self.include_paths = []
+               self.include_files = []
+               self.exclude_paths = []
+               self.exclude_files = []
+               self.exclude_expressions = []
+               self.created_paths = []
+               self.devices = {}
+               self.file_modes = {}
+               self.directory_owners = {}
+               self.remove_uid = None
+               self.remove_gid = None
 
-               __cache_dir = os.path.join(self.top_dir, 'build-cache')
-               self.cache_dir = os.environ.get('MATRIX_CACHEDIR', __cache_dir)
+class Config(object):
+       def __init__(self):
+               self.initial_config_dirs = []
+               self.config_dirs = []
 
+               self.top_dir = getenv('MATRIX_TOPDIR', '')
+               __cache_dir = join(self.top_dir, 'build-cache')
+               self.cache_dir = getenv('MATRIX_CACHEDIR', __cache_dir)
                self.script_dir = None
 
                self.boards = {}
                self.board = None
                self.components = {}
                self.roots = []
-               self.flags = []
-               self.libc = 'glibc'
+               self.flags = set()
                self.verbose = False
                self.debug = False
+               self.protocol = False
                self.force = False
                self.keep_going = False
+               self.pull_config_dirs = False
                self.jobs = 1
                self.make_jobs = 1
 
+               self.sb2_target = None
+               self.sb2_compiler = None
+               self.sb2_init_options = []
+
+actions = dict(
+       Board = Board,
+       CacheDir = cache_dir,
+       ClearFlag = clear_flag,
+       Component = component,
+       ConfigDir = config_dir,
+       GetVariables = get_variables,
+       Parse = parse,
+       ProvideComponent = provide_component,
+       PullConfigDirs = pull_config_dirs,
+       Root = root,
+       SB2Compiler = sb2_compiler,
+       SB2InitOptions = sb2_init_options,
+       SB2Target = sb2_target,
+       SetFlag = set_flag,
+       UseBoard = use_board,
+       RootFSRootPath = rootfs_root,
+       RootFSPaths = include_paths,
+       RootFSFiles = include_files,
+       RootFSExcludePaths = exclude_paths,
+       RootFSExcludeFiles = exclude_files,
+       RootFSExcludeExpressions = exclude_expressions,
+       RootFSCreatePaths = created_paths,
+       RootFSFileModes = file_modes,
+       RootFSDirectoryOwners = directory_owners,
+       RootFSDeviceNodes = device_nodes,
+       RootFSRemoveAccount = remove_account,
+)
+
 config = Config()
+rootfs = RootFS()
+