Differences From
Artifact [f82ab7409d]:
1 1 proc tclInit {} {
2 2 rename tclInit {}
3 3
4 4 global auto_path tcl_library tcl_libPath
5 5 global tcl_version tcl_rcFileName
6 6
7 - set noe [info nameofexecutable]
7 + set mountpoint [subst "$::TCLKIT_MOUNTPOINT_VAR"]
8 8
9 9 # Resolve symlinks
10 - set noe [file dirname [file normalize [file join $noe __dummy__]]]
10 + set mountpoint [file dirname [file normalize [file join $mountpoint __dummy__]]]
11 11
12 - set tcl_library [file join $noe lib tcl$tcl_version]
13 - set tcl_libPath [list $tcl_library [file join $noe lib]]
14 -
15 - # get rid of a build residue
16 - unset -nocomplain ::tclDefaultLibrary
12 + set tcl_library [file join $mountpoint lib tcl$tcl_version]
13 + set tcl_libPath [list $tcl_library [file join $mountpoint lib]]
17 14
18 15 # the following code only gets executed once on startup
19 - if {[info exists tcl_rcFileName]} {
16 + if {[info exists ::TCLKIT_INITVFS]} {
17 + catch {
18 + load {} vfs
19 + }
20 +
20 21 # lookup and emulate "source" of lib/vfs/{vfs*.tcl,mk4vfs.tcl}
21 22 switch -- $::tclKitStorage {
22 23 "mk4" {
23 - load {} vfs
24 -
25 24 # must use raw MetaKit calls because VFS is not yet in place
26 25 set d [mk::select exe.dirs parent 0 name lib]
27 26 set d [mk::select exe.dirs parent $d name vfs]
28 27
29 28 foreach x {vfsUtils vfslib mk4vfs} {
30 29 set n [mk::select exe.dirs!$d.files name $x.tcl]
31 30 set s [mk::get exe.dirs!$d.files!$n contents]
................................................................................
76 75 }
77 76 "cvfs" {
78 77 set vfsHandler [list ::vfs::kitdll::vfshandler tcl]
79 78 }
80 79 }
81 80
82 81 # mount the executable, i.e. make all runtime files available
83 - vfs::filesystem mount $noe $vfsHandler
82 + vfs::filesystem mount $mountpoint $vfsHandler
84 83
85 84 # alter path to find encodings
86 85 if {[info tclversion] eq "8.4"} {
87 86 load {} pwb
88 87 librarypath [info library]
89 88 } else {
90 89 encoding dirs [list [file join [info library] encoding]] ;# TIP 258
................................................................................
93 92 # fix system encoding, if it wasn't properly set up (200207.004 bug)
94 93 if {[encoding system] eq "identity"} {
95 94 if {[info exists ::tclkit_system_encoding] && $::tclkit_system_encoding != ""} {
96 95 catch {
97 96 encoding system $::tclkit_system_encoding
98 97 }
99 98 }
100 - unset -nocomplain ::tclkit_system_encoding
101 99 }
102 100
103 101 # If we've still not been able to set the encoding, revert to Tclkit defaults
104 102 if {[encoding system] eq "identity"} {
105 103 catch {
106 104 switch $::tcl_platform(platform) {
107 105 windows { encoding system cp1252 }
108 106 macintosh { encoding system macRoman }
109 107 default { encoding system iso8859-1 }
110 108 }
111 109 }
112 110 }
111 +
112 + # Re-evaluate mountpoint with correct encoding set
113 + set mountpoint [subst "$::TCLKIT_MOUNTPOINT_VAR"]
113 114
114 115 # now remount the executable with the correct encoding
115 116 vfs::filesystem unmount [lindex [::vfs::filesystem info] 0]
116 117
117 - set noe [info nameofexecutable]
118 + # Resolve symlinks
119 + set mountpoint [file dirname [file normalize [file join $mountpoint __dummy__]]]
118 120
119 - # Resolve symlinks
120 - set noe [file dirname [file normalize [file join $noe __dummy__]]]
121 + set tcl_library [file join $mountpoint lib tcl$tcl_version]
122 + set tcl_libPath [list $tcl_library [file join $mountpoint lib]]
121 123
122 - set tcl_library [file join $noe lib tcl$tcl_version]
123 - set tcl_libPath [list $tcl_library [file join $noe lib]]
124 -
125 - vfs::filesystem mount $noe $vfsHandler
124 + vfs::filesystem mount $mountpoint $vfsHandler
126 125 }
127 126
128 127 # load config settings file if present
129 128 namespace eval ::vfs { variable tclkit_version 1 }
130 - catch { uplevel #0 [list source [file join $noe config.tcl]] }
129 + catch { uplevel #0 [list source [file join $mountpoint config.tcl]] }
131 130
131 + # Perform expected initialization
132 132 uplevel #0 [list source [file join $tcl_library init.tcl]]
133 133
134 134 # reset auto_path, so that init.tcl's search outside of tclkit is cancelled
135 135 set auto_path $tcl_libPath
136 136
137 137 # This loads everything needed for "clock scan" to work
138 138 # "clock scan" is used within "vfs::zip", which may be
139 139 # loaded before this is run causing the root VFS to break
140 140 catch { clock scan }
141 141
142 - # Cleanup
143 - unset ::tclKitStorage
144 - unset -nocomplain ::tclKitStorage_fd
142 + if {$::TCLKIT_TYPE == "kitdll"} {
143 + # Set a maximum seek to avoid reading the entire file looking for a
144 + # zip header
145 + catch {
146 + package require vfs::zip
147 + set ::zip::max_header_seek 8192
148 + }
149 +
150 + # Now that the initialization is complete, mount the user VFS if needed
151 + ## Mount the VFS from the Shared Object
152 + if {[info exists ::TCLKIT_INITVFS] && [info exists ::tclKitFilename]} {
153 + catch {
154 + vfs::zip::Mount $::tclKitFilename "/.KITDLL_USER"
155 +
156 + lappend auto_path [file normalize "/.KITDLL_USER/lib"]
157 + }
158 + }
159 +
160 + ## Mount the VFS from executable
161 + if {[info exists ::TCLKIT_INITVFS]} {
162 + catch {
163 + vfs::zip::Mount [info nameofexecutable] "/.KITDLL_APP"
164 +
165 + lappend auto_path [file normalize "/.KITDLL_APP/lib"]
166 + }
167 + }
168 +
169 + }
170 +
171 + # Clean up
172 + unset -nocomplain ::zip::max_header_seek
173 + unset -nocomplain ::TCLKIT_TYPE ::TCLKIT_INITVFS
174 + unset -nocomplain ::TCLKIT_MOUNTPOINT ::TCLKIT_VFSSOURCE ::TCLKIT_MOUNTPOINT_VAR ::TCLKIT_VFSSOURCE_VAR
175 + unset -nocomplain ::tclKitStorage ::tclKitStorage_fd ::tclKitFilename
176 + unset -nocomplain ::tclkit_system_encoding
145 177 }