Cookbook: add an example of using default.do for text processing.
This commit is contained in:
parent
d663c9b67d
commit
3b305edc7e
18 changed files with 377 additions and 28 deletions
5
Documentation/cookbook/defaults/.gitignore
vendored
Normal file
5
Documentation/cookbook/defaults/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
date
|
||||
version
|
||||
include/version.h
|
||||
version.py
|
||||
test.txt
|
||||
2
Documentation/cookbook/defaults/all.do
Normal file
2
Documentation/cookbook/defaults/all.do
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
redo-ifchange test.txt version.py \
|
||||
test.py include/version.h
|
||||
2
Documentation/cookbook/defaults/clean.do
Normal file
2
Documentation/cookbook/defaults/clean.do
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
rm -f date version include/version.h \
|
||||
version.py test.txt *~ .*~
|
||||
3
Documentation/cookbook/defaults/date.do
Normal file
3
Documentation/cookbook/defaults/date.do
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
date +'%Y-%m-%d' >$3
|
||||
redo-always
|
||||
redo-stamp <$3
|
||||
25
Documentation/cookbook/defaults/default.do
Normal file
25
Documentation/cookbook/defaults/default.do
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# $1 is the target name, eg. test.txt
|
||||
# $2 in the same as $1. We'll talk about
|
||||
# that in a later example.
|
||||
# $3 is the temporary output file we should
|
||||
# create. If this script is successful,
|
||||
# redo will atomically replace $1 with $3.
|
||||
|
||||
if [ -e "$1.in" ]; then
|
||||
# if a .in file exists, then do some
|
||||
# text substitution.
|
||||
#
|
||||
# Remember, the user asks redo to build
|
||||
# a particular *target* name. It's the .do
|
||||
# file's job to figure out what source file(s)
|
||||
# to use to generate the target.
|
||||
redo-ifchange "$1.in" version date
|
||||
read VERSION <version
|
||||
read DATE <date
|
||||
sed -e "s/%VERSION%/$VERSION/g" \
|
||||
-e "s/%DATE%/$DATE/g" \
|
||||
<$1.in >$3
|
||||
else
|
||||
echo "$0: Fatal: don't know how to build '$1'" >&2
|
||||
exit 99
|
||||
fi
|
||||
8
Documentation/cookbook/defaults/include/version.h.in
Normal file
8
Documentation/cookbook/defaults/include/version.h.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// C/C++ header file identifying the current version
|
||||
#ifndef __VERSION_H
|
||||
#define __VERSION_H
|
||||
|
||||
#define VERSION "%VERSION%"
|
||||
#define DATE "%DATE%"
|
||||
|
||||
#endif // __VERSION_H
|
||||
6
Documentation/cookbook/defaults/test.py
Normal file
6
Documentation/cookbook/defaults/test.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
"""Test program for auto-generated version.py"""
|
||||
import version
|
||||
|
||||
print('Version %r has build date %r'
|
||||
% (version.VERSION, version.DATE))
|
||||
2
Documentation/cookbook/defaults/test.txt.in
Normal file
2
Documentation/cookbook/defaults/test.txt.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
This is the documentation for MyProgram version
|
||||
%VERSION%. It was generated on %DATE%.
|
||||
7
Documentation/cookbook/defaults/version.do
Normal file
7
Documentation/cookbook/defaults/version.do
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Try to get a version number from git, if possible.
|
||||
if ! git describe >$3; then
|
||||
echo "$0: Falling back to static version." >&2
|
||||
echo 'UNKNOWN' >$3
|
||||
fi
|
||||
redo-always
|
||||
redo-stamp <$3
|
||||
3
Documentation/cookbook/defaults/version.py.in
Normal file
3
Documentation/cookbook/defaults/version.py.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# python module identifying the current version
|
||||
VERSION='%VERSION%'
|
||||
DATE='%DATE%'
|
||||
Loading…
Add table
Add a link
Reference in a new issue