hs-coverage: make a symlink hpc_index.html
[ganeti-local] / Makefile.am
index 490107e..6c1fe1d 100644 (file)
@@ -22,6 +22,8 @@ CHECK_NEWS = $(top_srcdir)/autotools/check-news
 DOCPP = $(top_srcdir)/autotools/docpp
 REPLACE_VARS_SED = autotools/replace_vars.sed
 
+# Note: these are automake-specific variables, and must be named after
+# the directory + 'dir' suffix
 clientdir = $(pkgpythondir)/client
 hypervisordir = $(pkgpythondir)/hypervisor
 httpdir = $(pkgpythondir)/http
@@ -33,11 +35,17 @@ watcherdir = $(pkgpythondir)/watcher
 impexpddir = $(pkgpythondir)/impexpd
 utilsdir = $(pkgpythondir)/utils
 toolsdir = $(pkglibdir)/tools
+iallocatorsdir = $(pkglibdir)/iallocators
 docdir = $(datadir)/doc/$(PACKAGE)
 
 # Delete output file if an error occurred while building it
 .DELETE_ON_ERROR:
 
+HTOOLS_DIRS = \
+       htools \
+       htools/Ganeti \
+       htools/Ganeti/HTools
+
 DIRS = \
        autotools \
        daemons \
@@ -46,6 +54,7 @@ DIRS = \
        doc/examples \
        doc/examples/hooks \
        doc/examples/gnt-debug \
+       $(HTOOLS_DIRS) \
        lib \
        lib/client \
        lib/build \
@@ -66,8 +75,14 @@ DIRS = \
 
 BUILDTIME_DIR_AUTOCREATE = \
        scripts \
-       doc/api \
-       doc/coverage
+       $(APIDOC_DIR) \
+       $(APIDOC_PY_DIR) \
+       $(APIDOC_HS_DIR) \
+       $(APIDOC_HS_DIR)/Ganeti $(APIDOC_HS_DIR)/Ganeti/HTools \
+       $(COVERAGE_DIR) \
+       $(COVERAGE_PY_DIR) \
+       $(COVERAGE_HS_DIR) \
+       .hpc
 
 BUILDTIME_DIRS = \
        $(BUILDTIME_DIR_AUTOCREATE) \
@@ -80,6 +95,14 @@ DIRCHECK_EXCLUDE = \
 
 all_dirfiles = $(addsuffix /.dir,$(DIRS) $(BUILDTIME_DIR_AUTOCREATE))
 
+# some helper vars
+COVERAGE_DIR = doc/coverage
+COVERAGE_PY_DIR = $(COVERAGE_DIR)/py
+COVERAGE_HS_DIR = $(COVERAGE_DIR)/hs
+APIDOC_DIR = doc/api
+APIDOC_PY_DIR = $(APIDOC_DIR)/py
+APIDOC_HS_DIR = $(APIDOC_DIR)/hs
+
 MAINTAINERCLEANFILES = \
        $(docpng) \
        $(maninput) \
@@ -93,6 +116,8 @@ maintainer-clean-local:
 
 CLEANFILES = \
        $(addsuffix /*.py[co],$(DIRS)) \
+       $(addsuffix /*.hi,$(HTOOLS_DIRS)) \
+       $(addsuffix /*.o,$(HTOOLS_DIRS)) \
        $(all_dirfiles) \
        $(PYTHON_BOOTSTRAP) \
        epydoc.conf \
@@ -111,7 +136,10 @@ CLEANFILES = \
        $(manhtml) \
        tools/kvm-ifup \
        stamp-srclinks \
-       $(nodist_pkgpython_PYTHON)
+       $(nodist_pkgpython_PYTHON) \
+       $(HS_ALL_PROGS) $(HS_BUILT_SRCS) \
+       .hpc/*.mix htools/*.tix \
+       doc/hs-lint.html
 
 # BUILT_SOURCES should only be used as a dependency on phony targets. Otherwise
 # it'll cause the target to rebuild every time.
@@ -245,6 +273,10 @@ docrst = \
        doc/design-draft.rst \
        doc/design-oob.rst \
        doc/design-query2.rst \
+       doc/design-x509-ca.rst \
+       doc/design-http-server.rst \
+       doc/design-impexp2.rst \
+       doc/design-lu-generated-jobs.rst \
        doc/cluster-merge.rst \
        doc/design-shared-storage.rst \
        doc/devnotes.rst \
@@ -262,6 +294,46 @@ docrst = \
        doc/upgrade.rst \
        doc/walkthrough.rst
 
+HS_PROGS = \
+       htools/hbal \
+       htools/hscan \
+       htools/hail \
+       htools/hspace
+
+HS_ALL_PROGS = $(HS_PROGS) htools/test
+HS_PROG_SRCS = $(patsubst %,%.hs,$(HS_ALL_PROGS))
+# we don't add -Werror by default
+HFLAGS = -O -Wall -fwarn-monomorphism-restriction -fwarn-tabs -ihtools
+# extra flags that can be overriden on the command line
+HEXTRA =
+# exclude options for coverage reports
+HPCEXCL = --exclude Main --exclude Ganeti.HTools.QC
+
+HS_LIB_SRCS = \
+       htools/Ganeti/HTools/CLI.hs \
+       htools/Ganeti/HTools/Cluster.hs \
+       htools/Ganeti/HTools/Container.hs \
+       htools/Ganeti/HTools/ExtLoader.hs \
+       htools/Ganeti/HTools/Group.hs \
+       htools/Ganeti/HTools/IAlloc.hs \
+       htools/Ganeti/HTools/Instance.hs \
+       htools/Ganeti/HTools/Loader.hs \
+       htools/Ganeti/HTools/Luxi.hs \
+       htools/Ganeti/HTools/Node.hs \
+       htools/Ganeti/HTools/PeerMap.hs \
+       htools/Ganeti/HTools/QC.hs \
+       htools/Ganeti/HTools/Rapi.hs \
+       htools/Ganeti/HTools/Simu.hs \
+       htools/Ganeti/HTools/Text.hs \
+       htools/Ganeti/HTools/Types.hs \
+       htools/Ganeti/HTools/Utils.hs \
+       htools/Ganeti/Jobs.hs \
+       htools/Ganeti/Luxi.hs \
+       htools/Ganeti/OpCodes.hs
+
+HS_BUILT_SRCS = htools/Ganeti/HTools/Version.hs
+HS_BUILT_SRCS_IN = $(patsubst %,%.in,$(HS_BUILT_SRCS))
+
 $(RUN_IN_TEMPDIR): | $(all_dirfiles)
 
 # Note: we use here an order-only prerequisite, as the contents of
@@ -356,6 +428,25 @@ qa_scripts = \
        qa/qa_tags.py \
        qa/qa_utils.py
 
+bin_SCRIPTS =
+iallocators_SCRIPTS =
+if WANT_HTOOLS
+bin_SCRIPTS += $(filter-out htools/hail,$(HS_PROGS))
+iallocators_SCRIPTS += $(filter htools/hail,$(HS_PROGS))
+endif
+
+$(HS_ALL_PROGS): %: %.hs $(HS_LIB_SRCS) $(HS_BUILT_SRCS) Makefile
+       BINARY=$(@:htools/%=%); \
+       $(GHC) --make \
+         $(HFLAGS) $(HEXTRA) $(HTOOLS_NOCURL) \
+         -osuf $$BINARY.o -hisuf $$BINARY.hi \
+         $@
+
+# for the htools/test binary, we need to enable profiling/coverage
+htools/test: HEXTRA=-fhpc -Wwarn -fno-warn-missing-signatures \
+       -fno-warn-monomorphism-restriction -fno-warn-orphans \
+       -fno-warn-missing-methods -fno-warn-unused-imports
+
 dist_sbin_SCRIPTS = \
        tools/ganeti-listrunner
 
@@ -429,7 +520,9 @@ EXTRA_DIST = \
        $(manrst) \
        $(maninput) \
        qa/qa-sample.json \
-       $(qa_scripts)
+       $(qa_scripts) \
+       $(HS_LIB_SRCS) $(HS_BUILT_SRCS_IN) \
+       $(HS_PROG_SRCS)
 
 man_MANS = \
        man/ganeti.7 \
@@ -536,6 +629,8 @@ python_tests = \
        test/docs_unittest.py \
        test/tempfile_fork_unittest.py
 
+haskell_tests = htools/test
+
 dist_TESTS = \
        test/check-cert-expired_unittest.bash \
        test/daemon-util_unittest.bash \
@@ -544,6 +639,9 @@ dist_TESTS = \
        $(python_tests)
 
 nodist_TESTS =
+if WANT_HTOOLS
+nodist_TESTS += $(haskell_tests)
+endif
 
 TESTS = $(dist_TESTS) $(nodist_TESTS)
 
@@ -580,7 +678,8 @@ srclink_files = \
        test/daemon-util_unittest.bash \
        test/ganeti-cleaner_unittest.bash \
        test/import-export_unittest.bash \
-       $(all_python_code)
+       $(all_python_code) \
+       $(HS_LIB_SRCS) $(HS_PROG_SRCS)
 
 check_python_code = \
        $(BUILD_BASH_COMPLETION) \
@@ -686,6 +785,11 @@ regen-vcs-version:
          $(MAKE) vcs-version; \
        fi
 
+htools/Ganeti/HTools/Version.hs: htools/Ganeti/HTools/Version.hs.in vcs-version
+       set -e; \
+       VCSVER=`cat $(abs_top_srcdir)/vcs-version`; \
+       sed -e "s/%ver%/$$VCSVER/" < $< > $@
+
 lib/_autoconf.py: Makefile vcs-version | lib/.dir
        set -e; \
        VCSVER=`cat $(abs_top_srcdir)/vcs-version`; \
@@ -854,6 +958,11 @@ lint: $(BUILT_SOURCES)
          PYTHONPATH=$(abs_top_srcdir) $(PYLINT) $(LINT_OPTS) \
          --rcfile  ../pylintrc $(patsubst qa/%.py,%,$(qa_scripts))
 
+.PHONY: hlint
+hlint: $(HS_BUILT_SRCS)
+       if tty -s; then C="-c"; else C=""; fi; \
+       hlint --report=doc/hs-lint.html $$C htools
+
 # a dist hook rule for updating the vcs-version file; this is
 # hardcoded due to where it needs to build the file...
 dist-hook:
@@ -913,10 +1022,45 @@ install-exec-local:
        @mkdir_p@ $* && touch $@
 
 .PHONY: apidoc
-apidoc: epydoc.conf $(RUN_IN_TEMPDIR) $(BUILT_SOURCES)
+if WANT_HTOOLSAPIDOC
+apidoc: py-apidoc hs-apidoc
+else
+apidoc: py-apidoc
+endif
+
+.PHONY: py-apidoc
+py-apidoc: epydoc.conf $(RUN_IN_TEMPDIR) $(BUILT_SOURCES)
        $(RUN_IN_TEMPDIR) epydoc -v \
                --conf $(CURDIR)/epydoc.conf \
-               --output $(CURDIR)/doc/api
+               --output $(CURDIR)/$(APIDOC_PY_DIR)
+
+.PHONY: hs-apidoc
+hs-apidoc: $(HS_BUILT_SRCS)
+       @test -n "$(HSCOLOUR)" || \
+           { echo 'HsColour' not found during configure; exit 1; }
+       @test -n "$(HADDOCK)" || \
+           { echo 'haddock' not found during configure; exit 1; }
+       rm -rf $(APIDOC_HS_DIR)/*
+       @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/HTools
+       $(HSCOLOUR) -print-css > $(APIDOC_HS_DIR)/Ganeti/hscolour.css
+       ln -s ../hscolour.css $(APIDOC_HS_DIR)/Ganeti/HTools/hscolour.css
+       set -e ; \
+       cd htools; \
+       if [ "$(HTOOLS_NOCURL)" ]; \
+       then OPTGHC="--optghc=$(HTOOLS_NOCURL)"; \
+       else OPTGHC=""; \
+       fi; \
+       RELSRCS="$(HS_LIB_SRCS:htools/%=%)"; \
+       for file in $$RELSRCS; do \
+               hfile=`echo $$file|sed 's/\\.hs$$//'`.html; \
+               $(HSCOLOUR) -css -anchor $$file > ../$(APIDOC_HS_DIR)/$$hfile ; \
+       done ; \
+       $(HADDOCK) --odir ../$(APIDOC_HS_DIR) --html --ignore-all-exports -w \
+               -t ganeti-htools -p haddock-prologue \
+               --source-module="%{MODULE/.//}.html" \
+               --source-entity="%{MODULE/.//}.html#%{NAME}" \
+               $$OPTGHC \
+               $(filter-out Ganeti/HTools/ExtLoader.hs,$(HS_LIB_SRCS:htools/%=%))
 
 .PHONY: TAGS
 TAGS: $(BUILT_SOURCES)
@@ -927,14 +1071,45 @@ TAGS: $(BUILT_SOURCES)
          etags -l python -
 
 .PHONY: coverage
-coverage: $(BUILT_SOURCES) $(python_tests)
+if WANT_HTOOLS
+coverage: py-coverage hs-coverage
+else
+coverage: py-coverage
+endif
+
+.PHONY: py-coverage
+py-coverage: $(BUILT_SOURCES) $(python_tests)
        set -e; \
-       COVERAGE_FILE=$(CURDIR)/doc/coverage/data \
-       TEXT_COVERAGE=$(CURDIR)/doc/coverage/report.txt \
-       HTML_COVERAGE=$(CURDIR)/doc/coverage \
+       COVERAGE_FILE=$(CURDIR)/$(COVERAGE_PY_DIR)/data \
+       TEXT_COVERAGE=$(CURDIR)/$(COVERAGE_PY_DIR)/report.txt \
+       HTML_COVERAGE=$(CURDIR)/$(COVERAGE_PY_DIR) \
        $(PLAIN_TESTS_ENVIRONMENT) $(abs_top_srcdir)/autotools/gen-coverage \
        $(python_tests)
 
+.PHONY: hs-coverage
+hs-coverage: $(haskell_tests)
+       cd htools && rm -f *.tix *.mix && ./test
+       mkdir -p $(COVERAGE_HS_DIR)
+       hpc markup --destdir=$(COVERAGE_HS_DIR) htools/test $(HPCEXCL)
+       hpc report htools/test $(HPCEXCL)
+       ln -s hpc_index.html $(COVERAGE_HS_DIR)/index.html
+
+# Special "kind-of-QA" target for htools, needs special setup (all
+# tools compiled with -fhpc)
+.PHONY: live-test
+live-test: all
+       set -e ; \
+       cd htools; \
+       rm -f .hpc; ln -s ../.hpc .hpc; \
+       rm -f *.tix *.mix; \
+       ./live-test.sh; \
+       hpc sum --union $(HPCEXCL) $(addsuffix .tix,$(HS_PROGS:htools/%=%)) \
+         --output=live-test.tix ; \
+       @mkdir_p@ ../$(COVERAGE_HS_DIR) ; \
+       hpc markup --destdir=../$(COVERAGE_HS_DIR) live-test \
+               --srcdir=.. $(HPCEXCL) ; \
+       hpc report --srcdir=.. live-test $(HPCEXCL)
+
 commit-check: distcheck lint apidoc
 
 -include ./Makefile.local