Title: Recitation 2: Revision Control
1Recitation 2 Revision Control Makefiles
- George Nychis
- Spring 2009
2Quite different from 213
- Project size 1000s of lines vs 100s.
- Project duration 5 weeks vs 1-2 weeks
- Partners vs. solo developer
- Result
- You cant keep the state for 441 projects in
your head at all times. Its too big! - Requires one step more care in development.
3Software EngineeringFor Systems Hackers
- Goals and foundations
- 1-5 developers
- Context Systems code, but not too much is
systems specific - Very low overhead and up-front cost
- Like to see benefits w/in a single project
4Overview
- Today Intro Revision Control
- Managing your source code wisely
- Makefiles and automation
- Automate the boring stuff!
5Revision Control
- Before you write a line of code
- Use subversion/CVS/etc.
- Provides access to all old versions of your code
- No more cp file.c file.c.2006-01-01-1059am-oh-god
-please-let-this-work
6What is revision control?
- A repository that stores each version
- You explicitly check out and check in code
and changes. - /tmpgt svn checkout https//moo.cmcl.cs.cmu.edu/441
/svn/Project1Team1 -
-
Password for 'gnychis' A Project1Team1/trunk
A Project1Team1/branches A
Project1Team1/tags Checked out revision 1.
7Why do I want it?
- Super-undo Go to arbitrary versions
- rm rf your source tree? No problem!
- Tracking changes /why did this break?
- Concurrent development
- Snapshots
- Turning in the assignment just make a snapshot
when you want, and well grade that. You can
keep developing afterwords. - Useful, e.g., for optimization contest, or for
making sure you have something working.
8The repository
- Master copy of code is separate from what you
work on - You canhave multipleworking copieschecked
out.(So can your partner)?
Repository
Your working copy
Laptop working copy
Partner working copy
9Check out and commit
- Explicitly synchronize with the repository
Repository
Checkout / Update
Commit
Your working copy
10And you can see what changed
- Revision control lets you note (and then see)
what you changed - gt svn log gtcd.cc
- r986 ntolia 2006-08-01 171338 -0400 (Tue,
01 Aug 2006) 6 lines - This allows the sp to get rid of chunks early
before a transfer is complete. - Useful when a file is requested in-order and the
file size gt mem cache size - And makes it easy to go back to other versions
- --------------------------------------------------
------------------- - r987 ntolia 2006-08-02 131621 -0400 (Wed,
02 Aug 2006) 1 line - After much thought, I am reverting the last
patch. We will need to revisit the - issue when we think about DOT on storage-limited
clients
11Concurrent edits
Ann
Drew
File v1
Both check out file
Edits (drew-1)? Different part of same file
Edits (ann-1)?
commit
File v2
Update Successfully merged
12Concurrent edits
Ann
Drew
File v1
Both check out file
Edits (drew-1)? Overlap with ann-1
Edits (ann-1)?
commit
File v2
Update (CONFLICT)?
13Resolving Conflicts
- Subversion will give you 3 files
- The original with conflict markers
- The version you were editing
- The latest version in the repository
- You can
- Keep your changes, discarding others
- Toss your changes
- Manually resolve
14Branches
- Multiple paths of development, e.g.
- Release 1.0 only gets security patches
- Development branch gets everything
- tags or snapshots
- Save a good known state. E.g., for handing in.
- You will use tags for checkpoints and final
version!
15Brief walkthrough (CP1)?
svn co https//moo.cmcl.cs.cmu.edu/441/svn/Proje
ct1Team63 A Project1Team63/trunk A
Project1Team63/branches A Project1Team63/tags C
hecked out revision 1. cd Project1Team63/trunk/
echo -e "include ltstdio.hgt\n\n int main()
return 1 " gt sircd.c svn add sircd.c vim
Makefile svn add Makefile svn ci -m 'adding
Makefile and sircd.c!' cd ../ svn cp trunk
tags/checkpoint1 svn ci -m 'making a tag of the
trunk for checkpoint1!'
16Thoughts on Revision Control
- Update, make, test, then commit
- Update out of habit before you start editing
- Merge often
- Commit format changes separately
- Check svn diff before committing
- Try not to break the checked in copy
- Invasive changes? Maybe a branch
- Dont use svn lock
- Avoid conflicts by good decomposition
(modularity) and out-of-band coordination
17Rest of the Recitation
- Saving you time
- Learn how to use Makefiles
18Simple gcc
If we have files prog.c The main program
file lib.c Library .c file lib.h Library
header file gcc -c prog.c -o prog.o gcc -c
lib.c -o lib.o gcc lib.o prog.o -o binary
19gcc flags
- Useful flags
- -g debugging hook
- -Wall all warning
- -Werror treat warning as errors
- -O2, -O3 optimization
- -DDEBUG macro for DEBUG (define DEBUG)?
20Examples
- gcc -g -Wall -Werror -c prog.c -o prog.o
- gcc -g -Wall -Werror -c lib.c -o lib.o
- gcc -g -Wall -Werror lib.o prog.o -o binary
- But Dont Repeat Yourself!
21Makefile
- gcc -g -Wall -Werror -c prog.c -o prog.o
- gcc -g -Wall -Werror -c lib.c -o lib.o
- gcc -g -Wall -Werror lib.o prog.o -o binary
- CC gcc
- CFLAGS -g -Wall -Werror
- OUTPUT binary
22Makefile
target dependency1 dependency2 ... unix
command (start line with TAB)? unix
command ... gcc lib.o prog.o -o
binary binary lib.o prog.o gcc lib.o prog.o
-o binary
23 binary lib.o prog.o gcc -g -Wall lib.o
prog.o -o binary lib.o lib.c gcc -g -Wall -c
lib.c -o lib.o prog.o prog.c gcc -g -Wall -c
prog.c -o prog.o clean rm .o binary
24 binary lib.o prog.o gcc -g -Wall lib.o
prog.o -o binary lib.o lib.c gcc -g -Wall -c
lib.c -o lib.o prog.o prog.c gcc -g -Wall -c
prog.c -o prog.o clean rm .o binary
25 CC gcc CFLAGS -g -Wall OUTPUT
binary (OUTPUT) lib.o prog.o (CC)
(CFLAGS) lib.o prog.o -o binary lib.o
lib.c (CC) (CFLAGS) -c lib.c -o
lib.o prog.o prog.c (CC) (CFLAGS) -c
prog.c -o prog.o clean rm .o (OUTPUT)?
26 CC gcc CFLAGS -g -Wall OUTPUT
binary (OUTPUT) lib.o prog.o (CC)
(CFLAGS) lib.o prog.o -o binary lib.o
lib.c (CC) (CFLAGS) -c lib.c -o
lib.o prog.o prog.c (CC) (CFLAGS) -c
prog.c -o prog.o clean rm .o (OUTPUT)?
27 CC gcc CFLAGS -g -Wall OUTPUT
binary OBJFILES lib.o prog.o (OUTPUT)
(OBJFILES)? (CC) (CFLAGS) (OBJFILES) -o
binary lib.o lib.c (CC) (CFLAGS) -c lib.c
-o lib.o prog.o prog.c (CC) (CFLAGS) -c
prog.c -o prog.o clean rm .o (OUTPUT)?
28 CC gcc CFLAGS -g -Wall OUTPUT
binary OBJFILES lib.o prog.o (OUTPUT)
(OBJFILES)? (CC) (CFLAGS) (OBJFILES) -o
binary lib.o lib.c (CC) (CFLAGS) -c lib.c
-o lib.o prog.o prog.c (CC) (CFLAGS) -c
prog.c -o prog.o clean rm .o (OUTPUT)?
29 CC gcc CFLAGS -g -Wall OUTPUT
binary OBJFILES lib.o prog.o (OUTPUT)
(OBJFILES)? (CC) (CFLAGS) (OBJFILES) -o
binary .o .c lt dependency (.c)?
_at_ target (.o)? (CC) (CFLAGS) -c lt -o
_at_ clean rm .o (OUTPUT)?
30Simple Test Script
- ./server 6667
- cat testfile.01 ./testscript.py
- cat testfile.02 ./testscript.py
- killall -9 server
31Simple Test Script
- /bin/sh
- echo Starting server on port 6667.
- ./server 6667
- SERVERPID !
- echo Running test files.
- cat testfile.01 ./testscript.py
- cat testfile.02 ./testscript.py
- echo Killing server process.
- kill (SERVERPID)?
32 CC gcc CFLAGS -g -Wall OUTPUT
binary OBJFILES lib.o prog.o all
(OUTPUT)? (OUTPUT) (OBJFILES)? (CC)
(CFLAGS) (OBJFILES) -o binary .o .c
lt dependencies (.c)? _at_ target
(.o)? (CC) (CFLAGS) -c lt -o
_at_ clean rm .o (OUTPUT)?
33 CC gcc CFLAGS -g -Wall OUTPUT
binary OBJFILES lib.o prog.o all (OUTPUT)
test (OUTPUT) (OBJFILES)? (CC) (CFLAGS)
(OBJFILES) -o binary .o .c lt
dependencies (.c)? _at_ target (.o)? (CC)
(CFLAGS) -c lt -o _at_ test (OUTPUT)? sh
./testscript.sh clean rm .o (OUTPUT)?
34Use Makefile
- make
- make test
- make clean
- Google
- makefile example
- makefile template
- make tutorial
35Useful Unix Commands
- find func_name in files
- grep -r func_name .
- replace bad_func_name to good_func_name
- sed -e s/bad_func_name/good_func_name/g\
- prog.c gt prog.c.new
36Useful Unix Commands
- find a file named prog.c
- find -name prog.c
- download files from Internet
- wget http//address/to/file.tar.gz
- untar and unzip the file
- tar xzvf file.tar.gz
37Project 1
- Checkpoint 2
- Echo server
- Handle multiple clients
- Handle TCP framing
- Q A