Skip to content

Commit

Permalink
Merge pull request #4412 from commercialhaskell/new-build-plan
Browse files Browse the repository at this point in the history
New build plan construction with source maps
  • Loading branch information
qrilka authored Dec 20, 2018
2 parents 88a07ab + cc7bfd6 commit 1bbed48
Show file tree
Hide file tree
Showing 39 changed files with 1,488 additions and 899 deletions.
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ library:
- Stack.Sig.Sign
- Stack.Snapshot
- Stack.Solver
- Stack.SourceMap
- Stack.StoreTH
- Stack.Types.Build
- Stack.Types.BuildPlan
Expand All @@ -249,6 +250,7 @@ library:
- Stack.Types.Resolver
- Stack.Types.Runner
- Stack.Types.Sig
- Stack.Types.SourceMap
- Stack.Types.StylesUpdate
- Stack.Types.TemplateName
- Stack.Types.Version
Expand Down
1 change: 1 addition & 0 deletions snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ packages:
- http-api-data-0.3.8.1@rev:1
- cabal-doctest-1.0.6@rev:2
- unliftio-0.2.8.0@sha256:5a47f12ffcee837215c67b05abf35dffb792096564a6f81652d75a54668224cd,2250
- happy-1.19.9@sha256:f8c774230735a390c287b2980cfcd2703d24d8dde85a01ea721b7b4b4c82944f,4667

flags:
cabal-install:
Expand Down
48 changes: 30 additions & 18 deletions src/Stack/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ import Stack.Build.Execute
import Stack.Build.Haddock
import Stack.Build.Installed
import Stack.Build.Source
import Stack.Build.Target
import Stack.Package
import Stack.Types.Build
import Stack.Types.Config
import Stack.Types.NamedComponent
import Stack.Types.Package
import Stack.Types.SourceMap

import Stack.Types.Compiler (compilerVersionText, getGhcVersion)
import System.FileLock (FileLock, unlockFile)
Expand All @@ -57,39 +57,41 @@ import System.Terminal (fixCodePage)
build :: HasEnvConfig env
=> Maybe (Set (Path Abs File) -> IO ()) -- ^ callback after discovering all local files
-> Maybe FileLock
-> BuildOptsCLI
-> RIO env ()
build msetLocalFiles mbuildLk boptsCli = do
build msetLocalFiles mbuildLk = do
mcp <- view $ configL.to configModifyCodePage
ghcVersion <- view $ actualCompilerVersionL.to getGhcVersion
fixCodePage mcp ghcVersion $ do
bopts <- view buildOptsL
let profiling = boptsLibProfile bopts || boptsExeProfile bopts
let symbols = not (boptsLibStrip bopts || boptsExeStrip bopts)

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

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

checkComponentsBuildable allLocals

installMap <- toInstallMap sourceMap
(installedMap, globalDumpPkgs, snapshotDumpPkgs, localDumpPkgs) <-
getInstalled
GetInstalledOpts
{ getInstalledProfiling = profiling
, getInstalledHaddock = shouldHaddockDeps bopts
, getInstalledSymbols = symbols }
sourceMap
installMap

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

allowLocals <- view $ configL.to configAllowLocals
unless allowLocals $ case justLocals plan of
Expand Down Expand Up @@ -120,7 +122,7 @@ build msetLocalFiles mbuildLk boptsCli = do
snapshotDumpPkgs
localDumpPkgs
installedMap
targets
(smtTargets $ smTargets sourceMap)
plan

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

-- | Get the @BaseConfigOpts@ necessary for constructing configure options
mkBaseConfigOpts :: (MonadIO m, MonadReader env m, HasEnvConfig env, MonadThrow m)
=> BuildOptsCLI -> m BaseConfigOpts
mkBaseConfigOpts :: (HasEnvConfig env)
=> BuildOptsCLI -> RIO env BaseConfigOpts
mkBaseConfigOpts boptsCli = do
bopts <- view buildOptsL
snapDBPath <- packageDatabaseDeps
Expand Down Expand Up @@ -321,7 +323,7 @@ queryBuildInfo selectors0 =
-- | Get the raw build information object
rawBuildInfo :: HasEnvConfig env => RIO env Value
rawBuildInfo = do
(locals, _sourceMap) <- loadSourceMap NeedTargets defaultBuildOptsCLI
locals <- projectLocalPackages
wantedCompiler <- view $ wantedCompilerVersionL.to (utf8BuilderToText . display)
actualCompiler <- view $ actualCompilerVersionL.to compilerVersionText
return $ object
Expand All @@ -340,3 +342,13 @@ rawBuildInfo = do
[ "version" .= CabalString (packageVersion p)
, "path" .= toFilePath (parent $ lpCabalFile lp)
]

checkComponentsBuildable :: MonadThrow m => [LocalPackage] -> m ()
checkComponentsBuildable lps =
unless (null unbuildable) $ throwM $ SomeTargetsNotBuildable unbuildable
where
unbuildable =
[ (packageName (lpPackage lp), c)
| lp <- lps
, c <- Set.toList (lpUnbuildable lp)
]
20 changes: 10 additions & 10 deletions src/Stack/Build/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ import qualified System.FilePath as FP
import System.PosixCompat.Files (modificationTime, getFileStatus, setFileTimes)

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

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

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

-- | Mark the given executable as not installed
markExeNotInstalled :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow m)
=> InstallLocation -> PackageIdentifier -> m ()
markExeNotInstalled :: (HasEnvConfig env)
=> InstallLocation -> PackageIdentifier -> RIO env ()
markExeNotInstalled loc ident = do
dir <- exeInstalledDir loc
ident' <- parseRelFile $ packageIdentifierString ident
Expand Down Expand Up @@ -182,9 +182,9 @@ deleteCaches dir = do
cfp <- configCacheFile dir
liftIO $ ignoringAbsence (removeFile cfp)

flagCacheFile :: (MonadIO m, MonadThrow m, MonadReader env m, HasEnvConfig env)
flagCacheFile :: (HasEnvConfig env)
=> Installed
-> m (Path Abs File)
-> RIO env (Path Abs File)
flagCacheFile installed = do
rel <- parseRelFile $
case installed of
Expand Down
Loading

0 comments on commit 1bbed48

Please sign in to comment.