Another attempt at fixing htools build without curl
authorIustin Pop <iustin@google.com>
Wed, 23 Mar 2011 15:06:50 +0000 (16:06 +0100)
committerIustin Pop <iustin@google.com>
Wed, 23 Mar 2011 16:35:12 +0000 (17:35 +0100)
OK, my previous small fix was not good. There is another issue: haddoc
(the documentation generator) needs to pass the same compiler options
(i.e. in our case, -DNO_CURL) to ghc. But in case of no curl, then it
shouldn't scan at all the RAPI library, as that is not used in our
builds.

Clearly, this is not a nice thing. So this patch changes from
including/excluding RAPI conditionally (in two places, the
ExtLoader.hs module and in hscan.hs), to always include RAPI, and
moves the curl/no curl login to RAPI itself, where it belongs.

Together with passing --optghc to haddock, this makes the builds
consistent both with and without RAPI. I also undo the removal of RAPI
from QC.hs.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

Makefile.am
htools/Ganeti/HTools/ExtLoader.hs
htools/Ganeti/HTools/QC.hs
htools/Ganeti/HTools/Rapi.hs
htools/hscan.hs

index eb6de4f..cb750fa 100644 (file)
@@ -1046,6 +1046,10 @@ hs-apidoc: $(HS_BUILT_SRCS)
        ln -s ../hscolour.css $(APIDOC_HS_DIR)/Ganeti/HTools/hscolour.css
        set -e ; \
        cd htools; \
        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; \
        RELSRCS="$(HS_LIB_SRCS:htools/%=%)"; \
        for file in $$RELSRCS; do \
                hfile=`echo $$file|sed 's/\\.hs$$//'`.html; \
@@ -1055,6 +1059,7 @@ hs-apidoc: $(HS_BUILT_SRCS)
                -t ganeti-htools -p haddock-prologue \
                --source-module="%{MODULE/.//}.html" \
                --source-entity="%{MODULE/.//}.html#%{NAME}" \
                -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
                $(filter-out Ganeti/HTools/ExtLoader.hs,$(HS_LIB_SRCS:htools/%=%))
 
 .PHONY: TAGS
index 0412c1b..9be8dc7 100644 (file)
@@ -1,5 +1,3 @@
-{-# LANGUAGE CPP #-}
-
 {-| External data loader
 
 This module holds the external data loading, and thus is the only one
 {-| External data loader
 
 This module holds the external data loading, and thus is the only one
@@ -10,7 +8,7 @@ libraries implementing the low-level protocols.
 
 {-
 
 
 {-
 
-Copyright (C) 2009, 2010 Google Inc.
+Copyright (C) 2009, 2010, 2011 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
 
 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
@@ -43,9 +41,7 @@ import System
 import Text.Printf (printf, hPrintf)
 
 import qualified Ganeti.HTools.Luxi as Luxi
 import Text.Printf (printf, hPrintf)
 
 import qualified Ganeti.HTools.Luxi as Luxi
-#ifndef NO_CURL
 import qualified Ganeti.HTools.Rapi as Rapi
 import qualified Ganeti.HTools.Rapi as Rapi
-#endif
 import qualified Ganeti.HTools.Simu as Simu
 import qualified Ganeti.HTools.Text as Text
 import Ganeti.HTools.Loader (mergeData, checkData, ClusterData(..)
 import qualified Ganeti.HTools.Simu as Simu
 import qualified Ganeti.HTools.Text as Text
 import Ganeti.HTools.Loader (mergeData, checkData, ClusterData(..)
@@ -109,12 +105,7 @@ loadExternalData opts = do
                      exitWith $ ExitFailure 1)
   input_data <-
       case () of
                      exitWith $ ExitFailure 1)
   input_data <-
       case () of
-        _ | setRapi ->
-#ifdef NO_CURL
-              return $ Bad "RAPI/curl backend disabled at compile time"
-#else
-              wrapIO $ Rapi.loadData mhost
-#endif
+        _ | setRapi -> wrapIO $ Rapi.loadData mhost
           | setLuxi -> wrapIO $ Luxi.loadData $ fromJust lsock
           | setSim -> Simu.loadData simdata
           | setFile -> wrapIO $ Text.loadData $ fromJust tfile
           | setLuxi -> wrapIO $ Luxi.loadData $ fromJust lsock
           | setSim -> Simu.loadData simdata
           | setFile -> wrapIO $ Text.loadData $ fromJust tfile
index 62b00c1..534a7b1 100644 (file)
@@ -58,6 +58,7 @@ import qualified Ganeti.HTools.Luxi
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Group as Group
 import qualified Ganeti.HTools.PeerMap as PeerMap
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Group as Group
 import qualified Ganeti.HTools.PeerMap as PeerMap
+import qualified Ganeti.HTools.Rapi
 import qualified Ganeti.HTools.Simu
 import qualified Ganeti.HTools.Text as Text
 import qualified Ganeti.HTools.Types as Types
 import qualified Ganeti.HTools.Simu
 import qualified Ganeti.HTools.Text as Text
 import qualified Ganeti.HTools.Types as Types
index 19aa817..1b0b9d2 100644 (file)
@@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
 -}
 
 
 -}
 
-{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE BangPatterns, CPP #-}
 
 module Ganeti.HTools.Rapi
     (
 
 module Ganeti.HTools.Rapi
     (
@@ -32,8 +32,10 @@ module Ganeti.HTools.Rapi
     ) where
 
 import Data.Maybe (fromMaybe)
     ) where
 
 import Data.Maybe (fromMaybe)
+#ifndef NO_CURL
 import Network.Curl
 import Network.Curl.Types ()
 import Network.Curl
 import Network.Curl.Types ()
+#endif
 import Control.Monad
 import Text.JSON (JSObject, JSValue, fromJSObject, decodeStrict)
 import Text.JSON.Types (JSValue(..))
 import Control.Monad
 import Text.JSON (JSObject, JSValue, fromJSObject, decodeStrict)
 import Text.JSON.Types (JSValue(..))
@@ -46,6 +48,14 @@ import qualified Ganeti.HTools.Group as Group
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
 
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
 
+-- | Read an URL via curl and return the body if successful.
+getUrl :: (Monad m) => String -> IO (m String)
+
+#ifdef NO_CURL
+getUrl _ = return $ fail "RAPI/curl backend disabled at compile time"
+
+#else
+
 -- | The curl options we use
 curlOpts :: [CurlOption]
 curlOpts = [ CurlSSLVerifyPeer False
 -- | The curl options we use
 curlOpts :: [CurlOption]
 curlOpts = [ CurlSSLVerifyPeer False
@@ -54,14 +64,13 @@ curlOpts = [ CurlSSLVerifyPeer False
            , CurlConnectTimeout (fromIntegral connTimeout)
            ]
 
            , CurlConnectTimeout (fromIntegral connTimeout)
            ]
 
--- | Read an URL via curl and return the body if successful.
-getUrl :: (Monad m) => String -> IO (m String)
 getUrl url = do
   (code, !body) <- curlGetString url curlOpts
   return (case code of
             CurlOK -> return body
             _ -> fail $ printf "Curl error for '%s', error %s"
                  url (show code))
 getUrl url = do
   (code, !body) <- curlGetString url curlOpts
   return (case code of
             CurlOK -> return body
             _ -> fail $ printf "Curl error for '%s', error %s"
                  url (show code))
+#endif
 
 -- | Append the default port if not passed in.
 formatHost :: String -> String
 
 -- | Append the default port if not passed in.
 formatHost :: String -> String
index 6960133..07ab657 100644 (file)
@@ -1,5 +1,3 @@
-{-# LANGUAGE CPP #-}
-
 {-| Scan clusters via RAPI or LUXI and write state data files.
 
 -}
 {-| Scan clusters via RAPI or LUXI and write state data files.
 
 -}
@@ -40,9 +38,7 @@ import qualified Ganeti.HTools.Container as Container
 import qualified Ganeti.HTools.Cluster as Cluster
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
 import qualified Ganeti.HTools.Cluster as Cluster
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
-#ifndef NO_CURL
 import qualified Ganeti.HTools.Rapi as Rapi
 import qualified Ganeti.HTools.Rapi as Rapi
-#endif
 import qualified Ganeti.HTools.Luxi as Luxi
 import Ganeti.HTools.Loader (checkData, mergeData, ClusterData(..))
 import Ganeti.HTools.Text (serializeCluster)
 import qualified Ganeti.HTools.Luxi as Luxi
 import Ganeti.HTools.Loader (checkData, mergeData, ClusterData(..))
 import Ganeti.HTools.Text (serializeCluster)
@@ -155,12 +151,6 @@ main = do
          result <- writeData nlen name opts input_data
          unless result $ exitWith $ ExitFailure 2
 
          result <- writeData nlen name opts input_data
          unless result $ exitWith $ ExitFailure 2
 
-#ifndef NO_CURL
   results <- mapM (\name -> Rapi.loadData name >>= writeData nlen name opts)
              clusters
   unless (all id results) $ exitWith (ExitFailure 2)
   results <- mapM (\name -> Rapi.loadData name >>= writeData nlen name opts)
              clusters
   unless (all id results) $ exitWith (ExitFailure 2)
-#else
-  when (not $ null clusters) $ do
-    putStrLn "RAPI/curl backend disabled at compile time, cannot scan clusters"
-    exitWith $ ExitFailure 1
-#endif