Wednesday, June 1, 2016

Making your first contribution to snapd

Making your first contribution to snapd is quite easy but if you are not familiar with how go projects are structured it may be non-obvious where the code is or why your forked branch is not being used. Let's see how to do this step by step:


  1. Fork the project on github. You will need a github account.
  2. Set the GOPATH environment variable to something like ~/hacking or ~/fun or like I do ~/work (though I must say my work is full of fun hacking :-). You can set it directly with export GOPATH=~/hacking but I would recommend to add it to your ~/.profile file. Note that it will only be used on the next login so you can also set it directly or source the ~/.profile file with . ~/.profile after you've made the change.
  3. Set PATH to include $GOPATH/bin -- you will need this to run some of the programs you build and install (export PATH=$PATH:$GOPATH/bin) -- also make this persistent as described above
  4. Create $GOPATH/src/snapcore (mkdir -p $GOPATH/src/github.com/snapcore) and enter that directory (cd $GOPATH/src/github.com/snapcore)
  5. Clone your fork here (git clone git@github.com:zyga/snapd -- do replace zyga with your github account name)
  6. Add the upstream repository as a remote (git remote add upstream git@github.com:snapcore/snapd) - you will use this later to get latest changes from everyone
  7. Run the ./get-deps.sh script. You will probably need a few extra things (sudo apt-get install golang-go bzr)
  8. You are now good to go :-)

At this stage you can go build and go test individual packages. I would also advise you to have a look at my devtools repository where I've prepared useful scripts for various tasks. One thing you may want to use is the refresh-bits script. Having followed steps 1 through 8 above, let's use refresh-bits to run our locally built version of snapd and snap.
  1. Clone devtools to anywhere you want (git clone git@github.com:zyga/devtools) and enter the cloned repository (cd devtools)
  2. Assuming your GOPATH is still set, run ./refresh-bits snap snapd setup run-snapd restore
  3. Look at what is printed on screen, at some point you will notice that locally started snapd is running (you can always stop it by pressing ctrl+c) along with instructions on how to run your locally built snap executable to talk to it
  4. In another terminal, in the same directory, run sudo ./snap.amd64 --version
Voila :-)

If you have any questions about that, please use the comments section below. Thanks!

No comments:

Post a Comment