@@ -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.
@@ -347,10 +341,8 @@ def manage_run(generate_only, types_from_lkt, additional_args):
347341 if generate_unparser :
348342 argv .append ('--generate-unparser' )
349343
350- # For testsuite performance, do not generate mains unless told
351- # otherwise.
352- if not mains :
353- argv .append ('--disable-all-mains' )
344+ # No testcase uses the generated mains, so save time: never build them
345+ argv .append ('--disable-all-mains' )
354346
355347 argv .extend (additional_args )
356348 argv .extend (additional_make_args )
@@ -420,42 +412,45 @@ def run(*argv, **kwargs):
420412 args .append (py_script )
421413 run (* args )
422414
423- if ada_main is not None :
424- if isinstance (ada_main , str ):
425- ada_main = [ada_main ]
415+ if gpr_mains :
416+ source_dirs = ["." , c_support_dir ]
426417
427- langs = ["Ada" ]
428- source_dirs = ["." ]
429- if with_c :
430- langs .append ("C" )
431- 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" )
432426
433- # Generate a project file to build the given Ada main and then run
434- # the program. Do a static build to improve the debugging experience.
435- 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 :
436430
437431 def fmt_str_list (strings : List [str ]) -> str :
438432 return ", " .join (f'"{ s } "' for s in strings )
439433
440434 f .write (project_template .format (
441435 languages = fmt_str_list (langs ),
442436 source_dirs = fmt_str_list (source_dirs ),
443- main_sources = fmt_str_list (ada_main ),
437+ main_sources = fmt_str_list (gpr_mains ),
444438 ))
445- run ('gprbuild' , '-Pgen' , '-q' , '-p' ,
446- '-XLIBRARY_TYPE=static' ,
447- '-XXMLADA_BUILD=static' )
439+ run ("gprbuild" , "-Pgen" , "-q" , "-p" )
448440
449- for i , m in enumerate (ada_main ):
450- 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 ):
451444 if i > 0 :
452- print ('' )
453- if len (ada_main ) > 1 :
454- print (' == {} ==' . format ( m ) )
445+ print ("" )
446+ if len (gpr_mains ) > 1 :
447+ print (f" == { main } ==" )
455448 sys .stdout .flush ()
456- run (P .join ('obj' , m [:- 4 ]),
449+ run (
450+ P .join ("obj" , os .path .splitext (main )[0 ]),
457451 valgrind = True ,
458- valgrind_suppressions = ['gnat' ])
452+ valgrind_suppressions = ["gnat" ],
453+ )
459454
460455 if ocaml_main is not None :
461456 # Set up a Dune project
0 commit comments