Skip to content

Commit 1bbed48

Browse files
authored
Merge pull request #4412 from commercialhaskell/new-build-plan
New build plan construction with source maps
2 parents 88a07ab + cc7bfd6 commit 1bbed48

File tree

39 files changed

+1488
-899
lines changed

39 files changed

+1488
-899
lines changed

package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ library:
230230
- Stack.Sig.Sign
231231
- Stack.Snapshot
232232
- Stack.Solver
233+
- Stack.SourceMap
233234
- Stack.StoreTH
234235
- Stack.Types.Build
235236
- Stack.Types.BuildPlan
@@ -249,6 +250,7 @@ library:
249250
- Stack.Types.Resolver
250251
- Stack.Types.Runner
251252
- Stack.Types.Sig
253+
- Stack.Types.SourceMap
252254
- Stack.Types.StylesUpdate
253255
- Stack.Types.TemplateName
254256
- Stack.Types.Version

snapshot.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ packages:
1616
- http-api-data-0.3.8.1@rev:1
1717
- cabal-doctest-1.0.6@rev:2
1818
- unliftio-0.2.8.0@sha256:5a47f12ffcee837215c67b05abf35dffb792096564a6f81652d75a54668224cd,2250
19+
- happy-1.19.9@sha256:f8c774230735a390c287b2980cfcd2703d24d8dde85a01ea721b7b4b4c82944f,4667
1920

2021
flags:
2122
cabal-install:

src/Stack/Build.hs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ import Stack.Build.Execute
3838
import Stack.Build.Haddock
3939
import Stack.Build.Installed
4040
import Stack.Build.Source
41-
import Stack.Build.Target
4241
import Stack.Package
4342
import Stack.Types.Build
4443
import Stack.Types.Config
4544
import Stack.Types.NamedComponent
4645
import Stack.Types.Package
46+
import Stack.Types.SourceMap
4747

4848
import Stack.Types.Compiler (compilerVersionText, getGhcVersion)
4949
import System.FileLock (FileLock, unlockFile)
@@ -57,39 +57,41 @@ import System.Terminal (fixCodePage)
5757
build :: HasEnvConfig env
5858
=> Maybe (Set (Path Abs File) -> IO ()) -- ^ callback after discovering all local files
5959
-> Maybe FileLock
60-
-> BuildOptsCLI
6160
-> RIO env ()
62-
build msetLocalFiles mbuildLk boptsCli = do
61+
build msetLocalFiles mbuildLk = do
6362
mcp <- view $ configL.to configModifyCodePage
6463
ghcVersion <- view $ actualCompilerVersionL.to getGhcVersion
6564
fixCodePage mcp ghcVersion $ do
6665
bopts <- view buildOptsL
6766
let profiling = boptsLibProfile bopts || boptsExeProfile bopts
6867
let symbols = not (boptsLibStrip bopts || boptsExeStrip bopts)
6968

70-
(targets, ls, locals, extraToBuild, sourceMap) <- loadSourceMapFull NeedTargets boptsCli
69+
sourceMap <- view $ envConfigL.to envConfigSourceMap
70+
locals <- projectLocalPackages
71+
depsLocals <- localDependencies
72+
let allLocals = locals <> depsLocals
7173

7274
-- Set local files, necessary for file watching
7375
stackYaml <- view stackYamlL
74-
for_ msetLocalFiles $ \setLocalFiles -> liftIO $ do
76+
for_ msetLocalFiles $ \setLocalFiles -> do
7577
files <- sequence
76-
-- The `locals` value above only contains local project
77-
-- packages, not local dependencies. This will get _all_
78-
-- of the local files we're interested in
79-
-- watching.
80-
[lpFiles lp | PSFilePath lp _ <- Map.elems sourceMap]
81-
setLocalFiles $ Set.insert stackYaml $ Set.unions files
78+
[lpFiles lp | lp <- allLocals]
79+
liftIO $ setLocalFiles $ Set.insert stackYaml $ Set.unions files
8280

81+
checkComponentsBuildable allLocals
82+
83+
installMap <- toInstallMap sourceMap
8384
(installedMap, globalDumpPkgs, snapshotDumpPkgs, localDumpPkgs) <-
8485
getInstalled
8586
GetInstalledOpts
8687
{ getInstalledProfiling = profiling
8788
, getInstalledHaddock = shouldHaddockDeps bopts
8889
, getInstalledSymbols = symbols }
89-
sourceMap
90+
installMap
9091

92+
boptsCli <- view $ envConfigL.to envConfigBuildOptsCLI
9193
baseConfigOpts <- mkBaseConfigOpts boptsCli
92-
plan <- constructPlan ls baseConfigOpts locals extraToBuild localDumpPkgs loadPackage sourceMap installedMap (boptsCLIInitialBuildSteps boptsCli)
94+
plan <- constructPlan baseConfigOpts localDumpPkgs loadPackage sourceMap installedMap (boptsCLIInitialBuildSteps boptsCli)
9395

9496
allowLocals <- view $ configL.to configAllowLocals
9597
unless allowLocals $ case justLocals plan of
@@ -120,7 +122,7 @@ build msetLocalFiles mbuildLk boptsCli = do
120122
snapshotDumpPkgs
121123
localDumpPkgs
122124
installedMap
123-
targets
125+
(smtTargets $ smTargets sourceMap)
124126
plan
125127

126128
-- | If all the tasks are local, they don't mutate anything outside of our local directory.
@@ -211,7 +213,7 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do
211213
collect
212214
[ (exe,pkgName')
213215
| (pkgName',task) <- Map.toList (planTasks plan)
214-
, TTFilePath lp _ <- [taskType task]
216+
, TTLocalMutable lp <- [taskType task]
215217
, exe <- (Set.toList . exeComponents . lpComponents) lp
216218
]
217219
localExes :: Map Text (NonEmpty PackageName)
@@ -238,8 +240,8 @@ splitObjsWarning = unwords
238240
]
239241

240242
-- | Get the @BaseConfigOpts@ necessary for constructing configure options
241-
mkBaseConfigOpts :: (MonadIO m, MonadReader env m, HasEnvConfig env, MonadThrow m)
242-
=> BuildOptsCLI -> m BaseConfigOpts
243+
mkBaseConfigOpts :: (HasEnvConfig env)
244+
=> BuildOptsCLI -> RIO env BaseConfigOpts
243245
mkBaseConfigOpts boptsCli = do
244246
bopts <- view buildOptsL
245247
snapDBPath <- packageDatabaseDeps
@@ -321,7 +323,7 @@ queryBuildInfo selectors0 =
321323
-- | Get the raw build information object
322324
rawBuildInfo :: HasEnvConfig env => RIO env Value
323325
rawBuildInfo = do
324-
(locals, _sourceMap) <- loadSourceMap NeedTargets defaultBuildOptsCLI
326+
locals <- projectLocalPackages
325327
wantedCompiler <- view $ wantedCompilerVersionL.to (utf8BuilderToText . display)
326328
actualCompiler <- view $ actualCompilerVersionL.to compilerVersionText
327329
return $ object
@@ -340,3 +342,13 @@ rawBuildInfo = do
340342
[ "version" .= CabalString (packageVersion p)
341343
, "path" .= toFilePath (parent $ lpCabalFile lp)
342344
]
345+
346+
checkComponentsBuildable :: MonadThrow m => [LocalPackage] -> m ()
347+
checkComponentsBuildable lps =
348+
unless (null unbuildable) $ throwM $ SomeTargetsNotBuildable unbuildable
349+
where
350+
unbuildable =
351+
[ (packageName (lpPackage lp), c)
352+
| lp <- lps
353+
, c <- Set.toList (lpUnbuildable lp)
354+
]

src/Stack/Build/Cache.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ import qualified System.FilePath as FP
5555
import System.PosixCompat.Files (modificationTime, getFileStatus, setFileTimes)
5656

5757
-- | Directory containing files to mark an executable as installed
58-
exeInstalledDir :: (MonadReader env m, HasEnvConfig env, MonadThrow m)
59-
=> InstallLocation -> m (Path Abs Dir)
58+
exeInstalledDir :: (HasEnvConfig env)
59+
=> InstallLocation -> RIO env (Path Abs Dir)
6060
exeInstalledDir Snap = (</> relDirInstalledPackages) `liftM` installationRootDeps
6161
exeInstalledDir Local = (</> relDirInstalledPackages) `liftM` installationRootLocal
6262

6363
-- | Get all of the installed executables
64-
getInstalledExes :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow m)
65-
=> InstallLocation -> m [PackageIdentifier]
64+
getInstalledExes :: (HasEnvConfig env)
65+
=> InstallLocation -> RIO env [PackageIdentifier]
6666
getInstalledExes loc = do
6767
dir <- exeInstalledDir loc
6868
(_, files) <- liftIO $ handleIO (const $ return ([], [])) $ listDir dir
@@ -77,8 +77,8 @@ getInstalledExes loc = do
7777
mapMaybe (parsePackageIdentifier . toFilePath . filename) files
7878

7979
-- | Mark the given executable as installed
80-
markExeInstalled :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow m)
81-
=> InstallLocation -> PackageIdentifier -> m ()
80+
markExeInstalled :: (HasEnvConfig env)
81+
=> InstallLocation -> PackageIdentifier -> RIO env ()
8282
markExeInstalled loc ident = do
8383
dir <- exeInstalledDir loc
8484
ensureDir dir
@@ -95,8 +95,8 @@ markExeInstalled loc ident = do
9595
liftIO $ B.writeFile fp "Installed"
9696

9797
-- | Mark the given executable as not installed
98-
markExeNotInstalled :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow m)
99-
=> InstallLocation -> PackageIdentifier -> m ()
98+
markExeNotInstalled :: (HasEnvConfig env)
99+
=> InstallLocation -> PackageIdentifier -> RIO env ()
100100
markExeNotInstalled loc ident = do
101101
dir <- exeInstalledDir loc
102102
ident' <- parseRelFile $ packageIdentifierString ident
@@ -182,9 +182,9 @@ deleteCaches dir = do
182182
cfp <- configCacheFile dir
183183
liftIO $ ignoringAbsence (removeFile cfp)
184184

185-
flagCacheFile :: (MonadIO m, MonadThrow m, MonadReader env m, HasEnvConfig env)
185+
flagCacheFile :: (HasEnvConfig env)
186186
=> Installed
187-
-> m (Path Abs File)
187+
-> RIO env (Path Abs File)
188188
flagCacheFile installed = do
189189
rel <- parseRelFile $
190190
case installed of

0 commit comments

Comments
 (0)