Punk Tcl binary-artifact repository. 'Battery Included' Tclkits intended to support the punk shell - but can be used as ordinary runtimes for Tcl.
see: https://www.gitea1.intx.com.au/jn/punkshell
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
5.6 KiB
148 lines
5.6 KiB
package require sha1 |
|
set srcdir [file dirname [file normalize [info script]]] |
|
set basedir [file dirname $srcdir] |
|
puts stdout "processing using base folder $basedir" |
|
|
|
set rootfolders [glob -dir $basedir -types {d} -tail *] |
|
set os_list [list linux macosx win32 freebsd netbsd dragonflybsd openbsd msys] |
|
set known_skip_tails [list src test] |
|
set skip_extensions [list .md .txt] |
|
set original_cwd [pwd] |
|
set R "\x1b\[31m" ;#Red |
|
set G "\x1b\[32m" ;#Green |
|
set Y "\x1b\[33m" ;#Yellow |
|
set C "\x1b\[36m" ;#Cyan |
|
set RST "\x1b\[m" ;#reset |
|
|
|
proc do_sha1_in_folder {binaryfolder level} { |
|
global R G Y C RST skip_extensions |
|
set indent [string repeat " " $level] |
|
puts stdout "${indent}${C}[string repeat - 50]$RST" |
|
if {$level == 0} { |
|
puts stdout "${indent}Processing runtime folder $binaryfolder" |
|
} else { |
|
puts stdout "${indent}Processing sub folder $binaryfolder" |
|
} |
|
|
|
#temp |
|
if {$level > 0} { |
|
#return |
|
} |
|
|
|
set shafile [file join $binaryfolder sha1sums.txt] |
|
set existing_sha_dict [dict create] |
|
if {[file exists $shafile]} { |
|
puts stdout "${indent}Existing sha1sums.txt found" |
|
set fd [open $shafile r] |
|
set existing_sha_data [read $fd] |
|
close $fd |
|
foreach ln [split $existing_sha_data \n] { |
|
set trimln [string trim $ln] |
|
if {$trimln eq ""} {continue} |
|
set first_sp [string first " " $trimln] |
|
set h [string range $trimln 0 $first_sp-1] |
|
set tag [string range $trimln $first_sp+1 end] |
|
# e.g *tclkit where * indicates binary was used |
|
# or possibly a space instead of * (same output as unix 'sha1sum -b <filename>') |
|
dict set existing_sha_dict [string range $tag 1 end] $h |
|
} |
|
|
|
} else { |
|
puts stdout "${indent}No current sha1sums.txt file" |
|
} |
|
|
|
set candidate_file_tails [glob -nocomplain -dir $binaryfolder -type f -tail *] |
|
cd $binaryfolder |
|
set git_files [exec git ls-files --exclude-standard ":(glob)*"] |
|
set new_sha_dict [dict create] |
|
foreach ftail $candidate_file_tails { |
|
if {[string tolower [file extension $ftail]] in $skip_extensions} {continue} |
|
if {$ftail in $git_files} { |
|
set hash [sha1::sha1 -hex -filename [file join $binaryfolder $ftail]] |
|
dict set new_sha_dict $hash $ftail |
|
} else { |
|
puts stdout "${indent}${R}Skipping $ftail$RST (not in result of 'git ls-files --exclude-standard :(glob)*')" |
|
} |
|
} |
|
set changes 0 |
|
dict for {h f} $new_sha_dict { |
|
if {[dict exists $existing_sha_dict $f]} { |
|
if {$h ne [dict get $existing_sha_dict $f]} { |
|
puts -nonewline stdout "${indent}${Y}*UPD*$RST $h $f\n" |
|
incr changes |
|
} else { |
|
puts -nonewline stdout "${indent}SAME $h *$f$RST\n" |
|
} |
|
} else { |
|
puts -nonewline stdout "${indent}${G}*NEW*$RST $h *$f\n" |
|
incr changes |
|
} |
|
} |
|
if {[dict size $existing_sha_dict] != [dict size $new_sha_dict] || $changes > 0} { |
|
puts stderr "${indent}rewriting sha file at $shafile" |
|
set fd [open $shafile w] |
|
dict for {h f} $new_sha_dict { |
|
puts -nonewline $fd "$h *$f\n" |
|
} |
|
close $fd |
|
} else { |
|
puts stderr "${indent}No changes or additions detected" |
|
} |
|
set subfolder_tails [glob -nocomplain -dir $binaryfolder -type d -tail *] |
|
foreach sftail $subfolder_tails { |
|
if {[string match .* $sftail]} { |
|
continue |
|
} |
|
do_sha1_in_folder [file join $binaryfolder $sftail] [expr {$level + 1}] |
|
} |
|
} |
|
|
|
|
|
set level 0 |
|
set platform_tails [list] |
|
foreach dirtail $rootfolders { |
|
set level 0 |
|
set indent "" |
|
if {$dirtail in $known_skip_tails} {continue} |
|
set firstword [lindex [split $dirtail -] 0] |
|
if {$firstword ni $os_list} { |
|
puts stderr "skipping unrecognised folder: $dirtail" |
|
continue |
|
} |
|
lappend platform_tails $dirtail |
|
set runtimefolder [file join $basedir $dirtail] |
|
do_sha1_in_folder $runtimefolder 0 |
|
} |
|
|
|
#platforms.txt - the machine-readable list of platform folders this repo serves, |
|
#at the repo root so raw-file consumers (punk-runtime 'platforms -remote', and |
|
#third-party mirrors using the same layout) can discover platforms without a |
|
#directory-listing capability. One platform-dir name per line; '#' comment lines |
|
#and blanks are ignored by consumers. Names follow the punkshell canonical |
|
#platform names (punk::platform / 'help platforms' in the punk shell). |
|
set platformsfile [file join $basedir platforms.txt] |
|
set new_platforms [lsort $platform_tails] |
|
set existing_platforms [list] |
|
if {[file exists $platformsfile]} { |
|
set fd [open $platformsfile r] |
|
foreach ln [split [read $fd] \n] { |
|
set trimln [string trim $ln] |
|
if {$trimln eq "" || [string index $trimln 0] eq "#"} {continue} |
|
lappend existing_platforms $trimln |
|
} |
|
close $fd |
|
} |
|
if {$new_platforms ne $existing_platforms} { |
|
puts stderr "rewriting platforms file at $platformsfile ([llength $new_platforms] platforms)" |
|
set fd [open $platformsfile w] |
|
fconfigure $fd -translation lf |
|
puts $fd "#platform folders served by this artifact repo (generated by src/build_sha1sums.tcl)" |
|
puts $fd "#one punkshell canonical platform-dir name per line - see 'help platforms' in the punk shell" |
|
foreach p $new_platforms { |
|
puts $fd $p |
|
} |
|
close $fd |
|
} else { |
|
puts stderr "platforms.txt unchanged ([llength $new_platforms] platforms)" |
|
} |
|
cd $original_cwd
|
|
|