-
Notifications
You must be signed in to change notification settings - Fork 42
/
manage.py
executable file
·336 lines (279 loc) · 11.3 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#! /usr/bin/env python
import os.path
import subprocess
import sys
from langkit.utils import Language, LibraryType
# For developer convenience, add the "langkit" directory next to this script to
# the Python path so that.
sys.path.append(
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'langkit')
)
import ada.copyright
from langkit.diagnostics import check_source_language
from langkit.libmanage import ManageScript
import langkit.names as names
from langkit.utils import Colors, printcol
class Manage(ManageScript):
ENABLE_BUILD_WARNINGS_DEFAULT = True
ENABLE_JAVA_DEFAULT = True
def add_extra_subcommands(self) -> None:
########
# Test #
########
self.test_parser = self.add_subcommand(
self.do_test, accept_unknown_args=True
)
self.test_parser.add_argument(
'--disable-ocaml', action='store_true',
help='Disable tests involving the OCaml API'
)
self.test_parser.add_argument(
'--disable-java', action="store_true",
help='Disable tests involving the Java API'
)
self.test_parser.add_argument(
'testsuite-args', nargs='*',
help='Arguments to pass to testsuite.py.'
)
self.add_build_mode_arg(self.test_parser)
#########
# ACATS #
#########
self.acats_parser = self.add_subcommand(
self.do_acats, accept_unknown_args=False
)
self.acats_parser.add_argument(
'--acats-dir', default='acats',
help='The path to the acats repository. By default, use "acats" in'
' the current directory.'
)
self.acats_parser.add_argument(
'acats-args', nargs='*',
help='Arguments to pass to run_acats_test.py.'
)
self.add_build_mode_arg(self.acats_parser)
def create_context(self, args):
# Keep these import statements here so that they are executed only
# after the coverage computation actually started.
from langkit.compile_context import (
AdaSourceKind, CacheCollectionConf, CompileCtx, LibraryEntity
)
from ada.documentation import libadalang_docs
# Give Liblktlang access to our Lkt files
os.environ["LKT_PATH"] = os.path.join(os.path.dirname(__file__), "ada")
ctx = CompileCtx(
lang_name='Ada',
short_name='lal',
lexer=None,
grammar=None,
types_from_lkt=True,
lkt_file=os.path.join(os.path.dirname(__file__), "ada", "nodes.lkt"),
default_charset='iso-8859-1',
verbosity=args.verbosity,
default_unit_provider=LibraryEntity(
'Libadalang.Internal_Default_Provider', 'Create'
),
symbol_canonicalizer=LibraryEntity('Libadalang.Sources',
'Canonicalize'),
documentations=libadalang_docs,
property_exceptions={"Precondition_Failure"},
default_unparsing_config="default_unparsing_config.json",
# Setup a configuration of the cache collection mechanism that
# works well for Ada.
cache_collection_conf=CacheCollectionConf(
threshold_increment=100000,
decision_heuristic=LibraryEntity(
"Libadalang.Implementation.Extensions",
"Should_Collect_Env_Caches"
)
),
source_post_processors={
Language.ada: ada.copyright.AdaPostProcessor(),
Language.c_cpp: ada.copyright.CCppPostProcessor(),
Language.python: ada.copyright.PythonPostProcessor(),
Language.ocaml: ada.copyright.OCamlPostProcessor(),
},
)
# Internals need to access environment hooks, the symbolizer and
# internal configuration pragmas file tables.
ctx.add_with_clause('Implementation',
AdaSourceKind.body, 'Libadalang.Env_Hooks',
use_clause=True)
ctx.add_with_clause('Implementation',
AdaSourceKind.body, 'Libadalang.Sources',
use_clause=False)
ctx.add_with_clause('Implementation',
AdaSourceKind.spec,
'Libadalang.Config_Pragmas_Impl',
use_clause=True)
# Bind Libadalang's custom iterators to the public API
ctx.add_with_clause('Iterators',
AdaSourceKind.body,
'Libadalang.Iterators.Extensions')
# LAL.Analysis.Is_Keyword is implemented using LAL.Lexer's
ctx.add_with_clause('Analysis', AdaSourceKind.body, 'Libadalang.Lexer')
# LAL.Analysis.Create_Context_From_Project just calls the homonym
# function in LAL.Project_Provider.
for dep in [
"GNATCOLL.Projects", "GPR2.Project.Tree", "GPR2.Project.View"
]:
ctx.add_with_clause("Analysis", AdaSourceKind.spec, dep)
for dep in ["Libadalang.GPR_Impl", "Libadalang.Project_Provider"]:
ctx.add_with_clause("Analysis", AdaSourceKind.body, dep)
# The LAL.Analysis.Set_Target_Information interface and the
# Internal_Context type declaration interface both reference
# Libadalang.Target_Info.Target_Information.
for from_pkg in ["Analysis", "Implementation"]:
ctx.add_with_clause(
from_pkg,
AdaSourceKind.spec,
"Libadalang.Target_Info",
use_clause=True,
)
# The LAL.Analysis.Set_Target_Information implementation just redirects
# to extension code.
ctx.add_with_clause(
"Analysis",
AdaSourceKind.body,
"Libadalang.Implementation.Extensions",
)
# LAL.Lexer.Is_Keyword's implementation uses precomputed symbols
ctx.add_with_clause('Lexer',
AdaSourceKind.body,
'Libadalang.Implementation')
# Register our custom exception types
ctx.register_exception_type(
package=["GPR2"],
name=names.Name("Project_Error"),
doc_section="libadalang.project_provider",
)
ctx.register_exception_type(
package=["Libadalang", "Project_Provider"],
name=names.Name("Unsupported_View_Error"),
doc_section="libadalang.project_provider",
)
return ctx
@property
def main_source_dirs(self):
return super(Manage, self).main_source_dirs | {
os.path.join('testsuite', 'ada'),
os.path.join('testsuite', 'ada', 'gnat_compare')
}
@property
def extra_main_programs(self):
return {'nameres', 'navigate', 'gnat_compare', 'lal_dda', 'lal_prep'}
def do_generate(self, args):
# Report unused documentation entries
args.report_unused_doc_entries = True
super(Manage, self).do_generate(args)
do_generate.__doc__ = ManageScript.do_generate.__doc__
def do_install(self, args):
from e3.fs import sync_tree
super(Manage, self).do_install(args)
# Prepare an "examples" directory
examples_dir = self.dirs.install_dir(
"share", "examples", self.lib_name.lower(),
)
if not os.path.isdir(examples_dir):
os.makedirs(examples_dir)
# Install several items from "contrib" to this directory
for item in [
"check_deref_null.py",
"check_same_logic.py",
"check_same_operands.py",
"check_same_test.py",
"check_same_then_else.py",
"check_subp_boxes.py",
"check_test_not_null.py",
"check_useless_assign.py",
"detect_copy_paste_sa.py",
"highlight",
]:
item_from = self.dirs.lang_source_dir("contrib", item)
item_to = os.path.join(examples_dir, item)
sync_tree(item_from, item_to, delete=False)
do_install.__doc__ = ManageScript.do_generate.__doc__
def do_test(self, args, unknown_args):
"""
Run the testsuite.
This is a wrapper around testsuite/testsuite.py tuned for interactive
use: it correctly setups the environment according to the build
directory, it enables colored output and it displays test outputs on
error.
"""
self.set_context(args)
argv = [
sys.executable,
self.dirs.lang_source_dir('testsuite', 'testsuite.py'),
'-Edtmp', '--build-mode={}'.format(args.build_modes[0].name),
# Arguments to pass to GNATcoverage, just in case coverage is
# requested.
'--gnatcov-instr-dir={}'.format(
os.path.join(args.build_dir, 'obj', 'libadalang', 'instr')
)
]
if not args.disable_ocaml:
argv.append('--with-ocaml-bindings')
argv.append(os.path.join(args.build_dir, 'ocaml'))
if not args.disable_java:
argv.append('--with-java-bindings')
argv.append(os.path.join(args.build_dir, 'java'))
if not LibraryType.relocatable in args.library_types:
argv.append('--disable-shared')
argv.extend(unknown_args)
argv.extend(getattr(args, 'testsuite-args'))
try:
return self.check_call('Testsuite', argv, direct_c_header=True)
except KeyboardInterrupt:
# At this point, the testsuite already made it explicit we stopped
# after a keyboard interrupt, so we just have to exit.
sys.exit(1)
def do_acats(self, args):
"""
Run the ACATS testsuite.
This is a wrapper around run_acats_test.py of the libadalang part of
the ACATS testsuite.
"""
self.set_context(args)
path = args.acats_dir
argv = [
sys.executable,
self.dirs.lang_source_dir(path, 'run_acats_test.py'),
'--acats-dir', path,
'--mode=libadalang'
]
argv.extend(getattr(args, 'acats-args'))
try:
return self.check_call('ACATS', argv)
except KeyboardInterrupt:
sys.exit(1)
@staticmethod
def _mkdir(path):
"""
Create a new directory at `path` if it does not exist.
:param path: the path to the new directory.
:type path: str
:raise: OSError | IOError
"""
if os.path.isdir(path):
return
if os.path.exists(path):
raise IOError('{}: already exists'.format(path))
os.makedirs(path)
@staticmethod
def _find_ada_sources(work_dir):
"""
Return the list of .adb and .ads files in `work_dir`.
:param work_dir: the directory in which to search for ada sources.
:type work_dir: str
:rtype: set[str]
"""
ada_files = set()
for root, dirs, files in os.walk(work_dir):
for filename in files:
_, ext = os.path.splitext(filename)
if ext in ('.ads', '.adb'):
ada_files.add(os.path.join(root, filename))
return ada_files
if __name__ == '__main__':
Manage().run()