Skip to content

Commit 17219fe

Browse files
committed
Merge branch 'pmderodat/c' into 'master'
C-related testsuite refactorings See merge request eng/libadalang/langkit!848
2 parents ae4ffd3 + 4f0edda commit 17219fe

File tree

77 files changed

+364
-278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+364
-278
lines changed

langkit/libmanage.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,6 @@ def add_common_args(subparser: argparse.ArgumentParser) -> None:
372372
'--trace', '-t', action='append', default=[],
373373
help='Activate given debug trace.'
374374
)
375-
subparser.add_argument(
376-
'--no-ada-api', action='store_true',
377-
help='Do not generate units to provide an Ada API, and disable the'
378-
' generation of mains.'
379-
)
380375

381376
# Don't enable this by default so that errors will not make automated
382377
# tasks hang.

testsuite/python_support/utils.py

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ def build(grammar=None, lexer=None, lkt_file=None,
204204
warning_set=warning_set)
205205

206206

207-
def build_and_run(grammar=None, py_script=None, ada_main=None, with_c=False,
207+
def build_and_run(grammar=None, py_script=None, gpr_mains=None,
208208
lexer=None, lkt_file=None, types_from_lkt=False,
209209
lkt_semantic_checks=False, ocaml_main=None, java_main=None,
210-
ni_main=None, mains=False, warning_set=default_warning_set,
210+
ni_main=None, warning_set=default_warning_set,
211211
generate_unparser=False, symbol_canonicalizer=None,
212212
show_property_logging=False, unparse_script=unparse_script,
213213
case_insensitive: bool = False,
@@ -237,13 +237,9 @@ def build_and_run(grammar=None, py_script=None, ada_main=None, with_c=False,
237237
:param None|str py_script: If not None, name of the Python script to run
238238
with the built library available.
239239
240-
:param None|str|list[str] ada_main: If not None, list of name of main
241-
source files for Ada programs to build and run with the generated
242-
library. If the input is a single string, consider it's a single mail
243-
source file.
244-
245-
:param bool with_c: Whether to add "C" to the languages of the generated
246-
project.
240+
:param None|list[str] gpr_mains: If not None, list of name of main source
241+
files (Ada and/or C) for the generated GPR file, to build and run with
242+
the generated library.
247243
248244
:param None|str ocaml_main: If not None, name of the OCaml source file to
249245
build and run with the built library available.
@@ -258,8 +254,6 @@ def build_and_run(grammar=None, py_script=None, ada_main=None, with_c=False,
258254
:param langkit.compile_context.LibraryEntity|None symbol_canonicalizer:
259255
Symbol canonicalizer to use for this context, if any.
260256
261-
:param bool mains: Whether to build mains.
262-
263257
:param bool show_property_logging: If true, any property that has been
264258
marked with tracing activated will be traced on stdout by default,
265259
without need for any config file.
@@ -325,12 +319,6 @@ def manage_run(generate_only, types_from_lkt, additional_args):
325319
if full_error_traces:
326320
argv.append("--full-error-traces")
327321

328-
# Generate the public Ada API only when necessary (i.e. if we have
329-
# mains that do use this API). This reduces the time it takes to run
330-
# tests.
331-
if not mains and not ada_main:
332-
argv.append('--no-ada-api')
333-
334322
# If there is a Java main, enable the Java bindings building
335323
if java_main is not None or ni_main is not None:
336324
argv.append('--enable-java')
@@ -353,10 +341,8 @@ def manage_run(generate_only, types_from_lkt, additional_args):
353341
if generate_unparser:
354342
argv.append('--generate-unparser')
355343

356-
# For testsuite performance, do not generate mains unless told
357-
# otherwise.
358-
if not mains:
359-
argv.append('--disable-all-mains')
344+
# No testcase uses the generated mains, so save time: never build them
345+
argv.append('--disable-all-mains')
360346

361347
argv.extend(additional_args)
362348
argv.extend(additional_make_args)
@@ -426,42 +412,45 @@ def run(*argv, **kwargs):
426412
args.append(py_script)
427413
run(*args)
428414

429-
if ada_main is not None:
430-
if isinstance(ada_main, str):
431-
ada_main = [ada_main]
415+
if gpr_mains:
416+
source_dirs = [".", c_support_dir]
432417

433-
langs = ["Ada"]
434-
source_dirs = ["."]
435-
if with_c:
436-
langs.append("C")
437-
source_dirs.append(c_support_dir)
418+
# Detect languages based on the source files present in the test
419+
# directory.
420+
langs = set()
421+
for f in os.listdir("."):
422+
if any(f.endswith(ext) for ext in [".c", ".h"]):
423+
langs.add("C")
424+
if any(f.endswith(ext) for ext in [".adb", ".ads"]):
425+
langs.add("Ada")
438426

439-
# Generate a project file to build the given Ada main and then run
440-
# the program. Do a static build to improve the debugging experience.
441-
with open('gen.gpr', 'w') as f:
427+
# Generate a project file to build the given mains. Do a static build
428+
# (the default) to improve the debugging experience.
429+
with open("gen.gpr", "w") as f:
442430

443431
def fmt_str_list(strings: List[str]) -> str:
444432
return ", ".join(f'"{s}"' for s in strings)
445433

446434
f.write(project_template.format(
447435
languages=fmt_str_list(langs),
448436
source_dirs=fmt_str_list(source_dirs),
449-
main_sources=fmt_str_list(ada_main),
437+
main_sources=fmt_str_list(gpr_mains),
450438
))
451-
run('gprbuild', '-Pgen', '-q', '-p',
452-
'-XLIBRARY_TYPE=static',
453-
'-XXMLADA_BUILD=static')
439+
run("gprbuild", "-Pgen", "-q", "-p")
454440

455-
for i, m in enumerate(ada_main):
456-
assert m.endswith('.adb')
441+
# Now run all mains. If there are more than one main to run, print a
442+
# heading before each one.
443+
for i, main in enumerate(gpr_mains):
457444
if i > 0:
458-
print('')
459-
if len(ada_main) > 1:
460-
print('== {} =='.format(m))
445+
print("")
446+
if len(gpr_mains) > 1:
447+
print(f"== {main} ==")
461448
sys.stdout.flush()
462-
run(P.join('obj', m[:-4]),
449+
run(
450+
P.join("obj", os.path.splitext(main)[0]),
463451
valgrind=True,
464-
valgrind_suppressions=['gnat'])
452+
valgrind_suppressions=["gnat"],
453+
)
465454

466455
if ocaml_main is not None:
467456
# Set up a Dune project

testsuite/tests/ada_api/bigint_array_comp/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def prop(a=T.BigInt.array):
1919
return a
2020

2121

22-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main=['main.adb'],
23-
types_from_lkt=True)
24-
print('Done')
22+
build_and_run(
23+
lkt_file="expected_concrete_syntax.lkt",
24+
gpr_mains=["main.adb"],
25+
types_from_lkt=True,
26+
)
27+
print("Done")

testsuite/tests/ada_api/calls_on_null/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ class Decl(FooNode):
2222
value = Field(type=Identifier)
2323

2424

25-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main=['main.adb'])
25+
build_and_run(lkt_file="expected_concrete_syntax.lkt", gpr_mains=["main.adb"])
2626
print('Done')

testsuite/tests/ada_api/children_and_trivia/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Decl(FooNode):
2525
error = Field(type=DeclError)
2626

2727

28-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main='main.adb',
29-
types_from_lkt=True)
30-
print('Done')
28+
build_and_run(
29+
lkt_file="expected_concrete_syntax.lkt",
30+
gpr_mains=["main.adb"],
31+
types_from_lkt=True,
32+
)
33+
print("Done")

testsuite/tests/ada_api/event_handler/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Example(FooNode):
2828

2929
build_and_run(
3030
lkt_file="expected_concrete_syntax.lkt",
31-
ada_main="main.adb",
31+
gpr_mains=["main.adb"],
3232
types_from_lkt=True,
3333
)
3434

testsuite/tests/ada_api/general/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Decl(FooNode):
2525
error = Field(type=DeclError)
2626

2727

28-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main='main.adb',
29-
types_from_lkt=True)
30-
print('Done')
28+
build_and_run(
29+
lkt_file="expected_concrete_syntax.lkt",
30+
gpr_mains=["main.adb"],
31+
types_from_lkt=True,
32+
)
33+
print("Done")

testsuite/tests/ada_api/generic_api/test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ class Ref(Expr):
169169

170170
build_and_run(
171171
lkt_file="expected_concrete_syntax.lkt",
172-
ada_main=["analysis.adb", "introspection_types.adb",
173-
"introspection_values.adb", "hash.adb"]
172+
gpr_mains=[
173+
"analysis.adb",
174+
"introspection_types.adb",
175+
"introspection_values.adb",
176+
"hash.adb",
177+
],
174178
)
175179
print("Done")

testsuite/tests/ada_api/hashes/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Example(FooNode):
1515
token_node = True
1616

1717

18-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main=['main.adb'],
19-
types_from_lkt=True)
20-
print('Done')
18+
build_and_run(
19+
lkt_file="expected_concrete_syntax.lkt",
20+
gpr_mains=["main.adb"],
21+
types_from_lkt=True,
22+
)
23+
print("Done")

testsuite/tests/ada_api/lifetimes/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class Example(FooNode):
1616
token_node = True
1717

1818

19-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main=['main.adb'],
20-
types_from_lkt=True)
21-
print('Done')
19+
build_and_run(
20+
lkt_file="expected_concrete_syntax.lkt",
21+
gpr_mains=["main.adb"],
22+
types_from_lkt=True,
23+
)
24+
print("Done")

0 commit comments

Comments
 (0)