Skip to content

Commit 07e793f

Browse files
author
Elod Gyorgy
committed
Prevent fileio extended, checkin now copies checkout.tcl and cleanup scripts, bsp now support <processor>, git HEAD hash query
1 parent 584a44e commit 07e793f

File tree

5 files changed

+119
-21
lines changed

5 files changed

+119
-21
lines changed

checkin.tcl

+68-19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ if {[info exists ::create_path]} {
1212
set dest_dir [file normalize $script_dir/../src]
1313
}
1414

15+
if {[info exists ::debug_prevent_fileio]} {
16+
set debug_prevent_fileio $::debug_prevent_fileio
17+
} else {
18+
set debug_prevent_fileio 0
19+
}
20+
1521
puts "INFO: Targeting $dest_dir for export"
1622
set var_overwrite_ok [dict create]
1723

@@ -76,12 +82,24 @@ foreach pf $pf_names {
7682
}
7783
# For some reason it needs to be made active for report to work
7884
platform active $pf
85+
set pf_dest [file normalize $dest_dir/$pf/]
7986
# Get the xsa
80-
set xsa [dict get [platform report -dict $pf] {hw spec}]
81-
file copy -force -- "$xsa" $dest_dir/$pf/
82-
set pf_subscript $dest_dir/$pf/5_hw_pf_xsa.tcl
83-
file copy -force -- $script_dir/sub/hw_pf_xsa.tcl "$pf_subscript"
84-
set fid [open "$pf_subscript" a]
87+
set xsa [file normalize [dict get [platform report -dict $pf] {hw spec}]]
88+
set pf_subscript [file normalize $pf_dest/5_hw_pf_xsa.tcl]
89+
90+
if {$debug_prevent_fileio == 0} {
91+
# Check if xsa is linked from src already, copy if not
92+
if { [file dirname $xsa] ne $pf_dest } {
93+
file copy -force -- "$xsa" $pf_dest
94+
}
95+
file copy -force -- $script_dir/sub/hw_pf_xsa.tcl "$pf_subscript"
96+
set fid [open "$pf_subscript" a]
97+
} else {
98+
puts "TRACE: file copy -force -- \"$xsa\" $pf_dest"
99+
puts "TRACE: file copy -force -- $script_dir/sub/hw_pf_xsa.tcl \"$pf_subscript\""
100+
set fid stdout
101+
}
102+
85103
catch {
86104
# Export platform config
87105
puts $fid "\n"
@@ -90,7 +108,9 @@ foreach pf $pf_names {
90108
puts $fid "platform config -extra-compiler-flags pmufw \"[platform config -extra-compiler-flags pmufw]\""
91109
puts $fid "platform config -extra-linker-flags pmufw \"[platform config -extra-linker-flags pmufw]\""
92110
} result options
93-
close $fid
111+
if {$debug_prevent_fileio == 0} {
112+
close $fid
113+
}
94114
return -options $options $result
95115

96116
# Do the domains
@@ -130,16 +150,20 @@ foreach pf $pf_names {
130150
set d_subscript $dest_dir/$d/25_standalone_bsp.tcl
131151
puts "INFO: Generating $d_subscript."
132152

133-
set dfid [open $d_subscript w]
153+
if {$debug_prevent_fileio == 0} {
154+
set dfid [open $d_subscript w]
155+
} else {
156+
set dfid stdout
157+
}
134158
set sfid [open $script_dir/sub/standalone_bsp.tcl r]
135159
catch {
136160
# Get domain properties
137161
set proc [dict get [domain report -dict $d] {processor}]
138-
# Write to subscript's beginning
139-
puts $dfid "set proc \"$proc\""
140-
# Copy the rest of the subscript
162+
set var_map [list <processor> $proc \
163+
]
164+
# Copy the subcript while replacing variables
141165
while { [gets $sfid line] >= 0 } {
142-
puts $dfid $line
166+
puts $dfid [string map $var_map $line]
143167
}
144168
# Only SOME of the config params possible
145169
set bsp_configs {\
@@ -167,18 +191,14 @@ foreach pf $pf_names {
167191
}
168192

169193
} result options
170-
close $dfid
194+
if {$debug_prevent_fileio == 0} {
195+
close $dfid
196+
}
171197
close $sfid
172198
return -options $options $result
173199
}
174200
}
175201

176-
if {[info exists ::debug_prevent_fileio]} {
177-
set debug_prevent_fileio $::debug_prevent_fileio
178-
} else {
179-
set debug_prevent_fileio 0
180-
}
181-
182202
# Do the applications
183203
set app_names ""
184204
if { [catch {app list}] != 0 } {
@@ -342,4 +362,33 @@ foreach app_name $app_names {
342362
close $outfile
343363
}
344364
return -options $options $result
345-
}
365+
}
366+
367+
# When all sources are checked into src/, copy checkout script and README too
368+
if {$debug_prevent_fileio == 0} {
369+
file copy -force -- [file normalize $script_dir/checkout.tcl] $dest_dir/
370+
file copy -force -- [file normalize $script_dir/README.md] [file normalize $dest_dir/]
371+
# Attempt to query git HEAD hash
372+
if { [catch { set fid [open "|git -C \"$script_dir\" rev-parse HEAD" r] } errmsg] } {
373+
puts "WARNING: $errmsg"
374+
puts "WARNING: git command cannot be found (not in PATH?), so could not append $dest_dir/README.md with script versioning info."
375+
} elseif { [gets $fid hash] eq -1 } {
376+
puts "WARNING: git error so could not append $dest_dir/README.md with script versioning info."
377+
} else {
378+
set dfid [open [file normalize $dest_dir/README.md] a]
379+
catch {
380+
puts $dfid "\nThis README.md was created by the following commit hash:\n$hash"
381+
} result options
382+
close $dfid
383+
close $fid
384+
return -options $options $result
385+
}
386+
}
387+
388+
# Copy cleanup scripts to ws/, which is the default destination for checkout.tcl
389+
if {$debug_prevent_fileio == 0} {
390+
file copy -force -- [file normalize $script_dir/sub/cleanup._sh] [file normalize $dest_dir/../ws/cleanup.sh]
391+
file copy -force -- [file normalize $script_dir/sub/cleanup._cmd] [file normalize $dest_dir/../ws/cleanup.cmd]
392+
}
393+
394+
puts "INFO: Checked in workspace [getws] to $dest_dir"

checkout.tcl

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Run this script to create the Vitis workspace in the ws/ sub-directory
1+
# Run this script to create the Vitis workspace in the <repo>/ws/ sub-directory
22
# If ::create_path global variable is set, the project is created under that path instead of ws/
33

44
set script [info script]
@@ -72,6 +72,16 @@ catch {
7272
}
7373

7474
set scripts [deep_traverse $src_dir "*.tcl"]
75+
# Self should be there
76+
set selfs [lsearch -all $scripts [file normalize $script]]
77+
if { [llength $selfs] eq 0 } {
78+
return -code error "ERROR: Self not found while deep searching $src_dir"
79+
}
80+
# Remove all instances of self to avoid recursive call below
81+
foreach idx $selfs {
82+
set scripts [lreplace $scripts $idx $idx]
83+
}
84+
# Order by integer prefix
7585
set ordered_scripts [lsort -command sort_by_fileprefix $scripts]
7686

7787
puts "INFO: Found the following subscripts:"
@@ -89,4 +99,4 @@ catch {
8999
puts "Changing back working dir to: $popd"
90100
cd $popd
91101

92-
return -options $options $result
102+
return -options $options $result

sub/cleanup._cmd

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
rem save current working directory
3+
pushd %~dp0
4+
5+
rem delete all files from subfolders
6+
for /d /r %%i in (*) do del /f /q %%i\*
7+
rem delete all subfolders
8+
for /d %%i in (*) do rd /S /Q %%i
9+
10+
rem unmark read only from all files
11+
attrib -R .\* /S
12+
13+
rem mark read only those we wish to keep
14+
attrib +R .\cleanup.sh
15+
attrib +R .\cleanup.cmd
16+
17+
rem delete all non read-only
18+
del /Q /A:-R .\*
19+
20+
rem unmark read-only
21+
attrib -R .\*
22+
23+
rem restore original working directory
24+
popd

sub/cleanup._sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This script is useful for cleaning up the 'project'
2+
# directory of a Digilent Vivado-project git repository
3+
###
4+
# Run the following command to change permissions of
5+
# this 'cleanup' file if needed:
6+
# chmod u+x cleanup.sh
7+
###
8+
script_dir=$(dirname ${BASH_SOURCE[0]})
9+
# Remove directories/subdirectories
10+
find $script_dir -mindepth 1 -type d -exec rm -rf {} +
11+
# Remove any other files than:
12+
find $script_dir -type f ! -name 'cleanup.sh' \
13+
! -name 'cleanup.cmd' \
14+
-exec rm -rf {} +

sub/standalone_bsp.tcl

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set domain_name [file tail $script_dir]
1111
# Modify these for custom domain/BSP settings
1212
set arch "64-bit"
1313
set os "standalone"
14+
set proc "<processor>"
1415

1516
domain create -name $domain_name -proc $proc -arch $arch -os $os
1617

0 commit comments

Comments
 (0)