Quartus® II Tcl 自動封存專案

author-image

作者

當您在每次編譯過程中執行許多編譯,並且不同設定時,很難記住從編譯到編譯的設定和結果是什麼。透過封存專案,您可以保留一份完整的專案副本,包括編譯過程中產生的檔案。您可以在系統命令提示下以單一命令將專案存檔,但是建立 Tcl 腳本並新增一個設定以自動執行,讓程式變得更容易。

若要在每個編譯結束時自動執行腳本,請使用下列腳本,並在您的專案中新增作業。作業名稱為POST_FLOW_SCRIPT_FILE。如需此作業的詳細資訊,請參閱 自動腳本執行 範例。假設腳本命名為 autoqar.tcl,請將下列作業新增到您的 Quartus II 設定檔案 (.qsf):

set_global_assignment -name POST_FLOW_SCRIPT_FILE quartus_sh:autoqar.tcl

腳本會根據目前的日期和時間建立檔案名。如需變更日期與時程表述的相關資訊,請參閱 日期與時間格式化 頁面。

# Use these options to control what files get archived.
# -include_outputs: Includes Quartus II output files, including the
#     db directory and programming files
# -include_libraries: Includes system libraries referenced in your
#     project

set options "-include_outputs"
#set options "-include_libraries"
#set options "-include_outputs -include_libraries"

# Subdirectory to put the automatically created qars into
set qar_directory autoqar

# Generates a name for the qar based on the name of the revision
# and the current time.
proc generateQarName { project revision } {

    # time_format_string controls how the qar is named.
    # These values give the value month_dd_yyyy-hh.mm.ss.
    # For example, Jan_28_2004-13.00.05

    set time_format_string "%b_%d_%Y-%H_%M_%S"
    set time_value [clock format [clock seconds] \
      -format $time_format_string]

    # The name of the qar is based on the revision name and the time
    return $revision-$time_value
}

global quartus

set module_or_flow [lindex $quartus(args) 0]
set project [lindex $quartus(args) 1]
set revision [lindex $quartus(args) 2]

# If a qar is made, set this to 1 and attempt to move it later on
set ran_qar 0

# Add any modules or flows to the list in the switch statement
# As is, it'll make a qar after each compile, compile and simulate,
# and incremental fit.
switch -exact -- $module_or_flow {

    compile -
    compile_and_simulate -
    incremental_fitting {

    if { [catch {
        project_open -revision $revision $project
        set qar_name [generateQarName $project $revision]
        project_archive $options $qar_name
        project_close
    } res ] } {
        post_message -type warning $res
    } else {
        set ran_qar 1
    }
    }

}

# If a qar was made, try to move it to the right directory
if { $ran_qar } {

    if { [catch {

    file mkdir $qar_directory
    file copy $qar_name.qar $qar_directory
    file copy $qar_name.qarlog $qar_directory
    file delete $qar_name.qar
    file delete $qar_name.qarlog

    } res ] } {
    post_message -type warning $res
    } else {
         set qname [file join $qar_directory $qar_name]
    post_message "Successfully archived your project in $qname.qar"
    }
}

這個頁面的內容綜合了英文原始內容的人工翻譯譯文與機器翻譯譯文。本內容是基於一般資訊目的,方便您參考而提供,不應視同完整或準確的內容。如果這個頁面的英文版與譯文之間發生任何牴觸,將受英文版規範及管轄。 查看這個頁面的英文版。