1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import os, dircache
21 from qm.common import parse_string_list
22 from qm.extension import get_class_arguments
23 from qm.fields import *
24 import qm.label
25 import qm.structured_text
26 import qm.test.base
27 from qm.test.database import *
28 from qm.test.suite import *
29 from qm.test import context
30 from qm.test.classes.explicit_suite import ExplicitSuite
31 from qm.test.classes import compilation_test
32 from qm.test.classes.compiler import Compiler
33 from qm.test.classes.compiler_test import CompilationStep
34 from qm.test.classes.compiler_table import CompilerTable
35
36
37
38
39
41 """A CompilationTest fetches compilation parameters from environment
42 variables CPPFLAGS, <lang>_options, and <lang>_ldflags in addition
43 to the CompilerTable-related parameters."""
44
45 options = SetField(TextField(), computed="true")
46 ldflags = SetField(TextField(), computed="true")
47 source_files = SetField(TextField(), computed="true")
48 executable = TextField(computed="true")
49 language = TextField()
50
51
53
54 lang = self.language
55 compiler = c['CompilerTable.compilers'][lang]
56 label_components = self.GetDatabase().GetLabelComponents(self.GetId())
57 label_components[-1] = os.path.splitext(label_components[-1])[0]
58 selector = '.'.join(label_components)
59 path = c.GetDerivedValue(selector, lang + '_path')
60 if path:
61 compiler = Compiler(path, compiler.GetOptions(), compiler.GetLDFlags())
62 options = (parse_string_list(c.GetDerivedValue(
63 selector, 'CPPFLAGS', '')) +
64 parse_string_list(c.GetDerivedValue(
65 selector, lang + '_options', '')))
66 ldflags = (parse_string_list(c.GetDerivedValue(
67 selector, lang + '_ldflags', '')))
68
69 return [CompilationStep(compiler,
70 Compiler.MODE_LINK, self.source_files,
71 self.options + options,
72 self.ldflags + ldflags,
73 self.executable, [])]
74
75
77 """A 'CompilationTestDatabase' test database maps source code files to
78 compilation tests."""
79
80 srcdir = TextField(title = "Source Directory",
81 description = "The root of the test suite's source tree.")
82 excluded_subdirs = SetField(TextField(),
83 default_value = ['QMTest', 'CVS', '.svn', 'build'])
84 test_extensions = DictionaryField(TextField(),
85 EnumerationField(enumerals = ['c', 'cplusplus']),
86 default_value = {'.c':'c',
87 '.cpp':'cplusplus',
88 '.cxx':'cplusplus',
89 '.cc':'cplusplus',
90 '.C':'cplusplus',
91 '.f':'fortran'})
92 _is_generic_database = True
93
94
101
102
104
105 dirname = os.path.join(self.srcdir, directory)
106 return [subdir for subdir in dircache.listdir(dirname)
107 if (os.path.isdir(os.path.join(dirname, subdir)) and
108 subdir not in self.excluded_subdirs)]
109
110
111 - def GetIds(self, kind, directory = '', scan_subdirs = 1):
139
140
141 - def GetExtension(self, id):
142
143 if not id:
144 return DirectorySuite(self, id)
145
146 elif id == 'compiler_table':
147 return CompilerTable({},
148 qmtest_id = id,
149 qmtest_database = self)
150
151 id_components = self.GetLabelComponents(id)
152 file_ext = os.path.splitext(id_components[-1])[1]
153 if (file_ext in self.test_extensions and
154 os.path.isfile(os.path.join(self.srcdir, id))):
155 return self._MakeTest(id, self.test_extensions[file_ext])
156
157 elif os.path.isdir(os.path.join(self.srcdir, id)):
158 basename = os.path.basename(id)
159 if not basename in self.excluded_subdirs:
160 return DirectorySuite(self, id)
161
162 else:
163 return None
164
165
186