66import subprocess
77import sys
88import tempfile
9- from concurrent .futures import ThreadPoolExecutor
109from typing import Dict , List , Optional
1110
1211
@@ -141,6 +140,7 @@ def run_code_generation(
141140
142141 env = dict (os .environ )
143142 env ["SWIFT_BUILD_SCRIPT_ENVIRONMENT" ] = "1"
143+ env ["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION" ] = "1"
144144 check_call (swiftpm_call , env = env , verbose = verbose )
145145
146146
@@ -174,6 +174,7 @@ class Builder(object):
174174 build_dir : Optional [str ]
175175 multiroot_data_file : Optional [str ]
176176 release : bool
177+ enable_rawsyntax_validation : bool
177178 disable_sandbox : bool
178179
179180 def __init__ (
@@ -182,12 +183,14 @@ def __init__(
182183 build_dir : Optional [str ],
183184 multiroot_data_file : Optional [str ],
184185 release : bool ,
186+ enable_rawsyntax_validation : bool ,
185187 verbose : bool ,
186188 disable_sandbox : bool = False ,
187189 ) -> None :
188190 self .build_dir = build_dir
189191 self .multiroot_data_file = multiroot_data_file
190192 self .release = release
193+ self .enable_rawsyntax_validation = enable_rawsyntax_validation
191194 self .disable_sandbox = disable_sandbox
192195 self .verbose = verbose
193196 self .toolchain = toolchain
@@ -221,6 +224,8 @@ def __build(self, package_dir: str, product_name: str) -> None:
221224
222225 env = dict (os .environ )
223226 env ["SWIFT_BUILD_SCRIPT_ENVIRONMENT" ] = "1"
227+ if self .enable_rawsyntax_validation :
228+ env ["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION" ] = "1"
224229 # Tell other projects in the unified build to use local dependencies
225230 env ["SWIFTCI_USE_LOCAL_DEPS" ] = "1"
226231 env ["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH" ] = \
@@ -274,7 +279,8 @@ def check_generated_files_match(self_generated_dir: str,
274279
275280def run_tests (
276281 toolchain : str , build_dir : Optional [str ], multiroot_data_file : Optional [str ],
277- release : bool , filecheck_exec : Optional [str ], skip_lit_tests : bool , verbose : bool
282+ release : bool , enable_rawsyntax_validation : bool , filecheck_exec : Optional [str ],
283+ skip_lit_tests : bool , verbose : bool
278284) -> None :
279285 print ("** Running SwiftSyntax Tests **" )
280286
@@ -292,6 +298,7 @@ def run_tests(
292298 build_dir = build_dir ,
293299 multiroot_data_file = multiroot_data_file ,
294300 release = release ,
301+ enable_rawsyntax_validation = enable_rawsyntax_validation ,
295302 verbose = verbose ,
296303 )
297304
@@ -396,6 +403,7 @@ def run_lit_tests(toolchain: str, build_dir: Optional[str], release: bool,
396403
397404def run_xctests (toolchain : str , build_dir : Optional [str ],
398405 multiroot_data_file : Optional [str ], release : bool ,
406+ enable_rawsyntax_validation : bool ,
399407 verbose : bool ) -> None :
400408 print ("** Running XCTests **" )
401409 swiftpm_call = get_swiftpm_invocation (
@@ -414,6 +422,8 @@ def run_xctests(toolchain: str, build_dir: Optional[str],
414422
415423 env = dict (os .environ )
416424 env ["SWIFT_BUILD_SCRIPT_ENVIRONMENT" ] = "1"
425+ if enable_rawsyntax_validation :
426+ env ["SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION" ] = "1"
417427 # Tell other projects in the unified build to use local dependencies
418428 env ["SWIFTCI_USE_LOCAL_DEPS" ] = "1"
419429 env ["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH" ] = \
@@ -461,10 +471,11 @@ def verify_source_code_command(args: argparse.Namespace) -> None:
461471def build_command (args : argparse .Namespace ) -> None :
462472 try :
463473 builder = Builder (
464- toolchain = realpath (args .toolchain ),
474+ toolchain = realpath (args .toolchain ), # pyright: ignore
465475 build_dir = realpath (args .build_dir ),
466476 multiroot_data_file = args .multiroot_data_file ,
467477 release = args .release ,
478+ enable_rawsyntax_validation = args .enable_rawsyntax_validation ,
468479 verbose = args .verbose ,
469480 disable_sandbox = args .disable_sandbox ,
470481 )
@@ -484,10 +495,11 @@ def build_command(args: argparse.Namespace) -> None:
484495def test_command (args : argparse .Namespace ) -> None :
485496 try :
486497 builder = Builder (
487- toolchain = realpath (args .toolchain ),
498+ toolchain = realpath (args .toolchain ), # pyright: ignore
488499 build_dir = realpath (args .build_dir ),
489500 multiroot_data_file = args .multiroot_data_file ,
490501 release = args .release ,
502+ enable_rawsyntax_validation = args .enable_rawsyntax_validation ,
491503 verbose = args .verbose ,
492504 disable_sandbox = args .disable_sandbox ,
493505 )
@@ -496,10 +508,11 @@ def test_command(args: argparse.Namespace) -> None:
496508 builder .buildExample ("ExamplePlugin" )
497509
498510 run_tests (
499- toolchain = realpath (args .toolchain ),
511+ toolchain = realpath (args .toolchain ), # pyright: ignore
500512 build_dir = realpath (args .build_dir ),
501513 multiroot_data_file = args .multiroot_data_file ,
502514 release = args .release ,
515+ enable_rawsyntax_validation = args .enable_rawsyntax_validation ,
503516 filecheck_exec = realpath (args .filecheck_exec ),
504517 skip_lit_tests = args .skip_lit_tests ,
505518 verbose = args .verbose ,
@@ -552,6 +565,16 @@ def add_default_build_arguments(parser: argparse.ArgumentParser) -> None:
552565 """ ,
553566 )
554567
568+ parser .add_argument (
569+ "--enable-rawsyntax-validation" ,
570+ action = "store_true" ,
571+ help = """
572+ When constructing RawSyntax nodes validate that their layout matches that
573+ defined in `CodeGeneration` and that TokenSyntax nodes have a `tokenKind`
574+ matching the ones specified in `CodeGeneration`.
575+ """
576+ )
577+
555578 parser .add_argument (
556579 "--toolchain" ,
557580 required = True ,
0 commit comments