From dc03e317b40d640e6501be0fce3e32bc29699fbb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 28 Feb 2015 12:20:03 -0400 Subject: Propellor now builds itself without needing the Makefile. --- src/Propellor/Bootstrap.hs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/Propellor/CmdLine.hs | 35 ++++++++++++++++++----------------- src/wrapper.hs | 12 +++++------- 3 files changed, 65 insertions(+), 24 deletions(-) create mode 100644 src/Propellor/Bootstrap.hs (limited to 'src') diff --git a/src/Propellor/Bootstrap.hs b/src/Propellor/Bootstrap.hs new file mode 100644 index 00000000..7ad4bb1f --- /dev/null +++ b/src/Propellor/Bootstrap.hs @@ -0,0 +1,42 @@ +module Propellor.Bootstrap ( + buildPropellor +) where + +import Propellor +import Utility.SafeCommand + +import System.Posix.Files + +buildPropellor :: IO () +buildPropellor = unlessM (actionMessage "Propellor build" build) $ + errorMessage "Propellor build failed!" + +-- Build propellor using cabal, and symlink propellor to where cabal +-- leaves the built binary. +-- +-- For speed, only runs cabal configure when it's not been run before. +-- If the build fails cabal may need to have configure re-run. +build :: IO Bool +build = catchBoolIO $ do + make "dist/setup-config" ["propellor.cabal"] $ + cabal ["configure"] + unlessM (cabal ["build"]) $ do + void $ cabal ["configure"] + unlessM (cabal ["build"]) $ + error "cabal build failed" + nukeFile "propellor" + createSymbolicLink "dist/build/propellor-config/propellor-config" "propellor" + return True + +make :: FilePath -> [FilePath] -> IO Bool -> IO () +make dest srcs builder = do + dt <- getmtime dest + st <- mapM getmtime srcs + when (dt == Nothing || any (> dt) st) $ + unlessM builder $ + error $ "failed to make " ++ dest + where + getmtime = catchMaybeIO . getModificationTime + +cabal :: [String] -> IO Bool +cabal = boolSystem "cabal" . map Param diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs index 15dc09c3..9d7d0d95 100644 --- a/src/Propellor/CmdLine.hs +++ b/src/Propellor/CmdLine.hs @@ -12,6 +12,7 @@ import qualified Network.BSD import Propellor import Propellor.Gpg import Propellor.Git +import Propellor.Bootstrap import Propellor.Spin import Propellor.Types.CmdLine import qualified Propellor.Property.Docker as Docker @@ -31,6 +32,7 @@ usage h = hPutStrLn h $ unlines , " propellor --edit field context" , " propellor --list-fields" , " propellor --merge" + , " propellor --build" ] usageError :: [String] -> IO a @@ -128,19 +130,16 @@ unknownhost h hosts = errorMessage $ unlines ] buildFirst :: CmdLine -> IO () -> IO () -buildFirst cmdline next = ifM (doesFileExist "Makefile") - ( do - oldtime <- getmtime - ifM (actionMessage "Propellor build" $ boolSystem "make" [Param "build"]) - ( do - newtime <- getmtime - if newtime == oldtime - then next - else void $ boolSystem "./propellor" [Param "--continue", Param (show cmdline)] - , errorMessage "Propellor build failed!" - ) - , next - ) +buildFirst cmdline next = do + oldtime <- getmtime + buildPropellor + newtime <- getmtime + if newtime == oldtime + then next + else void $ boolSystem "./propellor" + [ Param "--continue" + , Param (show cmdline) + ] where getmtime = catchMaybeIO $ getModificationTime "propellor" @@ -155,10 +154,12 @@ updateFirst cmdline next = ifM hasOrigin (updateFirst' cmdline next, next) updateFirst' :: CmdLine -> IO () -> IO () updateFirst' cmdline next = ifM fetchOrigin - ( ifM (actionMessage "Propellor build" $ boolSystem "make" [Param "build"]) - ( void $ boolSystem "./propellor" [Param "--continue", Param (show cmdline)] - , errorMessage "Propellor build failed!" - ) + ( do + buildPropellor + void $ boolSystem "./propellor" + [ Param "--continue" + , Param (show cmdline) + ] , next ) diff --git a/src/wrapper.hs b/src/wrapper.hs index 304e833d..034eb2bf 100644 --- a/src/wrapper.hs +++ b/src/wrapper.hs @@ -15,6 +15,7 @@ module Main where import Propellor.Message +import Propellor.Bootstrap import Utility.UserInfo import Utility.Monad import Utility.Process @@ -91,13 +92,10 @@ wrapper args propellordir propellorbin = do warnoutofdate propellordir True buildruncfg = do changeWorkingDirectory propellordir - ifM (boolSystem "make" [Param "build"]) - ( do - putStrLn "" - putStrLn "" - chain - , error "Propellor build failed." - ) + buildPropellor + putStrLn "" + putStrLn "" + chain chain = do (_, _, _, pid) <- createProcess (proc propellorbin args) exitWith =<< waitForProcess pid -- cgit v1.2.3