matrix-rootfs: add jffs2_extra_args
[matrix.git] / matrix / config.py
index b7e4967..2b926fa 100644 (file)
@@ -1,16 +1,17 @@
-# 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 sre
+import re
 from glob import glob
 from os import getenv
-from os.path import basename, exists, isabs, join
+from os.path import basename, exists, isabs, isdir, join
 from sets import Set as set
 
 Error = RuntimeError
 
-exclude = sre.compile(r'^[.#].*|.*[~#]$')
+exclude = re.compile(r'^[.#].*|.*[~#]$')
 
 def _make_list(arg):
        if arg is None:
@@ -21,6 +22,44 @@ def _make_list(arg):
 
        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,
                     gcc_mcpu=None,
@@ -33,7 +72,10 @@ class Board(object):
                     ubifs_leb_size=0,
                     ubifs_max_leb_count=0,
                     ubifs_min_io_size=0,
-                    ubinize_config_vol_size=0):
+                    ubinize_config_vol_size=0,
+                    cleanmarkers="unknown",
+                    jffs2_extra_args="",
+                    flags=[]):
 
                self.name = name
                self.arch = arch
@@ -49,6 +91,9 @@ class Board(object):
                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
 
@@ -70,8 +115,8 @@ def parse(pattern, require=True):
        if isabs(pattern):
                dirs = [None]
        else:
-               all_confdirs = config.confdirs + config.initial_confdirs
-               dirs = [join(config.top_dir, dir) for dir in all_confdirs]
+               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)
 
        found = False
@@ -86,7 +131,7 @@ def parse(pattern, require=True):
                        if config.debug:
                                print 'Parsing', path
 
-                       execfile(path, actions, config.__dict__)
+                       execfile(path, actions.copy(), {})
 
        if not found:
                msg = 'Config file(s) not found: %s' % pattern
@@ -95,10 +140,85 @@ def parse(pattern, require=True):
                elif config.debug:
                        print msg
 
+def set_flag(name):
+       config.flags.add(name)
+
+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.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
+
 class Config(object):
        def __init__(self):
-               self.initial_confdirs = []
-               self.confdirs = []
+               self.initial_config_dirs = []
+               self.config_dirs = []
 
                self.top_dir = getenv('MATRIX_TOPDIR', '')
                __cache_dir = join(self.top_dir, 'build-cache')
@@ -110,21 +230,48 @@ class Config(object):
                self.components = {}
                self.roots = []
                self.flags = set()
-               self.libc = 'glibc'
                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,
-       ProvideComponent = provide_component,
+       ConfigDir = config_dir,
+       GetVariables = get_variables,
        Parse = parse,
-
-       set = set,
+       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()
+