diff --git a/bootstrap b/bootstrap index 0fbd4b5..dc68b4d 100644 --- a/bootstrap +++ b/bootstrap @@ -4,19 +4,4 @@ if [ ! -d "m4" ]; then mkdir m4 fi -export COG=$(command -v cog) -[ -z "$COG"] && export COG=$(command -v cog.py) - -if [ -z "$COG" ]; then - echo "Please install the Cog code generator, probably with pip install cogapp" - return 1 -fi - -echo "cog found at $COG" -for cogfile in $(find src -name "*.cog"); do - decogged=${cogfile%.cog} - echo "greasing cog for ${decogged}..." - $COG -d -o ${decogged} ${cogfile} -done - autoreconf --install diff --git a/cogrc b/cogrc new file mode 100644 index 0000000..252f51d --- /dev/null +++ b/cogrc @@ -0,0 +1,3 @@ +[version] +release=no +release_version=0.3 diff --git a/configure.ac b/configure.ac index 02b226a..ee8ffda 100644 --- a/configure.ac +++ b/configure.ac @@ -6,6 +6,16 @@ AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CXX AX_CXX_COMPILE_STDCXX_11 +AC_PATH_PROG([COG], [cog], [not found]) +if test "$COG" == "not found" ; then + AC_PATH_PROG([COGPY], [cog.py], [not found]) + if test "$COGPY" == "not found" ; then + AC_MSG_ERROR(["Please install the Cog code generator, probably via "pip install cogapp"]) + fi + COG="$COGPY" + AC_SUBST(COG) +fi + AX_BOOST_BASE([1.63], , [AC_MSG_ERROR([boost 1.63 required])]) AX_BOOST_SYSTEM AX_BOOST_FILESYSTEM diff --git a/src/Makefile.am b/src/Makefile.am index 45cfe27..71a330d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,12 @@ bin_PROGRAMS = cellar cellar_CPPFLAGS = $(BOOST_CPPFLAGS) cellar_LDFLAGS = $(BOOST_LDFLAGS) $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) -cellar_SOURCES = cellar.cpp fs.cpp bottles.cpp commands.cpp version.cpp +cellar_SOURCES = cellar.cpp fs.cpp bottles.cpp commands.cpp + +# Generated files +nodist_cellar_SOURCES = version.cpp + +CLEANFILES = version.cpp + +version.cpp: + $(COG) -d -o version.cpp version.cpp.cog diff --git a/src/version.cpp.cog b/src/version.cpp.cog index e808cb6..34cc24d 100644 --- a/src/version.cpp.cog +++ b/src/version.cpp.cog @@ -1,15 +1,44 @@ // vim: filetype=cpp : +#include +#include "commands.hpp" #include "version.hpp" +using namespace std; +using namespace cellar::version; + string cellar::version::short_version() { /*[[[cog import cog - import os + import configparser + import datetime - print(os.getcwd()) + today = datetime.datetime.today() - cog.outl("return \"dummy cog file!\";") + cparse = configparser.ConfigParser() + cparse.read("../cogrc") + config = cparse["version"] + + if config.getboolean("release"): + outstring = "version {0}, built {1}".format(config["release_version"], str(today)) + else: + try: + import subprocess + cmdoutput = subprocess.check_output(["git", "symbolic-ref", "HEAD"]).decode().strip() + gitbranch = cmdoutput.split("/")[2] + + githash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip() + outstring = "{0} {1}, built {2}".format(gitbranch, githash, str(today)) + except: + outstring = "exception raised when trying to read git data at precompile time" + raise + + cog.outl("return \"{0}\";".format(outstring)) ]]]*/ //[[[end]]] } + +void print_version(int argc, char** argv) { + cout << short_version() << endl; +} +bool _ = cellar::commands::add_command("version", &print_version);