Commit 1b2adaa6 authored by Jose A. Lopes's avatar Jose A. Lopes

Setup constant generation infrastructure

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: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent fec1fac1
......@@ -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
......@@ -240,6 +240,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
......@@ -266,6 +267,7 @@ built_base_sources = \
built_python_base_sources = \
lib/_autoconf.py \
lib/_constants.py \
lib/_vcsversion.py \
lib/opcodes.py
......@@ -549,7 +551,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 = \
......@@ -634,6 +636,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 \
......@@ -722,12 +725,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
......@@ -895,6 +900,22 @@ install-exec-hook:
done
endif
# This target cannot be merged with the '$(HS_ALL_PROGS)' target
# because 'hs2py-constants' cannot depend on 'Ganeti.Constants'. And
# the reason for this is because 'hs2py-constants' needs to generate
# Python code, and 'Ganeti.Constants' is generated by Python.
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
$(HS_ALL_PROGS): %: %.hs $(HS_LIBTESTBUILT_SRCS) Makefile
@if [ "$(notdir $@)" = "test" ] && [ "$(HS_NODEV)" ]; then \
echo "Error: cannot run unittests without the development" \
......@@ -1611,6 +1632,23 @@ 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' by extracting the left
## side of all lines containing an equal sign (i.e., '=') and
## prepending the apostrophe sign (i.e., "'").
##
## For example, the constant
## adminstDown = ...
## becomes
## 'adminstDown
NAMES=$$(sed -n -e "/=/ s/\(.*\) =.*/ '\1:/g p" \
$(abs_top_srcdir)/src/Ganeti/HsConstants.hs); \
m4 -DPY_CONSTANT_NAMES="$$NAMES" $(abs_top_srcdir)/$< > $@
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) \
......@@ -1716,6 +1754,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`; \
......
# 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).
"""
# pylint: disable=C0301,C0324
# because this is autogenerated, we do not want
# style warnings
{-| 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 ]
{-| 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"
{-| 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment