Skip to content

Commit

Permalink
Replace Makefile / make with sla (Simple Little Automator)
Browse files Browse the repository at this point in the history
  • Loading branch information
fboender committed Nov 25, 2018
1 parent c50e049 commit 48fda17
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 118 deletions.
110 changes: 0 additions & 110 deletions Makefile

This file was deleted.

167 changes: 167 additions & 0 deletions build.sla
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#
# This is a script containing functions that are used as build rules. You can
# use the Simple Little Automator (https://github.com/fboender/sla.git) to run
# these rules, or you can run them directly in your shell:
#
# $ bash -c ". build.sla && test"
#

PROG="ansible-cmdb"

test () {
# Run tests
OLD_PWD="$(pwd)"
cd test && ./test.sh
cd "$OLD_PWD"
example/generate.sh
}

example () {
# Generate example cmdb
PYTHONPATH=lib src/ansible-cmdb -q -i example/hosts example/out example/out_custom > cmdb.html
}

doc () {
# Generate documentation
markdown_py README.md > README.html
}

clean () {
# Remove build artifacts and other trash
rm -rf rel_deb
rm -f README.html
find ./ -name "*.pyc" -delete
find ./ -name "__pycache__" -type d -delete
rm -f example/gen_*
rm -rf example/cmdb/
rm -rf build/
rm -rf dist/
rm -rf src/ansible_cmdb.egg-info/
}

_release_check() {
# Verify and prepare for release

# Only run this rule once
if [ -z "$RELEASE_CHECK_DONE" ]; then
RELEASE_CHECK_DONE=1

# Prepare project for release
clean
doc
mkdir dist

# Check that REL_VERSION is set
if [ ! -z "$1" ]; then
REL_VERSION="$1"
shift
else
echo "REL_VERSION not set. Aborting" >&2
exit 1
fi

echo "$REL_VERSION" > src/ansiblecmdb/data/VERSION
fi
}

release_src () {
# Create release package (source tar.gz)
_release_check "$*"

# Cleanup. Only on release, since REL_VERSION doesn't exist otherwise
rm -rf $PROG-$REL_VERSION

# Prepare source
mkdir $PROG-$REL_VERSION
cp -a src/* $PROG-$REL_VERSION/
cp -r lib/* $PROG-$REL_VERSION/
cp LICENSE $PROG-$REL_VERSION/
cp README.md $PROG-$REL_VERSION/
cp contrib/release_Makefile $PROG-$REL_VERSION/Makefile
cp contrib/ansible-cmdb.man.1 $PROG-$REL_VERSION/

# Bump version numbers
find $PROG-$REL_VERSION/ -type f -print0 | xargs -0 sed -i "s/%%MASTER%%/$REL_VERSION/g"

# Create archives
zip -q -r dist/$PROG-$REL_VERSION.zip $PROG-$REL_VERSION
tar -czf dist/$PROG-$REL_VERSION.tar.gz $PROG-$REL_VERSION

# Remove source dir
rm -rf $PROG-$REL_VERSION
}

release_deb () {
# Create release package (debian / ubuntu)
_release_check "$*"

mkdir -p rel_deb/usr/bin
mkdir -p rel_deb/usr/lib/${PROG}
mkdir -p rel_deb/usr/share/doc/$PROG
mkdir -p rel_deb/usr/share/man/man1

# Copy the source to the release directory structure.
cp README.md rel_deb/usr/share/doc/$PROG/
cp README.html rel_deb/usr/share/doc/$PROG/
cp -r src/* rel_deb/usr/lib/${PROG}/
cp -r lib/* rel_deb/usr/lib/${PROG}/
ln -s ../lib/$PROG/ansible-cmdb rel_deb/usr/bin/ansible-cmdb
cp -a contrib/debian/DEBIAN rel_deb/
cp contrib/debian/copyright rel_deb/usr/share/doc/$PROG/
cp contrib/debian/changelog rel_deb/usr/share/doc/$PROG/
gzip -9 rel_deb/usr/share/doc/$PROG/changelog
cp -a contrib/ansible-cmdb.man.1 rel_deb/usr/share/man/man1/ansible-cmdb.1
gzip -9 rel_deb/usr/share/man/man1/ansible-cmdb.1

# Bump version numbers
find rel_deb/ -type f -print0 | xargs -0 sed -i "s/%%MASTER%%/$REL_VERSION/g"

# Create debian pacakge
fakeroot dpkg-deb --build rel_deb > /dev/null
mv rel_deb.deb dist/$PROG-$REL_VERSION.deb

# Cleanup
rm -rf rel_deb
rm -rf $PROG-$REL_VERSION
}

release_wheel () {
# Create release package (wheel)
_release_check "$*"

python setup.py -q bdist_wheel --universal
rm -rf build
echo `git rev-parse --abbrev-ref HEAD | tr "[:lower:]" "[:upper:]"` > src/ansiblecmdb/data/VERSION
}

release () {
# Create release packages
release_src "$*"
release_deb "$*"
release_wheel "$*"
}

install () {
# Install ansible-cmdb
PREFIX=${PREFIX:-/usr/local}
umask 0022 && mkdir -p $PREFIX/lib/$PROG
umask 0022 && mkdir -p $PREFIX/man/man1
umask 0022 && cp -a src/* $PREFIX/lib/$PROG
umask 0022 && cp -r lib/* $PREFIX/lib/$PROG
umask 0022 && cp LICENSE $PREFIX/lib/$PROG
umask 0022 && cp README.md $PREFIX/lib/$PROG
umask 0022 && gzip -9 -c contrib/ansible-cmdb.man.1 > $PREFIX/man/man1/ansible-cmdb.man.1.gz
if [ -f "$PREFIX/bin/ansible-cmdb" ]; then
rm "$PREFIX/bin/ansible-cmdb"
fi
umask 0022 && ln -s $PREFIX/lib/ansible-cmdb/ansible-cmdb $PREFIX/bin/ansible-cmdb
echo "Installed in $PREFIX/"
}

uninstall () {
# Uninstall ansible-cmdb
PREFIX=${PREFIX:-/usr/local}
rm -rf $PREFIX/lib/$PROG
rm -rf $PREFIX/man/man/ansible-cmdb*
rm -rf $PREFIX/bin/ansible-cmdb
}
33 changes: 26 additions & 7 deletions docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,32 @@ If you want to run ansible-cmdb directly from the Git repo:

# Building

## Make targets
## Build system

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

* `make test`: build some tests.
* `make release`: build a release.
* `make clean`: remove build and other artifacts.
You don't need to have `sla` installed`. You can run rules directly in your
shell. For example, to run the `test` rule:

$ . build.sla && test

Sla makes everything much easier though.

## Build targets

The following build targets are available:

- `test`: Run tests
- `example`: Generate example cmdb
- `doc`: Generate documentation
- `clean`: Remove build artifacts and other trash
- `release_src`: Create release package (source tar.gz)
- `release_deb`: Create release package (debian / ubuntu)
- `release_wheel`: Create release package (wheel)
- `release`: Create release packages
- `install`: Install ansible-cmdb
- `uninstall`: Uninstall ansible-cmdb

## Build packages and source-ball

Expand All @@ -76,9 +95,9 @@ dependencies:

You can then build the packages with

make release REL_VERSION=$VERSION
sla release <VERSION>

where `$VERSION` is a (arbitrary) version number.
where `VERSION` is a (arbitrary) version number.

In order to build releases, your repository will have to be completely clean:
everything must be commited and there must be no untracked files. If you want
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ Installation from **Git** repository:

git clone [email protected]:fboender/ansible-cmdb.git
cd ansible-cmdb
sudo make install
sudo bash -c ". build.sla && install"

0 comments on commit 48fda17

Please sign in to comment.