Skip to content

Commit 46d1454

Browse files
committed
Merge pull request #299 from commercialhaskell/283-test-suite-fix
Test suite overhaul
2 parents 34ecae1 + 02e379e commit 46d1454

File tree

9 files changed

+441
-387
lines changed

9 files changed

+441
-387
lines changed

src/Control/Concurrent/Execute.hs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Control.Concurrent.Execute
1111
) where
1212

1313
import Control.Applicative
14-
import Control.Concurrent.Async (Concurrently (..))
14+
import Control.Concurrent.Async (Concurrently (..), async)
1515
import Control.Concurrent.STM
1616
import Control.Exception
1717
import Control.Monad (join)
@@ -24,8 +24,7 @@ import Stack.Types
2424

2525
data ActionType
2626
= ATBuild
27-
| ATInstall
28-
| ATWanted
27+
| ATFinal
2928
deriving (Show, Eq, Ord)
3029
data ActionId = ActionId !PackageIdentifier !ActionType
3130
deriving (Show, Eq, Ord)
@@ -36,15 +35,16 @@ data Action = Action
3635
}
3736

3837
data ActionContext = ActionContext
39-
{ acRemaining :: !Int
38+
{ acRemaining :: !(Set ActionId)
4039
-- ^ Does not include the current action
4140
}
4241
deriving Show
4342

4443
data ExecuteState = ExecuteState
4544
{ esActions :: TVar [Action]
4645
, esExceptions :: TVar [SomeException]
47-
, esInAction :: TVar Int
46+
, esInAction :: TVar (Set ActionId)
47+
, esCompleted :: TVar Int
4848
}
4949

5050
data ExecuteException
@@ -58,12 +58,15 @@ instance Show ExecuteException where
5858

5959
runActions :: Int -- ^ threads
6060
-> [Action]
61+
-> (TVar Int -> IO ()) -- ^ progress updated
6162
-> IO [SomeException]
62-
runActions threads actions0 = do
63+
runActions threads actions0 withProgress = do
6364
es <- ExecuteState
6465
<$> newTVarIO actions0
6566
<*> newTVarIO []
67+
<*> newTVarIO Set.empty
6668
<*> newTVarIO 0
69+
_ <- async $ withProgress $ esCompleted es
6770
if threads <= 1
6871
then runActions' es
6972
else runConcurrently $ sequenceA_ $ replicate threads $ Concurrently $ runActions' es
@@ -87,28 +90,32 @@ runActions' ExecuteState {..} =
8790
case break (Set.null . actionDeps) as of
8891
(_, []) -> do
8992
inAction <- readTVar esInAction
90-
if inAction == 0
93+
if Set.null inAction
9194
then do
9295
modifyTVar esExceptions (toException InconsistentDependencies:)
9396
return $ return ()
9497
else retry
9598
(xs, action:ys) -> do
9699
let as' = xs ++ ys
97100
inAction <- readTVar esInAction
98-
let remaining = length as' + inAction
101+
let remaining = Set.union
102+
(Set.fromList $ map actionId as')
103+
inAction
99104
writeTVar esActions as'
100-
modifyTVar esInAction (+ 1)
105+
modifyTVar esInAction (Set.insert $ actionId action)
101106
return $ mask $ \restore -> do
102107
eres <- try $ restore $ actionDo action ActionContext
103108
{ acRemaining = remaining
104109
}
105110
case eres of
106111
Left err -> atomically $ do
107112
modifyTVar esExceptions (err:)
108-
modifyTVar esInAction (subtract 1)
113+
modifyTVar esInAction (Set.delete $ actionId action)
114+
modifyTVar esCompleted (+1)
109115
Right () -> do
110116
atomically $ do
111-
modifyTVar esInAction (subtract 1)
117+
modifyTVar esInAction (Set.delete $ actionId action)
118+
modifyTVar esCompleted (+1)
112119
let dropDep a = a { actionDeps = Set.delete (actionId action) $ actionDeps a }
113120
modifyTVar esActions $ map dropDep
114121
restore loop

src/Stack/Build.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ build bopts = do
6262
constructPlan mbp baseConfigOpts locals extraToBuild locallyRegistered loadPackage sourceMap installedMap
6363

6464
if boptsDryrun bopts
65-
then printPlan plan
65+
then printPlan (boptsFinalAction bopts) plan
6666
else executePlan menv bopts baseConfigOpts locals plan
6767
where
6868
profiling = boptsLibProfile bopts || boptsExeProfile bopts

src/Stack/Build/Cache.hs

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module Stack.Build.Cache
77
( tryGetBuildCache
88
, tryGetConfigCache
9+
, tryGetCabalMod
910
, getPackageFileModTimes
1011
, getInstalledExes
1112
, buildCacheTimes
@@ -15,6 +16,7 @@ module Stack.Build.Cache
1516
, writeFlagCache
1617
, writeBuildCache
1718
, writeConfigCache
19+
, writeCabalMod
1820
) where
1921

2022
import Control.Exception.Enclosed (handleIO, tryIO)
@@ -25,16 +27,12 @@ import Control.Monad.Logger (MonadLogger)
2527
import Control.Monad.Reader
2628
import Data.Binary (Binary)
2729
import qualified Data.Binary as Binary
28-
import Data.ByteString (ByteString)
2930
import qualified Data.ByteString as S
3031
import qualified Data.ByteString.Lazy as L
3132
import Data.Map (Map)
3233
import qualified Data.Map as Map
3334
import Data.Maybe (catMaybes, mapMaybe)
34-
import Data.Set (Set)
3535
import qualified Data.Set as Set
36-
import Data.Text (Text)
37-
import Data.Text.Encoding (encodeUtf8)
3836
import GHC.Generics (Generic)
3937
import Path
4038
import Path.IO
@@ -93,6 +91,11 @@ tryGetConfigCache :: (MonadIO m, MonadReader env m, HasConfig env, MonadThrow m,
9391
=> Path Abs Dir -> m (Maybe ConfigCache)
9492
tryGetConfigCache = tryGetCache configCacheFile
9593

94+
-- | Try to read the mod time of the cabal file from the last build
95+
tryGetCabalMod :: (MonadIO m, MonadReader env m, HasConfig env, MonadThrow m, MonadLogger m, HasEnvConfig env)
96+
=> Path Abs Dir -> m (Maybe ModTime)
97+
tryGetCabalMod = tryGetCache configCabalMod
98+
9699
-- | Try to load a cache.
97100
tryGetCache :: (MonadIO m, Binary a, MonadReader env m, HasConfig env, MonadThrow m, MonadLogger m, HasEnvConfig env)
98101
=> (Path Abs Dir -> m (Path Abs File))
@@ -124,32 +127,25 @@ writeBuildCache dir times =
124127
-- | Write the dirtiness cache for this package's configuration.
125128
writeConfigCache :: (MonadIO m, MonadReader env m, HasConfig env, MonadThrow m, MonadLogger m, HasEnvConfig env)
126129
=> Path Abs Dir
127-
-> [Text]
128-
-> Set GhcPkgId -- ^ dependencies
129-
-> Path Abs file
130-
-> TaskType
130+
-> ConfigCache
131131
-> m ()
132-
writeConfigCache dir opts deps cabalfp ttype =
133-
do now <- liftIO (getModificationTime (toFilePath cabalfp))
134-
let cache = ConfigCache
135-
{ configCacheOpts = map encodeUtf8 opts
136-
, configCacheDeps = deps
137-
, configCabalFileModTime =
138-
case ttype of
139-
TTLocal lp _ | lpWanted lp -> Just (modTime now)
140-
_ -> Nothing
141-
}
142-
writeCache
143-
dir
144-
configCacheFile
145-
cache
132+
writeConfigCache dir = writeCache dir configCacheFile
133+
134+
-- | See 'tryGetCabalMod'
135+
writeCabalMod :: (MonadIO m, MonadReader env m, HasConfig env, MonadThrow m, MonadLogger m, HasEnvConfig env)
136+
=> Path Abs Dir
137+
-> ModTime
138+
-> m ()
139+
writeCabalMod dir = writeCache dir configCabalMod
146140

147141
-- | Delete the caches for the project.
148142
deleteCaches :: (MonadIO m, MonadReader env m, HasConfig env, MonadLogger m, MonadThrow m, HasEnvConfig env)
149143
=> Path Abs Dir -> m ()
150144
deleteCaches dir = do
145+
{- FIXME confirm that this is acceptable to remove
151146
bfp <- buildCacheFile dir
152147
removeFileIfExists bfp
148+
-}
153149
cfp <- configCacheFile dir
154150
removeFileIfExists cfp
155151

@@ -167,16 +163,19 @@ writeCache dir get' content = do
167163
(Binary.encode content))
168164

169165
flagCacheFile :: (MonadIO m, MonadThrow m, MonadReader env m, HasBuildConfig env)
170-
=> GhcPkgId
166+
=> Installed
171167
-> m (Path Abs File)
172-
flagCacheFile gid = do
173-
rel <- parseRelFile $ ghcPkgIdString gid
168+
flagCacheFile installed = do
169+
rel <- parseRelFile $
170+
case installed of
171+
Library gid -> ghcPkgIdString gid
172+
Executable ident -> packageIdentifierString ident
174173
dir <- flagCacheLocal
175174
return $ dir </> rel
176175

177176
-- | Loads the flag cache for the given installed extra-deps
178177
tryGetFlagCache :: (MonadIO m, MonadThrow m, MonadReader env m, HasBuildConfig env)
179-
=> GhcPkgId
178+
=> Installed
180179
-> m (Maybe ConfigCache)
181180
tryGetFlagCache gid = do
182181
file <- flagCacheFile gid
@@ -186,22 +185,11 @@ tryGetFlagCache gid = do
186185
_ -> return Nothing
187186

188187
writeFlagCache :: (MonadIO m, MonadReader env m, HasBuildConfig env, MonadThrow m)
189-
=> GhcPkgId
190-
-> [ByteString]
191-
-> Set GhcPkgId
192-
-> Path Abs File
193-
-> TaskType
188+
=> Installed
189+
-> ConfigCache
194190
-> m ()
195-
writeFlagCache gid flags deps cabalfp ttype = do
191+
writeFlagCache gid cache = do
196192
file <- flagCacheFile gid
197-
now <- liftIO $ getModificationTime (toFilePath cabalfp)
198-
let cache = ConfigCache
199-
{ configCacheOpts = flags
200-
, configCacheDeps = deps
201-
, configCabalFileModTime = case ttype of
202-
TTLocal lp _ | lpWanted lp -> Just (modTime now)
203-
_ -> Nothing
204-
}
205193
liftIO $ do
206194
createDirectoryIfMissing True $ toFilePath $ parent file
207195

0 commit comments

Comments
 (0)