forked from facebook/wdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_update.tcl
executable file
·89 lines (71 loc) · 2.23 KB
/
version_update.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
#! /usr/bin/env tclsh
# Quick Tcl script to update the buildlevel (which is date+1 digit increment)
set fname "CMakeLists.txt"
set f [open $fname r+]
set content [read $f]
set re {^(project.*VERSION )([0-9]+)\.([0-9]+)\.([0-9]+)\)$}
if {![regexp -lineanchor $re $content all begin major minor build]} {
puts stderr "Searched for regular expression: $re"
puts stderr "Unable to find project version string in CMakeLists.txt!"
exit 1
}
puts "In $fname, found for $begin"
puts "Major V = $major"
puts "Minor V = $minor"
puts "Build L = $build"
if {[string length $build] != 7} {
puts stderr "Unexpected length for build \"$build\"";
}
set date [string range $build 0 5]
set incr [string range $build 6 6]
set today [clock format [clock seconds] -format "%y%m%d"]
puts "Previous build date $date ($incr) vs today $today"
if {[string equal $date $today]} {
incr incr
if {$incr > 9} {
puts stderr "Ran too many times (10) on same day, aborting"
exit 1
}
} else {
set incr 0
}
set newBuild "$today$incr"
puts "*** So new build is $newBuild"
set replace "\\1\\2.\\3.$newBuild)"
if {![regsub -lineanchor $re $content $replace content]} {
puts stderr "Error substituting new build - $re $replace"
exit 1
}
seek $f 0
puts -nonewline $f $content
close $f
puts "*** Updated $fname"
# Same on WdtConfig.h
set fname "WdtConfig.h"
set f [open $fname r+]
set content {}
while {![eof $f]} {
set line [gets $f]
if {[string match "#define WDT_VERSION_MAJOR*" $line]} {
puts "Changing $line to:"
set line "#define WDT_VERSION_MAJOR $major"
puts $line
} elseif {[string match "#define WDT_VERSION_MINOR*" $line]} {
puts "Changing $line to:"
set line "#define WDT_VERSION_MINOR $minor"
puts $line
} elseif {[string match "#define WDT_VERSION_BUILD*" $line]} {
puts "Changing $line to:"
set line "#define WDT_VERSION_BUILD $newBuild"
puts $line
} elseif {[string match "#define WDT_VERSION_STR*" $line]} {
puts "Changing $line to:"
set line "#define WDT_VERSION_STR \"$major.$minor.$newBuild-fbcode\""
puts $line
}
lappend content $line
}
seek $f 0
puts -nonewline $f [join $content "\n"]
close $f
puts "*** Updated $fname"