@@ -242,6 +242,30 @@ pub fn test(
242242 ] ,
243243 ) ?;
244244 }
245+ if let Some ( config_overlay) = project. config_overlay . as_deref ( ) {
246+ let config_file_name = config_file_name. ok_or_else ( || {
247+ anyhow:: anyhow!(
248+ "Hardhat project {project_name} has a config overlay but no hardhat.config.ts or hardhat.config.js"
249+ )
250+ } ) ?;
251+ let base_config_file_name = config_file_name. replace ( ".config." , ".config.base." ) ;
252+ std:: fs:: rename (
253+ project_directory. join ( config_file_name) ,
254+ project_directory. join ( base_config_file_name. as_str ( ) ) ,
255+ )
256+ . map_err ( |error| {
257+ anyhow:: anyhow!(
258+ "Renaming {config_file_name} of Hardhat project {project_name} to {base_config_file_name}: {error}"
259+ )
260+ } ) ?;
261+ std:: fs:: copy ( config_overlay, project_directory. join ( "hardhat.config.ts" ) ) . map_err (
262+ |error| {
263+ anyhow:: anyhow!(
264+ "Installing config overlay {config_overlay:?} into Hardhat project {project_name}: {error}"
265+ )
266+ } ,
267+ ) ?;
268+ }
245269
246270 let compiler_shim = compiler_shims
247271 . get ( identifier. as_str ( ) )
@@ -260,6 +284,9 @@ pub fn test(
260284 if toolchain_name. contains ( "solx" ) {
261285 npm_compile_command. env ( "USE_SOLX" , "true" ) ;
262286 npm_compile_command. env ( "SOLX" , & * compiler_path_str) ;
287+ if let Some ( build_profile) = project. build_profile . as_deref ( ) {
288+ npm_compile_command. args ( [ "--" , "--build-profile" , build_profile] ) ;
289+ }
263290 }
264291 npm_compile_command. env ( "VIA_IR" , ( codegen == "viaIR" ) . to_string ( ) ) ;
265292 let build_timestamp_start = Instant :: now ( ) ;
@@ -297,6 +324,7 @@ pub fn test(
297324 // toolchains can be identity-checked.
298325 if toolchain_name. contains ( "solx" ) {
299326 compiler_shim. verify ( toolchain_name. as_str ( ) , project_name. as_str ( ) ) ?;
327+ stub_slang_build_info_asts ( project_directory. as_path ( ) ) ?;
300328 }
301329
302330 let mut npm_test_command = Command :: new ( "npm" ) ;
@@ -312,6 +340,9 @@ pub fn test(
312340 if toolchain_name. contains ( "solx" ) {
313341 npm_test_command. env ( "USE_SOLX" , "true" ) ;
314342 npm_test_command. env ( "SOLX" , & * compiler_path_str) ;
343+ if let Some ( build_profile) = project. build_profile . as_deref ( ) {
344+ npm_test_command. args ( [ "--" , "--build-profile" , build_profile] ) ;
345+ }
315346 }
316347 npm_test_command. env ( "VIA_IR" , ( codegen == "viaIR" ) . to_string ( ) ) ;
317348 let test_timestamp_start = Instant :: now ( ) ;
@@ -472,3 +503,41 @@ pub fn test(
472503
473504 Ok ( ( ) )
474505}
506+
507+ ///
508+ /// Replaces every non-solc AST in the project's build infos with an empty solc source unit, since
509+ /// EDR refuses to start on an AST it cannot read and slang emits its own format.
510+ ///
511+ /// TODO: remove once Hardhat runs get slang stack traces (NomicFoundation/solx#806).
512+ ///
513+ fn stub_slang_build_info_asts ( project_directory : & std:: path:: Path ) -> anyhow:: Result < ( ) > {
514+ let pattern = project_directory. join ( "artifacts/build-info/*.json" ) ;
515+ for path in glob:: glob ( pattern. to_string_lossy ( ) . as_ref ( ) )
516+ . expect ( "Always valid" )
517+ . filter_map ( Result :: ok)
518+ {
519+ let content = std:: fs:: read_to_string ( path. as_path ( ) )
520+ . map_err ( |error| anyhow:: anyhow!( "Reading build info {path:?}: {error}" ) ) ?;
521+ let mut build_info: serde_json:: Value = serde_json:: from_str ( content. as_str ( ) )
522+ . map_err ( |error| anyhow:: anyhow!( "Parsing build info {path:?}: {error}" ) ) ?;
523+ let Some ( sources) = build_info
524+ . pointer_mut ( "/output/sources" )
525+ . and_then ( serde_json:: Value :: as_object_mut)
526+ else {
527+ continue ;
528+ } ;
529+ let mut is_stubbed = false ;
530+ for source in sources. values_mut ( ) {
531+ if source. pointer ( "/ast/nodeType" ) . is_some ( ) {
532+ continue ;
533+ }
534+ source[ "ast" ] = serde_json:: json!( { "nodeType" : "SourceUnit" , "nodes" : [ ] } ) ;
535+ is_stubbed = true ;
536+ }
537+ if is_stubbed {
538+ std:: fs:: write ( path. as_path ( ) , build_info. to_string ( ) )
539+ . map_err ( |error| anyhow:: anyhow!( "Writing build info {path:?}: {error}" ) ) ?;
540+ }
541+ }
542+ Ok ( ( ) )
543+ }
0 commit comments