From 4226a422b09b1c44811fd599d2ee24581d25d13c Mon Sep 17 00:00:00 2001 From: Shen Jiamin Date: Sat, 30 May 2026 22:37:27 +0800 Subject: [PATCH] Exit early when a sourced Tcl script fails Add a `safe_source` procedure to handle sourcing sub-scripts. If a script fails to execute, print an error message and exit immediately to prevent cascading failures. Signed-off-by: Shen Jiamin --- .../resources/base/scripts/create_project.tcl | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/linker/slashkit/resources/base/scripts/create_project.tcl b/linker/slashkit/resources/base/scripts/create_project.tcl index 9fd9b3b1..258f63f0 100644 --- a/linker/slashkit/resources/base/scripts/create_project.tcl +++ b/linker/slashkit/resources/base/scripts/create_project.tcl @@ -71,6 +71,14 @@ puts "IP REPOS: $iprepos" puts "ACTION: $action" puts "BUILD DIR: $cwd" +proc safe_source {tcl_path} { + puts "INFO: Sourcing $tcl_path ..." + catch {source $tcl_path} result + if {[string is integer -strict $result] && $result != 0} { + puts "EXIT: '$tcl_path' returned $result" + exit 1 + } +} set proj_exists [file normalize [file join $cwd "${design_name}.xpr"]] if {![file exists $proj_exists]} { @@ -84,14 +92,14 @@ if {![file exists $proj_exists]} { update_ip_catalog # Base shell / containers - source [file normalize [file join $src_dir "slash_base.tcl"]] - source [file normalize [file join $src_dir "service_layer.tcl"]] - source [file normalize [file join $src_dir "top.tcl"]] - source [file normalize [file join $src_dir "enable_dfx_bdc.tcl"]] + safe_source [file normalize [file join $src_dir "slash_base.tcl"]] + safe_source [file normalize [file join $src_dir "service_layer.tcl"]] + safe_source [file normalize [file join $src_dir "top.tcl"]] + safe_source [file normalize [file join $src_dir "enable_dfx_bdc.tcl"]] # Wrapper / XDC / build - source [file normalize [file join $src_dir "make_wrapper.tcl"]] - source [file normalize [file join $src_dir "add_constraints.tcl"]] + safe_source [file normalize [file join $src_dir "make_wrapper.tcl"]] + safe_source [file normalize [file join $src_dir "add_constraints.tcl"]] } else { puts "INFO: Project already exists; opening '$proj_exists'." open_project [file normalize [file join $cwd "slash.xpr"]] @@ -105,7 +113,7 @@ if {![file exists $proj_exists]} { } if {$do_build} { - source [file normalize [file join $src_dir "build_project.tcl"]] + safe_source [file normalize [file join $src_dir "build_project.tcl"]] build_project $project_name puts "INFO: Project build complete." } elseif {$do_create} {