Build Tools - Notes
Build Tools - Notes
compilers we use
gcc-c
g++-c++
javac-java
Makefile or makefile
It is used to generate executable from c and c++ source code.
Syntax
Target: dep1 dep2 dep3
<TAB>system commands
Suppose there are 3 .c files you need to build .exe for those
Abc.exe:f1.o f2.o f3.o
<TAB>gcc –o abc.exe f1.o f2.o f3.o
F1.o:f1.c
<TAB>gcc –c f1.c
F2.o:f2.c
<TAB>gcc –c f2.c
F3.o:f3.c
<TAB>gcc –c f3.c
Makefile
Abc.exe:big.o facr.o rev.o
<TAB>gcc –o abc.exe big.o facr.o rev.o
big.o:big.c
<TAB>gcc –c big.c
facr.o:facr.c
<TAB>gcc –c facr.c
rev.o:rev.c
<TAB>gcc –c rev.c
Is a untested build.
You need to trigger some task or action before commit or after commit, we go for hooks.
Makefile
It is a critical fix which needs to be deliver to a customer within few hours. Developers
will change only required files, make will compile only changed files and changes will
get incorporated to the build so patch build will take less time.
Load build
We compile source code from the scratch, before we start this build we delete all
intermediate files (.o files), so that all files will get compile from scratch. So it take more
time.
Which make
Which gcc
Mkdir srccode
Vi big3.c
Vi fact.c
Vi main.c
Main () { fact(); big3(); }
Vi makefile
1. Example code
Abc:main.o fact.o big3.o
Gcc –o abc main.o fact.o big3.o
Main.o:main.c
Gcc –c main.c
Fact.o:fact.c
Gcc –c fact.c
Big3.o:big3.c
Gcc –c big3.c
make
2. Example code
Abc:main.o fact.o big3.o
Gcc –o abc main.o fact.o big3.o
Main.o:main.c
Gcc –c main.c
Fact.o:fact.c
Gcc –c fact.c
Big3.o:big3.c
Gcc –c big3.c
Clean:
Rm –rf *.o
We have 2 branches, one is dev branch another one is master or production branch,
developers are allowed to commit changes on dev branch.
Once developers commits the code on dev branch. We build it, we do sanity or BVT and
we release to a testing team.
We merge this code to production branch. If the build is failed after developer commits
the changes, we don‘t merge the code from dev branch to production branch. We work
with development team to fix the issue.
So we always merge good code to productive branch so that production branch will have
clean working branch always.
If developer needs latest good code they can pull it from production branch, but they
can’t push it to production branch, because git push is restricted.
Maven is a project management tool which can manage complete build life cycle.
Maven simplifies and standardizes the project build process.
Maven repository
Maven repository is a directory to store all the project jars, libraries, plugins and any artifacts
related to project.
1. Local Repository
Is a local folder/directory on your machine (where we have installed or running
maven)
The default location of maven local repository is HOME_DIRECTORY/.m2
directory
.m2 is created whenever we run mvn command for the first time.
2. Central Repository
Maven central repository is managed by maven community and it contains large
number commonly used libraries.
We can also publish our own libraries to central repository.
The default location is https://repo1.maven.org/maven2
Ant Maven
Ant doesn't has formal Maven has a convention to place
conventions, so we need to provide source code, compiled code etc. So
information of the project structure we don't need to provide
in build.xml file. information about the project
structure in pom.xml file.
Ant is procedural, you need to Maven is declarative, everything
provide information about what to you define in the pom.xml file.
do and when to do through code.
You need to provide order.
There is no life cycle in Ant. There is life cycle in Maven.
It is a tool box. It is a framework.
It is mainly a build tool. It is mainly a project management
tool.
The ant scripts are not reusable. The maven plugins are reusable.
It is less preferred than Maven. It is more preferred than Ant.