Browse Source

attempt to fix make.tcl for use with tcl8.6 (no zipfs available)

master
Julian Noble 3 weeks ago
parent
commit
4fa6d67e3d
  1. 91
      src/make.tcl

91
src/make.tcl

@ -2839,56 +2839,65 @@ foreach vfstail $vfs_tails {
#zipfs mkimg replaces the entire zipped vfs in the runtime - so we need the original data to be part of our targetvfs.
puts stdout "building $vfsname.new with zipfs vfsdir:$vfstail cwd: [pwd]"
file mkdir $targetvfs
set rtmountpoint //zipfs:/rtmounts/$runtime_fullname
if {![file exists $rtmountpoint]} {
if {[catch {
tcl::zipfs::mount $building_runtime rtmounts/$runtime_fullname
} errM]} {
puts stderr "Failed to mount $building_runtime using standard api. Err:$errM\n trying reverse args on tcl::zipfs::mount..."
if {[info commands ::tcl::zipfs::mount] ne ""} {
set rtmountpoint //zipfs:/rtmounts/$runtime_fullname
if {![file exists $rtmountpoint]} {
if {[catch {
tcl::zipfs::mount rtmounts/$runtime_fullname $building_runtime
tcl::zipfs::mount $building_runtime rtmounts/$runtime_fullname
} errM]} {
puts stderr "ALSO Failed to mount $building_runtime using reverse args to api. Err:$errM - no mountable zipfs on runtime?"
puts stderr "Failed to mount $building_runtime using standard api. Err:$errM\n trying reverse args on tcl::zipfs::mount..."
if {[catch {
tcl::zipfs::mount rtmounts/$runtime_fullname $building_runtime
} errM]} {
puts stderr "ALSO Failed to mount $building_runtime using reverse args to api. Err:$errM - no mountable zipfs on runtime?"
}
}
}
}
#strip any existing zipfs on the runtime..
#2024 - 'zipfs info //zipfs:/mountpoint' is supposed to give us the offset - but it doesn't if the exe has been 'adjusted' to use file offsets.
#which unfortunately Tcl does by default after the 2021 'fix' :(
#https://core.tcl-lang.org/tcl/tktview/aaa84fbbc5
set raw_runtime $buildfolder/raw_$runtime_fullname
if {[file exists $rtmountpoint]} {
merge_over $rtmountpoint $targetvfs
#see if we can extract the exe part
set baseoffset [lindex [tcl::zipfs::info $rtmountpoint] 3]
if {$baseoffset != 0} {
#tcl was able to determine the compressed-data offset
#either because runtime is a basic catted exe+zip, or Tcl fixed 'zipfs info'
set fdrt [open $building_runtime r]
chan configure $fdrt -translation binary
set exedata [read $fdrt $baseoffset] ;#may include stored password and ending header // REVIEW - strip it?
close $fdrt
set fdraw [open $raw_runtime w]
chan configure $fdraw -translation binary
puts -nonewline $fdraw $exedata
close $fdraw
#strip any existing zipfs on the runtime..
#2024 - 'zipfs info //zipfs:/mountpoint' is supposed to give us the offset - but it doesn't if the exe has been 'adjusted' to use file offsets.
#which unfortunately Tcl does by default after the 2021 'fix' :(
#https://core.tcl-lang.org/tcl/tktview/aaa84fbbc5
set raw_runtime $buildfolder/raw_$runtime_fullname
if {[file exists $rtmountpoint]} {
merge_over $rtmountpoint $targetvfs
#see if we can extract the exe part
set baseoffset [lindex [tcl::zipfs::info $rtmountpoint] 3]
if {$baseoffset != 0} {
#tcl was able to determine the compressed-data offset
#either because runtime is a basic catted exe+zip, or Tcl fixed 'zipfs info'
set fdrt [open $building_runtime r]
chan configure $fdrt -translation binary
set exedata [read $fdrt $baseoffset] ;#may include stored password and ending header // REVIEW - strip it?
close $fdrt
set fdraw [open $raw_runtime w]
chan configure $fdraw -translation binary
puts -nonewline $fdraw $exedata
close $fdraw
} else {
#presumably the supplied building_runtime has had its offsets adjusted so that it all appears within offsets off the zip. (file relative offsets)
#due to zipfs info bug - zipfs now can't tell us the offset of the compressed data.
#we need to use a similarly assumptive method as tclZipfs.c uses to determine the start of the compressed contents
package require punk::zip
#we don't technically need to extract the raw exe for 'zip' - as zipfs mkimg can work on the combined file (ignores zip)
# - but for consistency we want raw_runtime to be emitted in the filesystem.
punk::zip::extract_preamble $building_runtime $raw_runtime
}
} else {
#presumably the supplied building_runtime has had its offsets adjusted so that it all appears within offsets off the zip. (file relative offsets)
#due to zipfs info bug - zipfs now can't tell us the offset of the compressed data.
#we need to use a similarly assumptive method as tclZipfs.c uses to determine the start of the compressed contents
package require punk::zip
#we don't technically need to extract the raw exe for 'zip' - as zipfs mkimg can work on the combined file (ignores zip)
# - but for consistency we want raw_runtime to be emitted in the filesystem.
punk::zip::extract_preamble $building_runtime $raw_runtime
#the input building_runtime wasn't mountable as a zip - so presumably a plain executable
#set building_runtime $buildfolder/build_$runtime_fullname ;#working copy of runtime executable - (possibly with kit/zipfs/cookfs etc attached!)
#set raw_runtime $buildfolder/raw_$runtime_fullname
file copy -force $building_runtime $raw_runtime
}
} else {
#the input building_runtime wasn't mountable - so presumably a plain executable
#set building_runtime $buildfolder/build_$runtime_fullname ;#working copy of runtime executable - (possibly with kit/zipfs/cookfs etc attached!)
#set raw_runtime $buildfolder/raw_$runtime_fullname
file copy -force $building_runtime $raw_runtime
#tcl we are calling with doesn't have zipfs - can't mount
puts stderr "WARNING: tcl shell '[info nameofexecutable]' being used to build doesn't have zipfs - falling back to punk::zip::extract_preamble"
punk::zip::extract_preamble $building_runtime $raw_runtime $buildfolder/extracted_$runtime_fullname.zip
merge_over $buildfolder/extracted_$runtime_fullname.zip $targetvfs
}
merge_over $sourcefolder/vfs/_vfscommon.vfs $targetvfs

Loading…
Cancel
Save