refactor(platform/xilinx): replace symbolic links with hard links for better compatibility

- Replaced symbolic links with hard links in the Vitis project source management.
- Symbolic links often cause reference issues during debugging in Xilinx Vitis.
- This change improves source visibility and debugger integration.
This commit is contained in:
Gatsby
2025-06-13 12:24:45 +08:00
parent 0eb4535dc8
commit d13f6cb8b3
+68 -38
View File
@@ -90,6 +90,46 @@ proc _configure_bsp {bsp_name bsp_config platform_name is_vitis} {
return $bsp_name
}
# Helper procedure to recursively create hard links for files in a directory
proc _link_or_copy_dir {source_dir target_dir link_mode} {
# Create target directory if it doesn't exist
if {![file exists $target_dir]} {
file mkdir $target_dir
_info "Created directory: $target_dir"
}
# Process each file and subdirectory in the source directory
foreach item [glob -nocomplain -directory $source_dir *] {
set item_name [file tail $item]
set target_item [file join $target_dir $item_name]
# Remove existing file or directory
if {[file exists $target_item]} {
file delete -force $target_item
_warn "Deleted existing item: $target_item"
}
if {[file isfile $item]} {
# Handle file - create hard link or copy
if {$link_mode eq "y"} {
if {[catch {
file link -hard $target_item $item
} err]} {
error "Failed to create hard link: $err"
} else {
_info "Created hard link: $target_item -> $item"
}
} else {
file copy $item $target_item
_info "Copied file: $item to $target_item"
}
} elseif {[file isdirectory $item]} {
# Handle subdirectory recursively
_link_or_copy_dir $item $target_item $link_mode
}
}
}
# Helper procedure to handle source files: link or copy based on LINK_SRCS
proc _handle_sources {app_name sources} {
# Check environment variable LINK_SRCS
@@ -104,52 +144,41 @@ proc _handle_sources {app_name sources} {
if {[llength $expanded_sources] == 0} {
_error "Source file not found" "No file or directory matches $source_file"
}
# Hanle each expanded source
# Handle each expanded source
foreach eval_source $expanded_sources {
set relative_source [string range $eval_source [expr [string length $::root] + 1] end]
set target_path [file join $::ws $app_name $relative_source]
# Ensure the target directory exists
set target_dir [file dirname $target_path]
if {![file exists $target_dir]} {
file mkdir $target_dir
_info "Created directory: $target_dir"
}
if {[file isfile $eval_source]} {
# For files, ensure the parent directory exists
set target_dir [file dirname $target_path]
if {![file exists $target_dir]} {
file mkdir $target_dir
_info "Created directory: $target_dir"
}
# Delete existing symbolic link or file if it exists
if {[file exists $target_path]} {
file delete -force $target_path
_warn "Deleted existing link or file: $target_path"
}
# Delete existing file if it exists
if {[file exists $target_path]} {
file delete -force $target_path
_warn "Deleted existing file: $target_path"
}
# Handle source based on the value of LINK_SRCS
switch $link_srcs {
"y" {
# Create symbolic link
# -- Symbolic link for file dose not support on NTFS
if {$::tcl_platform(platform) eq "windows" && [file isfile $eval_source]} {
if {[catch {
file link -hard $target_path $eval_source
} err]} {
error "Failed to create file hard link: $err"
}
} else {
if {[catch {
file link -symbolic $target_path $eval_source
} err]} {
error "Failed to create symbolic link: $err"
}
# Handle file based on LINK_SRCS
if {$link_srcs eq "y"} {
if {[catch {
file link -hard $target_path $eval_source
} err]} {
error "Failed to create hard link: $err"
}
_info "Created symbolic link: $target_path -> $eval_source"
}
"n" {
# Copy the source file
_info "Created hard link: $target_path -> $eval_source"
} else {
file copy $eval_source $target_path
_info "Copied source file: $eval_source to $target_path"
}
default {
_error "Unknown value for LINK_SRCS: ${link_srcs}."
_info "Copied file: $eval_source to $target_path"
}
} else {
# For directories, use the helper function
_link_or_copy_dir $eval_source $target_path $link_srcs
}
}
}
@@ -232,7 +261,8 @@ proc _update_app_build_config {app_name build_type build_config is_vitis} {
"linker-misc" -
"linker-script" {
if {$value ne ""} {
eval $cmd $app_name -set $param $value
set value_list [list $value]
eval $cmd $app_name -set $param $value_list
_info "Set $param: $value for $app_name."
}
}