rootfs.py: Added support for creating UBI images.
[matrix.git] / matrix / config.py
1 # Copyright (C) 2007-2008 Movial Oy
2 # Authors: Timo Savola <tsavola@movial.fi>
3 #          Kalle Vahlman <kalle.vahlman@movial.fi>
4
5 import sre
6 from glob import glob
7 from os import getenv
8 from os.path import basename, exists, isabs, join
9
10 Error = RuntimeError
11
12 exclude = sre.compile(r'^[.#].*|.*[~#]$')
13
14 class Board(object):
15         def __init__(self, name, arch, gcc_march,
16                      gcc_mcpu=None,
17                      gcc_mfpu=None,
18                      gcc_options=None,
19                      gnu_host=None,
20                      flash_erase_size=65536,
21                      flash_pad_size=0,
22                      flash_compression=None,
23                      ubifs_leb_size=0,
24                      ubifs_max_leb_count=0,
25                      ubifs_min_io_size=0,
26                      ubinize_config_vol_size=0):
27                 self.name = name
28                 self.arch = arch
29                 self.gcc_march = gcc_march
30                 self.gcc_mcpu = gcc_mcpu or ''
31                 self.gcc_mfpu = gcc_mfpu or ''
32                 self.gcc_options = gcc_options or ''
33                 self.gnu_host = gnu_host or ''
34                 self.flash_erase_size = flash_erase_size
35                 self.flash_pad_size = flash_pad_size
36                 self.flash_compression = flash_compression or ''
37                 self.ubifs_leb_size = ubifs_leb_size
38                 self.ubifs_max_leb_count = ubifs_max_leb_count
39                 self.ubifs_min_io_size = ubifs_min_io_size
40                 self.ubinize_config_vol_size = ubinize_config_vol_size
41
42                 config.boards[name] = self
43
44 def Component(*args, **kwargs):
45         import components
46
47         c = components.Component(*args, **kwargs)
48         config.components[c.name] = c
49         return c
50
51 def PlatformProvidedComponent(*args, **kwargs):
52         import components
53
54         c = components.PlatformProvidedComponent(*args, **kwargs)
55         config.components[c.name] = c
56         return c
57
58 def parse(pattern, required=False):
59         if isabs(pattern):
60                 dirs = [None]
61         else:
62                 dirs = [join(config.top_dir, dir) for dir in config.confdirs]
63                 dirs.insert(0, config.top_dir)
64
65         paths = {}
66         for dir in dirs:
67                 for path in glob(join(dir, pattern)):
68                         name = basename(path)
69                         if not exclude.match(name):
70                                 paths[name] = path
71
72         names = paths.keys()
73         names.sort()
74         for name in names:
75                 path = paths[name]
76
77                 if config.debug:
78                         print 'Parsing', path
79
80                 execfile(path, actions, config.__dict__)
81
82         if not paths:
83                 msg = 'Config file(s) not found: %s' % pattern
84                 if required:
85                         raise Error(msg)
86                 elif config.debug:
87                         print msg
88
89 class Config(object):
90         def __init__(self):
91                 self.confdirs = []
92
93                 self.top_dir = getenv('MATRIX_TOPDIR', '')
94                 __cache_dir = join(self.top_dir, 'build-cache')
95                 self.cache_dir = getenv('MATRIX_CACHEDIR', __cache_dir)
96                 self.script_dir = None
97
98                 self.boards = {}
99                 self.board = None
100                 self.components = {}
101                 self.roots = []
102                 self.flags = []
103                 self.libc = 'glibc'
104                 self.verbose = False
105                 self.debug = False
106                 self.force = False
107                 self.keep_going = False
108                 self.jobs = 1
109                 self.make_jobs = 1
110
111 actions = dict(
112         Board = Board,
113         Component = Component,
114         PlatformProvidedComponent = PlatformProvidedComponent,
115         parse = parse,
116 )
117
118 config = Config()