-
Notifications
You must be signed in to change notification settings - Fork 69
/
sak.tcl
executable file
·2468 lines (2037 loc) · 62 KB
/
sak.tcl
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@"}
# --------------------------------------------------------------
# Perform various checks and operations on the distribution.
# SAK = Swiss Army Knife.
set distribution [file dirname [info script]]
set auto_path [linsert $auto_path 0 [file join $distribution modules]]
set critcldefault {}
set critclnotes {}
set dist_excluded {}
proc package_name {text} {global package_name ; set package_name $text}
proc package_version {text} {global package_version ; set package_version $text}
proc dist_exclude {path} {global dist_excluded ; lappend dist_excluded $path}
proc critcl {name files} {
global critclmodules
set critclmodules($name) $files
return
}
proc critcl_main {name files} {
global critcldefault
set critcldefault $name
critcl $name $files
return
}
proc critcl_notes {text} {
global critclnotes
set critclnotes [string map {{\n } \n} $text]
return
}
source [file join $distribution support installation version.tcl] ; # Get version information.
set package_nv ${package_name}-${package_version}
catch {eval file delete -force [glob [file rootname [info script]].tmp.*]}
# --------------------------------------------------------------
# SAK internal debugging support.
# Configuration, change as needed
set debug 0
if {$debug} {
proc sakdebug {script} {uplevel 1 $script ; return}
} else {
proc sakdebug {args} {}
}
# --------------------------------------------------------------
# Internal helper to load packages straight out of the local directory
# tree. Not something from an installation, possibly incompatible.
proc getpackage {package tclmodule} {
global distribution
if {[catch {package present $package}]} {
set src [file join \
$distribution modules \
$tclmodule]
if {[file exists $src]} {
uplevel #0 [list source $src]
} else {
# Fallback
package require $package
}
}
}
# --------------------------------------------------------------
proc tclfiles {} {
global distribution
getpackage fileutil fileutil/fileutil.tcl
set fl [fileutil::findByPattern $distribution -glob *.tcl]
# Remove files under SCCS. They are repository, not sources to check.
set tmp {}
foreach f $fl {
if {[string match *SCCS* $f]} continue
lappend tmp $f
}
proc tclfiles {} [list return $tmp]
return $tmp
}
proc modtclfiles {modules} {
global mfiles guide
load_modinfo
set mfiles [list]
foreach m $modules {
eval $guide($m,pkg) $m __dummy__
}
return $mfiles
}
proc modules {} {
global distribution
set fl [list]
foreach f [glob -nocomplain [file join $distribution modules *]] {
if {![file isdirectory $f]} {continue}
if {[string match CVS [file tail $f]]} {continue}
if {![file exists [file join $f pkgIndex.tcl]]} {continue}
lappend fl [file tail $f]
}
set fl [lsort $fl]
proc modules {} [list return $fl]
return $fl
}
proc modules_mod {m} {
return [expr {[lsearch -exact [modules] $m] >= 0}]
}
proc dealias {modules} {
set _ {}
foreach m $modules {
if {[file exists $m]} {
set m [file tail $m]
}
lappend _ $m
}
return $_
}
proc load_modinfo {} {
global distribution modules guide
source [file join $distribution support installation modules.tcl] ; # Get list of installed modules.
source [file join $distribution support installation actions.tcl] ; # Get installer support code.
proc load_modinfo {} {}
return
}
proc imodules {} {global modules ; load_modinfo ; return $modules}
proc imodules_mod {m} {
global modules
load_modinfo
return [expr {[lsearch -exact $modules $m] > 0}]
}
# Result: dict (package name --> list of package versions).
proc loadpkglist {fname} {
set f [open $fname r]
foreach line [split [read $f] \n] {
set line [string trim $line]
if {[string match @* $line]} continue
if {$line == {}} continue
foreach {n v} $line break
lappend p($n) $v
set p($n) [lsort -uniq -dict $p($n)]
}
close $f
return [array get p]
}
# Result: dict (package name => list of (list of package versions, module)).
proc ipackages {args} {
# Determine indexed packages (ifneeded, pkgIndex.tcl)
global distribution
if {[llength $args] == 0} {set args [modules]}
array set p {}
foreach m $args {
set f [open [file join $distribution modules $m pkgIndex.tcl] r]
foreach line [split [read $f] \n] {
if { [regexp {#} $line]} {continue}
if {![regexp {ifneeded} $line]} {continue}
regsub {^.*ifneeded } $line {} line
regsub {([0-9]) \[.*$} $line {\1} line
foreach {n v} $line break
set v [string trimright $v \\]
if {![info exists p($n)]} {
set p($n) [list $v $m]
} else {
# We have multiple versions of the same package. We
# remember all versions.
foreach {vlist mx} $p($n) break
lappend vlist $v
set p($n) [list [lsort -uniq -dict $vlist] $mx]
}
}
close $f
}
return [array get p]
}
# Result: dict (package name --> list of package versions).
proc ppackages {args} {
# Determine provided packages (provide, *.tcl - pkgIndex.tcl)
# We cache results for a bit of speed, some stuff uses this
# multiple times for the same arguments.
global ppcache
if {[info exists ppcache($args)]} {
return $ppcache($args)
}
global p pf currentfile
array set p {}
if {[llength $args] == 0} {
set files [tclfiles]
} else {
set files [modtclfiles $args]
}
getpackage fileutil fileutil/fileutil.tcl
set capout [fileutil::tempfile] ; set capcout [open $capout w]
set caperr [fileutil::tempfile] ; set capcerr [open $caperr w]
array set notprovided {}
foreach f $files {
# We ignore package indices and all files not in a module.
if {[string equal pkgIndex.tcl [file tail $f]]} {continue}
if {![regexp modules $f]} {continue}
# We use two methods to extract the version information from a
# module and its packages. First we do a static scan for
# appropriate statements. If that did not work out we try to
# execute the script in a modified interpreter which lets us
# pick up dynamically generated version data (like stored in
# variables). If the second method fails as well we give up.
# Method I. Static scan.
# We do heuristic scanning of the code to locate suitable
# package provide statements.
set fh [open $f r]
set currentfile [eval file join [lrange [file split $f] end-1 end]]
set ok -1
foreach line [split [read $fh] \n] {
if {[regexp "\#\\s*@sak\\s+notprovided\\s+(\[^\\s\]+)" $line -> nppname]} {
sakdebug {puts stderr "PRAGMA notprovided = $nppname"}
set notprovided($nppname) .
}
regsub "\#.*$" $line {} line
if {![regexp {provide} $line]} {continue}
if {![regexp {package} $line]} {continue}
# Now a stronger check for the actual command
if {![regexp {package[ ][ ]*provide} $line]} {continue}
set xline $line
regsub {^.*provide } $line {} line
regsub {\].*$} $line {\1} line
sakdebug {puts stderr __$f\ _________$line}
#foreach {n v} $line break
if {[catch {
set n [lindex $line 0]
set v [lindex $line 1]
} err]} {
sakdebug {puts stderr "Line: $line of file $f threw $err"}
continue
}
# HACK ...
# Module 'page', package 'page::gen::peg::cpkg'.
# Has a provide statement inside a template codeblock.
# Name is placeholder @@. Ignore this specific name.
# Better would be to use general static Tcl parsing
# to find that the string is a variable value.
if {[string equal $n @@]} continue
if {[regexp {^[0-9]+(\.[0-9]+)*$} $v]} {
lappend p($n) $v
set p($n) [lsort -uniq -dict $p($n)]
set pf($n,$v) $currentfile
set ok 1
# We continue the scan. The file may provide several
# versions of the same package, or multiple packages.
continue
}
# 'package provide foo' are tests. Ignore.
if {$v == ""} continue
# We do not set the state to bad if we found ok provide
# statements before, only if nothing was found before.
if {$ok < 0} {
set ok 0
# No good version found on the current line. We scan
# further through the file and hope for more luck.
sakdebug {puts stderr @_$f\ _________$xline\t<$n>\t($v)}
}
}
close $fh
# Method II. Restricted Execution.
# We now try to run the code through a safe interpreter
# and hope for better luck regarding package information.
if {$ok == -1} {sakdebug {puts stderr $f\ IGNORE}}
if {$ok == 0} {
sakdebug {puts -nonewline stderr $f\ EVAL}
# Source the code into a sub-interpreter. The sub
# interpreter overloads 'package provide' so that the
# information about new packages goes directly to us. We
# also make sure that the sub interpreter doesn't kill us,
# and will not get stuck early by trying to load other
# files, or when creating procedures in namespaces which
# do not exist due to us disabling most of the package
# management.
set fh [open $f r]
set ip [interp create]
# Kill control structures. Namespace is required, but we
# skip everything related to loading of packages,
# i.e. 'command import'.
$ip eval {
rename ::if ::_if_
rename ::namespace ::_namespace_
proc ::if {args} {}
proc ::namespace {cmd args} {
#puts stderr "_nscmd_ $cmd"
::_if_ {[string equal $cmd import]} return
#puts stderr "_nsdo_ $cmd $args"
return [uplevel 1 [linsert $args 0 ::_namespace_ $cmd]]
}
}
# Kill more package stuff, and ensure that unknown
# commands are neither loaded nor abort execution. We also
# stop anything trying to kill the application at large.
interp alias $ip package {} xPackage
interp alias $ip source {} xNULL
interp alias $ip unknown {} xNULL
interp alias $ip proc {} xNULL
interp alias $ip exit {} xNULL
# From here on no redefinitions anymore, proc == xNULL !!
$ip eval {close stdout} ; interp share {} $capcout $ip
$ip eval {close stderr} ; interp share {} $capcerr $ip
if {[catch {$ip eval [read $fh]} msg]} {
sakdebug {puts stderr "ERROR in $currentfile:\n$::errorInfo\n"}
}
sakdebug {puts stderr ""}
close $fh
interp delete $ip
}
}
close $capcout ; file delete $capout
close $capcerr ; file delete $caperr
# Process the accumulated pragma information, remove all the
# packages which exist but not really, in terms of indexing.
foreach n [array names notprovided] {
catch { unset p($n) }
array unset pf $n,*
}
set pp [array get p]
unset p
set ppcache($args) $pp
return $pp
}
proc xNULL {args} {}
proc xPackage {cmd args} {
if {[string equal $cmd provide]} {
global p pf currentfile
foreach {n v} $args break
# No version specified, this is an inquiry, we ignore these.
if {$v == {}} {return}
sakdebug {puts stderr \tOK\ $n\ =\ $v}
lappend p($n) $v
set p($n) [lsort -uniq -dict $p($n)]
set pf($n,$v) $currentfile
}
return
}
proc sep {} {puts ~~~~~~~~~~~~~~~~~~~~~~~~}
proc gd-cleanup {} {
global package_nv
puts {Cleaning up...}
set fl [glob -nocomplain ${package_nv}*]
foreach f $fl {
puts " Deleting $f ..."
catch {file delete -force $f}
}
return
}
proc gd-gen-archives {} {
global package_name package_nv
puts {Generating archives...}
set tar [auto_execok tar]
if {$tar != {}} {
puts " Gzipped tarball (${package_nv}.tar.gz)..."
catch {
exec $tar cf - ${package_nv} | gzip --best > ${package_nv}.tar.gz
}
set bzip [auto_execok bzip2]
if {$bzip != {}} {
puts " Bzipped tarball (${package_nv}.tar.bz2)..."
exec tar cf - ${package_nv} | bzip2 > ${package_nv}.tar.bz2
}
set xz [auto_execok xz]
if {$xz != {}} {
puts " Xzipped tarball (${package_nv}.tar.xz)..."
exec tar cf - ${package_nv} | xz > ${package_nv}.tar.xz
}
}
set zip [auto_execok zip]
if {$zip != {}} {
puts " Zip archive (${package_nv}.zip)..."
catch {
exec $zip -r ${package_nv}.zip ${package_nv}
}
}
set sdx [auto_execok sdx]
if {$sdx != {}} {
file copy -force [file join ${package_nv} support installation main.tcl] \
[file join ${package_nv} main.tcl]
file rename ${package_nv} ${package_name}.vfs
puts " Starkit (${package_nv}.kit)..."
exec sdx wrap ${package_name}
file rename ${package_name} ${package_nv}.kit
if {![file exists tclkit]} {
puts " No tclkit present in current working directory, no starpack."
} else {
puts " Starpack (${package_nv}.exe)..."
exec sdx wrap ${package_name} -runtime tclkit
file rename ${package_name} ${package_nv}.exe
}
file rename ${package_name}.vfs ${package_nv}
}
puts { Keeping directory for other archive types}
## Keep the directory for 'sdx' - kit/pack
return
}
proc xcopyfile {src dest} {
# dest can be dir or file
global mfiles
lappend mfiles $src
return
}
proc xcopy {src dest recurse {pattern *}} {
if {[string equal $pattern *] || !$recurse} {
foreach file [glob [file join $src $pattern]] {
set base [file tail $file]
set sub [file join $dest $base]
if {0 == [string compare CVS $base]} {continue}
if {[file isdirectory $file]} then {
if {$recurse} {
xcopy $file $sub $recurse $pattern
}
} else {
xcopyfile $file $sub
}
}
} else {
foreach file [glob [file join $src *]] {
set base [file tail $file]
set sub [file join $dest $base]
if {[string equal CVS $base]} {continue}
if {[file isdirectory $file]} then {
if {$recurse} {
xcopy $file $sub $recurse $pattern
}
} else {
if {![string match $pattern $base]} {continue}
xcopyfile $file $sub
}
}
}
}
proc xxcopy {src dest recurse {pattern *}} {
global package_name
file mkdir $dest
foreach file [glob -nocomplain [file join $src $pattern]] {
set base [file tail $file]
set sub [file join $dest $base]
# Exclude CVS, SCCS, ... automatically, and possibly the temp
# hierarchy itself too.
if {0 == [string compare CVS $base]} {continue}
if {0 == [string compare SCCS $base]} {continue}
if {0 == [string compare BitKeeper $base]} {continue}
if {[string match ${package_name}-* $base]} {continue}
if {[string match *~ $base]} {continue}
if {[file isdirectory $file]} then {
if {$recurse} {
file mkdir $sub
xxcopy $file $sub $recurse $pattern
}
} else {
puts -nonewline stdout . ; flush stdout
file copy -force $file $sub
}
}
}
proc gd-assemble {} {
global package_nv distribution dist_excluded
puts "Assembling distribution in directory '${package_nv}'"
xxcopy $distribution ${package_nv} 1
foreach f $dist_excluded {
file delete -force [file join $package_nv $f]
}
puts ""
return
}
proc normalize-version {v} {
# Strip everything after the first non-version character, and any
# trailing dots left behind by that, to avoid the insertion of bad
# version numbers into the generated .tap file.
regsub {[^0-9.].*$} $v {} v
return [string trimright $v .]
}
proc gd-gen-tap {} {
getpackage textutil textutil/textutil.tcl
getpackage fileutil fileutil/fileutil.tcl
global package_name package_version distribution tcl_platform
set pname [textutil::cap $package_name]
set modules [imodules]
array set pd [getpdesc]
set lines [list]
# Header
lappend lines {format {TclDevKit Project File}}
lappend lines {fmtver 2.0}
lappend lines {fmttool {TclDevKit TclApp PackageDefinition} 2.5}
lappend lines {}
lappend lines "## Saved at : [clock format [clock seconds]]"
lappend lines "## By : $tcl_platform(user)"
lappend lines {##}
lappend lines "## Generated by \"[file tail [info script]] tap\""
lappend lines "## of $package_name $package_version"
lappend lines {}
lappend lines {########}
lappend lines {#####}
lappend lines {###}
lappend lines {##}
lappend lines {#}
# Bundle definition
lappend lines {}
lappend lines {# ###############}
lappend lines {# Complete bundle}
lappend lines {}
lappend lines [list Package [list $package_name [normalize-version $package_version]]]
lappend lines "Base @TAP_DIR@"
lappend lines "Platform *"
lappend lines "Desc \{$pname: Bundle of all packages\}"
lappend lines "Path pkgIndex.tcl"
lappend lines "Path [join $modules "\nPath "]"
set strip [llength [file split $distribution]]
incr strip 2
foreach m $modules {
# File set of module ...
lappend lines {}
lappend lines "# #########[::textutil::strRepeat {#} [string length $m]]" ; # {}
lappend lines "# Module \"$m\""
set n 0
foreach {p vlist} [ppackages $m] {
foreach v $vlist {
lappend lines "# \[[format %1d [incr n]]\] | \"$p\" ($v)"
}
}
if {$n > 1} {
# Multiple packages (*). We create one hidden package to
# contain all the files and then have all the true
# packages in the module refer to it.
#
# (*) This can also be one package for which we have
# several versions. Or a combination thereof.
array set _ {}
foreach {p vlist} [ppackages $m] {
catch {set _([lindex $pd($p) 0]) .}
}
set desc [string trim [join [array names _] ", "] " \n\t\r,"]
if {$desc == ""} {set desc "$pname module"}
unset _
lappend lines "# -------+"
lappend lines {}
lappend lines [list Package [list __$m 0.0]]
lappend lines "Platform *"
lappend lines "Desc \{$desc\}"
lappend lines Hidden
lappend lines "Base @TAP_DIR@/$m"
foreach f [lsort -dict [modtclfiles $m]] {
lappend lines "Path [fileutil::stripN $f $strip]"
}
# Packages in the module ...
foreach {p vlist} [ppackages $m] {
# NO DANGER. As we are listing only the packages P for
# the module any other version of P in a different
# module is _not_ listed here.
set desc ""
catch {set desc [string trim [lindex $pd($p) 1]]}
if {$desc == ""} {set desc "$pname package"}
foreach v $vlist {
lappend lines {}
lappend lines [list Package [list $p [normalize-version $v]]]
lappend lines "See [list __$m]"
lappend lines "Platform *"
lappend lines "Desc \{$desc\}"
}
}
} else {
# A single package in the module. And only one version of
# it as well. Otherwise we are in the multi-pkg branch.
foreach {p vlist} {{} {}} break
foreach {p vlist} [ppackages $m] break
set desc ""
catch {set desc [string trim [lindex $pd($p) 1]]}
if {$desc == ""} {set desc "$pname package"}
set v [lindex $vlist 0]
lappend lines "# -------+"
lappend lines {}
lappend lines [list Package [list $p [normalize-version $v]]]
lappend lines "Platform *"
lappend lines "Desc \{$desc\}"
lappend lines "Base @TAP_DIR@/$m"
foreach f [lsort -dict [modtclfiles $m]] {
lappend lines "Path [fileutil::stripN $f $strip]"
}
}
lappend lines {}
lappend lines {#}
lappend lines "# #########[::textutil::strRepeat {#} [string length $m]]"
}
lappend lines {}
lappend lines {#}
lappend lines {##}
lappend lines {###}
lappend lines {#####}
lappend lines {########}
# Write definition
set f [open [file join $distribution ${package_name}.tap] w]
puts $f [join $lines \n]
close $f
return
}
proc getpdesc {} {
global argv ; if {![checkmod]} return
package require sak::doc
sak::doc::Gen desc l $argv
array set _ {}
foreach file [glob -nocomplain doc/desc/*.l] {
set f [open $file r]
foreach l [split [read $f] \n] {
foreach {p sd d} $l break
set _($p) [list $sd $d]
}
close $f
}
file delete -force doc/desc
return [array get _]
}
proc gd-gen-rpmspec {} {
global package_version package_name distribution
set in [file join $distribution support releases package_rpm.txt]
set out [file join $distribution ${package_name}.spec]
write_out $out [string map \
[list \
@PACKAGE_VERSION@ $package_version \
@PACKAGE_NAME@ $package_name] \
[get_input $in]]
return
}
proc gd-gen-yml {} {
# YAML is the format used for the FreePAN archive network.
# http://freepan.org/
global package_version package_name distribution
set in [file join $distribution support releases package_yml.txt]
set out [file join $distribution ${package_name}.yml]
write_out $out [string map \
[list \
@PACKAGE_VERSION@ $package_version \
@PACKAGE_NAME@ $package_name] \
[get_input $in]]
return
}
proc docfiles {} {
global distribution
getpackage fileutil fileutil/fileutil.tcl
set res [list]
foreach f [fileutil::findByPattern $distribution -glob *.man] {
# Remove files under SCCS. They are repository, not sources to check.
if {[string match *SCCS* $f]} continue
lappend res [file rootname [file tail $f]].n
}
proc docfiles {} [list return $res]
return $res
}
proc gd-tip55 {} {
global package_version package_name distribution contributors
contributors
set in [file join $distribution support releases package_tip55.txt]
set out [file join $distribution DESCRIPTION.txt]
set md [string map \
[list \
@PACKAGE_VERSION@ $package_version \
@PACKAGE_NAME@ $package_name] \
[get_input $in]]
foreach person [lsort [array names contributors]] {
set mail $contributors($person)
regsub {@} $mail " at " mail
regsub -all {\.} $mail " dot " mail
append md "Contributor: $person <$mail>\n"
}
write_out $out $md
return
}
# Fill the global array of contributors to the bundle by processing
# the ChangeLog entries.
#
proc contributors {} {
global distribution contributors
if {![info exists contributors] || [array size contributors] == 0} {
get_contributors [file join $distribution ChangeLog]
foreach f [glob -nocomplain [file join $distribution modules *]] {
if {![file isdirectory $f]} {continue}
if {[string match CVS [file tail $f]]} {continue}
if {![file exists [file join $f ChangeLog]]} {continue}
get_contributors [file join $f ChangeLog]
}
}
}
proc get_contributors {changelog} {
global contributors
set f [open $changelog r]
while {![eof $f]} {
gets $f line
if {[regexp {^[\d-]+\s+(.*?)<(.*?)>} $line r name mail]} {
set name [string trim $name]
if {![info exists names($name)]} {
set contributors($name) $mail
}
}
}
close $f
}
proc validate_imodules_cmp {imvar dmvar} {
upvar $imvar im $dmvar dm
foreach m [lsort [array names im]] {
if {![info exists dm($m)]} {
puts " Installed, does not exist: $m"
}
}
foreach m [lsort [array names dm]] {
if {![info exists im($m)]} {
puts " Missing in installer: $m"
}
}
return
}
proc validate_imodules {} {
foreach m [imodules] {set im($m) .}
foreach m [modules] {set dm($m) .}
validate_imodules_cmp im dm
return
}
proc validate_imodules_mod {m} {
array set im {}
array set dm {}
if {[imodules_mod $m]} {set im($m) .}
if {[modules_mod $m]} {set dm($m) .}
validate_imodules_cmp im dm
return
}
proc validate_versions_cmp {ipvar ppvar} {
global pf
getpackage struct::set struct/sets.tcl
upvar $ipvar ip $ppvar pp
set maxl 0
foreach name [array names ip] {if {[string length $name] > $maxl} {set maxl [string length $name]}}
foreach name [array names pp] {if {[string length $name] > $maxl} {set maxl [string length $name]}}
foreach p [lsort [array names ip]] {
if {![info exists pp($p)]} {
puts " Indexed, no provider: $p"
}
}
foreach p [lsort [array names pp]] {
if {![info exists ip($p)]} {
foreach k [array names pf $p,*] {
puts " Provided, not indexed: [format "%-*s | %s" $maxl $p $pf($k)]"
}
}
}
foreach p [lsort [array names ip]] {
if {![info exists pp($p)]} continue
if {[struct::set equal $pp($p) $ip($p)]} continue
# Compute intersection and set differences.
foreach {__ pmi imp} [struct::set intersect3 $pp($p) $ip($p)] break
puts " Index/provided versions differ: [format "%-*s | %8s | %8s" $maxl $p $imp $pmi]"
}
}
proc validate_versions {} {
foreach {p vm} [ipackages] {set ip($p) [lindex $vm 0]}
foreach {p vlist} [ppackages] {set pp($p) $vlist}
validate_versions_cmp ip pp
return
}
proc validate_versions_mod {m} {
foreach {p vm} [ipackages $m] {set ip($p) [lindex $vm 0]}
foreach {p vlist} [ppackages $m] {set pp($p) $vlist}
validate_versions_cmp ip pp
return
}
proc validate_testsuite_mod {m} {
global distribution
if {[llength [glob -nocomplain [file join $distribution modules $m *.test]]] == 0} {
puts " Without testsuite : $m"
}
return
}
proc bench_mod {mlist paths interp flags norm format verbose output coll rep} {
global distribution env tcl_platform
getpackage logger logger/logger.tcl
getpackage bench bench/bench.tcl
::logger::setlevel $verbose
set pattern tclsh*
if {$interp != {}} {
set pattern [file tail $interp]
set paths [list [file dirname $interp]]
} elseif {![llength $paths]} {
# Using the environment PATH is not a good default for
# SAK. Use the interpreter running SAK as the default.
if 0 {
set paths [split $env(PATH) \
[expr {($tcl_platform(platform) == "windows") ? ";" : ":"}]]
}
set interp [info nameofexecutable]
set pattern [file tail $interp]
set paths [list [file dirname $interp]]
}
set interps [bench::versions \
[bench::locate $pattern $paths]]
if {![llength $interps]} {
puts "No interpreters found"
return
}
if {[llength $flags]} {
set cmd [linsert $flags 0 bench::run]
} else {
set cmd [list bench::run]
}
array set DATA {}
foreach m $mlist {
set files [glob -nocomplain [file join $distribution modules $m *.bench]]
if {![llength $files]} {
bench::log::warn "No benchmark files found for module \"$m\""
continue
}
for {set i 0} {$i <= $rep} {incr i} {
if {$i} { puts "Repeat $i" }
set run $cmd
lappend run $interps $files
array set tmp [eval $run]
# Merge new set of data into the previous run, if any.
foreach key [array names tmp] {
set val $tmp($key)
if {![info exists DATA($key)]} {
set DATA($key) $val
continue
} elseif {[string is double -strict $val]} {
# Call user-request collation type
set DATA($key) [collate_$coll $DATA($key) $val $i]
}
}
unset tmp
}
}