21 proc generate_prj_badge {prj_name ver color file {is_hls 0}} {
24 set max_characters 20.0
25 if { [
expr {[string length $prj_name] > $max_characters}] } {
26 set scaling_factor [
expr {$max_characters / [string length $prj_name]}]
27 set font_size [
expr {ceil($scaling_factor * $font_size)}]
32 set ver_text "HLS $ver"
40 set right_color "#4527A0"
42 set right_color "#262626"
46 set ver_font_size 11.0
47 set ver_max_characters 12.0
48 if { [
expr {[string length $ver_text] > $ver_max_characters}] } {
49 set ver_scaling [
expr {$ver_max_characters / [string length $ver_text]}]
50 set ver_font_size [
expr {ceil($ver_scaling * $ver_font_size)}]
53 set svg_content "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
54 <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"250\" height=\"20\">
55 <linearGradient id=\"b\" x2=\"0\" y2=\"100%\">
56 <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>
57 <stop offset=\"1\" stop-opacity=\".1\"/>
59 <mask id=\"hog_prj_badge\">
60 <rect width=\"250\" height=\"20\" rx=\"10\" fill=\"#fff\"/>
62 <g mask=\"url(#hog_prj_badge)\">
63 <path fill=\"$color\" d=\"M0 0h250v20H0z\"/>
64 <path fill=\"$right_color\" d=\"M160 0h90v20H160z\"/>
65 <path fill=\"$right_color\" d=\"M250,20 a1,1 0 0,0 0,-16\"/>
66 <path fill=\"url(#b)\" d=\"M0 0h250v20H0z\"/>
68 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"$font_size\">
69 <text x=\"80\" y=\"14\">$prj_name</text>
71 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"$ver_font_size\">
72 <text x=\"205\" y=\"14\">$ver_text</text>
83 error "Failed to write to file: $error_msg"
87 proc generate_res_badge {res res_value color file {is_hls 0}} {
92 set value_text $res_value
95 set value_font_size 11.0
96 set value_max_characters 9.0
97 if { [
expr {[string length $value_text] > $value_max_characters}] } {
98 set value_scaling [
expr {$value_max_characters / [string length $value_text]}]
99 set value_font_size [
expr {ceil($value_scaling * $value_font_size)}]
102 set svg_content "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
103 <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"120\" height=\"20\">
104 <linearGradient id=\"b\" x2=\"0\" y2=\"100%\">
105 <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>
106 <stop offset=\"1\" stop-opacity=\".1\"/>
108 <mask id=\"hog_res_badge\">
109 <rect width=\"120\" height=\"20\" rx=\"3\" fill=\"#fff\"/>
111 <g mask=\"url(#hog_res_badge)\">
112 <path fill=\"#555\" d=\"M0 0h60v20H0z\"/>
113 <path fill=\"$color\" d=\"M60 0h60v20H60z\"/>
114 <path fill=\"url(#b)\" d=\"M0 0h120v20H0z\"/>
116 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
117 <text x=\"30\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">$res</text>
118 <text x=\"30\" y=\"14\">$res</text>
120 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"$value_font_size\">
121 <text x=\"90\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">$value_text</text>
122 <text x=\"90\" y=\"14\">$value_text</text>
128 set fh [open $file w]
129 puts $fh $svg_content
133 error "Failed to write to file: $error_msg"
138 set TclPath [
file dirname [
info script]]/..
139 set repo_path [
file normalize "$TclPath/../.."]
140 source $TclPath/hog.tcl
143 set usage "- CI script that creates GitLab badges with utilisation and timing results for a chosen Hog project.\n\
144 USAGE: $::argv0 <push token> <Gitlab api url> <Gitlab project id> <Gitlab project url> <GitLab Server URL> <Hog project|hls:component> <ext_path>\n\
146 <Hog project> Name of a Vivado project in Top/ — produces Vivado badges from bin/<project>-<ver>/utilization.txt\n\
147 hls:<component> Produces HLS badges for a single HLS component located at bin/*/\[vitis_hls/\]<component>/utilization.txt"
149 if {[
llength $argv] < 7} {
155 set result [
catch {
package require json} JsonFound]
156 if {"$result" != "0"} {
157 Msg CriticalWarning "Cannot find JSON package equal or higher than 1.0.\n $JsonFound\n Exiting"
161 set push_token [
lindex $argv 0]
162 set api_url [
lindex $argv 1]
163 set project_id [
lindex $argv 2]
164 set project_url [
lindex $argv 3]
165 set gitlab_url [
lindex $argv 4]
166 set project [
lindex $argv 5]
167 set ext_path [
lindex $argv 6]
169 set resources [dict create "LUTs" "LUTs" "Registers" "FFs" "Block" "BRAM" "URAM" "URAM" "DSPs" "DSPs"]
177 if {[
string match "hls:*" $project]} {
179 set hls_component [
string range $project 4 end]
182 if {!$is_hls_badge} {
187 set current_badges [dict create]
190 Msg Info "Retrieving current badges..."
192 lassign [
ExecuteRet {*}$curl_cmd --header "PRIVATE-TOKEN: $push_token" "$api_url/projects/${project_id}/badges?page=$page" --request GET] ret content
193 set content_dict [json::json2dict $content]
194 if {[
llength $content_dict] > 0} {
195 foreach it $content_dict {
207 proc extract_ver_from_dir {dir_name} {
210 if {[regexp -- {-(v[0-9]+\.[0-9]+\.[0-9]+)(?:-[0-9a-fA-F]+)?$} $dir_name -> v]} {
221 set hls_matches [
concat \
222 [glob -nocomplain $repo_path/bin/*/vitis_hls/$hls_component/utilization.txt] \
223 [glob -nocomplain $repo_path/bin/*/$hls_component/utilization.txt]]
224 if {[
llength $hls_matches] == 0} {
225 Msg CriticalWarning "Cannot find HLS component '$hls_component' binaries in artifacts"
230 if {[
llength $hls_matches] > 1} {
231 Msg Warning "Multiple bin dirs contain HLS component '$hls_component'; using [
lindex $hls_matches 0]"
233 set prj_dir [
file dirname [
lindex $hls_matches 0]]
236 if {[
file tail [
file dirname $parent]] eq "vitis_hls"} {
237 set parent [
file dirname [
file dirname $parent]]
239 set parent [
file dirname $parent]
242 if {$ver eq ""} {
set ver "unknown"}
247 set prj_matches [glob -nocomplain -types d \
248 $repo_path/bin/$project-${ver} \
249 $repo_path/bin/$project-${ver}-*]
250 if {[
llength $prj_matches] == 0} {
251 Msg CriticalWarning "Cannot find $project binaries in artifacts"
255 set prj_dir [
lindex $prj_matches 0]
256 foreach m $prj_matches {
257 if {[
file tail $m] eq "$project-${ver}"} {
set prj_dir $m break}
264 proc parse_vivado_util {lines resources} {
265 set usage_dict [dict create]
266 foreach line $lines {
267 set str [
string map {| ""} $line]
268 set str [
string map {"<" ""} $str]
269 set str [
string trim $str]
270 set usage [
lindex [
split $str] end]
271 foreach res [dict keys $resources] {
272 if {[
string first $res $str] > -1} {
273 set res_name [dict get $resources $res]
274 dict set usage_dict $res_name $usage
284 proc parse_hls_util {lines} {
285 set usage_dict [dict create]
286 set hls_res_map [dict create LUT "LUTs" FF "FFs" BRAM "BRAM" BRAM_18K "BRAM" URAM "URAM" DSP "DSPs"]
287 foreach line $lines {
288 if {![regexp -- {^\s*\|\s*([A-Za-z_0-9]+)\s*\|\s*\S+\s*\|\s*\S+\s*\|\s*(\S+)\s*\|} $line -> site pct]} {
291 if {[dict exists $hls_res_map $site]} {
292 set res_name [dict get $hls_res_map $site]
293 if {[
string is double -strict $pct]} {
294 dict set usage_dict $res_name $pct
299 set ordered [dict create]
300 foreach res_name {LUTs FFs BRAM URAM DSPs} {
301 if {[dict exists $usage_dict $res_name]} {
302 dict set ordered $res_name [dict get $usage_dict $res_name]
318 proc emit_badges {util_dir badge_suffix label_left is_hls util_dict ver new_badges_var} {
319 upvar 1 $new_badges_var new_badges
322 if {[
file exists $util_dir/timing_error.txt]} {
324 }
elseif {[
file exists $util_dir/timing_ok.txt]} {
329 dict set new_badges "timing-$badge_suffix" "timing-$badge_suffix"
332 foreach res [dict keys $util_dict] {
333 set usage [
DictGet $util_dict $res]
334 set res_value "$usage\% "
335 if {[
expr {$usage < 50.0}]} {
337 }
elseif {[
expr {$usage < 80.0}]} {
342 dict set new_badges "$res-$badge_suffix" "$res-$badge_suffix"
348 set new_badges [dict create]
355 set fp [open utilization.txt]
356 set hls_lines [
split [read $fp] "\n"]
359 emit_badges "." $hls_component $hls_component 1 $hls_util_dict $ver new_badges
364 set prj_name [
string map {/ _} $project]
365 if {[
file exists utilization.txt]} {
366 set fp [open utilization.txt]
367 set vivado_lines [
split [read $fp] "\n"]
370 emit_badges "." $prj_name $prj_name 0 $vivado_util $ver new_badges
375 foreach badge_name [dict keys $new_badges] {
376 Msg Info "Uploading badge image $badge_name.svg ...."
378 lassign [
ExecuteRet {*}$curl_cmd --request POST --header "PRIVATE-TOKEN: ${push_token}" --form "file=@$badge_name.svg" $api_url/projects/$project_id/uploads] ret content
379 set image_url [
ParseJSON $content full_path]
380 set image_url $gitlab_url/$image_url
381 if {[dict exists $current_badges $badge_name]} {
382 Msg Info "Badge $badge_name exists, updating it..."
383 set badge_id [
DictGet $current_badges $badge_name]
384 Execute curl --header "PRIVATE-TOKEN: $push_token" "$api_url/projects/${project_id}/badges/$badge_id" --request PUT --data "image_url=$image_url"
386 Msg Info "Badge $badge_name does not exist yet. Creating it..."
388 Execute curl --header "PRIVATE-TOKEN: $push_token" --request POST --data "link_url=$project_url/-/releases&image_url=$image_url&name=$badge_name" "$api_url/projects/$project_id/badges"