From 15a47034a66662d3dcdfe72f2bb6b89630ef7f17 Mon Sep 17 00:00:00 2001 From: Vishal Chani Date: Wed, 8 May 2024 13:50:00 +0200 Subject: [PATCH 1/2] Add support for .prj files in vivado project enabled by -mig argument. --- scripts/git_wrapper.tcl | 64 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/scripts/git_wrapper.tcl b/scripts/git_wrapper.tcl index 240805e..ad44e35 100644 --- a/scripts/git_wrapper.tcl +++ b/scripts/git_wrapper.tcl @@ -68,7 +68,7 @@ namespace eval ::git_wrapper { exec git {*}$args } - proc wproj {} { + proc wproj {args} { # Change directory project directory if not in it yet set proj_dir [regsub {\/vivado_project$} [get_property DIRECTORY [current_project]] {}] set current_dir [pwd] @@ -82,7 +82,67 @@ namespace eval ::git_wrapper { # Generate project set proj_file [current_project].tcl - puts $proj_file + puts "$proj_dir" write_project_tcl_git -no_copy_sources -force $proj_file + if { ("-mig" in $args) } { + set PathList {} + if {[catch {open $proj_file r} file]} { + puts "Error: Unable to open file $proj_file" + } else { + while {[gets $file line] != -1} { + if {[string match "*\[file normalize *\[\"*\]*.prj\"*\]*" $line]} { + + set start [string first "\"" $line] + set end [string last "\"" $line] + set path [string range $line [expr {$start + 1}] [expr {$end - 1}]] + + + if {[string match "*{origin_dir}/*" $path]} { + set pathTemp [string map [list "\${origin_dir}/" ""] $path] + set destination_path "$proj_dir/prj_files/$pathTemp" + set directory [file dirname $pathTemp] + set destDirectory "$proj_dir/prj_files/$directory" + set newInFilePath "\${origin_dir}/prj_files/$pathTemp" + lappend PathList [list $path $newInFilePath] + + if {![file isdirectory $destDirectory]} { + puts "\[INFO\] prj_files Directory Created" + file mkdir $destDirectory + } + + file copy -force $pathTemp $destination_path + } + } + } + close $file + } + + + if {[file exists $proj_file]} { + # Open the input file for reading + if {[catch {open $proj_file r} original_scriptfile]} { + puts "Error: Unable to open file $proj_file" + } else { + set script_content [read $original_scriptfile] + close $original_scriptfile + foreach {inputPath} $PathList { + set oldPath [lindex $inputPath 0] + set newPath [lindex $inputPath 1] + set script_content [string map [list $oldPath $newPath] $script_content] + set oldPath [string map {"{" "" "}" ""} $oldPath] + set newPath [string map {"{" "" "}" ""} $newPath] + set script_content [string map [list $oldPath $newPath] $script_content] + } + + set modified_script_file $proj_file + set modified_script [open $modified_script_file w] + # Write the modified content to the modified script file + puts -nonewline $modified_script $script_content + + # Close the modified script file + close $modified_script + } + } + } } } From bdd6e672f3829760db947b4121bb5b08e50ded3a Mon Sep 17 00:00:00 2001 From: Vishal Chani Date: Tue, 21 May 2024 12:39:10 +0200 Subject: [PATCH 2/2] Removed Argument. Handler is called for all projects. --- scripts/git_wrapper.tcl | 104 ++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/scripts/git_wrapper.tcl b/scripts/git_wrapper.tcl index ad44e35..2fc3c68 100644 --- a/scripts/git_wrapper.tcl +++ b/scripts/git_wrapper.tcl @@ -84,65 +84,65 @@ namespace eval ::git_wrapper { set proj_file [current_project].tcl puts "$proj_dir" write_project_tcl_git -no_copy_sources -force $proj_file - if { ("-mig" in $args) } { - set PathList {} - if {[catch {open $proj_file r} file]} { - puts "Error: Unable to open file $proj_file" - } else { - while {[gets $file line] != -1} { - if {[string match "*\[file normalize *\[\"*\]*.prj\"*\]*" $line]} { - - set start [string first "\"" $line] - set end [string last "\"" $line] - set path [string range $line [expr {$start + 1}] [expr {$end - 1}]] - - - if {[string match "*{origin_dir}/*" $path]} { - set pathTemp [string map [list "\${origin_dir}/" ""] $path] - set destination_path "$proj_dir/prj_files/$pathTemp" - set directory [file dirname $pathTemp] - set destDirectory "$proj_dir/prj_files/$directory" - set newInFilePath "\${origin_dir}/prj_files/$pathTemp" - lappend PathList [list $path $newInFilePath] - - if {![file isdirectory $destDirectory]} { - puts "\[INFO\] prj_files Directory Created" - file mkdir $destDirectory - } - - file copy -force $pathTemp $destination_path + #if { ("-mig" in $args) } { + set PathList {} + if {[catch {open $proj_file r} file]} { + puts "Error: Unable to open file $proj_file" + } else { + while {[gets $file line] != -1} { + if {[string match "*\[file normalize *\[\"*\]*.prj\"*\]*" $line]} { + + set start [string first "\"" $line] + set end [string last "\"" $line] + set path [string range $line [expr {$start + 1}] [expr {$end - 1}]] + + + if {[string match "*{origin_dir}/vivado_project/*" $path]} { + set pathTemp [string map [list "\${origin_dir}/" ""] $path] + set destination_path "$proj_dir/prj_files/$pathTemp" + set directory [file dirname $pathTemp] + set destDirectory "$proj_dir/prj_files/$directory" + set newInFilePath "\${origin_dir}/prj_files/$pathTemp" + lappend PathList [list $path $newInFilePath] + + if {![file isdirectory $destDirectory]} { + puts "\[INFO\] prj_files Directory Created" + file mkdir $destDirectory } + + file copy -force $pathTemp $destination_path } } - close $file } + close $file + } - if {[file exists $proj_file]} { - # Open the input file for reading - if {[catch {open $proj_file r} original_scriptfile]} { - puts "Error: Unable to open file $proj_file" - } else { - set script_content [read $original_scriptfile] - close $original_scriptfile - foreach {inputPath} $PathList { - set oldPath [lindex $inputPath 0] - set newPath [lindex $inputPath 1] - set script_content [string map [list $oldPath $newPath] $script_content] - set oldPath [string map {"{" "" "}" ""} $oldPath] - set newPath [string map {"{" "" "}" ""} $newPath] - set script_content [string map [list $oldPath $newPath] $script_content] - } - - set modified_script_file $proj_file - set modified_script [open $modified_script_file w] - # Write the modified content to the modified script file - puts -nonewline $modified_script $script_content - - # Close the modified script file - close $modified_script + if {[file exists $proj_file]} { + # Open the input file for reading + if {[catch {open $proj_file r} original_scriptfile]} { + puts "Error: Unable to open file $proj_file" + } else { + set script_content [read $original_scriptfile] + close $original_scriptfile + foreach {inputPath} $PathList { + set oldPath [lindex $inputPath 0] + set newPath [lindex $inputPath 1] + set script_content [string map [list $oldPath $newPath] $script_content] + set oldPath [string map {"{" "" "}" ""} $oldPath] + set newPath [string map {"{" "" "}" ""} $newPath] + set script_content [string map [list $oldPath $newPath] $script_content] } + + set modified_script_file $proj_file + set modified_script [open $modified_script_file w] + # Write the modified content to the modified script file + puts -nonewline $modified_script $script_content + + # Close the modified script file + close $modified_script } } + # } } -} +} \ No newline at end of file