implement component comparison
[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', '')
8 cache_dir = _os.path.join(top_dir, 'build-cache')
9 global_cache_dir = '/usr/share/matrix/build-cache'
10 script_dir = None
11
12 boards = {}
13 board = None
14 components = {}
15 roots = []
16 flags = []
17 libc = 'glibc'
18 verbose = False
19 debug = False
20 force = False
21
22 class Board(object):
23         def __init__(self, name, arch, gcc_march, gcc_mcpu='', gcc_mfpu='', gcc_options='', gnu_host='', flash_erase_size='65536', flash_pad_size='0'):
24                 self.name = name
25                 self.arch = arch
26                 self.gcc_march = gcc_march
27                 self.gcc_mcpu = gcc_mcpu
28                 self.gcc_mfpu = gcc_mfpu
29                 self.gcc_options = gcc_options
30                 self.gnu_host = gnu_host
31                 self.flash_erase_size = flash_erase_size
32                 self.flash_pad_size = flash_pad_size
33
34                 boards[name] = self
35
36 class _Repository(object):
37         def __init__(self, name, path):
38                 self.name = name
39                 self.path = path
40                 self.active_url = None
41                 self.active_hash = None
42
43 class Component(object):
44         from_platform = False
45
46         def __init__(self, name, tag='master', tags={}, flags=[]):
47                 self.name = name
48
49                 self.repo = _Repository(
50                         'repo/%s' % name, _os.path.join(top_dir, 'src', name))
51                 self.meta = _Repository(
52                         'meta/%s' % name, _os.path.join(top_dir, 'src', name, 'meta'))
53
54                 self.tags = {}
55                 self.tags.update(tags)
56                 self.tags[None] = tag
57
58                 self.flags = flags
59
60                 self.__active_tag = None
61                 self.active_packages = None
62                 self.active_depends = None
63                 self.active_state = None
64
65                 components[name] = self
66
67         def __cmp__(self, other):
68                 return cmp(self.name, other.name)
69
70         def get_active_tag(self):
71                 global board
72
73                 if self.__active_tag is None:
74                         tag = self.tags.get(board)
75                         if not tag:
76                                 tag = self.tags.get(None)
77                         self.__active_tag = tag
78
79                 return self.__active_tag
80
81 class PlatformProvidedComponent(Component):
82         """A Component that is provided by the platform.
83            The sources will not be built during install."""
84
85         from_platform = True