User:Chrigi 1/DevelopmentSetup: Difference between revisions

From KDE TechBase
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 9: Line 9:
Layout:
Layout:


MainUser: chrigi
-Main User: chrigi


DevelopmentUser: devel
-Development User: devel


trunk KDEDIR: /opt/devel/KDE
-trunk KDEDIR: /opt/devel/KDE


trunk sourcecode: /home/chrigi/devel/kde
-trunk sourcecode: /home/chrigi/devel/kde




Line 24: Line 24:
First the setup of the MainUser which is used for the coding and compiling:
First the setup of the MainUser which is used for the coding and compiling:


This follows mainly the "development with scripts tutorial" but here is my exact configuration:
This follows mainly [[http://techbase.kde.org/Getting_Started/Increased_Productivity_in_KDE4_with_Scripts|Increased_Productivity_in_KDE4_with_Scripts]] but here is my exact configuration:


The following three scripts are used that the .my-setup file is sourced as soon as the sourcecode directory is entered:
The following three scripts are used that the .my-setup file is sourced as soon as the sourcecode directory is entered:
Line 282: Line 282:


With this setup you can already build kde from source, and install it to /opt/devel/KDE
With this setup you can already build kde from source, and install it to /opt/devel/KDE


== Devel User (Running programs) ==
== Devel User (Running programs) ==
Line 401: Line 400:
== Using the Setup ==
== Using the Setup ==
First you get the sourcecode. Download it into the /home/chrigi/devel/kde directory, and compile it with 'cmakekde'.
First you get the sourcecode. Download it into the /home/chrigi/devel/kde directory, and compile it with 'cmakekde'.
See [[http://techbase.kde.org/Getting_Started/Build/KDE4]] for further info on building kde.


After a first run of cmakekde you can also use Kdevelop to build and install things. If you select the existing build directory in /home/chrigi/devel/kde/build all neede cmake variables will be found (of course you could also set them manually).
After a first run of cmakekde you can also use Kdevelop to build and install things. If you select the existing build directory in /home/chrigi/devel/kde/build all neede cmake variables will be found (of course you could also set them manually).


To run the compiled program use a tool called 'sux' (see the devel page for further info). This is basically su with x forwarding.
To run the compiled program use a tool called 'sux' (see [[http://techbase.kde.org/Getting_Started/Set_up_KDE_4_for_development|Set_up_KDE_4_for_development]] for further info). This is basically su with x forwarding.


All you need to do is:
All you need to do is:


-login with 'sux devel'
-login with 'sux devel'
-run the program you want
-run the program you want


Line 416: Line 418:


-second shell: login with devel, start your program which uses akonadi (the right akonadi instance will be found via dbus
-second shell: login with devel, start your program which uses akonadi (the right akonadi instance will be found via dbus
== Solitary session ==
todo

Latest revision as of 17:06, 23 January 2011

Since the latest update of akonadi I was not able to run two akonadi instances with the same user anymore, so I switched to a setup using two users.

I have my main user (which I use for all daily tasks) and a devel user. My kde development happens with normal user, and the devel user is only used to run the trunk versions of the parts I'm working on. I.e. currently I'm working on an app using akonadi and nepomuk, so I run another instance of akonadi and nepomuk with the devel user (because I need the latest Akonadi Agents).

This setup is fairly flexible as you can run full sessions with of the trunk version, without touching your working environment. On the other hand you don't need to run a full session, you can also simply run the programs you want with the devel user, from you normal working session with you standard user.

Layout:

-Main User: chrigi

-Development User: devel

-trunk KDEDIR: /opt/devel/KDE

-trunk sourcecode: /home/chrigi/devel/kde


MainUser (development and compiling)

First the setup of the MainUser which is used for the coding and compiling:

This follows mainly [[1]] but here is my exact configuration:

The following three scripts are used that the .my-setup file is sourced as soon as the sourcecode directory is entered:

append to .bashrc so the findup script is called on cd:

function cd() {
  if test -z "$1"; then
    builtin cd         
  elif test -z "$2"; then
    builtin cd "$1"
  else
    builtin cd "$1" "$2"
  fi
  _f=`findup .my-setup`
  if test -n "$_f" -a "$_lastf" != "$_f"; then
    echo "Loading $_f"
    _lastf="$_f"
    source "$_f"
  fi
}

/usr/local/bin/findup:

#!/bin/sh

arg="$1"
if test -z "$arg"; then exit 1; fi

while ! test -f "$arg"; do
 cd ..
 if test "$PWD" = "/"; then
    exit 1
 fi
done

echo $PWD/$arg

/home/chrigi/devel/kde/.my-setup

prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" && export $1 ; } 



## A script to setup some needed variables and functions for KDE 4 development.
## This should normally go in the ~/.bashrc file of your kde-devel user, so    
## that it is executed when a session for that user is started.                
##                                                                             
## If you don't use a separate user, the first section with the                
## environment variables should go into a separate script.                     

 
# Otheng kde3 seems to be in /usr/bin so /usr/sbin seems okay to leave in. 
export PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin                   

# Qt 
# only set Qt related variables if you compiled Qt on your own 
# (which is discouraged). if you use the distro provided Qt, skip 
# this section. Comment it if necessary.                          
#export QTDIR=$HOME/qt4                                           
#prepend PATH $QTDIR/bin                                          
#prepend LD_LIBRARY_PATH $QTDIR/lib                               
#prepend PKG_CONFIG_PATH $QTDIR/lib/pkgconfig                     


# KDE 
export KDEDIR=/opt/devel/KDE
export KDEHOME=$HOME/.kde4src
export KDETMP=/tmp/$USER-kde4src
mkdir -p $KDETMP              
export KDEDIRS=$KDEDIR 
export KDESYCOCA=/var/tmp/kdesycoca-custom       
prepend PATH $KDEDIR/bin      
prepend LD_LIBRARY_PATH $KDEDIR/lib 
prepend PKG_CONFIG_PATH $KDEDIR/lib/pkgconfig 
prepend QT_PLUGIN_PATH $KDEDIR/lib/kde4/plugins 

export PATH
export LD_LIBRARY_PATH
export PKG_CONFIG_PATH
export QT_PLUGIN_PATH 

# CMake
# Make sure CMake searches the right places.
prepend CMAKE_PREFIX_PATH  $KDEDIR
prepend CMAKE_LIBRARY_PATH $KDEDIR/lib      
prepend CMAKE_INCLUDE_PATH $KDEDIR/include  

export CMAKE_PREFIX_PATH                                            
export CMAKE_LIBRARY_PATH                   
export CMAKE_INCLUDE_PATH                   


# you might want to change these: 
export KDE_BUILD=$HOME/devel/kde/build 
export KDE_SRC=$HOME/devel/kde         

 
 
# XDG
unset XDG_DATA_DIRS # to avoid seeing kde3 files from /usr
unset XDG_CONFIG_DIRS
#export XDG_CONFIG_HOME=$KDEDIR/.config                                    
#export XDG_DATA_HOME=$KDEDIR/.local/share                           
                               
                                                          
# make the debug output prettier                          
export KDE_COLOR_DEBUG=1                                  
export QTEST_COLORED=1                                    
                                                          
# Make                                                    
# Tell many scripts how to switch from source dir to build dir:
export OBJ_REPLACEMENT="s#$KDE_SRC#$KDE_BUILD#"                
# Use makeobj instead of make, to automatically switch to the build dir.
# If you don't have makeobj, install the package named kdesdk-scripts or 
# kdesdk, or check out kdesdk/scripts from svn.                          
alias make=makeobj                                                       


# A function to easily build the current directory of KDE.
#                                                         
# This builds only the sources in the current ~/{src,build}/KDE subdirectory.
# Usage: cs KDE/kdebase && cmakekde                                          
#   will build/rebuild the sources in ~/src/KDE/kdebase                      
function cmakekde {                                                          
        if test -n "$1"; then                                                
                # srcFolder is defined via command line argument             
                srcFolder="$1"                                               
        else                                                                 
                # get srcFolder for current dir                              
                srcFolder=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`              
        fi                                                            
        # we are in the src folder, change to build directory                
        # Alternatively, we could just use makeobj in the commands below...  
        current=`pwd`       
        #echo $current
        #echo $srcFolder
        #echo $KDE_SRC
        #echo $KDE_BUILD                                                 
        if [ "$srcFolder" == "$current" ]; then                               
                cb                                                           
        fi
        #echo $srcFolder                                                                   
        # to enable tests, add -DKDE4_BUILD_TESTS=TRUE to the next line.     
        # you can also change "debugfull" to "debug" to save disk space. -GKDevelop3    
        cmake "$srcFolder"  -DCMAKE_INSTALL_PREFIX=$KDEDIR -DCMAKE_BUILD_TYPE=debugfull -DKDE4_BUILD_TESTS=TRUE                                
                                                                             
        # uncomment the following two lines to make builds wait after        
        # configuration step, so that the user can check configure output    
        #echo "Press <ENTER> to continue..."                                 
        #read userinput                                                      
                                                                             
        # Note: To speed up compiling, change 'make -j2' to 'make -jx',      
        #   where x is your number of processors +1                          
        nice make -j3 && \                                                   
        make install;

        cs                                                        
}                                                                            
                                                                                                                                                    

                                                      

# A function to easily change to the build directory.
# Usage: cb KDE/kdebase                              
#   will change to $KDE_BUILD/KDE/kdebase            
# Usage: cb                                          
#   will simply go to the build folder if you are currently in a src folder
#   Example:                                                               
#     $ pwd                                                                
#     /home/user/src/KDE/kdebase                                           
#     $ cb && pwd                                                          
#     /home/user/build/KDE/kdebase                                         
function cb {                                                              
        # Make sure build directory exists.                                
        mkdir -p "$KDE_BUILD"                                              
                                                                           
        # command line argument                                            
        if test -n "$1"; then                                              
                cd "$KDE_BUILD/$1"                                         
                return                                                     
        fi                                                                 
        # substitute src dir with build dir                                
        dest=`pwd | sed -e s,$KDE_SRC,$KDE_BUILD,`                         
        if test ! -d "$dest"; then                                         
                # build directory does not exist, create                   
                mkdir -p "$dest"                                           
        fi                                                                 
        cd "$dest"                                                         
}                                                                          
                                                                           
# Change to the source directory.  Same as cb, except this                 
# switches to $KDE_SRC instead of $KDE_BUILD.                              
# Usage: cs KDE/kdebase                                                    
#       will change to $KDE_SRC/KDE/kdebase                                
# Usage: cs                                                                
#   will simply go to the source folder if you are currently in a build folder
#   Example:                                                                  
#     $ pwd                                                                   
#     /home/user/build/KDE/kdebase                                            
#     $ cs && pwd                                                             
#     /home/user/src/KDE/kdebase                                              
function cs {                                                                 
        # Make sure source directory exists.                                  
        mkdir -p "$KDE_SRC"                                                   
                                                                              
        # command line argument                                               
        if test -n "$1"; then                                                 
                cd "$KDE_SRC/$1"                                              
        else                                                                  
                # substitute build dir with src dir                           
                dest=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`                    
                current=`pwd`                                                 
                if [ "$dest" = "$current" ]; then                             
                        cd "$KDE_SRC"                                         
                else                                                          
                        cd "$dest"                                            
                fi                                                            
        fi                                                                    
}                                                                             
                                                                              
# Add autocompletion to cs function                                           
function _cs_scandir                                                          
{                                                                             
        base=$1                                                               
        ext=$2                                                                
        if [ -d $base ]; then                                                 
                for d in `ls $base`; do                                       
                        if [ -d $base/$d ]; then                              
                                dirs="$dirs $ext$d/"                          
                        fi                                                    
                done                                                          
        fi                                                                    
}                                                                             
                                                                              
function _cs()                                                                
{                                                                             
        local cur dirs                                                        
        _cs_scandir "$KDE_SRC"                                                
        _cs_scandir "$KDE_SRC/KDE" "KDE/"                                     
        COMPREPLY=()                                                          
        cur="${COMP_WORDS[COMP_CWORD]}"                                       
        COMPREPLY=( $(compgen -W "${dirs}" -- ${cur}) )                       
}                                                                             
                                                                              
# Remove comment on next line to enable cs autocompletion                     
#complete -F _cs cs

Some notes on .my-setup:

I removed all functions which I do not need. With this setup, it would also be possible to run programs which are compiled from trunk, directly as main user (chrigi). The KDEHOME is set appropriately therefore. However, you will run into problems when you try to run programs which use akonadi or nepomuk. Therefore we have the devel user.


With this setup you can already build kde from source, and install it to /opt/devel/KDE

Devel User (Running programs)

To run programs we need to setup the devel user:

First, create a new user called devel.

append the following to .bashrc:

prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" && export $1 ; } 



## A script to setup some needed variables and functions for KDE 4 development.
## This should normally go in the ~/.bashrc file of your kde-devel user, so    
## that it is executed when a session for that user is started.                
##                                                                             
## If you don't use a separate user, the first section with the                
## environment variables should go into a separate script.                     

 
# Otheng kde3 seems to be in /usr/bin so /usr/sbin seems okay to leave in. 
export PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin                   

# Qt 
# only set Qt related variables if you compiled Qt on your own 
# (which is discouraged). if you use the distro provided Qt, skip 
# this section. Comment it if necessary.                          
#export QTDIR=$HOME/qt4                                           
#prepend PATH $QTDIR/bin                                          
#prepend LD_LIBRARY_PATH $QTDIR/lib                               
#prepend PKG_CONFIG_PATH $QTDIR/lib/pkgconfig                     


# KDE 
export KDEDIR=/opt/devel/KDE
export KDEHOME=$HOME/.kde4src
export KDETMP=/tmp/$USER-kde4src
mkdir -p $KDETMP              
export KDEDIRS=$KDEDIR        
prepend PATH $KDEDIR/bin      
prepend LD_LIBRARY_PATH $KDEDIR/lib 
prepend PKG_CONFIG_PATH $KDEDIR/lib/pkgconfig 
prepend QT_PLUGIN_PATH $KDEDIR/lib/kde4/plugins 

export PATH
export LD_LIBRARY_PATH
export PKG_CONFIG_PATH
export QT_PLUGIN_PATH 

# CMake
# Make sure CMake searches the right places.
prepend CMAKE_PREFIX_PATH  $KDEDIR
prepend CMAKE_LIBRARY_PATH $KDEDIR/lib      
prepend CMAKE_INCLUDE_PATH $KDEDIR/include  

export CMAKE_PREFIX_PATH                                            
export CMAKE_LIBRARY_PATH                   
export CMAKE_INCLUDE_PATH                   


# you might want to change these: 
export KDE_BUILD=$HOME/devel/kde/build 
export KDE_SRC=$HOME/devel/kde         

 
 
# XDG
#unset XDG_DATA_DIRS # to avoid seeing kde3 files from /usr  (don not unset this, we need the dir for global mimetypes)
#unset XDG_CONFIG_DIRS                                     
prepend XDG_DATA_DIRS $KDEDIR/share
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
                                                          
# make the debug output prettier                          
export KDE_COLOR_DEBUG=1                                  
export QTEST_COLORED=1                                    
                                                          



DBUSFILE=/tmp/devel-kde4src/.dbus-session

if [ ! -f $DBUSFILE ]; then
        dbus-launch > $DBUSFILE
fi

if [ -f $DBUSFILE ]; then
        source $DBUSFILE
fi


This is mainly a copy of the .my-setup script, which exports all needed variables, there are some differences however:

-all functions for compiling were removed (since compiling is don using the main user)

- some XDG variables are set:

# XDG
#unset XDG_DATA_DIRS # to avoid seeing kde3 files from /usr  (don not unset this, we need the dir for global mimetypes)
#unset XDG_CONFIG_DIRS                                     
prepend XDG_DATA_DIRS $KDEDIR/share
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share

This makes sure that the correct XDG directories are found, they are used for things like mimetypes, icons and also the akonadi-database.

-at the very end, the devel users uses a separate dbus session (over which programs communicate to akonadi and nepomuk). The code simply creates a new dbus session when first loggin in with the devel user, for all subsequent logins the same session is used.

Notes

By setting the XDG variables and dbus sessions correctly, I believe it should be possible to achieve the same as single user, I never got it to work however. All in all, this way there aren't really any drawbacks in productivity by using a second user. The only difference to my previous setup is, that the akonadi database is not the same as the one of my main user, which is probably good.


Using the Setup

First you get the sourcecode. Download it into the /home/chrigi/devel/kde directory, and compile it with 'cmakekde'.

See [[2]] for further info on building kde.

After a first run of cmakekde you can also use Kdevelop to build and install things. If you select the existing build directory in /home/chrigi/devel/kde/build all neede cmake variables will be found (of course you could also set them manually).

To run the compiled program use a tool called 'sux' (see [[3]] for further info). This is basically su with x forwarding.

All you need to do is:

-login with 'sux devel'

-run the program you want

If you are developing with akonadi it makes sens to start akonadi in a separate shell, so the output is not mixed with the one of your program:

-first shell: login with devel, start akaondi "akonadictl start" (will start the trunk version of akonadi, with the database of the user devel. Further it will also automatically launch nepomuk)

-second shell: login with devel, start your program which uses akonadi (the right akonadi instance will be found via dbus

Solitary session

todo