diff --git a/Makefile b/Makefile deleted file mode 100644 index e6c63eb..0000000 --- a/Makefile +++ /dev/null @@ -1,110 +0,0 @@ -.PHONY: doc test example -PROG=ansible-cmdb - -fake: - # NOOP - -test: - cd test && ./test.sh - example/generate.sh - -example: - PYTHONPATH=lib src/ansible-cmdb -q -i example/hosts example/out example/out_custom > cmdb.html - -doc: - markdown_py README.md > README.html - -clean: - rm -rf rel_deb - rm -f *.deb - rm -f *.tar.gz - rm -f *.zip - rm -f *.whl - 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: - @echo "Making release for version $(REL_VERSION)" - @if [ -z "$(REL_VERSION)" ]; then echo "REL_VERSION required"; exit 1; fi - echo "$(REL_VERSION)" > src/ansiblecmdb/data/VERSION - -release: release_check release_src release_deb release_wheel - -release_src: release_check clean doc - # 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 $(PROG)-$(REL_VERSION).zip $(PROG)-$(REL_VERSION) - tar -czf $(PROG)-$(REL_VERSION).tar.gz $(PROG)-$(REL_VERSION) - -release_deb: release_check clean doc - 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 $(PROG)-$(REL_VERSION).deb - - # Cleanup - rm -rf rel_deb - rm -rf $(PROG)-$(REL_VERSION) - -release_wheel: release_check clean - echo "$(REL_VERSION)" > src/ansiblecmdb/data/VERSION - python setup.py bdist_wheel --universal - mv dist/*.whl . - rmdir dist - rm -rf build - echo `git rev-parse --abbrev-ref HEAD | tr "[:lower:]" "[:upper:]"` > src/ansiblecmdb/data/VERSION - -install: - umask 0022 && mkdir -p /usr/local/lib/$(PROG) - umask 0022 && mkdir -p /usr/local/man/man1 - umask 0022 && cp -a src/* /usr/local/lib/$(PROG) - umask 0022 && cp -r lib/* /usr/local/lib/$(PROG) - umask 0022 && cp LICENSE /usr/local/lib/$(PROG) - umask 0022 && cp README.md /usr/local/lib/$(PROG) - umask 0022 && gzip -9 -c contrib/ansible-cmdb.man.1 > /usr/local/man/man1/ansible-cmdb.man.1.gz - umask 0022 && ln -s /usr/local/lib/ansible-cmdb/ansible-cmdb /usr/local/bin/ansible-cmdb - -uninstall: - rm -rf /usr/local/lib/$(PROG) - rm -rf /usr/local/man/man/ansible-cmdb* - rm -rf /usr/local/bin/ansible-cmdb diff --git a/build.sla b/build.sla new file mode 100644 index 0000000..c3b7e91 --- /dev/null +++ b/build.sla @@ -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 +} diff --git a/docs/dev.md b/docs/dev.md index d60f8a6..3f3f8ac 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -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 @@ -76,9 +95,9 @@ dependencies: You can then build the packages with - make release REL_VERSION=$VERSION + sla release -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 diff --git a/docs/installation.md b/docs/installation.md index 555b1f1..abb9a8a 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -59,4 +59,4 @@ Installation from **Git** repository: git clone git@github.com:fboender/ansible-cmdb.git cd ansible-cmdb - sudo make install + sudo bash -c ". build.sla && install"