Hog v10.58.0
launch.tcl
Go to the documentation of this file.
1 #!/usr/bin/env tclsh
2 # tcl-lsp: disable=W300
3 
4 # @file
5 # Copyright 2018-2026 The University of Birmingham
6 # Copyright 2018-2026 Max-Planck-Institute for Physics
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # Launch Xilinx Vivado or ISE implementation and possibly write bitstream in text mode
20 # Developers Tip for new commands
21 # Add a hashtag sign # after the curly brake (e.g. \^C(REATE)?$ {# ...}) if the command requires a project name as an argument
22 set tcl_path [file normalize "[file dirname [info script]]"]
23 source $tcl_path/hog.tcl
24 source $tcl_path/create_project.tcl
25 source $tcl_path/commands.tcl
26 
27 # Initialize Vitis flags before InitLauncher so IsTclsh correctly returns 1
28 set globalSettings::vitis_unified 0
29 set globalSettings::vitis_classic 0
30 
31 # Check if we're already running in xsct (Vitis Classic)
32 # This must be done early, before InitLauncher, to prevent launching Vivado
33 if {[info commands platform] ne ""} {
34  set globalSettings::vitis_classic 1
35  set globalSettings::vitis_unified 0
36 }
37 
38 # Quartus needs extra packages and treats the argv in a different way
39 if {[IsQuartus]} {
40  load_package report
41  # noqa: W210
42  set argv $quartus(args)
43 }
44 
45 
46 # Msg Debug "s: $::argv0 a: $argv"
47 ### CUSTOM COMMANDS ###
48 set commands_path [file normalize "$tcl_path/../../hog-commands/"]
49 set custom_commands [GetCustomCommands $parameters $commands_path]
50 
51 lassign [InitLauncher $::argv0 $tcl_path $parameters $default_commands $argv $custom_commands] directive project \
52  project_name group_name repo_path old_path bin_dir top_path usage short_usage cmd ide list_of_options
53 
54 array set options $list_of_options
55 
56 if {$options(verbose) == 1} {
57  setDebugMode 1
58 }
59 Msg Debug \
60  "Returned by InitLauncher: \n - project: $project \n - project_name $project_name \n - group_name $group_name \n - \
61  repo_path $repo_path \n - old_path $old_path \n - bin_dir $bin_dir \n - top_path $top_path \n - cmd $cmd"
62 
63 set ext_path ""
64 if {$options(ext_path) ne ""} {
65  set ext_path $options(ext_path)
66 }
67 set lib_path ""
68 if {$options(lib) ne ""} {
69  set lib_path [file normalize $options(lib)]
70 } else {
71  if {[info exists env(HOG_SIMULATION_LIB_PATH)]} {
72  set lib_path $env(HOG_SIMULATION_LIB_PATH)
73  } else {
74  if {[file exists "$repo_path/SimulationLib"]} {
75  set lib_path [file normalize "$repo_path/SimulationLib"]
76  } else {
77  set lib_path ""
78  }
79  }
80 }
81 
82 
83 if {$options(verbose) == 1} {
84  setDebugMode 1
85  # Set environment variable for Vitis Unified Python scripts to enable debug output
86  set env(HOG_DEBUG_MODE) "1"
87 }
88 
89 # printDebugMode
90 # Msg Info "Number of jobs set to $options(njobs)."
91 set output_path ""
92 if {$options(output) ne ""} {
93  set output_path $options(output)
94 }
95 
96 set light_hierarchy $options(light)
97 set ignored_hierarchy $options(ignore)
98 set top_module $options(top)
99 set compile_order $options(compile_order)
100 set include_ieee $options(include_ieee)
101 set include_gen_prods $options(include_gen_prods)
102 
103 ######## DEFAULTS #########
104 set do_rtl 0
105 set do_checkproj_env 0
106 set do_check_ci_env 0
107 set do_checkproj_ver 0
108 set do_implementation 0
109 set do_synthesis 0
110 set do_bitstream 0
111 set do_create 0
112 set do_upgrade_ips 0
113 set do_compile 0
114 set do_simulation 0
115 set recreate 0
116 set do_reset 1
117 set do_list_all 2
118 set do_check_syntax 0
119 set do_vitis_build 0
120 set scripts_only 0
121 set compile_only 0
122 set ide_name ""
123 set allow_empty_proj 0
124 
125 ### Hog stand-alone directives ###
126 # The following directives are used WITHOUT ever calling the IDE, they are run in tclsh
127 # A place holder called new_directive can be followed to add new commands
128 set do_ipbus_xml 0
129 set do_cheby 0
130 set do_list_file_parse 0
131 set do_check_yaml_ref 0
132 set do_buttons 0
133 set do_check_list_files 0
134 set do_compile_lib 0
135 set do_sigasi 0
136 set do_sigasi_export 0; set do_sigasi_lint 0; set do_sigasi_docs 0; set do_sigasi_format 0;
137 set do_vhdl_ls 0
138 set do_cocotb 0
139 set do_hierarchy 0
140 set do_version 0
141 
142 set NO_DIRECTIVE_FOUND 0
143 Msg Debug "Looking for a $directive in : $default_commands"
144 switch -regexp -- $directive $default_commands
145 
146 if {$NO_DIRECTIVE_FOUND == 1} {
147  Msg Debug "No directive found in default commands, looking in custom commands..."
148  if {[string length $custom_commands] > 0 && [dict exists $custom_commands $directive]} {
149  Msg Debug "Directive $directive found in custom commands."
150  if {$cmd == "custom_tcl"} {
151  eval [dict get $custom_commands $directive SCRIPT]
152  exit
153  } else {
154  if {[IsTclsh]} {
155  Msg Info "Launching command: $cmd..."
156 
157  # Check if the IDE is actually in the path...
158  set ret [catch {exec which $ide}]
159  if {$ret != 0} {
160  Msg Error "$ide not found in your system. Make sure to add $ide to your PATH enviromental variable."
161  exit $ret
162  }
163 
164  if {[string first libero $cmd] >= 0} {
165  # The SCRIPT_ARGS: flag of libero makes tcl crazy...
166  # Let's pipe the command into a shell script and remove it later
167  set libero_script [open "launch-libero-hog.sh" w]
168  puts $libero_script "#!/bin/sh"
169  puts $libero_script $cmd
170  close $libero_script
171  set cmd "sh launch-libero-hog.sh"
172  }
173 
174  set ret [catch {exec -ignorestderr {*}$cmd >@ stdout 2>@ stderr} result]
175 
176  if {$ret != 0} {
177  Msg Error "IDE returned an error state: $result"
178  } else {
179  Msg Info "All done."
180  exit 0
181  }
182 
183  if {[string first libero $cmd] >= 0} {
184  file delete "launch-libero-hog.sh"
185  }
186 
187  exit $ret
188  }
189 
190  eval [dict get $custom_commands $directive SCRIPT]
191 
192  set no_exit [dict get $custom_commands $directive NO_EXIT]
193  if {$no_exit == 0} {
194  exit
195  }
196  }
197  } else {
198  Msg Info "No directive found, pre ide exiting..."
199  Msg Status "ERROR: Unknown directive $directive.\n\n"
200  puts $usage
201  exit
202  }
203 }
204 
205 if {$options(all) == 1} {
206  set do_list_all 1
207 } else {
208  set do_list_all 2
209 }
210 
211 set ci_run 0
212 if {$options(ci_run) == 1} {
213  set ci_run 1
214 }
215 
216 if {$options(dst_dir) == "" && ($do_ipbus_xml == 1 || $do_cheby == 1 || $do_check_list_files == 1) && $project != ""} {
217  # Getting all the versions and SHAs of the repository
218  set proj_dir [file normalize $repo_path/Top/$group_name/$project]
219  lassign [GetRepoVersions $proj_dir $repo_path $ext_path] commit version \
220  hog_hash hog_ver top_hash top_ver libs hashes vers cons_ver cons_hash ext_names ext_hashes xml_hash xml_ver \
221  user_ip_repos user_ip_hashes user_ip_vers cheby_hash cheby_ver
222  cd $repo_path
223 
224  set describe [GetHogDescribe $proj_dir $repo_path]
225  set dst_dir [file normalize "$repo_path/bin/$group_name/$project\-$describe"]
226 }
227 
228 if {$cmd == -1} {
229  # This is if the project was not found
230  Msg Status "\n\nPossible projects are:"
231  ListProjects $repo_path $do_list_all
232  Msg Status "\n"
233  exit 1
234 } elseif {$cmd == -2} {
235  # Project not given but needed
236  Msg Status "ERROR: You must specify a project with directive $directive."
237  # \n\n[cmdline::usage $parameters $usage]"
238  Msg Status "Possible projects are:"
239  ListProjects $repo_path $do_list_all
240  exit 1
241 } elseif {$cmd == 0} {
242  #This script was launched within the IDE,: Vivado, Quartus, etc
243  Msg Info "$::argv0 was launched from the IDE."
244 } else {
245  # This script was launched with Tclsh, we need to check the arguments
246  # and if everything is right launch the IDE on this script and return
247  #### Directives to be handled in tclsh should be here ###
248  ### IMPORTANT: Each if block should either end with "exit 0" or
249  ### set both $ide and $cmd to be executed when this script is run again
250  if {$do_checkproj_env == 1} {
251  CheckEnv $project_name $ide
252  exit 0
253  }
254 
255  if {$do_checkproj_ver == 1} {
256  cd $repo_path
257  set ci_config ""
258  if {$ci_run == 1} {
259  # Compile YAML to get list of projects
260  if {[info exists env(GITLAB_CI)] && $env(GITLAB_CI) eq "true" && [auto_execok glab] != ""} {
261  # running in GitLab CI
262  Msg Info "Running in the GitLab CI/CD. I will check only the active projects in the current pipeline..."
263  # Tell glab the host and project explicitly: on SaaS runners the git remote
264  # points to the CI gateway, which glab does not recognise as a GitLab host.
265  if {[info exists env(CI_SERVER_HOST)]} {
266  set env(GITLAB_HOST) $env(CI_SERVER_HOST)
267  }
268  if {[info exists env(CI_PROJECT_PATH)]} {
269  lassign [ExecuteRet glab ci get -p $env(CI_PIPELINE_ID)] ret ci_config
270  } else {
271  lassign [ExecuteRet glab ci get] ret ci_config
272  }
273  if {$ret != 0} {
274  Msg Warning "Failed to get CI config from GitLab, checking all projects instead."
275  set ci_run 0
276  }
277 
278  # Check if we are using the dynamic CI and set ci_run to 0 in case, so we check the version of all projects
279  if {[info exists env(CI_CONFIG_PATH)]} {
280  set ci_config_path $env(CI_CONFIG_PATH)
281  } else {
282  set ci_config_path $repo_path/.gitlab-ci.yml
283  }
284 
285  if {[file exists $ci_config_path]} {
286  set fh [open $ci_config_path r]
287  set content [read $fh]
288  close $fh
289  if {[string first "hog-dynamic.yml" $content] != -1} {
290  set ci_run 0
291  }
292  } else {
293  Msg Warning "CI config file $ci_config_path not found, checking all projects instead."
294  set ci_run 0
295  }
296  } elseif {[info exists env(GITHUB_ACTIONS)] && $env(GITHUB_ACTIONS) eq "true"} {
297  # running in GitHub Actions
298  set workflow_dir "$repo_path/.github/workflows"
299  set ci_run 0
300  foreach workflow_file [glob -nocomplain -directory $workflow_dir -- *.yml *.yaml] {
301  set fh [open $workflow_file r]
302  set content [read $fh]
303  close $fh
304  if {[string first "Hog-pull.yml" $content] != -1} {
305  set ci_config $content
306  set ci_run 1
307  break
308  }
309  }
310  } else {
311  set ci_run 0
312  }
313  }
314 
315  set proj_to_do {}
316  if {$project_name eq ""} {
317  set projects [ListProjects $repo_path 1 0 1]
318  foreach p $projects {
319  if {$ci_run == 0 || ($ci_run == 1 && [string first $p $ci_config] != -1)} {
320  if {[CheckProjVer $repo_path $p $options(simcheck) $options(ext_path)] == 0} {
321  lappend proj_to_do $p
322  }
323  }
324  }
325  } else {
326  if {[CheckProjVer $repo_path $project_name $options(simcheck) $options(ext_path)] == 0} {
327  lappend proj_to_do $project_name
328  }
329  }
330 
331  set n [llength $proj_to_do]
332  if {$n > 0} {
333  Msg Info "The following projects were modified: \n[join $proj_to_do \n]"
334  }
335 
336  Msg Info "$n projects were modified since last official version."
337  exit 0
338  }
339 
340  if {$do_check_ci_env == 1} {
341  CheckCIEnv
342  exit 0
343  }
344 
345 
346  if {$do_ipbus_xml == 1} {
347  if {[llength $project_name] == 0} {
348  Msg Error "XML option needs a project name."
349  exit
350  }
351  Msg Info "Handling IPbus XMLs for $project_name..."
352 
353  set proj_dir $repo_path/Top/$project_name
354 
355  if {$options(generate) == 1} {
356  set xml_gen 1
357  } else {
358  set xml_gen 0
359  }
360 
361  if {$options(dst_dir) != ""} {
362  set dst_dir $options(dst_dir)
363  } else {
364  if {![info exists dst_dir]} {
365  set dst_dir ""
366  }
367  }
368  set xml_dst "$dst_dir/xml"
369 
370 
371  if {[llength [glob -nocomplain $proj_dir/list/*.ipb]] > 0} {
372  if {![file exists $xml_dst]} {
373  Msg Info "$xml_dst directory not found, creating it..."
374  file mkdir $xml_dst
375  }
376  } else {
377  Msg Error "No .ipb files found in $proj_dir/list/"
378  exit
379  }
380 
381  set ret [GetRepoVersions $proj_dir $repo_path ""]
382  set sha [lindex $ret 13]
383  set hex_ver [lindex $ret 14]
384 
385  set ver [HexVersionToString $hex_ver]
386  CopyIPbusXMLs $proj_dir $repo_path $xml_dst $ver $sha 1 $xml_gen
387 
388  exit 0
389  }
390 
391  if {$do_cheby == 1} {
392  Msg Info "Handling Cheby register-map outputs for $project_name..."
393 
394  set proj_dir $repo_path/Top/$project_name
395 
396  if {$options(generate) == 1} {
397  set cheby_gen 1
398  } else {
399  set cheby_gen 0
400  }
401 
402  if {$options(dst_dir) != ""} {
403  set dst_dir $options(dst_dir)
404  }
405  set cheby_dst "$dst_dir/cheby"
406 
407  if {[llength [glob -nocomplain $proj_dir/list/*.chb]] > 0} {
408  if {![file exists $cheby_dst]} {
409  Msg Info "$cheby_dst directory not found, creating it..."
410  file mkdir $cheby_dst
411  }
412  } else {
413  Msg Error "No .chb files found in $proj_dir/list/"
414  exit
415  }
416 
417  set cheby_tool $options(tool)
418  if {$cheby_tool eq ""} {
419  if {[info exists env(HOG_CHEBY_TOOL)]} {
420  set cheby_tool $env(HOG_CHEBY_TOOL)
421  } else {
422  set cheby_tool "cheby"
423  }
424  }
425 
426  set cheby_profile $options(profile)
427  if {$cheby_profile eq ""} {
428  set cheby_profile "all"
429  }
430 
431  set ret [GetRepoVersions $proj_dir $repo_path ""]
432  set sha [lindex $ret 18]
433  set hex_ver [lindex $ret 19]
434  set ver [HexVersionToString $hex_ver]
435 
436  set n_errors [CopyChebyFiles $proj_dir $repo_path $cheby_dst \
437  $ver $sha $cheby_gen $cheby_profile $cheby_tool \
438  $options(strict) $options(verbose)]
439 
440  if {$n_errors > 0} {
441  Msg CriticalWarning "Cheby step finished with $n_errors error(s)."
442  exit 1
443  }
444  exit 0
445  }
446 
447  if {$do_list_file_parse == 1} {
448  set proj_dir $repo_path/Top/$project_name
449  set proj_list_dir $repo_path/Top/$project_name/list
450  GetHogFiles -print_log -list_files {.src,.con,.sim,.ext,.ipb,.chb} $proj_list_dir $repo_path
451  Msg Status " "
452  Msg Info "All Done."
453  exit 0
454  }
455 
456  if {$do_hierarchy == 1} {
457  source $tcl_path/utils/hierarchy.tcl
458  set proj_dir $repo_path/Top/$project_name
459  set proj_list_dir $repo_path/Top/$project_name/list
460  lassign [GetHogFiles -ext_path $ext_path -list_files ".src,.ext" $proj_list_dir $repo_path] listLibraries \
461  listProperties listSrcSets
462  set hierarchy_result \
463  [Hierarchy $listProperties $listLibraries $repo_path $output_path $compile_order $light_hierarchy $top_module \
464  $ignored_hierarchy $include_ieee $include_gen_prods]
465  puts $hierarchy_result
466  exit 0
467  }
468  if {$do_sigasi == 1} {
469  source $tcl_path/utils/sigasi_cli.tcl
470  if {$do_sigasi_export == 1} {
472  }
473 
474  if {$do_sigasi_lint == 1} {
476  }
477 
478  if {$do_sigasi_format == 1} {
480  }
481 
482  if {$do_sigasi_docs == 1} {
484  }
485  }
486 
487  if {$do_vhdl_ls == 1} {
488  cd $repo_path
489  Msg Info "Creating VHDL-LS configuration file for project $project_name..."
490  set proj_dir $repo_path/Top/$project_name
491  set proj_list_dir $repo_path/Top/$project_name/list
492  set project [file tail $project_name]
493  lassign [GetHogFiles -list_files {.src} $proj_list_dir $repo_path] libraries
494  set toml_file [open "vhdl_ls_$project.toml" w]
495  puts $toml_file "\[libraries\]"
496  dict for {lib source_files} $libraries {
497  puts $toml_file "[file rootname $lib].files = \["
498  foreach source_file $source_files {
499  if {
500  [file extension $source_file] == ".vhd"
501  || [file extension $source_file] == ".vhdl"
502  } {
503  # puts [Relative $repo_path $source_file ]
504  puts $toml_file "\'[Relative $repo_path $source_file]\',"
505  }
506  }
507  puts $toml_file "\]\n"
508  }
509  close $toml_file
510  Msg Info "VHDL-LS TOML File created: vhdl_ls_$project.toml"
511  Msg Info \
512  "You can copy the content of this file into your VHDL-LS configuration vhdl_ls.toml, to import all Hog libraries."
513  exit 0
514  }
515 
516  if {$do_cocotb == 1} {
517  source $tcl_path/utils/cocotb.tcl
518  source $tcl_path/utils/hierarchy.tcl
519  WriteCocoTbTemplate $project_name $repo_path $lib_path $ext_path
520  exit 0
521  }
522 
523  if {$do_check_yaml_ref == 1} {
524  Msg Info "Checking if \"ref\" in .gitlab-ci.yml actually matches the included yml file in Hog submodule"
525  CheckYmlRef $repo_path false
526  exit 0
527  }
528 
529  if {$do_buttons == 1} {
530  Msg Info "Adding Hog buttons to Vivado bar (will use the vivado currently in PATH)..."
531  set ide vivado
532  set cmd "vivado -nojournal -nolog -mode batch -notrace -source $repo_path/Hog/Tcl/utils/add_hog_custom_button.tcl"
533  }
534 
535  if {$do_compile_lib == 1} {
536  if {$project eq ""} {
537  Msg Error "You need to specify a simulator as first argument."
538  exit 1
539  } else {
540  set simulator $project
541  Msg Info "Selecting $simulator simulator..."
542  }
543  if {$options(dst_dir) != ""} {
544  set output_dir $options(dst_dir)
545  } else {
546  Msg Info "No destination directory defined. Using default: SimulationLib/"
547  set output_dir "SimulationLib"
548  }
549 
550  set ide vivado
551  set cmd \
552  "vivado -nojournal -nolog -mode batch -notrace -source $repo_path/Hog/Tcl/utils/compile_simlib.tcl -tclargs -simulator $simulator \
553  -output_dir $output_dir"
554  }
555 
556  set simsets ""
557  if {$do_simulation == 1} {
558  # Filter out HLS simsets (csim:*/cosim:*) -- GHDL only needs HDL simsets
559  set hdl_simsets_pre [list]
560  if {$options(simset) ne ""} {
561  foreach s $options(simset) {
562  if {![regexp {^(csim|cosim):} $s]} {
563  lappend hdl_simsets_pre $s
564  }
565  }
566  }
567 
568  # Get all simsets in the project that run with GHDL
569  set ghdl_simsets [GetSimSets $project_name $repo_path "$hdl_simsets_pre" 1]
570  set ghdl_import 0
571  dict for {simset_name simset_dict} $ghdl_simsets {
572  if {$ghdl_import == 0} {
573  ImportGHDL $project_name $repo_path $simset_name $simset_dict $ext_path
574  set ghdl_import 1
575  }
576  LaunchGHDL $project_name $repo_path $simset_name $simset_dict $ext_path
577  }
578  set ide_simsets [GetSimSets $project_name $repo_path $hdl_simsets_pre 0 1]
579 
580  if {[dict size $ide_simsets] == 0} {
581  # Check if there are HLS simsets to run before exiting
582  set has_hls [expr {$options(simset) eq ""}]
583  if {!$has_hls} {
584  foreach s $options(simset) {
585  if {[regexp {^(csim|cosim):} $s]} {
586  set has_hls 1
587  break
588  }
589  }
590  }
591  if {!$has_hls} {
592  Msg Info "All simulations have been run, exiting..."
593  exit 0
594  }
595  }
596  }
597 
598  if {$do_version == 1} {
599  cd $repo_path
600  set proj_dir $repo_path/Top/$project_name
601  lassign [GetRepoVersions $proj_dir $repo_path $ext_path] sha ver
602  if {$options(describe) == 1} {
603  puts [GetHogDescribe $proj_dir $repo_path]
604  } else {
605  puts "v[HexVersionToString $ver]"
606  }
607  exit 0
608  }
609 
610  # if {$do_new_directive ==1 } {
611  #
612  # # Do things here
613  #
614  # exit 0
615  #}
616  #### END of tclsh commands ####
617  Msg Info "Launching command: $cmd..."
618 
619  # Check if the IDE is actually in the path...
620  set ret [catch {exec which $ide}]
621  if {$ret != 0} {
622  if {[string match "*vitis_unified*" $ide_name]} {
623  Msg Error \
624  "This is a '$ide_name' project: make sure to add both Vivado and Vitis to your PATH environment variable."
625  } else {
626  Msg Error "$ide not found in your system. Make sure to add $ide to your PATH environment variable."
627  }
628  exit $ret
629  }
630 
631  if {[string first libero $cmd] >= 0} {
632  # The SCRIPT_ARGS: flag of libero makes tcl crazy...
633  # Let's pipe the command into a shell script and remove it later
634  set libero_script [open "launch-libero-hog.sh" w]
635  puts $libero_script "#!/bin/sh"
636  puts $libero_script $cmd
637  close $libero_script
638  set cmd "sh launch-libero-hog.sh"
639  }
640 
641  set ret [catch {exec -ignorestderr {*}$cmd >@ stdout 2>@ stderr} result]
642 
643  if {$ret != 0} {
644  Msg Error "IDE returned an error state: $result"
645  } else {
646  Msg Info "All done."
647  exit 0
648  }
649 
650  if {[string first libero $cmd] >= 0} {
651  file delete "launch-libero-hog.sh"
652  }
653 
654  exit $ret
655 }
656 
657 
658 #After this line, we are in the IDE
659 ##################################################################################
660 # We need to Import tcllib if we are using Libero
661 if {[IsLibero] || [IsDiamond]} {
662  if {[info exists env(HOG_TCLLIB_PATH)]} {
663  lappend auto_path $env(HOG_TCLLIB_PATH)
664  } else {
665  puts \
666  "ERROR: To run Hog with Microsemi Libero SoC or Lattice Diamond, you need to define the HOG_TCLLIB_PATH variable."
667  return
668  }
669 }
670 
671 if {[catch {package require cmdline} ERROR] || [catch {package require struct::matrix} ERROR]} {
672  puts \
673  "$ERROR\n Tcllib not found. If you are running this script on tclsh for debuggin purpose ONLY, you can fix this by \
674  installing 'tcllib'"
675  exit 1
676 }
677 
678 set run_folder [file normalize "$repo_path/Projects/$project_name/$project.runs/"]
679 if {[IsLibero]} {
680  set run_folder [file normalize "$repo_path/Projects/$project_name/"]
681 }
682 
683 # Only for quartus, not used otherwise
684 set project_path [file normalize "$repo_path/Projects/$project_name/"]
685 
686 # Get IDE name from project config file
687 if {$allow_empty_proj == 0 || $project_name ne ""} {
688  set proj_conf [ProjectExists $project_name $repo_path]
689 } else {
690  set proj_conf ""
691 }
692 set ide_name_and_ver [string tolower [GetIDEFromConf $proj_conf]]
693 set ide_name [lindex [regexp -all -inline {\S+} $ide_name_and_ver] 0]
694 
695 # Validate IDE name
696 set supported_ides \
697  [list vivado vivado_vitis_classic vivado_vitis_unified vitis_classic vitis_unified quartus planahead libero diamond \
698  ghdl]
699 if {$ide_name ni $supported_ides} {
700  if {$ide_name eq "vitis"} {
701  Msg Error \
702  "The IDE set in hog.conf ('vitis') is not supported. Did you mean 'vitis_unified' or 'vitis_classic'? Supported \
703  IDEs: [join $supported_ides {, }]"
704  } else {
705  Msg Error "The IDE set in hog.conf ('$ide_name') is not supported. Supported IDEs: [join $supported_ides {, }]"
706  }
707  exit 1
708 }
709 
710 # Vitis IDE detection
711 if {
712  ([string tolower $ide_name] eq "vivado_vitis_classic" || [string tolower $ide_name] eq "vitis_classic")
713  && ($options(vivado_only) != 1)
714 } {
715  set globalSettings::vitis_classic 1
716  set globalSettings::vitis_unified 0
717 } elseif {
718  ([string tolower $ide_name] eq "vivado_vitis_unified" || [string tolower $ide_name] eq "vitis_unified")
719  && ($options(vivado_only) != 1)
720 } {
721  set globalSettings::vitis_classic 0
722  set globalSettings::vitis_unified 1
723  if {[auto_execok vitis] eq ""} {
724  Msg Error \
725  "Vitis Unified IDE is required for project $project_name but 'vitis' was not found in PATH. Please source Vitis \
726  settings first."
727  }
728 } else {
729  set globalSettings::vitis_classic 0
730  set globalSettings::vitis_unified 0
731 }
732 
733 # Standalone vitis_unified / vitis_classic projects are implicitly vitis-only
734 if {$ide_name eq "vitis_unified" || $ide_name eq "vitis_classic"} {
735  set options(vitis_only) 1
736 }
737 
738 set is_vitis_ide [expr {$globalSettings::vitis_classic == 1 || $globalSettings::vitis_unified == 1}]
739 set is_build_step [expr {$do_synthesis == 1 || $do_implementation == 1 || $do_compile == 1}]
740 if {$is_vitis_ide && $options(vitis_only) == 1 && $is_build_step} {
741  set do_vitis_build 1
742 }
743 
744 
745 if {$options(no_bitstream) == 1} {
746  set do_bitstream 0
747  set do_compile 0
748 }
749 
750 if {$options(recreate) == 1} {
751  set recreate 1
752 }
753 
754 if {$options(synth_only) == 1} {
755  set do_implementation 0
756  set do_synthesis 1
757  set do_bitstream 0
758  set do_create 1
759  set do_compile 1
760 }
761 
762 if {$options(impl_only) == 1} {
763  set do_implementation 1
764  set do_synthesis 0
765  set do_bitstream 0
766  set do_create 0
767  set do_compile 1
768 }
769 
770 if {$options(vitis_only) == 1 || $ide_name eq "vitis_classic" || $ide_name eq "vitis_unified"} {
771  set do_implementation 0
772  set do_synthesis 0
773  set do_bitstream 0
774  set do_compile 0
775 }
776 
777 if {$options(bitstream_only) == 1} {
778  set do_bitstream_only 1
779  set do_bitstream 0
780  set do_implementation 0
781  set do_synthesis 0
782  set do_create 0
783  set do_compile 0
784 } else {
785  set do_bitstream_only 0
786 }
787 
788 if {$options(no_reset) == 1} {
789  set do_reset 0
790 }
791 
792 if {$options(check_syntax) == 1} {
793  set do_check_syntax 1
794 }
795 
796 if {$options(scripts_only) == 1} {
797  set scripts_only 1
798 }
799 
800 if {$options(compile_only) == 1} {
801  set compile_only 1
802 }
803 
804 
805 Msg Info "Number of jobs set to $options(njobs)."
806 
807 ############## Quartus ########################
808 set argv ""
809 
810 ############# CREATE or OPEN project ############
811 if {$options(vitis_only) == 1 && ($ide_name eq "vitis_unified" || $ide_name eq "vivado_vitis_unified")} {
812  cd $tcl_path
813  set project_file [file normalize $repo_path/Projects/$project_name/vitis_unified/_ide/settings.json]
814  Msg Info "Setting project file for Vitis Unified project $project_name to $project_file"
815 } elseif {$options(vitis_only) == 1 && ($ide_name eq "vitis_classic" || $ide_name eq "vivado_vitis_classic")} {
816  cd $tcl_path
817  set project_file [file normalize $repo_path/Projects/$project_name/vitis_classic/.metadata/]
818  Msg Info "Setting project file for Vitis Classic project $project_name to $project_file"
819 } elseif {[IsISE]} {
820  cd $tcl_path
821  set project_file [file normalize $repo_path/Projects/$project_name/$project.ppr]
822 } elseif {[IsVivado]} {
823  cd $tcl_path
824  set project_file [file normalize $repo_path/Projects/$project_name/$project.xpr]
825 } elseif {[IsVitisClassic]} {
826  cd $tcl_path
827  set project_file [file normalize $repo_path/Projects/$project_name/vitis_classic/.metadata/]
828  Msg Info "Setting project file for Vitis Classic project $project_name to $project_file"
829 } elseif {[IsVitisUnified]} {
830  cd $tcl_path
831  set project_file [file normalize $repo_path/Projects/$project_name/vitis_unified/_ide/settings.json]
832  Msg Info "Setting project file for Vitis Unified project $project_name to $project_file"
833 } elseif {[IsQuartus]} {
834  if {[catch {package require ::quartus::project} ERROR]} {
835  Msg Error "$ERROR\n Can not find package ::quartus::project"
836  cd $old_path
837  return 1
838  } else {
839  Msg Info "Loaded package ::quartus::project"
840  load_package flow
841  }
842  set project_file "$project_path/$project.qpf"
843 } elseif {[IsLibero]} {
844  set project_file [file normalize $repo_path/Projects/$project_name/$project.prjx]
845 } elseif {[IsDiamond]} {
846  sys_install version
847  set project_file [file normalize $repo_path/Projects/$project_name/$project.ldf]
848 } else {
849  Msg Error "Unknown IDE, can't set project file path."
850  exit 1
851 }
852 
853 if {[file exists $project_file]} {
854  Msg Info "Found project file $project_file for $project_name."
855  set proj_found 1
856 } else {
857  # Path from InitLauncher may resolve to a different mount for the same repo.
858  # Discover repo root and use first path where project exists (file or, for Vitis Unified, project dir).
859  set repo_norm [file normalize $repo_path]
860  set rel [string trimleft [string range $project_file [string length $repo_norm] end] "/"]
861  set proj_found 0
862  foreach start_dir [list [file dirname [info script]] [pwd]] {
863  set repo_candidate [FindRepoRoot $start_dir]
864  Msg Debug "FindRepoRoot([list $start_dir]) => [list $repo_candidate]"
865  if {$repo_candidate ne ""} {
866  set project_file_alt [file join $repo_candidate $rel]
867  set found 0
868  if {[file exists $project_file_alt]} {
869  set found 1
870  } elseif {$options(vitis_only) == 1 && [string match "*vitis_unified*" $rel]} {
871  set ide_dir [file join $repo_candidate Projects $project_name vitis_unified _ide]
872  if {[file exists $ide_dir]} {
873  set found 1
874  }
875  }
876  if {$options(vitis_only) == 1 && [string match "*vitis_unified*" $rel]} {
877  Msg Debug \
878  "Checking file [list $project_file_alt] exists=[file exists $project_file_alt]; _ide dir [list $ide_dir] \
879  exists=[file exists $ide_dir]"
880  } else {
881  Msg Debug "Checking [list $project_file_alt] exists=[file exists $project_file_alt]"
882  }
883  if {$found} {
884  set project_file $project_file_alt
885  set repo_path $repo_candidate
886  Msg Info "Found project file $project_file for $project_name."
887  set proj_found 1
888  break
889  }
890  }
891  }
892  if {!$proj_found} {
893  Msg Info "Project file not found for $project_name."
894  }
895 }
896 
897 if {$proj_found == 0 && $do_upgrade_ips == 1} {
898  Msg Error "Project $project_name not found. UPGRADE_IP requires an existing project."
899  exit 1
900 } elseif {($proj_found == 0 || $recreate == 1)} {
901  set do_create 1
902  Msg Info "Creating (possibly replacing) the project $project_name..."
903  Msg Debug "launch.tcl: calling GetConfFiles with $repo_path/Top/$project_name"
904  lassign [GetConfFiles $repo_path/Top/$project_name] conf sim pre post pre_rtl post_rtl
905 
906  if {[file exists $conf]} {
907  set globalSettings::vitis_only_pass $options(vitis_only)
908  if {$options(vivado_only) == 1} {
909  CreateProject -simlib_path $lib_path -xsa $options(xsa) -vivado_only $project_name $repo_path
910  } elseif {$options(vitis_only) == 1} {
911  CreateProject -simlib_path $lib_path -xsa $options(xsa) -vitis_only $project_name $repo_path
912  } else {
913  CreateProject -simlib_path $lib_path -xsa $options(xsa) $project_name $repo_path
914  }
915  Msg Info "Done creating project $project_name."
916  if {$options(vitis_only) == 1 && ($ide_name eq "vitis_unified" || $ide_name eq "vivado_vitis_unified")} {
917  set project_file [file join $repo_path Projects $project_name vitis_unified _ide settings.json]
918  }
919  } else {
920  Msg Error "Project $project_name is incomplete: no hog.conf file found, please create one..."
921  }
922 } elseif {$proj_found == 0} {
923  Msg Error "Project $project_name not found. Please create it first using the 'CREATE' or 'C' directive."
924  exit 1
925 } else {
926  Msg Info "Opening existing project file $project_file..."
927  if {$options(vitis_only) == 1 && ($ide_name eq "vitis_unified" || $ide_name eq "vivado_vitis_unified")} {
928  set vitis_workspace [file normalize $repo_path/Projects/$project_name/vitis_unified/]
929  Msg Info "Setting Vitis Unified workspace to $vitis_workspace"
930  } elseif {[IsXilinx]} {
931  file mkdir "$repo_path/Projects/$project_name/$project.gen/sources_1"
932  OpenProject $project_file $repo_path
933  } elseif {[IsVitisClassic]} {
934  set vitis_workspace [file normalize $repo_path/Projects/$project_name/vitis_classic/]
935  Msg Info "Setting workspace to $vitis_workspace"
936  } elseif {[IsVitisUnified]} {
937  set vitis_workspace [file normalize $repo_path/Projects/$project_name/vitis_unified/]
938  Msg Info "Setting workspace to $vitis_workspace"
939  } else {
940  OpenProject $project_file $repo_path
941  }
942 }
943 
944 if {$do_upgrade_ips == 1} {
945  if {![IsVivado]} {
946  Msg Error "The UPGRADE_IP directive is only supported for Vivado projects."
947  exit 1
948  }
949  UpgradeIPs
950  exit 0
951 }
952 
953 
954 ########## CHECK SYNTAX ###########
955 if {$do_check_syntax == 1} {
956  if {$ide_name eq "vitis_unified" || $ide_name eq "vitis_classic"} {
957  Msg Info "Skipping syntax check for $project_name: pure Vitis project has no HDL syntax to check"
958  } else {
959  Msg Info "Checking syntax for project $project_name..."
960  CheckSyntax $project_name $repo_path $project_file
961  }
962 }
963 
964 ######### RTL ANALYSIS ########
965 if {$do_rtl == 1} {
966  lassign [GetConfFiles $repo_path/Top/$project_name] conf sim pre post pre_rtl post_rtl
967  LaunchRTLAnalysis $repo_path $pre_rtl $post_rtl
968 }
969 
970 if {$do_vitis_build == 1} {
971  if {[IsVitisClassic] || [IsVitisUnified]} {
972  # Check for HLS components and build them
973  set conf_file_path [file normalize "$repo_path/Top/$project_name/hog.conf"]
974  if {[file exists $conf_file_path]} {
975  set proj_properties [ReadConf $conf_file_path]
976  set hls_components [dict filter $proj_properties key {hls:*}]
977  if {[dict size $hls_components] > 0} {
978  Msg Info "Found [dict size $hls_components] HLS component(s), launching HLS build..."
979  LaunchHlsBuild $project_name $repo_path
980  }
981  # Build apps/platforms if any exist
982  set has_apps [expr {[dict size [dict filter $proj_properties key {app:*}]] > 0}]
983  if {$has_apps} {
984  LaunchVitisBuild $project_name $repo_path
985  }
986  } else {
987  LaunchVitisBuild $project_name $repo_path
988  }
989  } else {
990  Msg Error "Vitis build is not supported for $ide_name (only Vitis Classic and Vitis Unified are supported)"
991  exit 1
992  }
993 }
994 
995 ######### LaunchSynthesis ########
996 if {$do_synthesis == 1} {
997  LaunchSynthesis $do_reset $do_create $run_folder $project_name $repo_path $ext_path $options(njobs)
998 }
999 
1000 if {$do_implementation == 1} {
1001  LaunchImplementation $do_reset $do_create $run_folder $project_name $repo_path $options(njobs) $do_bitstream
1002 }
1003 
1004 if {$do_bitstream_only == 1 && [IsXilinx]} {
1005  GenerateBitstreamOnly $project_name $repo_path
1006 } elseif {$do_bitstream_only == 1 && ![IsXilinx]} {
1007  Msg Error "Bitstream only option is not supported for this IDE."
1008 }
1009 
1010 if {$do_bitstream == 1 && ![IsXilinx]} {
1011  GenerateBitstream $run_folder $repo_path $options(njobs)
1012 }
1013 
1014 if {$do_simulation == 1} {
1015  # Separate HLS simsets (csim:*/cosim:*) from HDL simsets
1016  set hdl_simsets [list]
1017  set hls_simsets [list]
1018  if {$options(simset) ne ""} {
1019  foreach s $options(simset) {
1020  if {[regexp {^(csim|cosim):} $s]} {
1021  lappend hls_simsets $s
1022  } else {
1023  lappend hdl_simsets $s
1024  }
1025  }
1026  }
1027  set run_hdl [expr {[llength $hdl_simsets] > 0 || $options(simset) eq ""}]
1028  set run_hls [expr {[llength $hls_simsets] > 0 || $options(simset) eq ""}]
1029 
1030  # Run HDL simulations
1031  if {$run_hdl} {
1032  set simsets [GetSimSets $project_name $repo_path $hdl_simsets]
1033  if {[dict size $simsets] > 0} {
1034  LaunchSimulation $project_name $lib_path $simsets $repo_path $scripts_only $compile_only
1035  }
1036  }
1037 
1038  # Run HLS simulations (csim/cosim)
1039  if {$run_hls} {
1040  LaunchHlsSimulation $project_name $repo_path $hls_simsets
1041  }
1042 }
1043 
1044 
1045 if {$do_check_list_files} {
1046  Msg Info "Running list file checker..."
1047 
1048 
1049  #if {![file exists $dst_dir]} {
1050  # Msg Info "$dst_dir directory not found, creating it..."
1051  # file mkdir $dst_dir
1052  # }
1053  set argv0 check_list_files
1054  if {$ext_path ne ""} {
1055  set argv [list "-ext_path" "$ext_path" "-outDir" "$dst_dir" "-pedantic"]
1056  } else {
1057  set argv [list "-outDir" "$dst_dir" "-pedantic"]
1058  }
1059 
1060  source $tcl_path/utils/check_list_files.tcl
1061 }
1062 ## CLOSE Project
1064 
1065 Msg Info "All done."
1066 cd $old_path