Skip to content

Commit

Permalink
Merge pull request #1431 from kadoban/flag_use_git_status_in_version
Browse files Browse the repository at this point in the history
add flag to allow disabling compile-time git status checks
  • Loading branch information
borsboom committed Nov 26, 2015
2 parents 0c1e070 + 4a8fa69 commit 6d2310f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
14 changes: 11 additions & 3 deletions src/Stack/Upgrade.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
{-# LANGUAGE TemplateHaskell #-}
module Stack.Upgrade (upgrade) where

import Control.Monad (when)
import Control.Monad.Catch
import Control.Monad.IO.Class
import Control.Monad.Logger
import Control.Monad.Reader (MonadReader, asks)
import Control.Monad.Trans.Control
import Data.Foldable (forM_)
import qualified Data.Map as Map
import Data.Maybe (isNothing)
import Data.Monoid ((<>))
import qualified Data.Monoid
import qualified Data.Set as Set
import qualified Data.Text as T
import Development.GitRev (gitHash)
import Network.HTTP.Client.Conduit (HasHttpManager)
import Path
import Path.IO
Expand All @@ -35,14 +36,21 @@ import System.Process.Run
upgrade :: (MonadIO m, MonadMask m, MonadReader env m, HasConfig env, HasHttpManager env, MonadLogger m, HasTerminal env, HasReExec env, HasLogLevel env, MonadBaseControl IO m)
=> Maybe String -- ^ git repository to use
-> Maybe AbstractResolver
-> Maybe String -- ^ git hash at time of building, if known
-> m ()
upgrade gitRepo mresolver = withCanonicalizedSystemTempDirectory "stack-upgrade" $ \tmp -> do
upgrade gitRepo mresolver builtHash =
withCanonicalizedSystemTempDirectory "stack-upgrade" $ \tmp -> do
menv <- getMinimalEnvOverride
mdir <- case gitRepo of
Just repo -> do
remote <- liftIO $ readProcess "git" ["ls-remote", repo, "master"] []
let latestCommit = head . words $ remote
if latestCommit == $gitHash then do
when (isNothing builtHash) $
$logWarn $ "Information about the commit this version of stack was "
<> "built from is not available due to how it was built. "
<> "Will continue by assuming an upgrade is needed "
<> "because we have no information to the contrary."
if builtHash == Just latestCommit then do
$logInfo "Already up-to-date, no upgrade required"
return Nothing
else do $logInfo "Cloning stack"
Expand Down
18 changes: 16 additions & 2 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import qualified Data.Text.IO as T
import Data.Traversable
import Data.Typeable (Typeable)
import Data.Version (showVersion)
import Development.GitRev (gitCommitCount)
#ifdef USE_GIT_INFO
import Development.GitRev (gitCommitCount, gitHash)
#endif
import Distribution.System (buildArch)
import Distribution.Text (display)
import GHC.IO.Encoding (mkTextEncoding, textEncodingName)
Expand All @@ -43,7 +45,9 @@ import Options.Applicative
import Options.Applicative.Args
import Options.Applicative.Builder.Extra
import Options.Applicative.Complicated
#ifdef USE_GIT_INFO
import Options.Applicative.Simple (simpleVersion)
#endif
import Options.Applicative.Types (readerAsk)
import Path
import Path.Extra (toFilePathNoTrailingSep)
Expand Down Expand Up @@ -114,6 +118,7 @@ main = withInterpreterArgs stackProgName $ \args isInterpreter -> do
dockerHelpOptName
(dockerOptsParser False)
("Only showing --" ++ Docker.dockerCmdName ++ "* options.")
#ifdef USE_GIT_INFO
let commitCount = $gitCommitCount
versionString' = concat $ concat
[ [$(simpleVersion Meta.version)]
Expand All @@ -123,6 +128,9 @@ main = withInterpreterArgs stackProgName $ \args isInterpreter -> do
commitCount /= ("UNKNOWN" :: String)]
, [" ", display buildArch]
]
#else
let versionString' = showVersion Meta.version ++ ' ' : display buildArch
#endif

let globalOpts hide =
extraHelpOption hide progName (Docker.dockerCmdName ++ "*") dockerHelpOptName <*>
Expand Down Expand Up @@ -797,7 +805,13 @@ updateCmd () go = withConfigAndLock go $

upgradeCmd :: (Bool, String) -> GlobalOpts -> IO ()
upgradeCmd (fromGit, repo) go = withConfigAndLock go $
upgrade (if fromGit then Just repo else Nothing) (globalResolver go)
upgrade (if fromGit then Just repo else Nothing)
(globalResolver go)
#ifdef USE_GIT_INFO
(find (/= "UNKNOWN") [$gitHash])
#else
Nothing
#endif

-- | Upload to Hackage
uploadCmd :: ([String], Maybe PvpBounds, Bool) -> GlobalOpts -> IO ()
Expand Down
16 changes: 13 additions & 3 deletions stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ flag integration-tests
default: False
description: Run the integration test suite

flag disable-git-info
manual: True
default: False
description: Disable compile-time inclusion of current git info in stack
-- disabling git info can lead to a quicker workflow in certain
-- scenarios when you're developing on stack itself, but
-- should otherwise be avoided
-- see: https://github.com/commercialhaskell/stack/issues/1425

library
hs-source-dirs: src/
ghc-options: -Wall
Expand Down Expand Up @@ -141,7 +150,6 @@ library
, filelock >= 0.1.0.1
, filepath >= 1.3.0.2
, fsnotify >= 0.2.1
, gitrev >= 1.1
, hashable >= 1.2.3.2
, hpc
, http-client >= 0.4.17
Expand Down Expand Up @@ -207,15 +215,13 @@ executable stack
, exceptions
, filepath
, filelock >= 0.1.0.1
, gitrev >= 1.1
, http-conduit >= 2.1.5
, lifted-base
, monad-control
, monad-logger >= 0.3.13.1
, mtl >= 2.1.3.1
, old-locale >= 1.0.0.6
, optparse-applicative >= 0.11.0.2
, optparse-simple >= 0.0.3
, path
, process
, resourcet >= 1.1.4.1
Expand All @@ -233,6 +239,10 @@ executable stack
if os(windows)
build-depends: Win32
cpp-options: -DWINDOWS
if !flag(disable-git-info)
cpp-options: -DUSE_GIT_INFO
build-depends: gitrev >= 1.1
, optparse-simple >= 0.0.3

test-suite stack-test
type: exitcode-stdio-1.0
Expand Down

0 comments on commit 6d2310f

Please sign in to comment.