File: install.tcl

package info (click to toggle)
tcl9.0 9.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,000 kB
  • sloc: ansic: 219,245; tcl: 23,817; makefile: 3,556; sh: 2,572; ada: 1,681; pascal: 1,139; cpp: 1,001; cs: 879; yacc: 842; asm: 468; perl: 420; xml: 95
file content (275 lines) | stat: -rw-r--r-- 7,313 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
###
# Installer actions built into tclsh and invoked
# if the first command line argument is "install"
###
if {[llength $argv] < 2} {
    exit 0
}
namespace eval ::practcl {}
###
# Installer tools
###
proc ::practcl::_readfile {file} {
    set fin [open $file r]
    try {
	fconfigure $fin -encoding utf-8 -eofchar \x1A
	return [read $fin]
    } finally {
	close $fin
    }
}

###
# Return true if the pkgindex file contains
# any statement other than "package ifneeded"
# and/or if any package ifneeded loads a DLL
###
proc ::practcl::_pkgindex_directory {path} {
    set buffer {}
    set pkgidxfile [file join $path pkgIndex.tcl]
    if {![file exists $pkgidxfile]} {
	# No pkgIndex file, read the source
	foreach file [glob -nocomplain $path/*.tm] {
	    set file [file normalize $file]
	    set fname [file rootname [file tail $file]]
	    ###
	    # We used to be able to ... Assume the package is correct in the filename
	    # No hunt for a "package provides"
	    ###
	    lassign [split $fname -] package version
	    ###
	    # Read the file, and override assumptions as needed
	    ###
	    set dat [_readfile $file]
	    # Look for a teapot style Package statement
	    foreach line [split $dat \n] {
		set line [string trim $line]
		if {![string match "# Package *" $line]} {
		    continue
		}
		lassign $line - - package version
		break
	    }
	    # Look for a package provide statement
	    foreach line [split $dat \n] {
		set line [string trim $line]
		if {![string match "package provide *" $line]} {
		    continue
		}
		lassign $line - - package version
		break
	    }
	    append buffer "package ifneeded $package $version \[list\
		    source \[file join \$dir [file tail $file]\]\]" \n
	}
	foreach file [glob -nocomplain $path/*.tcl] {
	    if { [file tail $file] eq "version_info.tcl" } {
		continue
	    }
	    set dat [_readfile $file]
	    if {![regexp "package provide" $dat]} {
		continue
	    }
	    set fname [file rootname [file tail $file]]
	    # Look for a package provide statement
	    foreach line [split $dat \n] {
		set line [string trim $line]
		if {![string match "package provide *" $line]} {
		    continue
		}
		lassign $line - - package version
		if {[string index $package 0] in "\$ \[ @"} {
		    continue
		}
		if {[string index $version 0] in "\$ \[ @"} {
		    continue
		}
		append buffer "package ifneeded $package $version \[list\
			source \[file join \$dir [file tail $file]\]\]" \n
		break
	    }
	}
	return $buffer
    }
    set dat [_readfile $pkgidxfile]
    set trace 0
    #if {[file tail $path] eq "tool"} {
    #    set trace 1
    #}
    set thisline {}
    foreach line [split $dat \n] {
	append thisline $line \n
	if {![info complete $thisline]} {
	    continue
	}
	set line [string trim $line]
	if {$line eq ""} {
	    set thisline {}
	    continue
	}
	if {[string match "#*" $line]} {
	    set thisline {}
	    continue
	}
	if {[regexp "if.*catch.*package.*Tcl.*return" $thisline]} {
	    if {$trace} {
		puts "[file dirname $pkgidxfile] Ignoring $thisline"
	    }
	    set thisline {}
	    continue
	}
	if {[regexp "if.*package.*vsatisfies.*package.*provide.*return" $thisline]} {
	    if {$trace} {
		puts "[file dirname $pkgidxfile] Ignoring $thisline"
	    }
	    set thisline {}
	    continue
	}
	if {![regexp "package.*ifneeded" $thisline]} {
	    # This package index contains arbitrary code
	    # source instead of trying to add it to the main
	    # package index
	    if {$trace} {
		puts "[file dirname $pkgidxfile] Arbitrary code $thisline"
	    }
	    return {source [file join $dir pkgIndex.tcl]}
	}
	append buffer $thisline \n
	set thisline {}
    }
    if {$trace} {
	puts [list [file dirname $pkgidxfile] $buffer]
    }
    return $buffer
}


proc ::practcl::_pkgindex_path_subdir {path} {
    set result {}
    foreach subpath [glob -nocomplain [file join $path *]] {
	if {[file isdirectory $subpath]} {
	    lappend result $subpath {*}[_pkgindex_path_subdir $subpath]
	}
    }
    return $result
}
###
# Index all paths given as though they will end up in the same
# virtual file system
###
proc ::practcl::pkgindex_path args {
    set stack {}
    append buffer {lappend ::PATHSTACK $dir} "\n"
    foreach base $args {
	set base [file normalize $base]
	set paths {}
	foreach dir [glob -nocomplain [file join $base *]] {
	    if {[file tail $dir] eq "teapot"} {
		continue
	    }
	    lappend paths $dir {*}[::practcl::_pkgindex_path_subdir $dir]
	}
	set i [string length $base]
	# Build a list of all of the paths
	if {[llength $paths]} {
	    foreach path $paths {
		if {$path eq $base} {
		    continue
		}
		set path_indexed($path) 0
	    }
	} else {
	    puts [list WARNING: NO PATHS FOUND IN $base]
	}
	set path_indexed($base) 1
	set path_indexed([file join $base boot tcl]) 1
	foreach teapath [glob -nocomplain [file join $base teapot *]] {
	    set pkg [file tail $teapath]
	    append buffer [list set pkg $pkg] "\n"
	    append buffer {set pkginstall [file join $::g(HOME) teapot $pkg]} "\n"
	    append buffer {if {![file exists $pkginstall]} {
    installDir [file join $dir teapot $pkg] $pkginstall
}} "\n"
	}
	foreach path $paths {
	    if {$path_indexed($path)} {
		continue
	    }
	    set thisdir [file_relative $base $path]
	    set idxbuf [::practcl::_pkgindex_directory $path]
	    if { $idxbuf ne "" } {
		incr path_indexed($path)
		append buffer "set dir \[set PKGDIR\
			\[file join \[lindex \$::PATHSTACK end\] $thisdir\]\]" "\n"
		append buffer [string map {$dir $PKGDIR} [string trimright $idxbuf]] "\n"
	    }
	}
    }
    append buffer {set dir [lindex $::PATHSTACK end]} "\n"
    append buffer {set ::PATHSTACK [lrange $::PATHSTACK 0 end-1]} "\n"
    return $buffer
}

###
# topic: 64319f4600fb63c82b2258d908f9d066
# description: Script to build the VFS file system
###
proc ::practcl::installDir {d1 d2} {
    puts [format {%*sCreating %s} [expr {4 * [info level]}] {} [file tail $d2]]
    file delete -force -- $d2
    file mkdir $d2

    foreach ftail [glob -directory $d1 -nocomplain -tails *] {
	set f [file join $d1 $ftail]
	if {[file isdirectory $f] && [string compare CVS $ftail]} {
	    installDir $f [file join $d2 $ftail]
	} elseif {[file isfile $f]} {
	    file copy -force $f [file join $d2 $ftail]
	    if {$::tcl_platform(platform) eq {unix}} {
		file attributes [file join $d2 $ftail] -permissions 0o644
	    } else {
		file attributes [file join $d2 $ftail] -readonly 1
	    }
	}
    }

    if {$::tcl_platform(platform) eq {unix}} {
	file attributes $d2 -permissions 0o755
    } else {
	file attributes $d2 -readonly 1
    }
}

proc ::practcl::copyDir {d1 d2 {toplevel 1}} {
    #if {$toplevel} {
    #    puts [list ::practcl::copyDir $d1 -> $d2]
    #}
    #file delete -force -- $d2
    file mkdir $d2

    foreach ftail [glob -directory $d1 -nocomplain -tails *] {
	set f [file join $d1 $ftail]
	if {[file isdirectory $f] && $ftail ne "CVS"} {
	    copyDir $f [file join $d2 $ftail] 0
	} elseif {[file isfile $f]} {
	    file copy -force $f [file join $d2 $ftail]
	}
    }
}

switch -glob [lindex $argv 1] {
    mkzip {
	zipfs mkzip {*}[lrange $argv 2 end]
    }
    mkimg {
	zipfs mkimg {*}[lrange $argv 2 end]
    }
    [a-z]* {
	::practcl::[lindex $argv 1] {*}[lrange $argv 2 end]
    }
    default {
	puts stderr "usage: $argv0 operation ..."
	exit 1
    }
}
exit 0