Skip to content

Commit 48fda17

Browse files
committed
Replace Makefile / make with sla (Simple Little Automator)
https://www.electricmonk.nl/log/2018/11/19/sla-the-simple-little-automator/
1 parent c50e049 commit 48fda17

File tree

4 files changed

+194
-118
lines changed

4 files changed

+194
-118
lines changed

Makefile

Lines changed: 0 additions & 110 deletions
This file was deleted.

build.sla

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#
2+
# This is a script containing functions that are used as build rules. You can
3+
# use the Simple Little Automator (https://github.com/fboender/sla.git) to run
4+
# these rules, or you can run them directly in your shell:
5+
#
6+
# $ bash -c ". build.sla && test"
7+
#
8+
9+
PROG="ansible-cmdb"
10+
11+
test () {
12+
# Run tests
13+
OLD_PWD="$(pwd)"
14+
cd test && ./test.sh
15+
cd "$OLD_PWD"
16+
example/generate.sh
17+
}
18+
19+
example () {
20+
# Generate example cmdb
21+
PYTHONPATH=lib src/ansible-cmdb -q -i example/hosts example/out example/out_custom > cmdb.html
22+
}
23+
24+
doc () {
25+
# Generate documentation
26+
markdown_py README.md > README.html
27+
}
28+
29+
clean () {
30+
# Remove build artifacts and other trash
31+
rm -rf rel_deb
32+
rm -f README.html
33+
find ./ -name "*.pyc" -delete
34+
find ./ -name "__pycache__" -type d -delete
35+
rm -f example/gen_*
36+
rm -rf example/cmdb/
37+
rm -rf build/
38+
rm -rf dist/
39+
rm -rf src/ansible_cmdb.egg-info/
40+
}
41+
42+
_release_check() {
43+
# Verify and prepare for release
44+
45+
# Only run this rule once
46+
if [ -z "$RELEASE_CHECK_DONE" ]; then
47+
RELEASE_CHECK_DONE=1
48+
49+
# Prepare project for release
50+
clean
51+
doc
52+
mkdir dist
53+
54+
# Check that REL_VERSION is set
55+
if [ ! -z "$1" ]; then
56+
REL_VERSION="$1"
57+
shift
58+
else
59+
echo "REL_VERSION not set. Aborting" >&2
60+
exit 1
61+
fi
62+
63+
echo "$REL_VERSION" > src/ansiblecmdb/data/VERSION
64+
fi
65+
}
66+
67+
release_src () {
68+
# Create release package (source tar.gz)
69+
_release_check "$*"
70+
71+
# Cleanup. Only on release, since REL_VERSION doesn't exist otherwise
72+
rm -rf $PROG-$REL_VERSION
73+
74+
# Prepare source
75+
mkdir $PROG-$REL_VERSION
76+
cp -a src/* $PROG-$REL_VERSION/
77+
cp -r lib/* $PROG-$REL_VERSION/
78+
cp LICENSE $PROG-$REL_VERSION/
79+
cp README.md $PROG-$REL_VERSION/
80+
cp contrib/release_Makefile $PROG-$REL_VERSION/Makefile
81+
cp contrib/ansible-cmdb.man.1 $PROG-$REL_VERSION/
82+
83+
# Bump version numbers
84+
find $PROG-$REL_VERSION/ -type f -print0 | xargs -0 sed -i "s/%%MASTER%%/$REL_VERSION/g"
85+
86+
# Create archives
87+
zip -q -r dist/$PROG-$REL_VERSION.zip $PROG-$REL_VERSION
88+
tar -czf dist/$PROG-$REL_VERSION.tar.gz $PROG-$REL_VERSION
89+
90+
# Remove source dir
91+
rm -rf $PROG-$REL_VERSION
92+
}
93+
94+
release_deb () {
95+
# Create release package (debian / ubuntu)
96+
_release_check "$*"
97+
98+
mkdir -p rel_deb/usr/bin
99+
mkdir -p rel_deb/usr/lib/${PROG}
100+
mkdir -p rel_deb/usr/share/doc/$PROG
101+
mkdir -p rel_deb/usr/share/man/man1
102+
103+
# Copy the source to the release directory structure.
104+
cp README.md rel_deb/usr/share/doc/$PROG/
105+
cp README.html rel_deb/usr/share/doc/$PROG/
106+
cp -r src/* rel_deb/usr/lib/${PROG}/
107+
cp -r lib/* rel_deb/usr/lib/${PROG}/
108+
ln -s ../lib/$PROG/ansible-cmdb rel_deb/usr/bin/ansible-cmdb
109+
cp -a contrib/debian/DEBIAN rel_deb/
110+
cp contrib/debian/copyright rel_deb/usr/share/doc/$PROG/
111+
cp contrib/debian/changelog rel_deb/usr/share/doc/$PROG/
112+
gzip -9 rel_deb/usr/share/doc/$PROG/changelog
113+
cp -a contrib/ansible-cmdb.man.1 rel_deb/usr/share/man/man1/ansible-cmdb.1
114+
gzip -9 rel_deb/usr/share/man/man1/ansible-cmdb.1
115+
116+
# Bump version numbers
117+
find rel_deb/ -type f -print0 | xargs -0 sed -i "s/%%MASTER%%/$REL_VERSION/g"
118+
119+
# Create debian pacakge
120+
fakeroot dpkg-deb --build rel_deb > /dev/null
121+
mv rel_deb.deb dist/$PROG-$REL_VERSION.deb
122+
123+
# Cleanup
124+
rm -rf rel_deb
125+
rm -rf $PROG-$REL_VERSION
126+
}
127+
128+
release_wheel () {
129+
# Create release package (wheel)
130+
_release_check "$*"
131+
132+
python setup.py -q bdist_wheel --universal
133+
rm -rf build
134+
echo `git rev-parse --abbrev-ref HEAD | tr "[:lower:]" "[:upper:]"` > src/ansiblecmdb/data/VERSION
135+
}
136+
137+
release () {
138+
# Create release packages
139+
release_src "$*"
140+
release_deb "$*"
141+
release_wheel "$*"
142+
}
143+
144+
install () {
145+
# Install ansible-cmdb
146+
PREFIX=${PREFIX:-/usr/local}
147+
umask 0022 && mkdir -p $PREFIX/lib/$PROG
148+
umask 0022 && mkdir -p $PREFIX/man/man1
149+
umask 0022 && cp -a src/* $PREFIX/lib/$PROG
150+
umask 0022 && cp -r lib/* $PREFIX/lib/$PROG
151+
umask 0022 && cp LICENSE $PREFIX/lib/$PROG
152+
umask 0022 && cp README.md $PREFIX/lib/$PROG
153+
umask 0022 && gzip -9 -c contrib/ansible-cmdb.man.1 > $PREFIX/man/man1/ansible-cmdb.man.1.gz
154+
if [ -f "$PREFIX/bin/ansible-cmdb" ]; then
155+
rm "$PREFIX/bin/ansible-cmdb"
156+
fi
157+
umask 0022 && ln -s $PREFIX/lib/ansible-cmdb/ansible-cmdb $PREFIX/bin/ansible-cmdb
158+
echo "Installed in $PREFIX/"
159+
}
160+
161+
uninstall () {
162+
# Uninstall ansible-cmdb
163+
PREFIX=${PREFIX:-/usr/local}
164+
rm -rf $PREFIX/lib/$PROG
165+
rm -rf $PREFIX/man/man/ansible-cmdb*
166+
rm -rf $PREFIX/bin/ansible-cmdb
167+
}

docs/dev.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,32 @@ If you want to run ansible-cmdb directly from the Git repo:
5252

5353
# Building
5454

55-
## Make targets
55+
## Build system
5656

57-
For building, `make` is used. Here are some useful targets:
57+
Ansible-cmdb uses [sla (the Simple Little
58+
Automator)](https://github.com/fboender/sla) to do builds and run tests.
5859

59-
* `make test`: build some tests.
60-
* `make release`: build a release.
61-
* `make clean`: remove build and other artifacts.
60+
You don't need to have `sla` installed`. You can run rules directly in your
61+
shell. For example, to run the `test` rule:
62+
63+
$ . build.sla && test
64+
65+
Sla makes everything much easier though.
66+
67+
## Build targets
68+
69+
The following build targets are available:
70+
71+
- `test`: Run tests
72+
- `example`: Generate example cmdb
73+
- `doc`: Generate documentation
74+
- `clean`: Remove build artifacts and other trash
75+
- `release_src`: Create release package (source tar.gz)
76+
- `release_deb`: Create release package (debian / ubuntu)
77+
- `release_wheel`: Create release package (wheel)
78+
- `release`: Create release packages
79+
- `install`: Install ansible-cmdb
80+
- `uninstall`: Uninstall ansible-cmdb
6281

6382
## Build packages and source-ball
6483

@@ -76,9 +95,9 @@ dependencies:
7695

7796
You can then build the packages with
7897

79-
make release REL_VERSION=$VERSION
98+
sla release <VERSION>
8099

81-
where `$VERSION` is a (arbitrary) version number.
100+
where `VERSION` is a (arbitrary) version number.
82101

83102
In order to build releases, your repository will have to be completely clean:
84103
everything must be commited and there must be no untracked files. If you want

docs/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ Installation from **Git** repository:
5959

6060
git clone git@github.com:fboender/ansible-cmdb.git
6161
cd ansible-cmdb
62-
sudo make install
62+
sudo bash -c ". build.sla && install"

0 commit comments

Comments
 (0)