~vojtech-horky/helenos/waf

« back to all changes in this revision

Viewing changes to tools/waf/config.py

  • Committer: Vojtech Horky
  • Date: 2012-08-29 14:32:58 UTC
  • Revision ID: vojtechhorky@users.sourceforge.net-20120829143258-xqp844efhpvvvft0
Load simple options from external file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
 
 
3
import re
 
4
 
3
5
# Global configuration -- storage for various information that 
4
6
# has to be passed across tasks and there is no direct way to do it
5
7
# (well, at least I do not know about it).
11
13
        uspace_entry_point_objfile_node = None
12
14
        config = {}
13
15
 
 
16
class helenos_configuration_file:
 
17
        
 
18
        def __init__(self, file_name):
 
19
                fd = open(file_name, 'r')
 
20
                
 
21
                self.settings = {}
 
22
                
 
23
                line = ""
 
24
                condition = ""
 
25
                line_continuation = False
 
26
                for l in fd:
 
27
                        if not(line_continuation):
 
28
                                line = ''
 
29
                        
 
30
                        line = line + l
 
31
                                
 
32
                        line_continuation = l.endswith('\\\n')
 
33
                        if line_continuation:
 
34
                                continue
 
35
                        
 
36
                        line = re.sub('[\\\\][\n][ \t]*', ' ', line).rstrip()
 
37
                                
 
38
                        if line.strip().startswith('#') or (line.strip() == ''):
 
39
                                continue
 
40
                        
 
41
                        if line.startswith('\t') or line.startswith(' '):
 
42
                                line = line.strip()
 
43
                                parts = line.partition('=')
 
44
                                if parts[1] == '':
 
45
                                        raise RuntimeError("Variable assignment expected: %s" % line)
 
46
                                if condition == '':
 
47
                                        raise RuntimeError("No condition specified for %s" % line)
 
48
                                
 
49
                                varname = parts[0].strip()
 
50
                                value = parts[2].strip().split()
 
51
                                                                                                
 
52
                                if not(condition in self.settings):
 
53
                                        self.settings[condition] = {}
 
54
                                
 
55
                                self.settings[condition][varname] = value
 
56
                                continue
 
57
                        
 
58
                        if line.endswith(':'):
 
59
                                condition = line[:-1]
 
60
                                continue
 
61
                        
 
62
                        raise RuntimeError("Unknown line: %s" % line)
 
63
                
 
64
                fd.close()
 
65
                
 
66
        def get_config(self, variable_name, default_value = []):
 
67
                result = []
 
68
                for cond, values in self.settings.items():
 
69
                        if not(variable_name in values):
 
70
                                continue
 
71
                        result += helenos_config_choose(cond, values[variable_name], [])
 
72
                
 
73
                if result == []:
 
74
                        result = default_value
 
75
                
 
76
                return result
 
77
 
14
78
def helenos_select_by_config(options_and_values):
15
79
        result = []
16
80
        for cond, values in options_and_values.items():