################################################################################ # # This file provides a basic wrapper to use git directly from the tcl console in # Vivado. # It requires the write_project_tcl_git.tcl script to work properly. # Unversioned files will be put in the work_dir folder # # Ricardo Barbedo # ################################################################################ namespace eval ::git_wrapper { namespace export git namespace export wproj namespace import ::custom_projutils::write_project_tcl_git namespace import ::current_project namespace import ::common::get_property proc git {args} { set command [lindex $args 0] # Change directory project directory if not in it yet set proj_dir [regsub {\/work_dir$} [get_property DIRECTORY [current_project]] {}] set current_dir [pwd] if { [string compare -nocase $proj_dir $current_dir] } then { puts "Not in project directory" puts "Changing directory to: ${proj_dir}" cd $proj_dir } switch $command { "init" {git_init {*}$args} "commit" {git_commit {*}$args} "default" {exec git {*}$args} } } proc git_init {args} { set vivado_version [version -short] set current_project [current_project] # Generate gitignore file puts "Generate gitignore file" set file [open ".gitignore" "w"] puts $file "work_dir/*" puts $file ".Xil/*" puts $file "*.str" puts $file "*.log" puts $file "*.jobs" puts $file "*.jou" close $file # Generate readme file puts "Generate readme file" set file [open "README.md" "w"] puts $file "# ${current_project}" puts $file "" puts $file "Created with Vivado Version ${vivado_version}" puts $file "" puts $file "### Getting started" puts $file "" puts $file "After cloning this repo open the project with Vivado by using `Tools -> Run Tcl Script...` and selecting the `${current_project}.tcl` file" puts $file "" puts $file "### Workflow" puts $file "" puts $file "- Place source/design files in folder created in the top directory of the repo (e.g. `REPO/src/` or `REPO/design/`)." puts $file "" puts $file "- **The `work_dir` folder will be untracked!**" puts $file "" puts $file "- Wenn you are done, `git add` your source/design files." puts $file "" puts $file "- Use the **Tcl Console** from Vivado to `git commit -m \"COMMIT_MESSAGE\"` your work. The `${current_project}.tcl` file will be recreated" puts $file "" puts $file "### Notes" puts $file "" puts $file "#### Block design" puts $file "" puts $file "When you change a block design, **befor you run synthesis** you have to *delete* the current HDL wrapper and *create a new* HDL wrapper for each changed design!" close $file # Initialize the repo puts "Initialize the repo" exec git {*}$args exec git add .gitignore exec git add README.md git_commit commit -m "create project" puts "finished!" } proc git_commit {args} { # Get project name set proj_file [current_project].tcl # Generate project and add it write_project_tcl_git -no_copy_sources -force $proj_file puts $proj_file exec git add $proj_file # Now commit everything exec git {*}$args } proc wproj {} { # Change directory project directory if not in it yet set proj_dir [regsub {\/work_dir$} [get_property DIRECTORY [current_project]] {}] set current_dir [pwd] if { [string compare -nocase $proj_dir $current_dir] } then { puts "Not in project directory" puts "Changing directory to: ${proj_dir}" cd $proj_dir } # Generate project set proj_file [current_project].tcl puts $proj_file write_project_tcl_git -no_copy_sources -force $proj_file } }