8 namespace eval Tools::Sigasi {
13 description "Sigasi-cli toolchain"
16 RegisterCommand export {
18 description " exports a CSV file for sigasi project creation "
21 {new "Create a new style Sigasi project file"}
23 script { Tools::Sigasi::sigasi-export}
25 RegisterCommand format {
28 description " sigasi-cli wrapper to run repo formatting settings across all files in the repo "
29 script { Tools::Sigasi::sigasi-format }
31 RegisterCommand document {
32 aliases {sigasi-d doc d docs}
33 description " sigasi-cli wrapper to create basic documentation of the project "
35 script {Tools::Sigasi::sigasi-document}
37 RegisterCommand lint {
39 description " sigasi-cli wrapper to generate a code quality report "
41 script {Tools::Sigasi::sigasi-lint}
45 puts "Initializing Sigasi tool..."
46 if { [
catch {
exec which sigasi-cli}] } {
47 puts "sigasi-cli not available -- check sigasi-cli is in PATH"
50 if { [
catch {
exec -- sigasi-cli --license}] } {
51 puts "check SIGASI_LM_LICENSE_FILE is set"
56 if { ![
namespace exists ::Repo] } {
57 Msg Error " sigasi has been called before Repo namespace has been created "
62 proc _test_sigasi_project {repo_path} {
63 if { ![
file exists $repo_path/project.sigasi] } {
64 Msg Info "attempting to create associated sigasi project file"
72 proc _create_sigasi_default_dict {} {
73 dict set sigasi_defaults DIAGRAMS "LINKED"
74 dict set sigasi_defaults DESIGN_UNITS_PER_PAGE 25
75 dict set sigasi_defaults DIAGRAM_NODE_LIMIT 2500
76 dict set sigasi_defaults DOC_DIR "./sigasi-docs"
77 dict set sigasi_defaults REPORT_FORMAT "plain"
78 dict set sigasi_defaults REPORT_OUTFILE "./sigasi_report.txt"
79 dict set sigasi_defaults VHDL_VERSION 2008
80 dict set sigasi_defaults KEYWORDS "lowercase"
81 dict set sigasi_defaults TAB_WIDTH 4
83 return $sigasi_defaults
87 proc get_sigasi_conf {} {
89 set out_dict $default_dict
91 Msg Info " retrieving the sigasi configuration settings "
92 if { [Repo::Exists config sigasi] } {
94 Msg Debug "debug merge 1 $sigasi_dict "
95 set out_dict [dict merge $default_dict $sigasi_dict]
98 set config [ CurrentProject::Get config]
99 if { [ CurrentProject::Exists config sigasi] } {
100 set sigasi_dict [
::tobj::native [ CurrentProject::Get config sigasi]]
101 Msg Debug "debug merge 2 $sigasi_dict "
102 set out_dict [dict merge $out_dict $sigasi_dict]
108 proc sigasi-export {} {
109 if {[Launcher::GetOr options new 0] == 1} {
113 set repo_path [Repo::Get repo_path]
114 set project_name [Launcher::Get project_name]
115 Msg Info "Creating Sigasi CSV files for project $project_name..."
117 set project_files [
::tobj::native [ CurrentProject::Get project_files]]
120 set csv_file [open "$repo_path/sigasi_$project_name.csv" w]
122 foreach source_file $project_files {
124 [
file extension $source_file] eq ".vhd"
125 || [
file extension $source_file] eq ".vhdl"
126 || [
file extension $source_file] eq ".sv"
127 || [
file extension $source_file] eq ".v"
129 set file_dict [dict get $project_files $source_file]
130 puts $csv_file [
concat [
file rootname [dict get $file_dict libraries]] "," $source_file]
135 Msg Info "Sigasi CSV file created: sigasi_$project_name.csv"
136 Msg Info "You can use the python script provided by Sigasi to convert the generated csv file into a Sigasi project."
137 Msg Info "More info at: \
138 https://www.sigasi.com/knowledge/how_tos/generating-sigasi-project-vivado-project/#2-generate-the-sigasi-project-files-from-the-csv-file"
142 proc _new_sigasi-export {} {
143 set repo_path [Repo::Get repo_path]
144 set project_name [Launcher::Get project_name]
145 Msg Info "Creating new style Sigasi project file for project $project_name..."
147 set project_files [
::tobj::native [ CurrentProject::Get project_files]]
150 Sigasi::Set name $project_name
151 Sigasi::Set targets ""
152 Sigasi::Set targets hdl
153 Sigasi::Set targets hdl libraryMapping
156 foreach source_file $project_files {
158 [
file extension $source_file] eq ".vhd"
159 || [
file extension $source_file] eq ".vhdl"
160 || [
file extension $source_file] eq ".sv"
161 || [
file extension $source_file] eq ".v"
163 set file_dict [dict get $project_files $source_file]
164 set lib [
file rootname [dict get $file_dict libraries]]
165 Sigasi::Set targets hdl libraryMapping $source_file $lib
170 Sigasi::SaveJsonToFile "$repo_path/project.sigasi" 1
171 Msg Info "Sigasi project file created: $repo_path/project.sigasi"
174 proc sigasi-lint {} {
176 set repo_path [Repo::Get repo_path]
177 set project_name [Launcher::Get project_name]
179 Msg Info "Generating a code quality report for project $project_name..."
181 file mkdir $repo_path/sigasi_lint
182 set outfile "$repo_path/sigasi_lint/$project_name"
189 if {[dict exists $sigasi_conf LIBRARY_DATABASE]} {
190 set libraries [dict get $sigasi_conf LIBRARY_DATABASE]
191 foreach lib [
split $libraries ,] {
192 lappend options_list "--library-database=[
string trim $lib]"
196 set report_format [dict get $sigasi_conf REPORT_FORMAT]
197 lappend options_list "--$report_format"
199 if { $report_format == "json" || $report_format == "sonarqube" } {
201 }
elseif { $report_format == "warnings-ng" } {
207 if {[dict exists $sigasi_conf REPORT_ABSOLUTE]} {
208 lappend options_list "--absolute"
210 if {[dict exists $sigasi_conf REPORT_SUPPRESSED]} {
211 lappend options_list "--include-suppressed"
213 if {[dict exists $sigasi_conf FAIL]} {
214 lappend options_list "--fail-on-[dict get $sigasi_conf FAIL]"
217 lappend options_list "--out=$outfile$filetype"
219 puts "sigasi-cli verify $repo_path $options_list "
220 if { [
catch {
exec -- sigasi-cli verify $repo_path {*}$options_list}] } {
221 Msg Error "sigasi-cli verify failed - please review $outfile$filetype for issues"
225 Msg Info "Despite passing there maybe minor code violations caught. See $outfile$filetype"
226 if { $remove_project_file == "yes" } {
227 file delete $repo_path/project.sigasi
232 proc sigasi-format {} {
234 set repo_path [Repo::Get repo_path]
235 set project_name [Launcher::Get project_name]
236 Msg Info "Formatting VHDL files for project $project_name ..."
242 Msg Info "sigasi config dict: $sigasi_conf"
244 if {[dict exists $sigasi_conf TABS]} {
245 lappend options_list ""
247 lappend options_list "--spaces-for-tabs"
249 if {[dict exists $sigasi_conf PRESERVE_NEWLINES]} {
250 lappend options_list "--preserve-newlines"
252 if {[dict exists $sigasi_conf NO_ALIGN]} {
253 lappend options_list "--no-align"
256 lappend options_list "--vhdl-version=[dict get $sigasi_conf VHDL_VERSION]"
257 lappend options_list "--tab-width=[dict get $sigasi_conf TAB_WIDTH]"
258 lappend options_list "--keywords=[dict get $sigasi_conf KEYWORDS]"
260 if {[dict exists $sigasi_conf IGNORE_DIR]} {
261 set ignore [dict get $sigasi_conf IGNORE_DIR]
262 foreach dir [
split $ignore ,] {
263 lappend ignore_list "$repo_path/[
string trim $dir]"
267 set project_files [
::tobj::native [ CurrentProject::Get project_files]]
270 foreach source_file $project_files {
272 foreach dir $ignore_list {
273 if { [
string match $dir* $source_file] } {
278 puts "skipping $source_file due to IGNORE_DIR setting"
280 if {[
file extension $source_file] == ".vhd" ||
281 [
file extension $source_file] == ".vhdl" } {
282 puts "sigasi-cli format $options_list $source_file"
283 exec -- sigasi-cli format {*}$options_list $source_file
290 proc sigasi-document {} {
292 set repo_path [Repo::Get repo_path]
293 set project_name [Launcher::Get project_name]
295 Msg Info "Generating project documentation for $project_name..."
300 Msg Info "sigasi config dict: $sigasi_conf"
302 if {[dict exists $sigasi_conf LIBRARY_DATABASE]} {
303 set libraries [dict get $sigasi_conf LIBRARY_DATABASE]
304 foreach lib [
split $libraries ,] {
305 lappend options_list "--library-database=[
string trim $lib]"
309 lappend options_list "--diagram-node-limit=[dict get $sigasi_conf DIAGRAM_NODE_LIMIT]"
310 lappend options_list "--design-units-per-page=[dict get $sigasi_conf DESIGN_UNITS_PER_PAGE]"
311 lappend options_list "--diagrams=[dict get $sigasi_conf DIAGRAMS]"
312 if {[dict exists $sigasi_conf TOP_LEVEL]} {
313 lappend options_list "--top-level=[dict get $sigasi_conf TOP_LEVEL]"
315 set outdir "$repo_path/sigasi_doc/$project_name"
316 lappend options_list "--output-directory=$outdir"
318 puts "sigasi-cli document $repo_path $options_list "
320 set results [exec -- sigasi-cli document $repo_path {*}$options_list 2>@1 ]
322 } trap CHILDSTATUS {results} {
323 Msg Error "Generation of documentation has failed. Please debug sigasi command outside of HOG"
326 Msg Info "Documentation successfully saved to $outdir"
327 if { $remove_project_file == "yes" } {
328 file delete $repo_path/project.sigasi