You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1922 lines
70 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. ####################################################################################
  2. #
  3. # write_project_tcl.tcl (write a Vivado project tcl script for re-creating project)
  4. #
  5. # Script created on 02/08/2013 by Raj Klair (Xilinx, Inc.)
  6. #
  7. # 2014.2 - v2.0 (rev 4)
  8. # * do not return value from main proc
  9. # * fixed bug with relative file path calculation (break from loop while comparing
  10. # directory elements of file paths for file to make relative to o/p script dir)
  11. # 2014.1 - v2.0 (rev 3)
  12. # * make source file paths relative to script output directory
  13. #
  14. # 2013.4 -
  15. # 2013.3 -
  16. # 2013.2 - v1.0 (rev 2)
  17. # * no change
  18. #
  19. # 2013.1 - v1.0 (rev 1)
  20. # * initial version
  21. #
  22. ####################################################################################
  23. #
  24. # Modified version to better support revision control.
  25. # Can be called as write_project_tcl_git from the tcl console in Vivado.
  26. #
  27. # Differences:
  28. #
  29. # 1. The project directory is now relative to the scripts location.
  30. # Project directory was relative to the tcl console current directory.
  31. #
  32. # 2. When recreating a project, the generated files will be put in a "work" directory
  33. # under the project directory. If the work exists already, it will be rewritten.
  34. #
  35. # 3. After recreating a project, the tcl console will change directory to the project directory.
  36. #
  37. # 4. No mention to the creation time of the project script, so that it is not different
  38. # every time it is generated.
  39. #
  40. ####################################################################################
  41. package require Vivado 1.2014.1
  42. namespace eval ::custom {
  43. namespace export write_project_tcl_git
  44. }
  45. namespace eval ::custom {
  46. proc write_project_tcl_git {args} {
  47. # Summary:
  48. # Export Tcl script for re-creating the current project
  49. # Argument Usage:
  50. # [-paths_relative_to <arg> = Script output directory path]: Override the reference directory variable for source file relative paths
  51. # [-target_proj_dir <arg> = Current project directory path]: Directory where the project needs to be restored
  52. # [-force]: Overwrite existing tcl script file
  53. # [-all_properties]: Write all properties (default & non-default) for the project object(s)
  54. # [-no_copy_sources]: Do not import sources even if they were local in the original project
  55. # [-absolute_path]: Make all file paths absolute wrt the original project directory
  56. # [-dump_project_info]: Write object values
  57. # file: Name of the tcl script file to generate
  58. # Return Value:
  59. # true (0) if success, false (1) otherwise
  60. # Categories: xilinxtclstore, projutils
  61. # reset global variables
  62. variable a_global_vars
  63. reset_global_vars
  64. # process options
  65. for {set i 0} {$i < [llength $args]} {incr i} {
  66. set option [string trim [lindex $args $i]]
  67. switch -regexp -- $option {
  68. "-paths_relative_to" { incr i;set a_global_vars(s_relative_to) [file normalize [lindex $args $i]] }
  69. "-target_proj_dir" { incr i;set a_global_vars(s_target_proj_dir) [lindex $args $i] }
  70. "-force" { set a_global_vars(b_arg_force) 1 }
  71. "-all_properties" { set a_global_vars(b_arg_all_props) 1 }
  72. "-no_copy_sources" { set a_global_vars(b_arg_no_copy_srcs) 1 }
  73. "-absolute_path" { set a_global_vars(b_absolute_path) 1 }
  74. "-dump_project_info" { set a_global_vars(b_arg_dump_proj_info) 1 }
  75. default {
  76. # is incorrect switch specified?
  77. if { [regexp {^-} $option] } {
  78. send_msg_id Vivado-projutils-001 ERROR "Unknown option '$option', please type 'write_project_tcl -help' for usage info.\n"
  79. return
  80. }
  81. set a_global_vars(script_file) $option
  82. }
  83. }
  84. }
  85. # script file is a must
  86. if { [string equal $a_global_vars(script_file) ""] } {
  87. send_msg_id Vivado-projutils-002 ERROR "Missing value for option 'file', please type 'write_project_tcl -help' for usage info.\n"
  88. return
  89. }
  90. # should not be a directory
  91. if { [file isdirectory $a_global_vars(script_file)] } {
  92. send_msg_id Vivado-projutils-003 ERROR "The specified filename is a directory ($a_global_vars(script_file)), please type 'write_project_tcl -help' for usage info.\n"
  93. return
  94. }
  95. # check extension
  96. if { [file extension $a_global_vars(script_file)] != ".tcl" } {
  97. set a_global_vars(script_file) $a_global_vars(script_file).tcl
  98. }
  99. set a_global_vars(script_file) [file normalize $a_global_vars(script_file)]
  100. # error if file directory path does not exist
  101. set file_path [file dirname $a_global_vars(script_file)]
  102. if { ! [file exists $file_path] } {
  103. set script_filename [file tail $a_global_vars(script_file)]
  104. send_msg_id Vivado-projutils-013 ERROR "Directory in which file ${script_filename} is to be written does not exist \[$a_global_vars(script_file)\]\n"
  105. return
  106. }
  107. # recommend -force if file exists
  108. if { [file exists $a_global_vars(script_file)] && !$a_global_vars(b_arg_force) } {
  109. send_msg_id Vivado-projutils-004 ERROR "Tcl Script '$a_global_vars(script_file)' already exist. Use -force option to overwrite.\n"
  110. return
  111. }
  112. # set script file directory path
  113. set a_global_vars(s_path_to_script_dir) [file normalize $file_path]
  114. # now write
  115. if {[write_project_tcl_script]} {
  116. return
  117. }
  118. }
  119. }
  120. namespace eval ::custom {
  121. #
  122. # write_project_tcl tcl script argument & file handle vars
  123. #
  124. variable a_global_vars
  125. variable l_script_data [list]
  126. variable l_local_files [list]
  127. variable l_remote_files [list]
  128. variable b_project_board_set 0
  129. # set file types to filter
  130. variable l_filetype_filter [list]
  131. # Setup filter for non-user-settable filetypes
  132. set l_filetype_filter [list "ip" "ipx" "embedded design sources" "elf" "coefficient files" "configuration files" \
  133. "block diagrams" "block designs" "dsp design sources" "text" \
  134. "design checkpoint" "waveform configuration file"]
  135. # ip file extension types
  136. variable l_valid_ip_extns [list]
  137. set l_valid_ip_extns [list ".xci" ".bd" ".slx"]
  138. # set fileset types
  139. variable a_fileset_types
  140. set a_fileset_types {
  141. {{DesignSrcs} {srcset}}
  142. {{BlockSrcs} {blockset}}
  143. {{Constrs} {constrset}}
  144. {{SimulationSrcs} {simset}}
  145. }
  146. proc reset_global_vars {} {
  147. # Summary: initializes global namespace vars
  148. # This helper command is used to reset the variables used in the script.
  149. # Argument Usage:
  150. # none
  151. # Return Value:
  152. # None
  153. variable a_global_vars
  154. set a_global_vars(s_relative_to) {.}
  155. set a_global_vars(s_path_to_script_dir) ""
  156. set a_global_vars(s_target_proj_dir) ""
  157. set a_global_vars(b_arg_force) 0
  158. set a_global_vars(b_arg_no_copy_srcs) 0
  159. set a_global_vars(b_absolute_path) 0
  160. set a_global_vars(b_arg_all_props) 0
  161. set a_global_vars(b_arg_dump_proj_info) 0
  162. set a_global_vars(b_local_sources) 0
  163. set a_global_vars(curr_time) [clock format [clock seconds]]
  164. set a_global_vars(fh) 0
  165. set a_global_vars(dp_fh) 0
  166. set a_global_vars(def_val_fh) 0
  167. set a_global_vars(script_file) ""
  168. set l_script_data [list]
  169. set l_local_files [list]
  170. set l_remote_files [list]
  171. }
  172. proc write_project_tcl_script {} {
  173. # Summary: write project script
  174. # This helper command is used to script help.
  175. # Argument Usage:
  176. # none
  177. # Return Value:
  178. # true (0) if success, false (1) otherwise
  179. variable a_global_vars
  180. variable l_script_data
  181. variable l_remote_files
  182. variable l_local_files
  183. set l_script_data [list]
  184. set l_local_files [list]
  185. set l_remote_files [list]
  186. # get the project name
  187. set tcl_obj [current_project]
  188. set proj_name [file tail [get_property name $tcl_obj]]
  189. set proj_dir [get_property directory $tcl_obj]
  190. set part_name [get_property part $tcl_obj]
  191. # output file script handle
  192. set file $a_global_vars(script_file)
  193. if {[catch {open $file w} a_global_vars(fh)]} {
  194. send_msg_id Vivado-projutils-005 ERROR "failed to open file for write ($file)\n"
  195. return 1
  196. }
  197. # dump project in canonical form
  198. if { $a_global_vars(b_arg_dump_proj_info) } {
  199. set dump_file [file normalize [file join $a_global_vars(s_path_to_script_dir) ${proj_name}_dump.txt]]
  200. if {[catch {open $dump_file w} a_global_vars(dp_fh)]} {
  201. send_msg_id Vivado-projutils-006 ERROR "failed to open file for write ($dump_file)\n"
  202. return 1
  203. }
  204. # default value output file script handle
  205. set def_val_file [file normalize [file join $a_global_vars(s_path_to_script_dir) ${proj_name}_def_val.txt]]
  206. if {[catch {open $def_val_file w} a_global_vars(def_val_fh)]} {
  207. send_msg_id Vivado-projutils-007 ERROR "failed to open file for write ($file)\n"
  208. return 1
  209. }
  210. }
  211. # explicitly update the compile order for current source/simset, if following conditions are met
  212. if { {All} == [get_property source_mgmt_mode [current_project]] &&
  213. {0} == [get_property is_readonly [current_project]] &&
  214. {RTL} == [get_property design_mode [current_fileset]] } {
  215. # re-parse source fileset compile order for the current top
  216. if {[llength [get_files -compile_order sources -used_in synthesis]] > 1} {
  217. update_compile_order -fileset [current_fileset] -quiet
  218. }
  219. # re-parse simlulation fileset compile order for the current top
  220. if {[llength [get_files -compile_order sources -used_in simulation]] > 1} {
  221. update_compile_order -fileset [current_fileset -simset] -quiet
  222. }
  223. }
  224. # writer helpers
  225. wr_create_project $proj_dir $proj_name $part_name
  226. wr_project_properties $proj_dir $proj_name
  227. wr_filesets $proj_dir $proj_name
  228. wr_runs $proj_dir $proj_name
  229. wr_proj_info $proj_name
  230. # write header
  231. write_header $proj_dir $proj_name $file
  232. # write script data
  233. foreach line $l_script_data {
  234. puts $a_global_vars(fh) $line
  235. }
  236. close $a_global_vars(fh)
  237. if { $a_global_vars(b_arg_dump_proj_info) } {
  238. close $a_global_vars(def_val_fh)
  239. close $a_global_vars(dp_fh)
  240. }
  241. set script_filename [file tail $file]
  242. set out_dir [file dirname [file normalize $file]]
  243. send_msg_id Vivado-projutils-008 INFO "Tcl script '$script_filename' generated in output directory '$out_dir'\n\n"
  244. if { $a_global_vars(b_absolute_path) } {
  245. send_msg_id Vivado-projutils-016 INFO "Please note that the -absolute_path switch was specified, hence the project source files will be referenced using\n\
  246. absolute path only, in the generated script. As such, the generated script will only work in the same filesystem where those absolute paths are accessible."
  247. } else {
  248. if { "." != $a_global_vars(s_relative_to) } {
  249. send_msg_id Vivado-projutils-017 INFO "Please note that the -paths_relative_to switch was specified, hence the project source files will be referenced\n\
  250. wrt the path that was specified with this switch. The 'origin_dir' variable is set to this path in the generated script."
  251. } else {
  252. send_msg_id Vivado-projutils-015 INFO "Please note that by default, the file path for the project source files were set wrt the 'origin_dir' variable in the\n\
  253. generated script. When this script is executed from the output directory, these source files will be referenced wrt this 'origin_dir' path value.\n\
  254. In case this script was later physically moved to a different directory, the 'origin_dir' value MUST be set manually in the script with the path\n\
  255. relative to the new output directory to make sure that the source files are referenced correctly from the original project. You can also set the\n\
  256. 'origin_dir' automatically by setting the 'origin_dir_loc' variable in the tcl shell before sourcing this generated script. The 'origin_dir_loc'\n\
  257. variable should be set to the path relative to the new output directory. Alternatively, if you are sourcing the script from the Vivado command line,\n\
  258. then set the origin dir using '-tclargs --origin_dir <path>'. For example, 'vivado -mode tcl -source $script_filename -tclargs --origin_dir \"..\"\n"
  259. }
  260. }
  261. if { $a_global_vars(b_local_sources) } {
  262. print_local_file_msg "warning"
  263. } else {
  264. print_local_file_msg "info"
  265. }
  266. reset_global_vars
  267. return 0
  268. }
  269. proc wr_create_project { proj_dir name part_name } {
  270. # Summary: write create project command
  271. # This helper command is used to script help.
  272. # Argument Usage:
  273. # proj_dir: project directory path
  274. # name: project name
  275. # Return Value:
  276. # none
  277. variable a_global_vars
  278. variable l_script_data
  279. lappend l_script_data "# Set the reference directory for source file relative paths (by default the value is script directory path)"
  280. lappend l_script_data "set origin_dir \[file dirname \[info script\]\]"
  281. lappend l_script_data ""
  282. set var_name "origin_dir_loc"
  283. lappend l_script_data "# Use origin directory path location variable, if specified in the tcl shell"
  284. lappend l_script_data "if \{ \[info exists ::$var_name\] \} \{"
  285. lappend l_script_data " set origin_dir \$::$var_name"
  286. lappend l_script_data "\}"
  287. lappend l_script_data ""
  288. lappend l_script_data "variable script_file"
  289. lappend l_script_data "set script_file \"[file tail $a_global_vars(script_file)]\"\n"
  290. lappend l_script_data "# Help information for this script"
  291. lappend l_script_data "proc help \{\} \{"
  292. lappend l_script_data " variable script_file"
  293. lappend l_script_data " puts \"\\nDescription:\""
  294. lappend l_script_data " puts \"Recreate a Vivado project from this script. The created project will be\""
  295. lappend l_script_data " puts \"functionally equivalent to the original project for which this script was\""
  296. lappend l_script_data " puts \"generated. The script contains commands for creating a project, filesets,\""
  297. lappend l_script_data " puts \"runs, adding/importing sources and setting properties on various objects.\\n\""
  298. lappend l_script_data " puts \"Syntax:\""
  299. lappend l_script_data " puts \"\$script_file\""
  300. lappend l_script_data " puts \"\$script_file -tclargs \\\[--origin_dir <path>\\\]\""
  301. lappend l_script_data " puts \"\$script_file -tclargs \\\[--help\\\]\\n\""
  302. lappend l_script_data " puts \"Usage:\""
  303. lappend l_script_data " puts \"Name Description\""
  304. lappend l_script_data " puts \"-------------------------------------------------------------------------\""
  305. lappend l_script_data " puts \"\\\[--origin_dir <path>\\\] Determine source file paths wrt this path. Default\""
  306. lappend l_script_data " puts \" origin_dir path value is \\\".\\\", otherwise, the value\""
  307. lappend l_script_data " puts \" that was set with the \\\"-paths_relative_to\\\" switch\""
  308. lappend l_script_data " puts \" when this script was generated.\\n\""
  309. lappend l_script_data " puts \"\\\[--help\\\] Print help information for this script\""
  310. lappend l_script_data " puts \"-------------------------------------------------------------------------\\n\""
  311. lappend l_script_data " exit 0"
  312. lappend l_script_data "\}\n"
  313. lappend l_script_data "if \{ \$::argc > 0 \} \{"
  314. lappend l_script_data " for \{set i 0\} \{\$i < \[llength \$::argc\]\} \{incr i\} \{"
  315. lappend l_script_data " set option \[string trim \[lindex \$::argv \$i\]\]"
  316. lappend l_script_data " switch -regexp -- \$option \{"
  317. lappend l_script_data " \"--origin_dir\" \{ incr i; set origin_dir \[lindex \$::argv \$i\] \}"
  318. lappend l_script_data " \"--help\" \{ help \}"
  319. lappend l_script_data " default \{"
  320. lappend l_script_data " if \{ \[regexp \{^-\} \$option\] \} \{"
  321. lappend l_script_data " puts \"ERROR: Unknown option '\$option' specified, please type '\$script_file -tclargs --help' for usage info.\\n\""
  322. lappend l_script_data " return 1"
  323. lappend l_script_data " \}"
  324. lappend l_script_data " \}"
  325. lappend l_script_data " \}"
  326. lappend l_script_data " \}"
  327. lappend l_script_data "\}\n"
  328. lappend l_script_data "# Set the directory path for the original project from where this script was exported"
  329. if { $a_global_vars(b_absolute_path) } {
  330. lappend l_script_data "set orig_proj_dir \"$proj_dir\""
  331. } else {
  332. set rel_file_path "[get_relative_file_path_for_source $proj_dir [get_script_execution_dir]]"
  333. set path "\[file normalize \"\$origin_dir/$rel_file_path\"\]"
  334. lappend l_script_data "set orig_proj_dir \"$path\""
  335. }
  336. lappend l_script_data ""
  337. # create project
  338. lappend l_script_data "# Create project"
  339. set tcl_cmd ""
  340. # set target project directory path if specified. If not, create project dir in current dir.
  341. set target_dir $a_global_vars(s_target_proj_dir)
  342. if { {} == $target_dir } {
  343. set tcl_cmd "create_project $name \$origin_dir/work -part $part_name -quiet -force"
  344. } else {
  345. # is specified target proj dir == current dir?
  346. set cwd [file normalize [string map {\\ /} [pwd]]]
  347. set dir [file normalize [string map {\\ /} $target_dir]]
  348. if { [string equal $cwd $dir] } {
  349. set tcl_cmd "create_project $name -part $part_name"
  350. } else {
  351. set tcl_cmd "create_project $name \"$target_dir\" -part $part_name"
  352. }
  353. }
  354. if { [get_property managed_ip [current_project]] } {
  355. set tcl_cmd "$tcl_cmd -ip"
  356. }
  357. lappend l_script_data $tcl_cmd
  358. if { $a_global_vars(b_arg_dump_proj_info) } {
  359. puts $a_global_vars(dp_fh) "project_name=$name"
  360. }
  361. lappend l_script_data ""
  362. lappend l_script_data "# Set the directory path for the new project"
  363. lappend l_script_data "set proj_dir \[get_property directory \[current_project\]\]"
  364. lappend l_script_data ""
  365. lappend l_script_data "# Reconstruct message rules"
  366. set msg_control_rules [ debug::get_msg_control_rules -as_tcl ]
  367. if { [string length $msg_control_rules] > 0 } {
  368. lappend l_script_data "${msg_control_rules}"
  369. } else {
  370. lappend l_script_data "# None"
  371. }
  372. lappend l_script_data ""
  373. }
  374. proc wr_project_properties { proj_dir proj_name } {
  375. # Summary: write project properties
  376. # This helper command is used to script help.
  377. # Argument Usage:
  378. # proj_name: project name
  379. # Return Value:
  380. # None
  381. variable l_script_data
  382. variable b_project_board_set
  383. # write project properties
  384. set tcl_obj [current_project]
  385. set get_what "get_projects"
  386. lappend l_script_data "# Set project properties"
  387. lappend l_script_data "set obj \[$get_what $tcl_obj\]"
  388. # is project "board_part" set already?
  389. if { [string length [get_property "board_part" $tcl_obj]] > 0 } {
  390. set b_project_board_set 1
  391. }
  392. write_props $proj_dir $proj_name $get_what $tcl_obj "project"
  393. }
  394. proc wr_filesets { proj_dir proj_name } {
  395. # Summary: write fileset object properties
  396. # This helper command is used to script help.
  397. # Argument Usage:
  398. # proj_name: project name
  399. # Return Value:
  400. # None
  401. variable a_fileset_types
  402. # write fileset data
  403. foreach {fs_data} $a_fileset_types {
  404. set filesets [get_filesets -filter FILESET_TYPE==[lindex $fs_data 0]]
  405. write_specified_fileset $proj_dir $proj_name $filesets
  406. }
  407. }
  408. proc write_specified_fileset { proj_dir proj_name filesets } {
  409. # Summary: write fileset properties and sources
  410. # This helper command is used to script help.
  411. # Argument Usage:
  412. # proj_name: project name
  413. # filesets: list of filesets
  414. # Return Value:
  415. # None
  416. variable a_global_vars
  417. variable l_script_data
  418. variable a_fileset_types
  419. # write filesets
  420. set type "file"
  421. foreach tcl_obj $filesets {
  422. # Is this a IP block fileset for a proxy IP that is owned by another composite file?
  423. # If so, we don't want to write it out as an independent file. The parent will take care of it.
  424. if { [is_proxy_ip_fileset $tcl_obj] } {
  425. continue
  426. }
  427. set fs_type [get_property fileset_type [get_filesets $tcl_obj]]
  428. # is this a IP block fileset? if yes, do not create block fileset, but create for a pure HDL based fileset (no IP's)
  429. if { [is_ip_fileset $tcl_obj] } {
  430. # do not create block fileset
  431. } else {
  432. lappend l_script_data "# Create '$tcl_obj' fileset (if not found)"
  433. lappend l_script_data "if \{\[string equal \[get_filesets -quiet $tcl_obj\] \"\"\]\} \{"
  434. set fs_sw_type [get_fileset_type_switch $fs_type]
  435. lappend l_script_data " create_fileset $fs_sw_type $tcl_obj"
  436. lappend l_script_data "\}\n"
  437. }
  438. set get_what_fs "get_filesets"
  439. # set IP REPO PATHS (if any) for filesets of type "DesignSrcs" or "BlockSrcs"
  440. if { (({DesignSrcs} == $fs_type) || ({BlockSrcs} == $fs_type)) } {
  441. # If BlockSet contains only one IP, then this indicates the case of OOC1
  442. # This means that we should not write these properties, they are read-only
  443. set blockset_is_ooc1 false
  444. if { {BlockSrcs} == $fs_type } {
  445. set current_fs_files [get_files -of_objects [get_filesets $tcl_obj] -norecurse]
  446. if { [llength $current_fs_files] == 1 } {
  447. set only_file_in_fs [lindex $current_fs_files 0]
  448. set file_type [get_property FILE_TYPE $only_file_in_fs]
  449. set blockset_is_ooc1 [expr {$file_type == {IP}} ? true : false]
  450. }
  451. }
  452. if { $blockset_is_ooc1} {
  453. # We do not write properties for OOC1
  454. } elseif { ({RTL} == [get_property design_mode [get_filesets $tcl_obj]]) } {
  455. set repo_paths [get_ip_repo_paths $tcl_obj]
  456. if { [llength $repo_paths] > 0 } {
  457. lappend l_script_data "# Set IP repository paths"
  458. lappend l_script_data "set obj \[get_filesets $tcl_obj\]"
  459. set path_list [list]
  460. foreach path $repo_paths {
  461. if { $a_global_vars(b_absolute_path) } {
  462. lappend path_list $path
  463. } else {
  464. set rel_file_path "[get_relative_file_path_for_source $path [get_script_execution_dir]]"
  465. set path "\[file normalize \"\$origin_dir/$rel_file_path\"\]"
  466. lappend path_list $path
  467. }
  468. }
  469. set repo_path_str [join $path_list " "]
  470. lappend l_script_data "set_property \"ip_repo_paths\" \"${repo_path_str}\" \$obj"
  471. lappend l_script_data ""
  472. lappend l_script_data "# Rebuild user ip_repo's index before adding any source files"
  473. lappend l_script_data "update_ip_catalog -rebuild"
  474. lappend l_script_data ""
  475. }
  476. }
  477. }
  478. # is this a IP block fileset? if yes, then set the current srcset object (IP's will be added to current source fileset)
  479. if { [is_ip_fileset $tcl_obj] } {
  480. set srcset [current_fileset -srcset]
  481. lappend l_script_data "# Set '$srcset' fileset object"
  482. lappend l_script_data "set obj \[$get_what_fs $srcset\]"
  483. } else {
  484. lappend l_script_data "# Set '$tcl_obj' fileset object"
  485. lappend l_script_data "set obj \[$get_what_fs $tcl_obj\]"
  486. }
  487. if { {Constrs} == $fs_type } {
  488. lappend l_script_data ""
  489. write_constrs $proj_dir $proj_name $tcl_obj $type
  490. } else {
  491. write_files $proj_dir $proj_name $tcl_obj $type
  492. }
  493. # is this a IP block fileset? if yes, do not write block fileset properties (block fileset doesnot exist in new project)
  494. if { [is_ip_fileset $tcl_obj] } {
  495. # do not write ip fileset properties
  496. } else {
  497. lappend l_script_data "# Set '$tcl_obj' fileset properties"
  498. lappend l_script_data "set obj \[$get_what_fs $tcl_obj\]"
  499. write_props $proj_dir $proj_name $get_what_fs $tcl_obj "fileset"
  500. }
  501. }
  502. }
  503. proc wr_runs { proj_dir proj_name } {
  504. # Summary: write runs and properties
  505. # This helper command is used to script help.
  506. # Argument Usage:
  507. # proj_name: project name
  508. # Return Value:
  509. # None
  510. variable l_script_data
  511. # write runs (synthesis, Implementation)
  512. set runs [get_runs -filter {IS_SYNTHESIS == 1}]
  513. write_specified_run $proj_dir $proj_name $runs
  514. if { {RTL} == [get_property design_mode [current_fileset]] } {
  515. lappend l_script_data "# set the current synth run"
  516. lappend l_script_data "current_run -synthesis \[get_runs [current_run -synthesis]\]\n"
  517. }
  518. set runs [get_runs -filter {IS_IMPLEMENTATION == 1}]
  519. write_specified_run $proj_dir $proj_name $runs
  520. lappend l_script_data "# set the current impl run"
  521. lappend l_script_data "current_run -implementation \[get_runs [current_run -implementation]\]"
  522. lappend l_script_data ""
  523. lappend l_script_data "# Change current directory to project folder"
  524. lappend l_script_data "cd \[file dirname \[info script\]\]"
  525. }
  526. proc wr_proj_info { proj_name } {
  527. # Summary: write generated project status message
  528. # This helper command is used to script help.
  529. # Argument Usage:
  530. # proj_name: project name
  531. # Return Value:
  532. # None
  533. variable l_script_data
  534. lappend l_script_data "\nputs \"INFO: Project created:$proj_name\""
  535. }
  536. proc write_header { proj_dir proj_name file } {
  537. # Summary: write script header
  538. # This helper command is used to script help.
  539. # Argument Usage:
  540. # Return Value:
  541. # None
  542. variable a_global_vars
  543. variable l_local_files
  544. variable l_remote_files
  545. set version_txt [split [version] "\n"]
  546. set version [lindex $version_txt 0]
  547. set copyright [lindex $version_txt 2]
  548. set product [lindex [split $version " "] 0]
  549. set version_id [join [lrange $version 1 end] " "]
  550. set tcl_file [file tail $file]
  551. puts $a_global_vars(fh) "#\n# $product (TM) $version_id"
  552. puts $a_global_vars(fh) "#\n# $tcl_file: Tcl script for re-creating project '$proj_name'\n#"
  553. puts $a_global_vars(fh) "# $copyright"
  554. puts $a_global_vars(fh) "#\n# This file contains the $product Tcl commands for re-creating the project to the state*"
  555. puts $a_global_vars(fh) "# when this script was generated. In order to re-create the project, please source this"
  556. puts $a_global_vars(fh) "# file in the $product Tcl Shell."
  557. puts $a_global_vars(fh) "#"
  558. puts $a_global_vars(fh) "# * Note that the runs in the created project will be configured the same way as the"
  559. puts $a_global_vars(fh) "# original project, however they will not be launched automatically. To regenerate the"
  560. puts $a_global_vars(fh) "# run results please launch the synthesis/implementation runs as needed.\n#"
  561. puts $a_global_vars(fh) "#*****************************************************************************************"
  562. }
  563. proc print_local_file_msg { msg_type } {
  564. # Summary: print warning on finding local sources
  565. # This helper command is used to script help.
  566. # Argument Usage:
  567. # Return Value:
  568. # None
  569. puts ""
  570. if { [string equal $msg_type "warning"] } {
  571. send_msg_id Vivado-projutils-010 WARNING "Found source(s) that were local or imported into the project. If this project is being source controlled, then\n\
  572. please ensure that the project source(s) are also part of this source controlled data. The list of these local source(s) can be found in the generated script\n\
  573. under the header section."
  574. } else {
  575. send_msg_id Vivado-projutils-011 INFO "If this project is being source controlled, then please ensure that the project source(s) are also part of this source\n\
  576. controlled data. The list of these local source(s) can be found in the generated script under the header section."
  577. }
  578. puts ""
  579. }
  580. proc get_ip_repo_paths { tcl_obj } {
  581. # Summary:
  582. # Iterate over the fileset properties and get the ip_repo_paths (if set)
  583. # Argument Usage:
  584. # tcl_obj : fileset
  585. # Return Value:
  586. # List of repo paths
  587. set repo_path_list [list]
  588. foreach path [get_property ip_repo_paths [get_filesets $tcl_obj]] {
  589. lappend repo_path_list $path
  590. }
  591. return $repo_path_list
  592. }
  593. proc is_deprecated { prop } {
  594. # Summary: filter deprecated properties
  595. # Argument Usage:
  596. # Return Value:
  597. # true (1) if found, false (1) otherwise
  598. set prop [string toupper $prop]
  599. if { $prop == "BOARD" } {
  600. return 1
  601. }
  602. return 0
  603. }
  604. proc filter { prop val { file {} } } {
  605. # Summary: filter special properties
  606. # This helper command is used to script help.
  607. # Argument Usage:
  608. # Return Value:
  609. # true (1) if found, false (1) otherwise
  610. variable l_filetype_filter
  611. variable l_valid_ip_extns
  612. set prop [string toupper $prop]
  613. if { [expr { $prop == "BOARD" } || \
  614. { $prop == "IS_HD" } || \
  615. { $prop == "IS_PARTIAL_RECONFIG" } || \
  616. { $prop == "ADD_STEP" }]} {
  617. return 1
  618. }
  619. if { [string equal type "project"] } {
  620. if { [expr { $prop == "DIRECTORY" }] } {
  621. return 1
  622. }
  623. }
  624. # error reported if file_type is set
  625. # e.g ERROR: [Vivado 12-563] The file type 'IP' is not user settable.
  626. set val [string tolower $val]
  627. if { [string equal $prop "FILE_TYPE"] } {
  628. if { [lsearch $l_filetype_filter $val] != -1 } {
  629. return 1
  630. }
  631. }
  632. # filter readonly is_managed property for ip
  633. if { [string equal $prop "IS_MANAGED"] } {
  634. if { [lsearch -exact $l_valid_ip_extns [string tolower [file extension $file]]] >= 0 } {
  635. return 1
  636. }
  637. }
  638. # filter ip_repo_paths (ip_repo_paths is set before adding sources)
  639. if { [string equal -nocase $prop {ip_repo_paths}] } {
  640. return 1
  641. }
  642. return 0
  643. }
  644. proc is_local_to_project { file } {
  645. # Summary: check if file is local to the project directory structure
  646. # This helper command is used to script help.
  647. # Argument Usage:
  648. # Return Value:
  649. # true (1), if file is local to the project (inside project directory structure)
  650. # false (0), if file is outside the project directory structure
  651. set dir [get_property directory [current_project]]
  652. set proj_comps [split [string trim [file normalize [string map {\\ /} $dir]]] "/"]
  653. set file_comps [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  654. set is_local 1
  655. for {set i 1} {$i < [llength $proj_comps]} {incr i} {
  656. if { [lindex $proj_comps $i] != [lindex $file_comps $i] } {
  657. set is_local 0;break
  658. }
  659. }
  660. return $is_local
  661. }
  662. proc is_ip_readonly_prop { name } {
  663. # Summary: Return true if dealing with following IP properties that are not settable for an IP in read-only state
  664. # Argument Usage:
  665. # name: property name
  666. # Return Value:
  667. # true if success, false otherwise
  668. if { [regexp -nocase {synth_checkpoint_mode} $name] ||
  669. [regexp -nocase {is_locked} $name] ||
  670. [regexp -nocase {generate_synth_checkpoint} $name] } {
  671. return true
  672. }
  673. return false
  674. }
  675. proc write_properties { prop_info_list get_what tcl_obj } {
  676. # Summary: write object properties
  677. # This helper command is used to script help.
  678. # Argument Usage:
  679. # Return Value:
  680. # None
  681. variable a_global_vars
  682. variable l_script_data
  683. if {[llength $prop_info_list] > 0} {
  684. set b_add_closing_brace 0
  685. foreach x $prop_info_list {
  686. set elem [split $x "#"]
  687. set name [lindex $elem 0]
  688. set value [lindex $elem 1]
  689. if { [regexp "more options" $name] } {
  690. set cmd_str "set_property -name {$name} -value {$value} -objects"
  691. } elseif { ([is_ip_readonly_prop $name]) && ([string equal $get_what "get_files"]) } {
  692. set cmd_str "if \{ !\[get_property \"is_locked\" \$file_obj\] \} \{"
  693. lappend l_script_data "$cmd_str"
  694. set cmd_str " set_property \"$name\" \"$value\""
  695. set b_add_closing_brace 1
  696. } else {
  697. set cmd_str "set_property \"$name\" \"$value\""
  698. }
  699. if { [string equal $get_what "get_files"] } {
  700. lappend l_script_data "$cmd_str \$file_obj"
  701. if { $b_add_closing_brace } {
  702. lappend l_script_data "\}"
  703. set b_add_closing_brace 0
  704. }
  705. } else {
  706. # comment "is_readonly" project property
  707. if { [string equal $get_what "get_projects"] && [string equal "$name" "is_readonly"] } {
  708. if { ! $a_global_vars(b_arg_all_props) } {
  709. send_msg_id Vivado-projutils-012 INFO "The current project is in 'read_only' state. The generated script will create a writable project."
  710. }
  711. continue
  712. }
  713. lappend l_script_data "$cmd_str \$obj"
  714. }
  715. }
  716. }
  717. lappend l_script_data ""
  718. }
  719. proc write_props { proj_dir proj_name get_what tcl_obj type } {
  720. # Summary: write first class object properties
  721. # This helper command is used to script help.
  722. # Argument Usage:
  723. # Return Value:
  724. # none
  725. variable a_global_vars
  726. variable l_script_data
  727. variable b_project_board_set
  728. set obj_name [get_property name [$get_what $tcl_obj]]
  729. set read_only_props [rdi::get_attr_specs -class [get_property class $tcl_obj] -filter {is_readonly}]
  730. set prop_info_list [list]
  731. set properties [list_property [$get_what $tcl_obj]]
  732. foreach prop $properties {
  733. if { [is_deprecated $prop] } { continue }
  734. # skip read-only properties
  735. if { [lsearch $read_only_props $prop] != -1 } { continue }
  736. # skip ip_output_repo (contains absolute path)
  737. if {
  738. [string equal $type "project"] && [string equal -nocase $prop "ip_output_repo"]
  739. } { continue }
  740. set prop_type "unknown"
  741. if { [string equal $type "run"] } {
  742. if { [regexp "STEPS" $prop] } {
  743. # skip step properties
  744. } else {
  745. set attr_names [rdi::get_attr_specs -class [get_property class [get_runs $tcl_obj] ]]
  746. if { [lsearch $attr_names $prop] != -1 } {
  747. set prop_type [get_property type [lindex $attr_names [lsearch $attr_names $prop]]]
  748. }
  749. }
  750. } else {
  751. set attr_spec [rdi::get_attr_specs -quiet $prop -object [$get_what $tcl_obj]]
  752. if { {} == $attr_spec } {
  753. set prop_lower [string tolower $prop]
  754. set attr_spec [rdi::get_attr_specs -quiet $prop_lower -object [$get_what $tcl_obj]]
  755. }
  756. set prop_type [get_property type $attr_spec]
  757. }
  758. set def_val [list_property_value -default $prop $tcl_obj]
  759. set dump_prop_name [string tolower ${obj_name}_${type}_$prop]
  760. set cur_val [get_property $prop $tcl_obj]
  761. # filter special properties
  762. if { [filter $prop $cur_val] } { continue }
  763. # do not set "runs" or "project" part, if "board_part" is set
  764. if { ([string equal $type "project"] || [string equal $type "run"]) &&
  765. [string equal -nocase $prop "part"] &&
  766. $b_project_board_set } {
  767. continue
  768. }
  769. # do not set "fileset" target_part, if "board_part" is set
  770. if { [string equal $type "fileset"] &&
  771. [string equal -nocase $prop "target_part"] &&
  772. $b_project_board_set } {
  773. continue
  774. }
  775. # re-align values
  776. set cur_val [get_target_bool_val $def_val $cur_val]
  777. set prop_entry "[string tolower $prop]#[get_property $prop [$get_what $tcl_obj]]"
  778. # fix paths wrt the original project dir
  779. if {([string equal -nocase $prop "top_file"]) && ($cur_val != "") } {
  780. set file $cur_val
  781. set srcs_dir "${proj_name}.srcs"
  782. set file_dirs [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  783. set src_file [join [lrange $file_dirs [lsearch -exact $file_dirs "$srcs_dir"] end] "/"]
  784. if { [is_local_to_project $file] } {
  785. set proj_file_path "\$proj_dir/$src_file"
  786. } else {
  787. set proj_file_path "[get_relative_file_path_for_source $src_file [get_script_execution_dir]]"
  788. }
  789. set prop_entry "[string tolower $prop]#$proj_file_path"
  790. } elseif {([string equal -nocase $prop "target_constrs_file"] ||
  791. [string equal -nocase $prop "target_ucf"]) &&
  792. ($cur_val != "") } {
  793. set file $cur_val
  794. set fs_name $tcl_obj
  795. set path_dirs [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  796. set src_file [join [lrange $path_dirs [lsearch -exact $path_dirs "$fs_name"] end] "/"]
  797. set file_object [lindex [get_files -of_objects [get_filesets $fs_name] [list $file]] 0]
  798. set file_props [list_property $file_object]
  799. if { [lsearch $file_props "IMPORTED_FROM"] != -1 } {
  800. if { $a_global_vars(b_arg_no_copy_srcs) } {
  801. set proj_file_path "\$orig_proj_dir/${proj_name}.srcs/$src_file"
  802. } else {
  803. set proj_file_path "\$proj_dir/${proj_name}.srcs/$src_file"
  804. }
  805. } else {
  806. # is file new inside project?
  807. if { [is_local_to_project $file] } {
  808. # is file inside fileset dir?
  809. if { [regexp "^${fs_name}/" $src_file] } {
  810. set proj_file_path "\$orig_proj_dir/${proj_name}.srcs/$src_file"
  811. } else {
  812. set file_no_quotes [string trim $file "\""]
  813. set rel_file_path [get_relative_file_path_for_source $file_no_quotes [get_script_execution_dir]]
  814. set proj_file_path "\[file normalize \"\$origin_dir/$rel_file_path\"\]"
  815. #set proj_file_path "$file"
  816. }
  817. } else {
  818. if { $a_global_vars(b_absolute_path) } {
  819. set proj_file_path "$file"
  820. } else {
  821. set file_no_quotes [string trim $file "\""]
  822. set rel_file_path [get_relative_file_path_for_source $file_no_quotes [get_script_execution_dir]]
  823. set proj_file_path "\[file normalize \"\$origin_dir/$rel_file_path\"\]"
  824. }
  825. }
  826. }
  827. set prop_entry "[string tolower $prop]#$proj_file_path"
  828. }
  829. # re-align compiled_library_dir
  830. if { [string equal -nocase $prop "compxlib.compiled_library_dir"] ||
  831. [string equal -nocase $prop "compxlib.modelsim_compiled_library_dir"] ||
  832. [string equal -nocase $prop "compxlib.questa_compiled_library_dir"] ||
  833. [string equal -nocase $prop "compxlib.ies_compiled_library_dir"] ||
  834. [string equal -nocase $prop "compxlib.vcs_compiled_library_dir"] ||
  835. [string equal -nocase $prop "compxlib.riviera_compiled_library_dir"] ||
  836. [string equal -nocase $prop "compxlib.activehdl_compiled_library_dir"] } {
  837. set compile_lib_dir_path $cur_val
  838. set cache_dir "${proj_name}.cache"
  839. set path_dirs [split [string trim [file normalize [string map {\\ /} $cur_val]]] "/"]
  840. if {[lsearch -exact $path_dirs "$cache_dir"] > 0} {
  841. set dir_path [join [lrange $path_dirs [lsearch -exact $path_dirs "$cache_dir"] end] "/"]
  842. set compile_lib_dir_path "\$proj_dir/$dir_path"
  843. }
  844. set prop_entry "[string tolower $prop]#$compile_lib_dir_path"
  845. }
  846. # process run step tcl pre/post properties
  847. if { [string equal $type "run"] } {
  848. if { [regexp "STEPS" $prop] } {
  849. if { [regexp "TCL.PRE" $prop] || [regexp "TCL.POST" $prop] } {
  850. if { ($cur_val != "") } {
  851. set file $cur_val
  852. set srcs_dir "${proj_name}.srcs"
  853. set file_dirs [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  854. set src_file [join [lrange $file_dirs [lsearch -exact $file_dirs "$srcs_dir"] end] "/"]
  855. set tcl_file_path {}
  856. if { [is_local_to_project $file] } {
  857. set tcl_file_path "\$proj_dir/$src_file"
  858. } else {
  859. if { $a_global_vars(b_absolute_path) } {
  860. set tcl_file_path "$file"
  861. } else {
  862. set rel_file_path "[get_relative_file_path_for_source $src_file [get_script_execution_dir]]"
  863. set tcl_file_path "\[file normalize \"\$origin_dir/$rel_file_path\"\]"
  864. }
  865. }
  866. set prop_entry "[string tolower $prop]#$tcl_file_path"
  867. }
  868. }
  869. }
  870. }
  871. if { $a_global_vars(b_arg_all_props) } {
  872. lappend prop_info_list $prop_entry
  873. } else {
  874. if { $def_val != $cur_val } {
  875. lappend prop_info_list $prop_entry
  876. }
  877. }
  878. if { $a_global_vars(b_arg_dump_proj_info) } {
  879. if { ([string equal -nocase $prop "top_file"] ||
  880. [string equal -nocase $prop "target_constrs_file"] ||
  881. [string equal -nocase $prop "target_ucf"] ) && [string equal $type "fileset"] } {
  882. # fix path
  883. set file $cur_val
  884. set srcs_dir "${proj_name}.srcs"
  885. set file_dirs [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  886. set src_file [join [lrange $file_dirs [lsearch -exact $file_dirs "$srcs_dir"] end] "/"]
  887. set cur_val "\$PSRCDIR/$src_file"
  888. }
  889. puts $a_global_vars(def_val_fh) "$prop:($prop_type) DEFAULT_VALUE ($def_val)==CURRENT_VALUE ($cur_val)"
  890. puts $a_global_vars(dp_fh) "${dump_prop_name}=$cur_val"
  891. }
  892. }
  893. if { {fileset} == $type } {
  894. set fs_type [get_property fileset_type [get_filesets $tcl_obj]]
  895. if { {SimulationSrcs} == $fs_type } {
  896. if { ![get_property is_readonly [current_project]] } {
  897. add_simulator_props $get_what $tcl_obj prop_info_list
  898. }
  899. }
  900. }
  901. # write properties now
  902. write_properties $prop_info_list $get_what $tcl_obj
  903. }
  904. proc add_simulator_props { get_what tcl_obj prop_info_list_arg } {
  905. # Summary: write file and file properties
  906. # This helper command is used to script help.
  907. # Argument Usage:
  908. # Return Value:
  909. # none
  910. upvar $prop_info_list_arg prop_info_list
  911. set target_simulator [get_property target_simulator [current_project]]
  912. set simulators [get_simulators]
  913. foreach simulator [get_simulators] {
  914. if { $target_simulator == $simulator } { continue }
  915. set_property target_simulator $simulator [current_project]
  916. set prefix [string tolower [lindex [split $simulator {.}] 0]]
  917. write_simulator_props $prefix $get_what $tcl_obj prop_info_list
  918. }
  919. set_property target_simulator $target_simulator [current_project]
  920. }
  921. proc write_simulator_props { prefix get_what tcl_obj prop_info_list_arg } {
  922. # Summary: write non-default simulator properties
  923. # Argument Usage:
  924. # Return Value:
  925. # none
  926. upvar $prop_info_list_arg prop_info_list
  927. variable a_global_vars
  928. variable l_script_data
  929. set read_only_props [rdi::get_attr_specs -class [get_property class $tcl_obj] -filter {is_readonly}]
  930. foreach prop [list_property [$get_what $tcl_obj]] {
  931. if { [lsearch $read_only_props $prop] != -1 } { continue }
  932. if { [is_deprecated_property $prop] } { continue }
  933. set sim_prefix [string tolower [lindex [split $prop {.}] 0]]
  934. if { $prefix != $sim_prefix } { continue }
  935. set attr_spec [rdi::get_attr_specs -quiet $prop -object [$get_what $tcl_obj]]
  936. if { {} == $attr_spec } {
  937. set prop_lower [string tolower $prop]
  938. set attr_spec [rdi::get_attr_specs -quiet $prop_lower -object [$get_what $tcl_obj]]
  939. }
  940. set prop_type [get_property type $attr_spec]
  941. set def_val [list_property_value -default $prop $tcl_obj]
  942. set cur_val [get_property $prop $tcl_obj]
  943. set cur_val [get_target_bool_val $def_val $cur_val]
  944. set prop_entry "[string tolower $prop]#[get_property $prop [$get_what $tcl_obj]]"
  945. if { $def_val != $cur_val } {
  946. lappend prop_info_list $prop_entry
  947. }
  948. }
  949. }
  950. proc is_deprecated_property { property } {
  951. # Summary: filter old properties
  952. # Argument Usage:
  953. # Return Value:
  954. set property [string tolower $property]
  955. if { [string equal $property "runtime"] ||
  956. [string equal $property "unit_under_test"] ||
  957. [string equal $property "xelab.snapshot"] ||
  958. [string equal $property "xelab.debug_level"] ||
  959. [string equal $property "xelab.relax"] ||
  960. [string equal $property "xelab.mt_level"] ||
  961. [string equal $property "xelab.load_glbl"] ||
  962. [string equal $property "xelab.rangecheck"] ||
  963. [string equal $property "xelab.sdf_delay"] ||
  964. [string equal $property "xelab.unifast"] ||
  965. [string equal $property "xelab.nosort"] ||
  966. [string equal $property "xelab.more_options"] ||
  967. [string equal $property "xsim.view"] ||
  968. [string equal $property "xsim.wdb"] ||
  969. [string equal $property "xsim.saif"] ||
  970. [string equal $property "xsim.more_options"] ||
  971. [string equal $property "modelsim.custom_do"] ||
  972. [string equal $property "modelsim.custom_udo"] ||
  973. [string equal $property "modelsim.vhdl_syntax"] ||
  974. [string equal $property "modelsim.use_explicit_decl"] ||
  975. [string equal $property "modelsim.log_all_signals"] ||
  976. [string equal $property "modelsim.sdf_delay"] ||
  977. [string equal $property "modelsim.saif"] ||
  978. [string equal $property "modelsim.incremental"] ||
  979. [string equal $property "modelsim.unifast"] ||
  980. [string equal $property "modelsim.64bit"] ||
  981. [string equal $property "modelsim.vsim_more_options"] ||
  982. [string equal $property "modelsim.vlog_more_options"] ||
  983. [string equal $property "modelsim.vcom_more_options"] } {
  984. return true
  985. }
  986. return false
  987. }
  988. proc write_files { proj_dir proj_name tcl_obj type } {
  989. # Summary: write file and file properties
  990. # This helper command is used to script help.
  991. # Argument Usage:
  992. # Return Value:
  993. # none
  994. variable a_global_vars
  995. variable l_script_data
  996. set l_local_file_list [list]
  997. set l_remote_file_list [list]
  998. # return if empty fileset
  999. if {[llength [get_files -quiet -of_objects [get_filesets $tcl_obj]]] == 0 } {
  1000. lappend l_script_data "# Empty (no sources present)\n"
  1001. return
  1002. }
  1003. set fs_name [get_filesets $tcl_obj]
  1004. set import_coln [list]
  1005. set add_file_coln [list]
  1006. foreach file [get_files -norecurse -of_objects [get_filesets $tcl_obj]] {
  1007. if { [file extension $file] == ".xcix" } { continue }
  1008. set path_dirs [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  1009. set begin [lsearch -exact $path_dirs "$proj_name.srcs"]
  1010. set src_file [join [lrange $path_dirs $begin+1 end] "/"]
  1011. # fetch first object
  1012. set file_object [lindex [get_files -of_objects [get_filesets $fs_name] [list $file]] 0]
  1013. set file_props [list_property $file_object]
  1014. if { [lsearch $file_props "IMPORTED_FROM"] != -1 } {
  1015. # import files
  1016. set imported_path [get_property "imported_from" $file]
  1017. set rel_file_path [get_relative_file_path_for_source $file [get_script_execution_dir]]
  1018. set proj_file_path "\$origin_dir/$rel_file_path"
  1019. set file "\"[file normalize $proj_dir/${proj_name}.srcs/$src_file]\""
  1020. if { $a_global_vars(b_arg_no_copy_srcs) } {
  1021. # add to the local collection
  1022. lappend l_remote_file_list $file
  1023. if { $a_global_vars(b_absolute_path) } {
  1024. lappend add_file_coln "$file"
  1025. } else {
  1026. lappend add_file_coln "\"\[file normalize \"$proj_file_path\"\]\""
  1027. }
  1028. } else {
  1029. # add to the import collection
  1030. lappend l_local_file_list $file
  1031. if { $a_global_vars(b_absolute_path) } {
  1032. lappend import_coln "$file"
  1033. } else {
  1034. lappend import_coln "\"\[file normalize \"$proj_file_path\"\]\""
  1035. }
  1036. }
  1037. } else {
  1038. set file "\"$file\""
  1039. # is local? add to local project, add to collection and then import this collection by default unless -no_copy_sources is specified
  1040. if { [is_local_to_project $file] } {
  1041. if { $a_global_vars(b_arg_dump_proj_info) } {
  1042. set src_file "\$PSRCDIR/$src_file"
  1043. }
  1044. # add to the import collection
  1045. set file_no_quotes [string trim $file "\""]
  1046. set org_file_path "\$origin_dir/[get_relative_file_path_for_source $file_no_quotes [get_script_execution_dir]]"
  1047. lappend import_coln "\"\[file normalize \"$org_file_path\"\]\""
  1048. lappend l_local_file_list $file
  1049. } else {
  1050. lappend l_remote_file_list $file
  1051. }
  1052. # add file to collection
  1053. if { $a_global_vars(b_arg_no_copy_srcs) && (!$a_global_vars(b_absolute_path))} {
  1054. set file_no_quotes [string trim $file "\""]
  1055. set rel_file_path [get_relative_file_path_for_source $file_no_quotes [get_script_execution_dir]]
  1056. set file1 "\"\[file normalize \"\$origin_dir/$rel_file_path\"\]\""
  1057. lappend add_file_coln "$file1"
  1058. } else {
  1059. lappend add_file_coln "$file"
  1060. }
  1061. # set flag that local sources were found and print warning at the end
  1062. if { !$a_global_vars(b_local_sources) } {
  1063. set a_global_vars(b_local_sources) 1
  1064. }
  1065. }
  1066. }
  1067. if {[llength $add_file_coln]>0} {
  1068. lappend l_script_data "set files \[list \\"
  1069. foreach file $add_file_coln {
  1070. if { $a_global_vars(b_absolute_path) } {
  1071. lappend l_script_data " $file\\"
  1072. } else {
  1073. if { $a_global_vars(b_arg_no_copy_srcs) } {
  1074. lappend l_script_data " $file\\"
  1075. } else {
  1076. set file_no_quotes [string trim $file "\""]
  1077. set rel_file_path [get_relative_file_path_for_source $file_no_quotes [get_script_execution_dir]]
  1078. lappend l_script_data " \"\[file normalize \"\$origin_dir/$rel_file_path\"\]\"\\"
  1079. }
  1080. }
  1081. }
  1082. lappend l_script_data "\]"
  1083. lappend l_script_data "add_files -norecurse -fileset \$obj \$files"
  1084. lappend l_script_data ""
  1085. }
  1086. # now import local files if -no_copy_sources is not specified
  1087. if { ! $a_global_vars(b_arg_no_copy_srcs)} {
  1088. if { [llength $import_coln] > 0 } {
  1089. lappend l_script_data "# Import local files from the original project"
  1090. lappend l_script_data "set files \[list \\"
  1091. foreach ifile $import_coln {
  1092. lappend l_script_data " $ifile\\"
  1093. }
  1094. lappend l_script_data "\]"
  1095. # is this a IP block fileset? if yes, import files into current source fileset
  1096. if { [is_ip_fileset $tcl_obj] } {
  1097. lappend l_script_data "set imported_files \[import_files -fileset [current_fileset -srcset] \$files\]"
  1098. } else {
  1099. lappend l_script_data "set imported_files \[import_files -fileset $tcl_obj \$files\]"
  1100. }
  1101. lappend l_script_data ""
  1102. }
  1103. }
  1104. # write fileset file properties for remote files (added sources)
  1105. write_fileset_file_properties $tcl_obj $fs_name $proj_dir $l_remote_file_list "remote"
  1106. # write fileset file properties for local files (imported sources)
  1107. write_fileset_file_properties $tcl_obj $fs_name $proj_dir $l_local_file_list "local"
  1108. }
  1109. proc write_constrs { proj_dir proj_name tcl_obj type } {
  1110. # Summary: write constrs fileset files and properties
  1111. # Argument Usage:
  1112. # Return Value:
  1113. # none
  1114. variable a_global_vars
  1115. variable l_script_data
  1116. set fs_name [get_filesets $tcl_obj]
  1117. # return if empty fileset
  1118. if {[llength [get_files -quiet -of_objects [get_filesets $tcl_obj]]] == 0 } {
  1119. lappend l_script_data "# Empty (no sources present)\n"
  1120. return
  1121. }
  1122. foreach file [get_files -norecurse -of_objects [get_filesets $tcl_obj]] {
  1123. lappend l_script_data "# Add/Import constrs file and set constrs file properties"
  1124. set constrs_file {}
  1125. set file_category {}
  1126. set path_dirs [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  1127. set begin [lsearch -exact $path_dirs "$proj_name.srcs"]
  1128. set src_file [join [lrange $path_dirs $begin+1 end] "/"]
  1129. set file_object [lindex [get_files -of_objects [get_filesets $fs_name] [list $file]] 0]
  1130. set file_props [list_property $file_object]
  1131. # constrs sources imported?
  1132. if { [lsearch $file_props "IMPORTED_FROM"] != -1 } {
  1133. set imported_path [get_property "imported_from" $file]
  1134. set rel_file_path [get_relative_file_path_for_source $file [get_script_execution_dir]]
  1135. set proj_file_path "\$origin_dir/$rel_file_path"
  1136. set file "\"[file normalize $proj_dir/${proj_name}.srcs/$src_file]\""
  1137. # donot copy imported constrs in new project? set it as remote file in new project.
  1138. if { $a_global_vars(b_arg_no_copy_srcs) } {
  1139. set constrs_file $file
  1140. set file_category "remote"
  1141. if { $a_global_vars(b_absolute_path) } {
  1142. add_constrs_file "$file"
  1143. } else {
  1144. set str "\"\[file normalize \"$proj_file_path\"\]\""
  1145. add_constrs_file $str
  1146. }
  1147. } else {
  1148. # copy imported constrs in new project. Set it as local file in new project.
  1149. set constrs_file $file
  1150. set file_category "local"
  1151. if { $a_global_vars(b_absolute_path) } {
  1152. import_constrs_file $tcl_obj "$file"
  1153. } else {
  1154. set str "\"\[file normalize \"$proj_file_path\"\]\""
  1155. import_constrs_file $tcl_obj $str
  1156. }
  1157. }
  1158. } else {
  1159. # constrs sources were added, so check if these are local or added from remote location
  1160. set file "\"$file\""
  1161. set constrs_file $file
  1162. # is added constrs local to the project? import it in the new project and set it as local in the new project
  1163. if { [is_local_to_project $file] } {
  1164. # file is added from within project, so set it as local in the new project
  1165. set file_category "local"
  1166. if { $a_global_vars(b_arg_dump_proj_info) } {
  1167. set src_file "\$PSRCDIR/$src_file"
  1168. }
  1169. set file_no_quotes [string trim $file "\""]
  1170. set org_file_path "\$origin_dir/[get_relative_file_path_for_source $file_no_quotes [get_script_execution_dir]]"
  1171. set str "\"\[file normalize \"$org_file_path\"\]\""
  1172. if { $a_global_vars(b_arg_no_copy_srcs)} {
  1173. add_constrs_file "$str"
  1174. } else {
  1175. import_constrs_file $tcl_obj $str
  1176. }
  1177. } else {
  1178. # file is added from remote location, so set it as remote in the new project
  1179. set file_category "remote"
  1180. # find relative file path of the added constrs if no_copy in the new project
  1181. if { $a_global_vars(b_arg_no_copy_srcs) && (!$a_global_vars(b_absolute_path))} {
  1182. set file_no_quotes [string trim $file "\""]
  1183. set rel_file_path [get_relative_file_path_for_source $file_no_quotes [get_script_execution_dir]]
  1184. set file_1 "\"\[file normalize \"\$origin_dir/$rel_file_path\"\]\""
  1185. add_constrs_file "$file_1"
  1186. } else {
  1187. add_constrs_file "$file"
  1188. }
  1189. }
  1190. # set flag that local sources were found and print warning at the end
  1191. if { !$a_global_vars(b_local_sources) } {
  1192. set a_global_vars(b_local_sources) 1
  1193. }
  1194. }
  1195. write_constrs_fileset_file_properties $tcl_obj $fs_name $proj_dir $constrs_file $file_category
  1196. }
  1197. }
  1198. proc add_constrs_file { file_str } {
  1199. # Summary: add constrs file
  1200. # This helper command is used to script help.
  1201. # Argument Usage:
  1202. # Return Value:
  1203. # none
  1204. variable a_global_vars
  1205. variable l_script_data
  1206. if { $a_global_vars(b_absolute_path) } {
  1207. lappend l_script_data "set file $file_str"
  1208. } else {
  1209. if { $a_global_vars(b_arg_no_copy_srcs) } {
  1210. lappend l_script_data "set file $file_str"
  1211. } else {
  1212. set file_no_quotes [string trim $file_str "\""]
  1213. set rel_file_path [get_relative_file_path_for_source $file_no_quotes [get_script_execution_dir]]
  1214. lappend l_script_data "set file \"\[file normalize \"\$origin_dir/$rel_file_path\"\]\""
  1215. }
  1216. }
  1217. lappend l_script_data "set file_added \[add_files -norecurse -fileset \$obj \$file\]"
  1218. }
  1219. proc import_constrs_file { tcl_obj file_str } {
  1220. # Summary: import constrs file
  1221. # This helper command is used to script help.
  1222. # Argument Usage:
  1223. # Return Value:
  1224. # none
  1225. variable a_global_vars
  1226. variable l_script_data
  1227. # now import local files if -no_copy_sources is not specified
  1228. if { ! $a_global_vars(b_arg_no_copy_srcs)} {
  1229. lappend l_script_data "set file $file_str"
  1230. lappend l_script_data "set file_imported \[import_files -fileset $tcl_obj \$file\]"
  1231. }
  1232. }
  1233. proc write_constrs_fileset_file_properties { tcl_obj fs_name proj_dir file file_category } {
  1234. # Summary: write constrs fileset file properties
  1235. # This helper command is used to script help.
  1236. # Argument Usage:
  1237. # Return Value:
  1238. # none
  1239. variable a_global_vars
  1240. variable l_script_data
  1241. variable l_local_files
  1242. variable l_remote_files
  1243. set file_prop_count 0
  1244. # collect local/remote files for the header section
  1245. if { [string equal $file_category "local"] } {
  1246. lappend l_local_files $file
  1247. } elseif { [string equal $file_category "remote"] } {
  1248. lappend l_remote_files $file
  1249. }
  1250. set file [string trim $file "\""]
  1251. # fix file path for local files
  1252. if { [string equal $file_category "local"] } {
  1253. set path_dirs [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  1254. set src_file [join [lrange $path_dirs end-1 end] "/"]
  1255. set src_file [string trimleft $src_file "/"]
  1256. set src_file [string trimleft $src_file "\\"]
  1257. set file $src_file
  1258. }
  1259. set file_object ""
  1260. if { [string equal $file_category "local"] } {
  1261. set file_object [lindex [get_files -of_objects [get_filesets $fs_name] [list "*$file"]] 0]
  1262. } elseif { [string equal $file_category "remote"] } {
  1263. set file_object [lindex [get_files -of_objects [get_filesets $fs_name] [list $file]] 0]
  1264. }
  1265. # get the constrs file properties
  1266. set file_props [list_property $file_object]
  1267. set prop_info_list [list]
  1268. set prop_count 0
  1269. foreach file_prop $file_props {
  1270. set is_readonly [get_property is_readonly [rdi::get_attr_specs $file_prop -object $file_object]]
  1271. if { [string equal $is_readonly "1"] } {
  1272. continue
  1273. }
  1274. set prop_type [get_property type [rdi::get_attr_specs $file_prop -object $file_object]]
  1275. set def_val [list_property_value -default $file_prop $file_object]
  1276. set cur_val [get_property $file_prop $file_object]
  1277. # filter special properties
  1278. if { [filter $file_prop $cur_val $file] } { continue }
  1279. # re-align values
  1280. set cur_val [get_target_bool_val $def_val $cur_val]
  1281. set dump_prop_name [string tolower ${fs_name}_file_${file_prop}]
  1282. set prop_entry ""
  1283. if { [string equal $file_category "local"] } {
  1284. set prop_entry "[string tolower $file_prop]#[get_property $file_prop $file_object]"
  1285. } elseif { [string equal $file_category "remote"] } {
  1286. set prop_value_entry [get_property $file_prop $file_object]
  1287. set prop_entry "[string tolower $file_prop]#$prop_value_entry"
  1288. }
  1289. # include all properties?
  1290. if { $a_global_vars(b_arg_all_props) } {
  1291. lappend prop_info_list $prop_entry
  1292. incr prop_count
  1293. } else {
  1294. # include only non-default (default behavior)
  1295. if { $def_val != $cur_val } {
  1296. lappend prop_info_list $prop_entry
  1297. incr prop_count
  1298. }
  1299. }
  1300. if { $a_global_vars(b_arg_dump_proj_info) } {
  1301. puts $a_global_vars(def_val_fh) "[file tail $file]=$file_prop ($prop_type) :DEFAULT_VALUE ($def_val)==CURRENT_VALUE ($cur_val)"
  1302. puts $a_global_vars(dp_fh) "$dump_prop_name=$cur_val"
  1303. }
  1304. }
  1305. # write properties now
  1306. if { $prop_count>0 } {
  1307. if { {remote} == $file_category } {
  1308. if { $a_global_vars(b_absolute_path) } {
  1309. lappend l_script_data "set file \"$file\""
  1310. } else {
  1311. lappend l_script_data "set file \"\$origin_dir/[get_relative_file_path_for_source $file [get_script_execution_dir]]\""
  1312. lappend l_script_data "set file \[file normalize \$file\]"
  1313. }
  1314. } else {
  1315. lappend l_script_data "set file \"$file\""
  1316. }
  1317. lappend l_script_data "set file_obj \[get_files -of_objects \[get_filesets $tcl_obj\] \[list \"*\$file\"\]\]"
  1318. set get_what "get_files"
  1319. write_properties $prop_info_list $get_what $tcl_obj
  1320. incr file_prop_count
  1321. }
  1322. if { $file_prop_count == 0 } {
  1323. lappend l_script_data "# None"
  1324. }
  1325. }
  1326. proc write_specified_run { proj_dir proj_name runs } {
  1327. # Summary: write the specified run information
  1328. # This helper command is used to script help.
  1329. # Argument Usage:
  1330. # Return Value:
  1331. # none
  1332. variable a_global_vars
  1333. variable l_script_data
  1334. set get_what "get_runs"
  1335. foreach tcl_obj $runs {
  1336. # is block fileset based run that contains IP? donot create OOC run
  1337. if { [is_ip_run $tcl_obj] } {
  1338. continue
  1339. }
  1340. # fetch run attributes
  1341. set part [get_property part [$get_what $tcl_obj]]
  1342. set parent_run [get_property parent [$get_what $tcl_obj]]
  1343. set src_set [get_property srcset [$get_what $tcl_obj]]
  1344. set constrs_set [get_property constrset [$get_what $tcl_obj]]
  1345. set strategy [get_property strategy [$get_what $tcl_obj]]
  1346. set parent_run_str ""
  1347. if { $parent_run != "" } {
  1348. set parent_run_str " -parent_run $parent_run"
  1349. }
  1350. set def_flow_type_val [list_property_value -default flow [$get_what $tcl_obj]]
  1351. set cur_flow_type_val [get_property flow [$get_what $tcl_obj]]
  1352. set def_strat_type_val [list_property_value -default strategy [$get_what $tcl_obj]]
  1353. set cur_strat_type_val [get_property strategy [$get_what $tcl_obj]]
  1354. lappend l_script_data "# Create '$tcl_obj' run (if not found)"
  1355. lappend l_script_data "if \{\[string equal \[get_runs -quiet $tcl_obj\] \"\"\]\} \{"
  1356. set cmd_str " create_run -name $tcl_obj -part $part -flow {$cur_flow_type_val} -strategy \"$cur_strat_type_val\""
  1357. lappend l_script_data "$cmd_str -constrset $constrs_set$parent_run_str"
  1358. lappend l_script_data "\} else \{"
  1359. lappend l_script_data " set_property strategy \"$cur_strat_type_val\" \[get_runs $tcl_obj\]"
  1360. lappend l_script_data " set_property flow \"$cur_flow_type_val\" \[get_runs $tcl_obj\]"
  1361. lappend l_script_data "\}"
  1362. lappend l_script_data "set obj \[$get_what $tcl_obj\]"
  1363. write_props $proj_dir $proj_name $get_what $tcl_obj "run"
  1364. }
  1365. }
  1366. proc get_fileset_type_switch { fileset_type } {
  1367. # Summary: Return the fileset type switch for a given fileset
  1368. # Argument Usage:
  1369. # Return Value:
  1370. # Fileset type switch name
  1371. variable a_fileset_types
  1372. set fs_switch ""
  1373. foreach {fs_data} $a_fileset_types {
  1374. set fs_type [lindex $fs_data 0]
  1375. if { [string equal -nocase $fileset_type $fs_type] } {
  1376. set fs_switch [lindex $fs_data 1]
  1377. set fs_switch "-$fs_switch"
  1378. break
  1379. }
  1380. }
  1381. return $fs_switch
  1382. }
  1383. proc get_target_bool_val { def_val cur_val } {
  1384. # Summary: Resolve current boolean property value wrt its default value
  1385. # Argument Usage:
  1386. # Return Value:
  1387. # Resolved boolean value
  1388. set target_val $cur_val
  1389. if { [string equal $def_val "false"] && [string equal $cur_val "0"] } { set target_val "false" } \
  1390. elseif { [string equal $def_val "true"] && [string equal $cur_val "1"] } { set target_val "true" } \
  1391. elseif { [string equal $def_val "false"] && [string equal $cur_val "1"] } { set target_val "true" } \
  1392. elseif { [string equal $def_val "true"] && [string equal $cur_val "0"] } { set target_val "false" } \
  1393. elseif { [string equal $def_val "{}"] && [string equal $cur_val ""] } { set target_val "{}" }
  1394. return $target_val
  1395. }
  1396. proc write_fileset_file_properties { tcl_obj fs_name proj_dir l_file_list file_category } {
  1397. # Summary:
  1398. # Write fileset file properties for local and remote files
  1399. # Argument Usage:
  1400. # tcl_obj: object to inspect
  1401. # fs_name: fileset name
  1402. # l_file_list: list of files (local or remote)
  1403. # file_category: file catwgory (local or remote)
  1404. # Return Value:
  1405. # none
  1406. variable a_global_vars
  1407. variable l_script_data
  1408. variable l_local_files
  1409. variable l_remote_files
  1410. # is this a IP block fileset? if yes, set current source fileset
  1411. if { [is_ip_fileset $tcl_obj] } {
  1412. lappend l_script_data "# Set '[current_fileset -srcset]' fileset file properties for $file_category files"
  1413. } else {
  1414. lappend l_script_data "# Set '$tcl_obj' fileset file properties for $file_category files"
  1415. }
  1416. set file_prop_count 0
  1417. # collect local/remote files
  1418. foreach file $l_file_list {
  1419. if { [string equal $file_category "local"] } {
  1420. lappend l_local_files $file
  1421. } elseif { [string equal $file_category "remote"] } {
  1422. lappend l_remote_files $file
  1423. } else {}
  1424. }
  1425. foreach file $l_file_list {
  1426. set file [string trim $file "\""]
  1427. # fix file path for local files
  1428. if { [string equal $file_category "local"] } {
  1429. set path_dirs [split [string trim [file normalize [string map {\\ /} $file]]] "/"]
  1430. set src_file [join [lrange $path_dirs end-1 end] "/"]
  1431. set src_file [string trimleft $src_file "/"]
  1432. set src_file [string trimleft $src_file "\\"]
  1433. set file $src_file
  1434. }
  1435. set file_object ""
  1436. if { [string equal $file_category "local"] } {
  1437. set file_object [lindex [get_files -of_objects [get_filesets $fs_name] [list "*$file"]] 0]
  1438. } elseif { [string equal $file_category "remote"] } {
  1439. set file_object [lindex [get_files -of_objects [get_filesets $fs_name] [list $file]] 0]
  1440. }
  1441. set file_props [list_property $file_object]
  1442. set prop_info_list [list]
  1443. set prop_count 0
  1444. foreach file_prop $file_props {
  1445. set is_readonly [get_property is_readonly [rdi::get_attr_specs $file_prop -object $file_object]]
  1446. if { [string equal $is_readonly "1"] } {
  1447. continue
  1448. }
  1449. set prop_type [get_property type [rdi::get_attr_specs $file_prop -object $file_object]]
  1450. set def_val [list_property_value -default $file_prop $file_object]
  1451. set cur_val [get_property $file_prop $file_object]
  1452. # filter special properties
  1453. if { [filter $file_prop $cur_val $file] } { continue }
  1454. # re-align values
  1455. set cur_val [get_target_bool_val $def_val $cur_val]
  1456. set dump_prop_name [string tolower ${fs_name}_file_${file_prop}]
  1457. set prop_entry ""
  1458. if { [string equal $file_category "local"] } {
  1459. set prop_entry "[string tolower $file_prop]#[get_property $file_prop $file_object]"
  1460. } elseif { [string equal $file_category "remote"] } {
  1461. set prop_value_entry [get_property $file_prop $file_object]
  1462. set prop_entry "[string tolower $file_prop]#$prop_value_entry"
  1463. } else {}
  1464. if { $a_global_vars(b_arg_all_props) } {
  1465. lappend prop_info_list $prop_entry
  1466. incr prop_count
  1467. } else {
  1468. if { $def_val != $cur_val } {
  1469. lappend prop_info_list $prop_entry
  1470. incr prop_count
  1471. }
  1472. }
  1473. if { $a_global_vars(b_arg_dump_proj_info) } {
  1474. puts $a_global_vars(def_val_fh) "[file tail $file]=$file_prop ($prop_type) :DEFAULT_VALUE ($def_val)==CURRENT_VALUE ($cur_val)"
  1475. puts $a_global_vars(dp_fh) "$dump_prop_name=$cur_val"
  1476. }
  1477. }
  1478. # write properties now
  1479. if { $prop_count>0 } {
  1480. if { {remote} == $file_category } {
  1481. if { $a_global_vars(b_absolute_path) } {
  1482. lappend l_script_data "set file \"$file\""
  1483. } else {
  1484. lappend l_script_data "set file \"\$origin_dir/[get_relative_file_path_for_source $file [get_script_execution_dir]]\""
  1485. lappend l_script_data "set file \[file normalize \$file\]"
  1486. }
  1487. } else {
  1488. lappend l_script_data "set file \"$file\""
  1489. }
  1490. # is this a IP block fileset? if yes, get files from current source fileset
  1491. if { [is_ip_fileset $tcl_obj] } {
  1492. lappend l_script_data "set file_obj \[get_files -of_objects \[get_filesets [current_fileset -srcset]\] \[list \"*\$file\"\]\]"
  1493. } else {
  1494. lappend l_script_data "set file_obj \[get_files -of_objects \[get_filesets $tcl_obj\] \[list \"*\$file\"\]\]"
  1495. }
  1496. set get_what "get_files"
  1497. write_properties $prop_info_list $get_what $tcl_obj
  1498. incr file_prop_count
  1499. }
  1500. }
  1501. if { $file_prop_count == 0 } {
  1502. lappend l_script_data "# None"
  1503. }
  1504. lappend l_script_data ""
  1505. }
  1506. proc get_script_execution_dir { } {
  1507. # Summary: Return script directory path from where the script will be executed
  1508. # Argument Usage:
  1509. # none
  1510. # Return Value:
  1511. # Path to the script direc
  1512. variable a_global_vars
  1513. # default: return script directory path
  1514. set scr_exe_dir $a_global_vars(s_path_to_script_dir)
  1515. # is -path_to_relative specified and the path exists? return this dir
  1516. set rel_to_dir $a_global_vars(s_relative_to)
  1517. if { ("." != $rel_to_dir) } {
  1518. set rel_to_dir [file normalize $rel_to_dir]
  1519. if { [file exists $rel_to_dir] } {
  1520. set scr_exe_dir $rel_to_dir
  1521. }
  1522. }
  1523. return $scr_exe_dir
  1524. }
  1525. # TODO: This is the same as xcs_get_relative_file_path for simulators, see common/utils.tcl
  1526. # Remember to add the 'source .../common/utils.tcl' in the write_project_tcl proc to load the common file
  1527. proc get_relative_file_path_for_source { file_path_to_convert relative_to } {
  1528. # Summary: Get the relative path wrt to path specified
  1529. # Argument Usage:
  1530. # file_path_to_convert: input file to make relative to specfied path
  1531. # Return Value:
  1532. # Relative path wrt the path specified
  1533. variable a_xport_sim_vars
  1534. # make sure we are dealing with a valid relative_to directory. If regular file or is not a directory, get directory
  1535. if { [file isfile $relative_to] || ![file isdirectory $relative_to] } {
  1536. set relative_to [file dirname $relative_to]
  1537. }
  1538. set cwd [file normalize [pwd]]
  1539. if { [file pathtype $file_path_to_convert] eq "relative" } {
  1540. # is relative_to path same as cwd?, just return this path, no further processing required
  1541. if { [string equal $relative_to $cwd] } {
  1542. return $file_path_to_convert
  1543. }
  1544. # the specified path is "relative" but something else, so make it absolute wrt current working dir
  1545. set file_path_to_convert [file join $cwd $file_path_to_convert]
  1546. }
  1547. # is relative_to "relative"? convert to absolute as well wrt cwd
  1548. if { [file pathtype $relative_to] eq "relative" } {
  1549. set relative_to [file join $cwd $relative_to]
  1550. }
  1551. # normalize
  1552. set file_path_to_convert [file normalize $file_path_to_convert]
  1553. set relative_to [file normalize $relative_to]
  1554. set file_path $file_path_to_convert
  1555. set file_comps [file split $file_path]
  1556. set relative_to_comps [file split $relative_to]
  1557. set found_match false
  1558. set index 0
  1559. set fc_comps_len [llength $file_comps]
  1560. set rt_comps_len [llength $relative_to_comps]
  1561. # compare each dir element of file_to_convert and relative_to, set the flag and
  1562. # get the final index till these sub-dirs matched. Break if limit reaches.
  1563. while { [lindex $file_comps $index] == [lindex $relative_to_comps $index] } {
  1564. if { !$found_match } { set found_match true }
  1565. incr index
  1566. if { ($index == $fc_comps_len) || ($index == $rt_comps_len) } {
  1567. break;
  1568. }
  1569. }
  1570. # any common dirs found? convert path to relative
  1571. if { $found_match } {
  1572. set parent_dir_path ""
  1573. set rel_index $index
  1574. # keep traversing the relative_to dirs and build "../" levels
  1575. while { [lindex $relative_to_comps $rel_index] != "" } {
  1576. set parent_dir_path "../$parent_dir_path"
  1577. incr rel_index
  1578. }
  1579. #
  1580. # at this point we have parent_dir_path setup with exact number of sub-dirs to go up
  1581. #
  1582. # now build up part of path which is relative to matched part
  1583. set rel_path ""
  1584. set rel_index $index
  1585. while { [lindex $file_comps $rel_index] != "" } {
  1586. set comps [lindex $file_comps $rel_index]
  1587. if { $rel_path == "" } {
  1588. # first dir
  1589. set rel_path $comps
  1590. } else {
  1591. # append remaining dirs
  1592. set rel_path "${rel_path}/$comps"
  1593. }
  1594. incr rel_index
  1595. }
  1596. # prepend parent dirs, this is the complete resolved path now
  1597. set resolved_path "${parent_dir_path}${rel_path}"
  1598. return $resolved_path
  1599. }
  1600. # no common dirs found, just return the normalized path
  1601. return $file_path
  1602. }
  1603. proc is_ip_fileset { fileset } {
  1604. # Summary: Find IP's if any from the specified fileset and return true if 'generate_synth_checkpoint' is set to 1
  1605. # Argument Usage:
  1606. # fileset: fileset name
  1607. # Return Value:
  1608. # true (1) if success, false (0) otherwise
  1609. # make sure fileset is block fileset type
  1610. if { {BlockSrcs} != [get_property fileset_type [get_filesets $fileset]] } {
  1611. return false
  1612. }
  1613. set ip_filter "FILE_TYPE == \"IP\" || FILE_TYPE==\"Block Designs\""
  1614. set ips [get_files -all -quiet -of_objects [get_filesets $fileset] -filter $ip_filter]
  1615. set b_found false
  1616. foreach ip $ips {
  1617. if { [get_property generate_synth_checkpoint [lindex [get_files -all $ip] 0]] } {
  1618. set b_found true
  1619. break
  1620. }
  1621. }
  1622. if { $b_found } {
  1623. return true
  1624. }
  1625. return false
  1626. }
  1627. proc is_proxy_ip_fileset { fileset } {
  1628. # Summary: Determine if the fileset is an OOC run for a proxy IP that has a parent composite
  1629. # Argument Usage:
  1630. # fileset: fileset name
  1631. # Return Value:
  1632. # true (1) if the fileset contains an IP at its root with a parent composite, false (0) otherwise
  1633. # make sure fileset is block fileset type
  1634. if { {BlockSrcs} != [get_property fileset_type [get_filesets $fileset]] } {
  1635. return false
  1636. }
  1637. set ip_with_parent_filter "FILE_TYPE == IP && PARENT_COMPOSITE_FILE != \"\""
  1638. if {[llength [get_files -norecurse -quiet -of_objects [get_filesets $fileset] -filter $ip_with_parent_filter]] == 1} {
  1639. return true
  1640. }
  1641. return false
  1642. }
  1643. proc is_ip_run { run } {
  1644. # Summary: Find IP's if any from the fileset linked with the block fileset run
  1645. # Argument Usage:
  1646. # run: run name
  1647. # Return Value:
  1648. # true (1) if success, false (0) otherwise
  1649. set fileset [get_property srcset [get_runs $run]]
  1650. return [is_ip_fileset $fileset]
  1651. }
  1652. }