On Tue, Aug 27, 2013 at 3:40 PM, Jose A. Lopes <[email protected]> wrote:
> From: "Jose A. Lopes" <[email protected]>
>
> Setup a transitional Haskell to Python constant generation
> infrastructure. This infrastructure is transitional and Python
> constants will not be migrated to Haskell all at once. Instead, some
> constants will be incrementally pulled from Python and moved to
> Haskell. This is a list of the relevant modules in this
> infrastructure:
>
> * Ganeti.HsConstants: contains the Haskell constants that are used
> both in Haskell (once re-exported through Ganeti.Constants) and
> generated in Python
>
> * Ganety.Hs2Py.ListConstants: contains the list of Haskell constants
> to be generated in Python; these constants are defined in the
> previous module and the list is automatically generated by the
> Makefile
>
> * hs2py-constants: Haskell program that outputs the actual constant
> definitions in Python; this task cannot be performed by 'hs2py' just
> yet because this programs depends on the 'Constants' module. But
> once all the constants have migrated to Haskell, then
> 'hs2py-constants' and 'hs2py' can be merged.
>
> Signed-off-by: Jose A. Lopes <[email protected]>
> ---
> .gitignore | 3 +++
> Makefile.am | 42
> +++++++++++++++++++++++++++++++++++-
> lib/_constants.py.in | 15 +++++++++++++
> src/Ganeti/Hs2Py/ListConstants.hs.in | 38 ++++++++++++++++++++++++++++++++
> src/Ganeti/HsConstants.hs | 41 +++++++++++++++++++++++++++++++++++
> src/hs2py-constants.hs | 31 ++++++++++++++++++++++++++
> 6 files changed, 169 insertions(+), 1 deletion(-)
> create mode 100644 lib/_constants.py.in
> create mode 100644 src/Ganeti/Hs2Py/ListConstants.hs.in
> create mode 100644 src/Ganeti/HsConstants.hs
> create mode 100644 src/hs2py-constants.hs
>
> diff --git a/.gitignore b/.gitignore
> index ded2efb..9ac726b 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -77,6 +77,7 @@
>
> # lib
> /lib/_autoconf.py
> +/lib/_constants.py
> /lib/_vcsversion.py
> /lib/_generated_rpc.py
> /lib/opcodes.py
> @@ -130,6 +131,7 @@
> /src/hconfd
> /src/hluxid
> /src/hs2py
> +/src/hs2py-constants
> /src/ganeti-confd
> /src/ganeti-luxid
> /src/ganeti-mond
> @@ -137,6 +139,7 @@
>
> # automatically-built Haskell files
> /src/Ganeti/Curl/Internal.hs
> +/src/Ganeti/Hs2Py/ListConstants.hs
> /src/Ganeti/PyConstants.hs
> /src/Ganeti/Version.hs
> /test/hs/Test/Ganeti/TestImports.hs
> diff --git a/Makefile.am b/Makefile.am
> index 1839857..ef6f278 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -218,6 +218,7 @@ CLEANFILES = \
> src/ganeti-confd \
> src/ganeti-luxid \
> src/ganeti-mond \
> + src/hs2py-constants \
> .hpc/*.mix src/*.tix test/hs/*.tix \
> doc/hs-lint.html
>
> @@ -244,6 +245,7 @@ built_base_sources = \
>
> built_python_base_sources = \
> lib/_autoconf.py \
> + lib/_constants.py \
> lib/_vcsversion.py \
> lib/opcodes.py
>
> @@ -526,7 +528,7 @@ HS_ALL_PROGS = \
> test/hs/htest \
> $(HS_COMPILE_PROGS)
>
> -HS_PROG_SRCS = $(patsubst %,%.hs,$(HS_ALL_PROGS))
> +HS_PROG_SRCS = $(patsubst %,%.hs,$(HS_ALL_PROGS)) src/hs2py-constants.hs
^
> HS_BUILT_TEST_HELPERS = $(HS_BIN_ROLES:%=test/hs/%) test/hs/hail
>
> HFLAGS = \
> @@ -611,6 +613,7 @@ HS_LIB_SRCS = \
> src/Ganeti/Hs2Py/GenConstants.hs \
> src/Ganeti/Hs2Py/GenOpCodes.hs \
> src/Ganeti/Hs2Py/OpDoc.hs \
> + src/Ganeti/HsConstants.hs \
> src/Ganeti/JQueue.hs \
> src/Ganeti/JSON.hs \
> src/Ganeti/Jobs.hs \
> @@ -699,12 +702,14 @@ HS_LIBTEST_SRCS = $(HS_LIB_SRCS) $(HS_TEST_SRCS)
>
> HS_BUILT_SRCS = \
> test/hs/Test/Ganeti/TestImports.hs \
> + src/Ganeti/Hs2Py/ListConstants.hs \
> src/Ganeti/PyConstants.hs \
> src/Ganeti/Curl/Internal.hs \
> src/Ganeti/Version.hs
> HS_BUILT_SRCS_IN = \
> $(patsubst %,%.in,$(filter-out
> src/Ganeti/Curl/Internal.hs,$(HS_BUILT_SRCS))) \
> src/Ganeti/Curl/Internal.hsc \
> + lib/_constants.py.in \
> lib/opcodes.py.in_after \
> lib/opcodes.py.in_before
>
> @@ -872,6 +877,18 @@ install-exec-hook:
> done
> endif
>
> +src/hs2py-constants: src/hs2py-constants.hs src/Ganeti/BasicTypes.hs \
> + src/Ganeti/JSON.hs src/Ganeti/THH.hs \
> + src/Ganeti/Hs2Py/GenConstants.hs \
> + src/Ganeti/Hs2Py/ListConstants.hs \
> + src/Ganeti/HsConstants.hs \
> + src/Ganeti/PyValueInstances.hs \
> + | stamp-srclinks
> + $(GHC) --make \
> + $(HFLAGS) \
> + -osuf $(notdir $@).o -hisuf $(notdir $@).hi \
> + $(HEXTRA) $(HEXTRA_INT) src/hs2py-constants.hs
> +
This and HS_PROG_SRCS above are good just because this is going away soon. :)
> $(HS_ALL_PROGS): %: %.hs $(HS_LIBTESTBUILT_SRCS) Makefile
> @if [ "$(notdir $@)" = "test" ] && [ "$(HS_NODEV)" ]; then \
> echo "Error: cannot run unittests without the development" \
> @@ -1573,6 +1590,22 @@ src/Ganeti/Version.hs: src/Ganeti/Version.hs.in \
> VCSVER=`cat $(abs_top_srcdir)/vcs-version`; \
> sed -e "s/%ver%/$$VCSVER/" < $< > $@
>
> +src/Ganeti/Hs2Py/ListConstants.hs: src/Ganeti/Hs2Py/ListConstants.hs.in \
> + src/Ganeti/HsConstants.hs \
> + | stamp-directories
> + @echo Generating $@
> + @set -e; \
> +## Extract constant names from 'HsConstants.hs'
> +## For example, the constant
> +## adminstDown = ...
> +## becomes
> +## 'adminstDown
> + NAMES=`cat $(abs_top_srcdir)/src/Ganeti/HsConstants.hs \
> + | grep "=" | sed -e "s/\(.*\) =.*/ '\1:/g"`; \
> + m4 -DPY_CONSTANT_NAMES="$$NAMES" \
> + $(abs_top_srcdir)/$< \
> + > $@
> +
$(...) and not ` `
Also: Ouch! Any way to make it slightly more beautiful? Or should we
have a small script that does it instead of grep + sed + m4?
(or maybe we can have fewer commands and optimize it a bit?)
> src/Ganeti/PyConstants.hs: src/Ganeti/PyConstants.hs.in \
> lib/constants.py lib/_autoconf.py lib/luxi.py lib/errors.py \
> lib/jstore.py $(RUN_IN_TEMPDIR) \
> @@ -1678,6 +1711,13 @@ lib/_autoconf.py: Makefile | stamp-directories
> echo "}"; \
> } > $@
>
> +lib/_constants.py: Makefile lib/_constants.py.in src/hs2py-constants \
> + | stamp-directories
> + cat $(abs_top_srcdir)/lib/_constants.py.in > $@
> + src/hs2py-constants >> $@
> +
> +lib/constants.py: lib/_constants.py
> +
> lib/_vcsversion.py: Makefile vcs-version | stamp-directories
> set -e; \
> VCSVER=`cat $(abs_top_srcdir)/vcs-version`; \
> diff --git a/lib/_constants.py.in b/lib/_constants.py.in
> new file mode 100644
> index 0000000..e0c7a7b
> --- /dev/null
> +++ b/lib/_constants.py.in
> @@ -0,0 +1,15 @@
> +# This file is automatically generated, do not edit!
> +#
> +
> +"""Automatically generated constants for Python
> +
> +This file is autogenerated by the build process.
> +For any changes you need to re-run ./configure (and
> +not edit by hand).
./configure and make ?
> +
> +"""
> +
> +# pylint: disable=C0301,C0324
> +# because this is autogenerated, we do not want
> +# style warnings
> +
> diff --git a/src/Ganeti/Hs2Py/ListConstants.hs.in
> b/src/Ganeti/Hs2Py/ListConstants.hs.in
> new file mode 100644
> index 0000000..7f319e2
> --- /dev/null
> +++ b/src/Ganeti/Hs2Py/ListConstants.hs.in
> @@ -0,0 +1,38 @@
> +{-| Contains the list of the Haskell to Python constants.
> +
> +-}
> +
> +{-
> +
> +Copyright (C) 2013 Google Inc.
> +
> +This program is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 2 of the License, or
> +(at your option) any later version.
> +
> +This program is distributed in the hope that it will be useful, but
> +WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with this program; if not, write to the Free Software
> +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> +02110-1301, USA.
> +
> +-}
> +{-# LANGUAGE TemplateHaskell #-}
> +module Ganeti.Hs2Py.ListConstants where
> +
> +import Ganeti.Hs2Py.GenConstants
> +import Ganeti.HsConstants
> +import Ganeti.PyValueInstances ()
> +
> +$(genPyConstants "pyConstants"
> + (
> +PY_CONSTANT_NAMES[]))
> +
> +putConstants :: IO ()
> +putConstants =
> + sequence_ [ putStrLn (k ++ " = " ++ v) | (k, v) <- pyConstants ]
> diff --git a/src/Ganeti/HsConstants.hs b/src/Ganeti/HsConstants.hs
> new file mode 100644
> index 0000000..10832df
> --- /dev/null
> +++ b/src/Ganeti/HsConstants.hs
> @@ -0,0 +1,41 @@
> +{-| HsConstants contains the Haskell constants
> +
> +This is a transitional module complementary to 'Ganeti.Constants'. It
> +is intended to contain the Haskell constants that are meant to be
> +generated in Python.
> +
> +-}
> +
> +{-
> +
> +Copyright (C) 2013 Google Inc.
> +
> +This program is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 2 of the License, or
> +(at your option) any later version.
> +
> +This program is distributed in the hope that it will be useful, but
> +WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with this program; if not, write to the Free Software
> +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> +02110-1301, USA.
> +
> +-}
> +module Ganeti.HsConstants where
> +
> +-- | Admin states
> +adminstDown :: String
> +adminstDown = "down"
> +
> +-- | Admin states
> +adminstOffline :: String
> +adminstOffline = "offline"
> +
> +-- | Admin states
> +adminstUp :: String
> +adminstUp = "up"
> diff --git a/src/hs2py-constants.hs b/src/hs2py-constants.hs
> new file mode 100644
> index 0000000..9eea997
> --- /dev/null
> +++ b/src/hs2py-constants.hs
> @@ -0,0 +1,31 @@
> +{-| hs2py-constants
> +
> +This program outputs the all the converted Haskell to Python
> +constants.
> +
> +-}
> +
> +{-
> +
> +Copyright (C) 2013 Google Inc.
> +
> +This program is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 2 of the License, or
> +(at your option) any later version.
> +
> +This program is distributed in the hope that it will be useful, but
> +WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with this program; if not, write to the Free Software
> +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> +02110-1301, USA.
> +
> +-}
> +import Ganeti.Hs2Py.ListConstants
> +
> +main :: IO ()
> +main = putConstants
rest LGTM
Thanks,
Guido