use new-style classes
[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 os as __os
6
7 top_dir = __os.environ.get('MATRIX_TOPDIR', __os.getcwd())
8 cache_dir = __os.path.join(top_dir, '.mtxbld-cache')
9 global_cache_dir = '/usr/share/matrix/build-cache'
10
11 boards = {}
12 board = None
13 components = {}
14 roots = []
15 flags = []
16 libc = 'glibc'
17 verbose = False
18 debug = False
19
20 class Board(object):
21         def __init__(self, name, arch, gcc_march, gcc_mcpu='', gcc_mfpu='', gcc_options='', gnu_host='', flash_erase_size='65536', flash_pad_size='0'):
22                 self.name = name
23                 self.arch = arch
24                 self.gcc_march = gcc_march
25                 self.gcc_mcpu = gcc_mcpu
26                 self.gcc_mfpu = gcc_mfpu
27                 self.gcc_options = gcc_options
28                 self.gnu_host = gnu_host
29                 self.flash_erase_size = flash_erase_size
30                 self.flash_pad_size = flash_pad_size
31
32                 boards[name] = self
33
34 class Component(object):
35         import git
36
37         from_platform = False
38
39         def __init__(self, name, tag='matrix', tags={}, flags=[]):
40                 self.name = name
41
42                 self.tags = {}
43                 self.tags.update(tags)
44                 self.tags[None] = tag
45
46                 self.flags = flags
47
48                 self.active_url = None
49                 self.__active_tag = None
50                 self.active_packages = None
51                 self.active_depends = None
52                 self.__active_hash = None
53                 self.active_state = None
54
55                 components[name] = self
56
57         def get_active_tag(self):
58                 global board
59
60                 if self.__active_tag is None:
61                         tag = self.tags.get(board)
62                         if not tag:
63                                 tag = self.tags.get(None)
64                         self.__active_tag = tag
65
66                 return self.__active_tag
67
68         def get_active_hash(self):
69                 if self.__active_hash is None:
70                         self.__active_hash \
71                             = self.git.rev_parse(self.name, 'HEAD')
72
73                 return self.__active_hash
74
75 class PlatformProvidedComponent(Component):
76         """A Component that is provided by the platform.
77            The sources will not be built during install."""
78
79         from_platform = True