While searching about TCL scripting I ended up finding this:
http://www.altera.com/support/examples/tcl/tcl-version-number.html Which suits my case very well, since we use SVN here. But I am still very new to all this scripting and all, so I still have some doubts.
I implemented that script into one project just for testing purposes, and the script is:
# Gets SVN revision number for the specified file
proc get_subversion_revision { file_name } {
global done
# The maximum number of seconds to wait for the svn info
# command to complete
set timeout_seconds 30
# The svn info command with filename that is run
set cmd "svn info ${file_name}"
# Attempt to get the version information.
# If the command can't be run, return an error.
# Otherwise set up a file event to process the command output.
if { } {
return -code error $input
} else {
fileevent $input readable
# Set up a timeout so that the process can't hang if the
# repository is down.
set timeout
]
# Don't continue until the revision number is found,
# or the operation times out. Cancel the timeout anyway.
vwait done
after cancel $timeout
}
}
# Helper procedure for the above procedure
proc get_revision_info { inp } {
global done revision_number
if { } {
catch {close $inp}
set done 1
} elseif { $done } {
gets $inp line
} else {
gets $inp line
# Use a regular expression to match the line with the
# revision number.
if { } {
set done 1
}
}
}
# Creates a register bank in a vhdl file with the specified hex value
proc generate_vhdl { hex_value } {
set num_digits
set bit_width
set high_index
set reset_value
if {
puts $fh "LIBRARY ieee;\nUSE ieee.std_logic_1164.ALL;"
puts $fh "ENTITY version_reg IS"
puts $fh " PORT ("
puts $fh " clock: IN STD_LOGIC;"
puts $fh " reset: IN STD_LOGIC;"
puts $fh " data_out: OUT STD_LOGIC_VECTOR(${high_index} downto 0)"
puts $fh " );"
puts $fh "END version_reg;"
puts $fh "ARCHITECTURE rtl OF version_reg IS"
puts $fh "BEGIN"
puts $fh "PROCESS (clock,reset)"
puts $fh " BEGIN"
puts $fh " IF (reset='0') THEN"
puts $fh " data_out <=X\"${reset_value}\";"
puts $fh " ELSIF rising_edge (clock) THEN"
puts $fh " data_out <= X\"${hex_value}\";"
puts $fh " END IF;"
puts $fh "END PROCESS;"
puts $fh "END rtl;"
close $fh
} res ] } {
return -code error $res
} else {
return 1
}
}
# This line accommodates script automation
foreach { flow project revision } $quartus(args) { break }
set file_name ${project}.qpf
set done 0
set revision_number ""
# Call procedure to get file revision number and handle any errors
if { } {
post_message -type critical_warning "Couldn't run command to get
revision number. $msg"
} else {
if { -1 == $done } {
post_message -type critical_warning "Timeout getting revision number."
} elseif { } {
post_message -type critical_warning
"Couldn't find revision number in output of svn info $file_name."
} else {
# Call procedure to store the number
if { } {
post_message -type critical_warning
"Couldn't generate VHDL file. $res"
} else {
post_message "Successfully updated version number to
version 0x${revision_number}"
}
}
}
I am using the automatic run of that script as well. So when I compile my project I got the following warning:
Critical Warning: Couldn't run command to get revision number. couldn't execute "svn": no such file or directory
And I'm not sure what is wrong, since I commited the whole folder of the project in SVN, also not sure how the script gets the version number, if it's by the commited folder or by a txt file included in it.
And I put in red parts of the code that I don't know if I'm supposed to change them or not.
Anyone?