@@ -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
0 commit comments