Shell for SOFA Development
From SOFAWiki
Contents |
Detailed Instructions
A shell is a very low level but very powerful interface to work in. In this section, we show a few useful commands that will be useful when working with projects such as Sofa. Note that instead of repeatedly typing or copy/pasting these sometimes long commands, you can make use of the following tips :
- use aliases: you can put the following in your ~/.bashrc and then simply use the shortname alias
alias shortname='my very long command'
- use the history: using up/down arrow keys, you can recall previous commands, and you can also use an '!' followed by a few characters to reuse the last command with the given prefix
- use the tab key to auto-complete command names and file paths. You can additionally install bash-completion to have more powerful auto-completion specific to each command and argument
SVN support
Everything can be done using the svn command.
It is auto-documented:svn helpsvn help checkoutSetup
If you just have access to the public Sofa SVN, then no setup is required, simply checkout the code usingsvn checkout svn://scm.gforge.inria.fr/svn/sofa/branches/Sofa-1.0
To commit code to the development Sofa SVN, it is recommended to use ssh as it is faster. See http://siteadmin.gforge.inria.fr/FAQ.html#Q6 for instructions.
To reduce cross-platform issues with end-of-line codings, it is recommended to add the following to the ~/.subversion/config configuration file:
[miscellany] enable-auto-props = yes [auto-props] *.c = svn:eol-style=native *.cu = svn:eol-style=native *.cpp = svn:eol-style=native *.h = svn:eol-style=native *.hpp = svn:eol-style=native *.inl = svn:eol-style=native *.cuh = svn:eol-style=native *.pro = svn:eol-style=native *.pri = svn:eol-style=native *.prf = svn:eol-style=native *.cfg = svn:eol-style=native *.dsp = svn:eol-style=CRLF *.dsw = svn:eol-style=CRLF *.bat = svn:eol-style=CRLF;svn:executable *.sh = svn:eol-style=native;svn:executable *.txt = svn:eol-style=native *.scn = svn:eol-style=native *.pscn = svn:eol-style=native *.xml = svn:eol-style=native *.png = svn:mime-type=image/png *.jpg = svn:mime-type=image/jpeg Makefile = svn:eol-style=native
To edit commit messages, or conflicted files, you can also set the EDITOR environment variable to your favorite editor (such as emacs, gedit, ...).
Usage
The following tips show how svn and a few other commands can be used to easily work with the source code :
- Listing modified files but not new / temporary files :
svn status | grep -v '^?'
- Color diff of local changes :
svn diff | colordiff
Building SOFA
Configuration
To (re)create the makefiles, use ./Project\ Linux.sh or ./Project\ MacOS.sh.
If you edited some flags in sofa-local.cfg or other places, you might need to force the compilation of affected source files. This can be done automatically if you use sofaConfiguration, but you can also do it manually using the c++touch SOFA_FLAGS where SOFA_FLAG is the flag that you changed, and c++touch is the following script, that you need to place in a directory within your PATH :
#!/bin/bash find \( -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' -o -iname '*.inl' -o -iname '*.c' -o -iname '*.cu' -o -iname '*.cuh' -o -iname '*.pro' \) -print0 | xargs -0 grep -lZ "$1" | xargs -0 touch
Compilation
To compile SOFA, a simple make will do, but the following command will make it faster :
nice -19 make -j3
The "nice -19" command put the compilation in the background, so that you can use your computer for other tasks (you can omit it if you go get a coffee instead ;))
The "-j3" option starts 3 jobs in parallel. Change it to the number of cores that you have plus one.
When there are errors, it will be easier to see from which file they come from if you recompile without using multiple jobs, and using colorgcc to highlight error messages :
make CXX=colorgcc
Editing Source Code
While editing the code will be done outside of the shell (unless you want to type it directly using cat > myfile.cpp ...), the following commands can be useful:
- To quickly find relevant files by searching for files containing the given identifier : c++find identifier with c++find the following script. Note that this is a little bit faster that using "grep -R" as it will not look within large binary files.
#!/bin/bash find \( -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' -o -iname '*.inl' -o -iname '*.c' -o -iname '*.cu' -o -iname '*.cuh' -o -iname '*.pro' \) -print0 | xargs -0 grep -n "$1"
- Replace a given name in all the source code below the current directory : c++replace old new with c++replace the following script.
#!/bin/bash find -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' -o -iname '*.inl' -o -iname '*.c' -o -iname '*.cu' -o -iname '*.cuh' -o -iname '*.pro' | xargs grep -l "$1" | xargs sed -i'~' "s|$1|$2|g"
- Open the current directory in the GUI :
open . # for Mac OS nautilus . # for Linux / GTK dolphin . >/dev/null 2>/dev/null & # for Linux / KDE
