summaryrefslogtreecommitdiff
path: root/toolbin/precheck.tcl
blob: 35dc94e99373bc499b0b0d806cfb8ce7d3584457 (plain)
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
#!/usr/bin/tclsh

# Copyright (C) 2001-2023 Artifex Software, Inc.
# All Rights Reserved.
#
# This software is provided AS-IS with no warranty, either express or
# implied.
#
# This software is distributed under license and may not be copied,
# modified or distributed except as expressly authorized under the terms
# of the license contained in the file LICENSE in this distribution.
#
# Refer to licensing information at http://www.artifex.com or contact
# Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
# CA 94129, USA, for further information.
#


# Check various aspects of an about-to-be-released source fileset.

# Sets the following globals for use by files using this one:
#	CHANGED(f) - defined as 1 for each f such that f~ or f.orig exists
#	NEWSCHANGED(f) - defined as 1 for each f listed as changed in the
#	  NEWS* file
#	NEWSDATE - the date in NEWSVERSION
#	NEWSVERSION - the most recent Version line from the NEWS* file

# ---------------- Utilities ---------------- #

# Print an error message.
proc message {str} {
    puts stderr "**** $str"
}

# Search for one or more occurrences of a pattern in a file.
# If any are found, set $linevar to the line containing the first occurrence,
# and return 1; otherwise, return 0.
proc grep1 {pattern file linevar} {
    upvar $linevar line
    set line ""
    set cmd [list exec egrep $pattern $file]
    catch "set line \[$cmd\]"
    if {$line == ""} {return 0}
    set line [lindex [split $line "\n"] 0]
    return 1
}

# ---------------- Main program ---------------- #

# Identify the relevant NEWS file, setting NEWS.

set news {}
foreach f [glob -nocomplain NEWS* News*.htm doc/News*.htm] {
    if {[regexp {^(doc/|)(NEWS([-_][A-Z0-9]*|)|News([-_][A-Za-z0-9]*|)\.htm)$} $f]} {lappend news $f}
}
if {[llength $news] != 1} {
    if {$news == {}} {set news -nothing-}
    puts "**** Looking for NEWS or News.htm, found: $news"
    exit 1
}
set NEWS [lindex $news 0]

# Check the date and version number in the NEWS file.
# Set NEWSVERSION

if {![grep1 {^Version [0-9.]+[( ]} $NEWS vdate]} {
    if {![grep1 {[<]/a>Version [0-9.]+[( ]} $NEWS vdate]} {
	message "Unable to parse $NEWS!"
	exit 1
    }
}
regsub -all {<[^>]*>} $vdate "" vdate
puts "Most recent version in $NEWS: $vdate"
set vdmypat {^Version [0-9.]+(.*)\((([0-9x]+)/([0-9x]+)/([0-9x]+))\)$}
set vymdpat {^Version [0-9.]+(.*)\((([0-9x]+)-([0-9x]+)-([0-9x]+))\)$}
if [regexp $vdmypat $vdate skip skip2 rdate rmonth rday ryear] {
    set dateformat %-m/%-d/%y
} elseif [regexp $vymdpat $vdate skip skip2 rdate ryear rmonth rday] {
    set dateformat %Y-%m-%d
} else {
    message "$NEWS release date is missing"
    exit 1
}
if {![string match *x* $ryear]} {
    if {$ryear >= 1900} {
    } elseif {$ryear >= 50} {
	set ryear [expr $ryear + 1900]
    } else {
	set ryear [expr $ryear + 2000]
    }
}
set curdate [exec date +$dateformat]
if {$rdate != $curdate} {
    message "Warning: current date is $curdate, release date is $rdate"
}
set NEWSVERSION $vdate

# Collect the list of changed files (those with a ~-file or .orig file,
# other than t and t.*).

proc changed_files {} {
    set changed {}
    foreach prefix {doc/ examples/ lib/ man/ src/ toolbin/ gnu/*/} {
	foreach fx [glob -nocomplain ${prefix}*~ ${prefix}*.orig] {
	    if {[regexp {^(.*)(~|\.orig)$} $fx skip f]} {
		lappend changed $f
	    }
	}
    }
    return $changed
}
catch {unset CHANGED}
foreach f [changed_files] {set CHANGED($f) 1}

# Collect the list of files identified as changed in the current NEWS
# section.

proc news_changed_files {in} {
    set changed {}
    set para {}
    set fnamepat {[-0-9A-Za-z_.*/]+}
    set fn1pat "${fnamepat}( \\\[deleted\\\]| => $fnamepat|)"
    set fnlistpat "${fn1pat}(,\[ \]*$fn1pat)*"
    while {[gets $in l] >= 0 && ![regexp {(^|</a>)Version} $l]} {
	set l [string trimright $l]
	if {$l == "" || $l != [string trimleft $l]} {
	    # End of paragraph.  Look for changed files in the previous one.
	    regsub {\) \*\*\*(.*)\*\*\*$} $para {)} para
	    if {[regexp "\\(($fnlistpat)\\)\$" $para skip files]} {
		regsub -all {,} $files { } files
		foreach f $files {
		    if {$f == {[deleted]}} {continue}
		    if {![regexp / $f]} {set f src/$f}
		    set fl [glob -nocomplain $f]
		    if {$fl != ""} {append changed " $fl"}
		}
	    }
	    set para $l
	} else {
	    append para " $l"
	}
    }
    return $changed
}
catch {unset NEWSCHANGED}
set news [open $NEWS]
while {![regexp {(^|</a>)Version} [gets $news]]} { }
foreach f [news_changed_files $news] {set NEWSCHANGED($f) 1}
close $news

# Check that the files with ~- or .orig-files are 1-for-1 with files listed
# in the current NEWS section.

puts "[array size CHANGED] files with ~ or .orig,\
 [array size NEWSCHANGED] changed in $NEWS."

# We'd like to handle gs_init.ps properly, but its embedded version number
# changes in every fileset.  **** SPECIAL HACK FOR GS ****
foreach f "$NEWS lib/gs_init.ps src/version.mak" {catch {unset CHANGED($f)}}
foreach f {lib/gs_init.ps} {catch {unset NEWSCHANGED($f)}}
set c_n {}
foreach f [array names CHANGED] {if {![info exists NEWSCHANGED($f)]} {lappend c_n $f}}
set n_c {}
foreach f [array names NEWSCHANGED] {if {![info exists CHANGED($f)]} {lappend n_c $f}}
if {$c_n != ""} {puts "**** Changed, not in $NEWS: [lsort $c_n]"}
if {$n_c != ""} {puts "**** In $NEWS, not changed: [lsort $n_c]"}