Hog v10.58.0
sigasi_cli.tcl
Go to the documentation of this file.
1 
2 # Note: This is mostly for the benefit of CI/CD pipelines as if using a code editor
3 # with Sigasi integration then code quality and formatting are easy to access
4 
5 # The CLI functionality requires a paid license.
6 
7 # These proceedures should be available regardless of which synthesis tool is used.
8 
9 proc _test_sigasi {} {
10  if { [catch {exec which sigasi-cli} ] } {
11  puts "sigasi-cli not available -- check sigasi-cli is in PATH"
12  exit 1
13  } else {
14  if { [catch {exec -- sigasi-cli --license } ] } {
15  puts "check SIGASI_LM_LICENSE_FILE is set"
16  exit 1
17  }
18  }
19 }
20 
21 proc sigasi-export {} {
22  global repo_path
23  global project_name
24 
25  cd $repo_path
26  Msg Info "Creating Sigasi CSV files for project $project_name..."
27  set proj_dir $repo_path/Top/$project_name
28  set proj_list_dir $repo_path/Top/$project_name/list
29  set project [file tail $project_name]
30  lassign [GetHogFiles -list_files {.src} $proj_list_dir $repo_path] libraries
31  set csv_file [open "sigasi_$project.csv" w]
32  foreach lib $libraries {
33  set source_files [DictGet $libraries $lib]
34  foreach source_file $source_files {
35  if {
36  [file extension $source_file] eq ".vhd"
37  || [file extension $source_file] eq ".vhdl"
38  || [file extension $source_file] eq ".sv"
39  || [file extension $source_file] eq ".v"
40  } {
41  puts $csv_file [concat [file rootname $lib] "," $source_file]
42  }
43  }
44  }
45  lassign [GetHogFiles -list_files ".sim" $proj_list_dir $repo_path] \
46  listSimLibraries
47  foreach lib $listSimLibraries {
48  set source_files [DictGet $listSimLibraries $lib]
49  foreach source_file $source_files {
50  if {
51  [file extension $source_file] eq ".vhd"
52  || [file extension $source_file] eq ".vhdl"
53  || [file extension $source_file] eq ".sv"
54  || [file extension $source_file] eq ".v"
55  } {
56  puts $csv_file [concat [file rootname $lib] "," $source_file]
57  }
58  }
59  }
60  close $csv_file
61  Msg Info "Sigasi CSV file created: sigasi_$project.csv"
62  Msg Info "You can use the python script provided by Sigasi to convert the generated csv file into a Sigasi project."
63  Msg Info \
64  "More info at: \
65  https://www.sigasi.com/knowledge/how_tos/generating-sigasi-project-vivado-project/#2-generate-the-sigasi-project-files-from-the-csv-file"
66  exit 0
67 }
68 
69 
70 proc sigasi-lint {} {
72  global repo_path
73  global project_name
74 
75  cd $repo_path
76  Msg Info "Generating a code quality report for project $project_name..."
77 
78  # set default values then parse repo.conf for any custom set properties
79  set filetype ".txt"
80  file mkdir $repo_path/sigasi_lint
81  set outfile "$repo_path/sigasi_lint/$project_name"
82  set repo_conf $repo_path/Top/repo.conf
83  set options_list ""
84 
85  if {[file exists $repo_conf]} {
86  set PROPERTIES [ReadConf $repo_conf]
87  if {[dict exists $PROPERTIES sigasi]} {
88  set sigasiDict [dict get $PROPERTIES sigasi]
89  if {[dict exists $sigasiDict LIBRARY_DATABASE]} {
90  set libraries [dict get $sigasiDict LIBRARY_DATABASE]
91  foreach lib [split $libraries ,] {
92  lappend options_list "--library-database=[string trim $lib]"
93  }
94  }
95  if {[dict exists $sigasiDict REPORT_FORMAT]} {
96  set report_format [dict get $sigasiDict REPORT_FORMAT]
97  lappend options_list "--$report_format"
98 
99  if { $report_format == "json" || $report_format == "sonarqube" } {
100  set filetype ".json"
101  } elseif { $report_format == "warnings-ng" } {
102  set filetype ".xml"
103  }
104  }
105  # if {[dict exists $sigasiDict REPORT_OUTFILE]} {
106  # set outdir [dict get $sigasiDict REPORT_OUTFILE]
107  # set outdir [file rootname [file normalize $outdir]]
108  # if { [file writable $outdir] } {
109  # set outfile $outdir
110  # }
111  # }
112  if {[dict exists $sigasiDict REPORT_ABSOLUTE]} {
113  lappend options_list "--absolute"
114  }
115  if {[dict exists $sigasiDict REPORT_SUPPRESSED]} {
116  lappend options_list "--include-suppressed"
117  }
118  if {[dict exists $sigasiDict FAIL]} {
119  lappend options_list "--fail-on-[dict get $sigasiDict FAIL]"
120  }
121  }
122  }
123 
124  lappend options_list "--out=$outfile$filetype"
125 
126  puts "sigasi-cli verify $repo_path $options_list "
127  if { [catch { exec -- sigasi-cli verify $repo_path {*}$options_list } ] } {
128  Msg Error "sigasi-cli verify failed - please review $outfile$filetype for issues"
129  exit 1
130  }
131 
132  Msg Info "Despite passing there maybe minor code violations caught. See $outfile$filetype"
133  exit 0
134 }
135 
136 proc sigasi-format {} {
138  global repo_path
139  global project_name
140 
141  cd $repo_path
142  Msg Info "Formatting VHDL files for project $project_name ..."
143 
144  # set default values then parse repo.conf for any custom set properties
145  set tab_width 4
146  set keywords "lowercase"
147  set repo_conf $repo_path/Top/repo.conf
148  set options_list ""
149  set ignore_list ""
150 
151  if {[file exists $repo_conf]} {
152  set PROPERTIES [ReadConf $repo_conf]
153  if {[dict exists $PROPERTIES sigasi]} {
154  set sigasiDict [dict get $PROPERTIES sigasi]
155  if {[dict exists $sigasiDict TABS]} {
156  lappend options_list ""
157  } else {
158  lappend options_list "--spaces-for-tabs"
159  }
160  if {[dict exists $sigasiDict PRESERVE_NEWLINES]} {
161  lappend options_list "--preserve-newlines"
162  }
163  if {[dict exists $sigasiDict NO_ALIGN]} {
164  lappend options_list "--no-align"
165  }
166  if {[dict exists $sigasiDict VHDL_VERSION]} {
167  lappend options_list "--vhdl-version=[dict get $sigasiDict VHDL_VERSION]"
168  }
169  if {[dict exists $sigasiDict TAB_WIDTH]} {
170  set tab_width [dict get $sigasiDict TAB_WIDTH]
171  }
172  if {[dict exists $sigasiDict KEYWORDS]} {
173  set keywords [dict get $sigasiDict KEYWORDS]
174  }
175  if {[dict exists $sigasiDict IGNORE_DIR]} {
176  set ignore [dict get $sigasiDict IGNORE_DIR]
177  foreach dir [split $ignore ,] {
178  lappend ignore_list "$repo_path/[string trim $dir]"
179  }
180  }
181  }
182  }
183 
184  set proj_dir $repo_path/Top/$project_name
185  set proj_list_dir $repo_path/Top/$project_name/list
186  set project [file tail $project_name]
187 
188  lassign [GetHogFiles -list_files {.src} $proj_list_dir $repo_path] libraries
189  lappend [GetHogFiles -list_files ".sim" $proj_list_dir $repo_path] libraries
190 
191  foreach lib $libraries {
192  set source_files [DictGet $libraries $lib]
193 
194  foreach source_file $source_files {
195  set skip 0
196  foreach dir $ignore_list {
197  if { [string match $dir* $source_file] } {
198  set skip 1
199  }
200  }
201  if { $skip == 1 } {
202  puts "skipping $source_file due to IGNORE_DIR setting"
203  } else {
204  if {[file extension $source_file] == ".vhd" ||
205  [file extension $source_file] == ".vhdl" } {
206  puts "sigasi-cli format $options_list --keywords=$keywords --tab-width=$tab_width $source_file"
207  exec -- sigasi-cli format {*}$options_list --keywords=$keywords --tab-width=$tab_width $source_file
208  }
209  }
210  }
211  }
212  exit 0
213 }
214 
215 proc sigasi-document {} {
217  global repo_path
218  global project_name
219 
220  cd $repo_path
221  Msg Info "Generating project documentation for $project_name..."
222 
223  set options_list ""
224  set outdir "$repo_path/sigasi_doc/$project_name"
225  set repo_conf $repo_path/Top/repo.conf
226  set project_conf $repo_path/Top/$project_name/hog.conf
227  set proj_top 0
228 
229  if {[file exists $project_conf]} {
230  set PROJ_PROPS [ReadConf $project_conf]
231  if {[dict exists $PROJ_PROPS sigasi]} {
232  set sigasiDict [dict get $PROJ_PROPS sigasi]
233  if {[dict exists $sigasiDict TOP_LEVEL]} {
234  lappend options_list "--top-level=[dict get $sigasiDict TOP_LEVEL]"
235  set proj_top 1
236  }
237  }
238  }
239 
240  if {[file exists $repo_conf]} {
241  set PROPERTIES [ReadConf $repo_conf]
242  if {[dict exists $PROPERTIES sigasi]} {
243  set sigasiDict [dict get $PROPERTIES sigasi]
244  if {[dict exists $sigasiDict LIBRARY_DATABASE]} {
245  set libraries [dict get $sigasiDict LIBRARY_DATABASE]
246  foreach lib [split $libraries ,] {
247  lappend options_list "--library-database=[string trim $lib]"
248  }
249  }
250  # if {[dict exists $sigasiDict DOC_DIR]} {
251  # set outdir [dict get $sigasiDict DOC_DIR]
252  # set outdir [file normalize $outdir]
253  # }
254  if {[dict exists $sigasiDict DIAGRAM_NODE_LIMIT]} {
255  lappend options_list "--diagram-node-limit=[dict get $sigasiDict DIAGRAM_NODE_LIMIT]"
256  }
257  if {[dict exists $sigasiDict DESIGN_UNITS_PER_PAGE]} {
258  lappend options_list "--design-units-per-page=[dict get $sigasiDict DESIGN_UNITS_PER_PAGE]"
259  }
260  if {[dict exists $sigasiDict DIAGRAMS]} {
261  lappend options_list "--diagrams=[dict get $sigasiDict DIAGRAMS]"
262  }
263  if { $proj_top == 0} {
264  if {[dict exists $sigasiDict TOP_LEVEL]} {
265  lappend options_list "--top-level=[dict get $sigasiDict TOP_LEVEL]"
266  }
267  }
268  }
269  }
270  lappend options_list "--output-directory=$outdir"
271 
272  puts "sigasi-cli document $repo_path $options_list "
273  try {
274  set results [exec -- sigasi-cli document $repo_path {*}$options_list 2>@1 ]
275  set status 0
276  } trap CHILDSTATUS {results} {
277  Msg Error "Generation of documentation has failed. Please debug sigasi command outside of HOG"
278  exit 1
279  }
280  Msg Info "Documentation successfully saved to $outdir"
281  exit 0
282 }