Skip to content

Commit

Permalink
Merge branch 'master' into 805-enable-tests-whenever-possible
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Aug 19, 2015
2 parents 251d5b1 + b763b0e commit 8cbf096
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ install:
- cabal --version
- echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
- travis_retry cabal update
- cabal install --only-dependencies --enable-tests --enable-benchmarks --force-reinstalls --ghc-options=-O0
- cabal install --only-dependencies --enable-tests --enable-benchmarks --force-reinstalls --ghc-options="-O0 -Werror"

script:
- if [ -f configure.ac ]; then autoreconf -i; fi
- cabal configure --enable-tests --enable-benchmarks -v2 --ghc-options=-O0 # -v2 provides useful information for debugging
- cabal configure --enable-tests --enable-benchmarks -v2 --ghc-options="-O0 -Werror" # -v2 provides useful information for debugging
- cabal build # this builds all libraries and executables (including tests/benchmarks)
- cabal test
- cabal check
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased changes

* Added the `--docker-env` argument, to set environment variables in Docker container.

## 0.1.3.1

Major changes:
Expand Down
1 change: 0 additions & 1 deletion src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ getSetupExe setupHs tmpdir = do
liftIO $ D.createDirectoryIfMissing True $ toFilePath setupDir

menv <- getMinimalEnvOverride
wc <- getWhichCompiler
let args =
[ "-clear-package-db"
, "-global-package-db"
Expand Down
17 changes: 16 additions & 1 deletion src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,22 @@ loadSourceMap needTargets bopts = do

-- Overwrite any flag settings with those from the config file
extraDeps3 = Map.mapWithKey
(\n (v, f) -> PSUpstream v Local $ fromMaybe f $ Map.lookup n $ bcFlags bconfig)
(\n (v, f) -> PSUpstream v Local $
case ( Map.lookup (Just n) $ boptsFlags bopts
, Map.lookup Nothing $ boptsFlags bopts
, Map.lookup n $ bcFlags bconfig
) of
-- Didn't have any flag overrides, fall back to the flags
-- defined in the snapshot.
(Nothing, Nothing, Nothing) -> f
-- Either command line flag for this package, general
-- command line flag, or flag in stack.yaml is defined.
-- Take all of those and ignore the snapshot flags.
(x, y, z) -> Map.unions
[ fromMaybe Map.empty x
, fromMaybe Map.empty y
, fromMaybe Map.empty z
])
extraDeps2

let sourceMap = Map.unions
Expand Down
2 changes: 2 additions & 0 deletions src/Stack/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ runContainerAndExit modConfig
,concatMap (\(k,v) -> ["-e", k ++ "=" ++ v]) envVars
,concatMap sandboxSubdirArg sandboxSubdirs
,concatMap mountArg (dockerMount docker)
,concatMap (\nv -> ["-e", nv]) (dockerEnv docker)
,case dockerContainerName docker of
Just name -> ["--name=" ++ name]
Nothing -> []
Expand Down Expand Up @@ -677,6 +678,7 @@ dockerOptsFromMonoid mproject stackRoot DockerOptsMonoid{..} = DockerOpts
,dockerContainerName = emptyToNothing dockerMonoidContainerName
,dockerRunArgs = dockerMonoidRunArgs
,dockerMount = dockerMonoidMount
,dockerEnv = dockerMonoidEnv
,dockerDatabasePath =
case dockerMonoidDatabasePath of
Nothing -> stackRoot </> $(mkRelFile "docker.db")
Expand Down
9 changes: 7 additions & 2 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ ghciSetup
-> [Text]
-> m (Map PackageName SimpleTarget, Maybe (Map PackageName SimpleTarget), [GhciPkgInfo])
ghciSetup mainIs stringTargets = do
(_,_,targets) <- parseTargetsFromBuildOpts AllowNoTargets defaultBuildOpts
(_,_,targets) <-
parseTargetsFromBuildOpts
AllowNoTargets
defaultBuildOpts
{ boptsTargets = stringTargets
}
mainIsTargets <-
case mainIs of
Nothing -> return Nothing
Expand Down Expand Up @@ -187,7 +192,7 @@ ghciSetup mainIs stringTargets = do
forM locals $
\(name,(cabalfp,components)) ->
makeGhciPkgInfo sourceMap (map fst locals) name cabalfp components
build (const (return ())) Nothing bopts
unless (M.null realTargets) (build (const (return ())) Nothing bopts)
return (realTargets, mainIsTargets, infos)
where
makeBuildOpts targets =
Expand Down
7 changes: 6 additions & 1 deletion src/Stack/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ dockerOptsParser showOptions =
hide <>
metavar "(PATH | HOST-PATH:CONTAINER-PATH)" <>
help ("Mount volumes from host in container " ++
"(may specify mutliple times)")))
"(may specify multiple times)")))
<*> many (option str (long (dockerOptName dockerEnvArgName) <>
hide <>
metavar "NAME=VALUE" <>
help ("Set environment variable in container " ++
"(may specify multiple times)")))
<*> maybeStrOption (long (dockerOptName dockerDatabasePathArgName) <>
hide <>
metavar "PATH" <>
Expand Down
11 changes: 11 additions & 0 deletions src/Stack/Types/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ data DockerOpts = DockerOpts
-- ^ Arguments to pass directly to @docker run@.
,dockerMount :: ![Mount]
-- ^ Volumes to mount in the container.
,dockerEnv :: ![String]
-- ^ Environment variables to set in the container.
,dockerDatabasePath :: !(Path Abs File)
-- ^ Location of image usage database.
}
Expand Down Expand Up @@ -70,6 +72,8 @@ data DockerOptsMonoid = DockerOptsMonoid
-- ^ Arguments to pass directly to @docker run@
,dockerMonoidMount :: ![Mount]
-- ^ Volumes to mount in the container
,dockerMonoidEnv :: ![String]
-- ^ Environment variables to set in the container
,dockerMonoidDatabasePath :: !(Maybe String)
-- ^ Location of image usage database.
}
Expand All @@ -92,6 +96,7 @@ instance FromJSON (DockerOptsMonoid, [JSONWarning]) where
dockerMonoidContainerName <- o ..:? dockerContainerNameArgName
dockerMonoidRunArgs <- o ..:? dockerRunArgsArgName ..!= []
dockerMonoidMount <- o ..:? dockerMountArgName ..!= []
dockerMonoidEnv <- o ..:? dockerEnvArgName ..!= []
dockerMonoidDatabasePath <- o ..:? dockerDatabasePathArgName
return DockerOptsMonoid{..})

Expand All @@ -110,6 +115,7 @@ instance Monoid DockerOptsMonoid where
,dockerMonoidContainerName = Nothing
,dockerMonoidRunArgs = []
,dockerMonoidMount = []
,dockerMonoidEnv = []
,dockerMonoidDatabasePath = Nothing
}
mappend l r = DockerOptsMonoid
Expand All @@ -125,6 +131,7 @@ instance Monoid DockerOptsMonoid where
,dockerMonoidContainerName = dockerMonoidContainerName l <|> dockerMonoidContainerName r
,dockerMonoidRunArgs = dockerMonoidRunArgs r <> dockerMonoidRunArgs l
,dockerMonoidMount = dockerMonoidMount r <> dockerMonoidMount l
,dockerMonoidEnv = dockerMonoidEnv r <> dockerMonoidEnv l
,dockerMonoidDatabasePath = dockerMonoidDatabasePath l <|> dockerMonoidDatabasePath r
}

Expand Down Expand Up @@ -195,6 +202,10 @@ dockerRunArgsArgName = "run-args"
dockerMountArgName :: Text
dockerMountArgName = "mount"

-- | Docker environment variable argument name.
dockerEnvArgName :: Text
dockerEnvArgName = "env"

-- | Docker container name argument name.
dockerContainerNameArgName :: Text
dockerContainerNameArgName = "container-name"
Expand Down
2 changes: 2 additions & 0 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Traversable
import Distribution.System (buildArch)
import Development.GitRev (gitCommitCount)
import Network.HTTP.Client
import Options.Applicative.Args
Expand Down Expand Up @@ -149,6 +150,7 @@ main = withInterpreterArgs stackProgName $ \args isInterpreter -> do
-- Leave out number of commits for --depth=1 clone
-- See https://github.com/commercialhaskell/stack/issues/792
, [" (" ++ $gitCommitCount ++ " commits)" | $gitCommitCount /= ("1"::String)]
, [" ", show buildArch]
]
eGlobalRun <- try $
simpleOptions
Expand Down
1 change: 1 addition & 0 deletions stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ executable stack

build-depends: base >=4.7 && < 5
, bytestring >= 0.10.4.0
, Cabal
, containers
, exceptions
, filepath
Expand Down

0 comments on commit 8cbf096

Please sign in to comment.