Build System#
make is one of the most commonly used build systems, and you will find that it is usually installed on almost all UNIX-based systems. make is not perfect, but it is good enough for small to medium-sized projects. When you execute make, it will refer to the file named Makefile in the current directory.
paper.pdf: paper.tex plot-data.png
pdflatex paper.tex
plot-%.png: %.dat plot.py
./plot.py -i $*.dat -o $@
The left side of the colon is the build target, and the right side is the dependencies required to build it. The indented part is a program segment used to build the target from the dependencies. In make, the first command also specifies the purpose of the build. If you use make without any parameters, this is our final build result. Alternatively, you can use the command make plot-data.png to build other targets.
$ cat paper.tex
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[scale=0.65]{plot-data.png}
\end{document}
$ cat plot.py
#!/usr/bin/env python
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-i', type=argparse.FileType('r'))
parser.add_argument('-o')
args = parser.parse_args()
data = np.loadtxt(args.i)
plt.plot(data[:, 0], data[:, 1])
plt.savefig(args.o)
$ cat data.dat
1 1
2 2
3 3
4 4
5 8
Dependency Management#
Continuous Integration Systems#
Exercises#
-
Most makefiles provide a build target called
clean, which does not mean that we generate a file namedclean, but that we can use it to clean files and let make rebuild them. You can think of it as "undoing" all the build steps. Implement acleantarget forpaper.pdfin the above makefile. You need to set the build target as phony. You may find thegit ls-filessubcommand useful. Other useful make build targets can be found here;paper.pdf: paper.tex plot-data.png pdflatex paper.tex plot-%.png: %.dat plot.py ./plot.py -i $*.dat -o $@ .PHONY: clean clean: Rm *. Pdf *. Aux *. Log *. Png #git ls-files -o | xargs rm -f ~$ cat makefile paper.pdf: paper.tex plot-data.png pdflatex paper.tex plot-%.png: %.dat plot.py ./plot.py -i $*.dat -o $@ .phony: clean clean: mkdir -p Untrack rm -f *~ .*~ git ls-files -o | grep -v Untrack | xargs -r mv -u -t Untrack ~$ cat .gitignore Untrack # Set git to ignore this directory, used to place untracked files -
There are many ways to specify version requirements. Let's learn about dependency management in the Rust build system. Most package management repositories support similar syntax. For each syntax (caret, tilde, wildcard, comparison, multiplication), build a scenario that makes sense;
-
Git can be used as a simple CI system. In the
.git/hooksdirectory of any git repository, you can find some files (currently inactive) that act like scripts and can be automatically executed when certain events occur. Write apre-commithook that executesmake paper.pdfbefore committing and rejects your commit if the build fails. This avoids committing versions that cannot be built; -
Create a page that can be automatically published based on GitHub Pages. Add a GitHub Action to the repository to execute
shellcheckon all shell files in the repository (one method); -
Build your own GitHub action to execute
proselintorwrite-goodon all.mdfiles in the repository. Enable this feature in your repository and submit a file with errors to see if it works.