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 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Propellor/Bootstrap.hs (limited to 'src/Propellor/Bootstrap.hs') 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 -- cgit v1.3-2-g0d8e From e26c232d154eb1a6b6eca631414ed7526993f88c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 28 Feb 2015 12:50:28 -0400 Subject: avoid using the makefile when bootstrapping with --spin --- Makefile | 15 +++++-------- debian/changelog | 3 ++- src/Propellor/Bootstrap.hs | 53 +++++++++++++++++++++++++++++++++++++++++++++- src/Propellor/Spin.hs | 5 +++-- 4 files changed, 62 insertions(+), 14 deletions(-) (limited to 'src/Propellor/Bootstrap.hs') diff --git a/Makefile b/Makefile index d706d8ef..acd70a5f 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,12 @@ CABAL?=cabal -DEBDEPS=gnupg ghc cabal-install libghc-missingh-dev libghc-ansi-terminal-dev libghc-ifelse-dev libghc-unix-compat-dev libghc-hslogger-dev libghc-network-dev libghc-quickcheck2-dev libghc-mtl-dev libghc-monadcatchio-transformers-dev - -# this target is provided to keep old versions of the propellor cron job -# working, and will eventually be removed -run: deps build +# this target is provided (and is first) to keep old versions of the +# propellor cron job working, and will eventually be removed +run: build ./propellor dev: build tags -deps: - @if [ $$(whoami) = root ]; then apt-get --no-upgrade --no-install-recommends -y install $(DEBDEPS) || (apt-get update && apt-get --no-upgrade --no-install-recommends -y install $(DEBDEPS)); fi || true - @if [ $$(whoami) = root ]; then apt-get --no-upgrade --no-install-recommends -y install libghc-async-dev || (cabal update; cabal install async); fi || true - install: propellor.1 install -d $(DESTDIR)/usr/bin $(DESTDIR)/usr/src/propellor install -s dist/build/propellor/propellor $(DESTDIR)/usr/bin/propellor @@ -50,7 +44,8 @@ hackage: .PHONY: tags # The rules below are only used when bootstrapping new propellor -# installations; propellor contains equivilant haksell code. +# installations and building packages; propellor contains equivilant +# haskell code that it uses to re-build itself. build: dist/setup-config @if ! $(CABAL) build; then $(CABAL) configure; $(CABAL) build; fi diff --git a/debian/changelog b/debian/changelog index ca7452a3..5dc849dd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,7 +4,8 @@ propellor (2.2.0) UNRELEASED; urgency=medium improve process name visible in ps. * Add shebang to cron.daily etc files. * Some changes to tor configuration, minor API change. - * Propellor now builds itself without needing the Makefile. + * Propellor now builds itself, and gets its build dependencies installed + when deploying to a new host, without needing the Makefile. -- Joey Hess Mon, 16 Feb 2015 19:00:48 -0400 diff --git a/src/Propellor/Bootstrap.hs b/src/Propellor/Bootstrap.hs index 7ad4bb1f..0b3072b2 100644 --- a/src/Propellor/Bootstrap.hs +++ b/src/Propellor/Bootstrap.hs @@ -1,11 +1,62 @@ module Propellor.Bootstrap ( - buildPropellor + bootstrapPropellorCommand, + installGitCommand, + buildPropellor, ) where import Propellor import Utility.SafeCommand import System.Posix.Files +import Data.List + +type ShellCommand = String + +-- Shell command line to build propellor, used when bootstrapping on a new +-- host. Should be run inside the propellor source tree, and will install +-- all necessary build dependencies. +bootstrapPropellorCommand :: ShellCommand +bootstrapPropellorCommand = "if ! test -x ./propellor; then " ++ go ++ "; fi" + where + go = intercalate " && " + [ depsCommand + , buildCommand + ] + +buildCommand :: ShellCommand +buildCommand = intercalate " && " + [ "cabal configure" + , "cabal build" + , "ln -sf dist/build/propellor-config/propellor-config propellor" + ] + +depsCommand :: ShellCommand +depsCommand = "(" ++ aptinstall debdeps ++ " || (apt-get update && " ++ aptinstall debdeps ++ ")) || true;" + ++ "(" ++ aptinstall ["libghc-async-dev"] ++ " || (cabal update; cabal install async)) || true" + where + aptinstall ps = "apt-get --no-upgrade --no-install-recommends -y install " ++ unwords ps + + -- This is the same build deps listed in debian/control. + debdeps = + [ "gnupg" + , "ghc" + , "cabal-install" + -- async is not available in debian stable + -- , "libghc-async-dev" + , "libghc-missingh-dev" + , "libghc-hslogger-dev" + , "libghc-unix-compat-dev" + , "libghc-ansi-terminal-dev" + , "libghc-ifelse-dev" + , "libghc-network-dev" + , "libghc-quickcheck2-dev" + , "libghc-mtl-dev" + , "libghc-monadcatchio-transformers-dev" + ] + + +installGitCommand :: ShellCommand +installGitCommand = "if ! git --version >/dev/null; then apt-get update && apt-get --no-install-recommends --no-upgrade -y install git; fi" buildPropellor :: IO () buildPropellor = unlessM (actionMessage "Propellor build" build) $ diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 5063145e..f55f2977 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -24,6 +24,7 @@ import Propellor.PrivData.Paths import Propellor.Git import Propellor.Ssh import Propellor.Gpg +import Propellor.Bootstrap import Propellor.Types.CmdLine import qualified Propellor.Shim as Shim import Utility.FileMode @@ -69,7 +70,7 @@ spin target relay hst = do probecmd = intercalate " ; " [ "if [ ! -d " ++ localdir ++ "/.git ]" , "then (" ++ intercalate " && " - [ "if ! git --version || ! make --version; then apt-get update && apt-get --no-install-recommends --no-upgrade -y install git make; fi" + [ installGitCommand , "echo " ++ toMarked statusMarker (show NeedGitClone) ] ++ ") || echo " ++ toMarked statusMarker (show NeedPrecompiled) , "else " ++ updatecmd @@ -78,7 +79,7 @@ spin target relay hst = do updatecmd = intercalate " && " [ "cd " ++ localdir - , "if ! test -x ./propellor; then make deps build; fi" + , bootstrapPropellorCommand , if viarelay then "./propellor --continue " ++ shellEscape (show (Relay target)) -- cgit v1.3-2-g0d8e From 42c1106ea0926be314e3d7d40b953f8d93950483 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 28 Feb 2015 12:57:20 -0400 Subject: support installing build deps using pure cabal, rather than debian packages for non-debian systems --- src/Propellor/Bootstrap.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Propellor/Bootstrap.hs') diff --git a/src/Propellor/Bootstrap.hs b/src/Propellor/Bootstrap.hs index 0b3072b2..45340832 100644 --- a/src/Propellor/Bootstrap.hs +++ b/src/Propellor/Bootstrap.hs @@ -31,11 +31,15 @@ buildCommand = intercalate " && " ] depsCommand :: ShellCommand -depsCommand = "(" ++ aptinstall debdeps ++ " || (apt-get update && " ++ aptinstall debdeps ++ ")) || true;" - ++ "(" ++ aptinstall ["libghc-async-dev"] ++ " || (cabal update; cabal install async)) || true" +depsCommand = + "(" ++ aptinstall debdeps ++ " || (apt-get update && " ++ aptinstall debdeps ++ ")) && " + ++ "(" ++ aptinstall ["libghc-async-dev"] ++ " || (" ++ cabalinstall ["async"] ++ ")) || " + ++ "(" ++ cabalinstall ["--only-dependencies"] ++ ")" where aptinstall ps = "apt-get --no-upgrade --no-install-recommends -y install " ++ unwords ps + cabalinstall ps = "cabal update; cabal install " ++ unwords ps + -- This is the same build deps listed in debian/control. debdeps = [ "gnupg" -- cgit v1.3-2-g0d8e