-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_rev.tcl
54 lines (48 loc) · 2.29 KB
/
update_rev.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
proc update_version_number { input_file output_file } {
# If the input file can't be opened, return an error.
if { [catch {open $input_file} input] } {
return -code error $input
puts "cant open input"
}
# If the output file can't be opened, return an error
if { [catch {open $output_file w} output] } {
return -code error $output
puts "cant open output"
}
# Read through the input file a line at a time
while {-1 != [gets $input line] } {
if { [regexp {^\s*constant compile_rev : integer := ([[:digit:]]+);\s*$} \ $line match version_number] } {
set decimal_value $version_number
incr decimal_value
# Substitute the new version number in for the old one
regsub $version_number $line $decimal_value line
# post_message "File src/revision/revision.vhd updated with Current Compile Revision: $decimal_value"
} elseif { [regexp {^\s*constant compile_year_stamp : integer := ([[:digit:]]+);\s*$} \ $line match version_number] } {
set decimal_value [clock format [clock seconds] -format {%y}]
regsub $version_number $line $decimal_value line
} elseif { [regexp {^\s*constant compile_month_stamp : integer := ([[:digit:]]+);\s*$} \ $line match version_number] } {
set decimal_value [clock format [clock seconds] -format {%m}]
regsub $version_number $line $decimal_value line
} elseif { [regexp {^\s*constant compile_day_stamp : integer := ([[:digit:]]+);\s*$} \ $line match version_number] } {
set decimal_value [clock format [clock seconds] -format {%d}]
regsub $version_number $line $decimal_value line
} elseif { [regexp {^\s*constant compile_hour_stamp : integer := ([[:digit:]]+);\s*$} \ $line match version_number] } {
set decimal_value [clock format [clock seconds] -format {%H}]
regsub $version_number $line $decimal_value line
}
# Write out the line to the new file
puts $output $line
}
close $input
close $output
}
set script_path [file dirname [file normalize [info script]]]
set file_name "[file normalize "$script_path/src/hdl/revision/revisions.vhd"]"
set output_file_name ${file_name}.updated_version_number
if { [catch { update_version_number $file_name $output_file_name } res ] } {
# todo: insert debug message
} else {
if { [catch { file rename -force $output_file_name $file_name } res ] } {
# todo: insert debug message
}
}