Skip to content

Commit

Permalink
Provide all globals to Setup.hs #941
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Sep 7, 2015
1 parent f111b2c commit 6e12f46
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/Stack/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ build setLocalFiles mbuildLk bopts = do
$ Set.unions
$ map lpFiles locals

(installedMap, locallyRegistered) <-
(installedMap, globallyRegistered, locallyRegistered) <-
getInstalled menv
GetInstalledOpts
{ getInstalledProfiling = profiling
Expand All @@ -98,7 +98,11 @@ build setLocalFiles mbuildLk bopts = do

if boptsDryrun bopts
then printPlan plan
else executePlan menv bopts baseConfigOpts locals sourceMap installedMap plan
else executePlan menv bopts baseConfigOpts locals
(Map.keysSet globallyRegistered)
sourceMap
installedMap
plan
where
profiling = boptsLibProfile bopts || boptsExeProfile bopts

Expand Down
15 changes: 11 additions & 4 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ data ExecuteEnv = ExecuteEnv
, eeLocals :: ![LocalPackage]
, eeSourceMap :: !SourceMap
, eeGlobalDB :: !(Path Abs Dir)
, eeGlobalPackages :: !(Set GhcPkgId)
}

-- | Get a compiled Setup exe
Expand Down Expand Up @@ -277,10 +278,11 @@ withExecuteEnv :: M env m
-> BuildOpts
-> BaseConfigOpts
-> [LocalPackage]
-> Set GhcPkgId -- ^ global packages
-> SourceMap
-> (ExecuteEnv -> m a)
-> m a
withExecuteEnv menv bopts baseConfigOpts locals sourceMap inner = do
withExecuteEnv menv bopts baseConfigOpts locals globals sourceMap inner = do
withSystemTempDirectory stackProgName $ \tmpdir -> do
tmpdir' <- parseAbsDir tmpdir
configLock <- newMVar ()
Expand Down Expand Up @@ -311,6 +313,7 @@ withExecuteEnv menv bopts baseConfigOpts locals sourceMap inner = do
, eeLocals = locals
, eeSourceMap = sourceMap
, eeGlobalDB = globalDB
, eeGlobalPackages = globals
}

-- | Perform the actual plan
Expand All @@ -319,12 +322,13 @@ executePlan :: M env m
-> BuildOpts
-> BaseConfigOpts
-> [LocalPackage]
-> Set GhcPkgId -- ^ globals
-> SourceMap
-> InstalledMap
-> Plan
-> m ()
executePlan menv bopts baseConfigOpts locals sourceMap installedMap plan = do
withExecuteEnv menv bopts baseConfigOpts locals sourceMap (executePlan' installedMap plan)
executePlan menv bopts baseConfigOpts locals globals sourceMap installedMap plan = do
withExecuteEnv menv bopts baseConfigOpts locals globals sourceMap (executePlan' installedMap plan)

unless (Map.null $ planInstallExes plan) $ do
snapBin <- (</> bindirSuffix) `liftM` installationRootDeps
Expand Down Expand Up @@ -694,7 +698,10 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
let depsMinusCabal = filter (not . isPrefixOf "Cabal-")
. map ghcPkgIdString
. Set.toList
$ deps
$ Set.union deps eeGlobalPackages
-- We also provide all global packages to
-- the Setup.hs file, see:
-- https://github.com/commercialhaskell/stack/issues/941
in
"-clear-package-db"
: "-global-package-db"
Expand Down
18 changes: 11 additions & 7 deletions src/Stack/Build/Installed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ getInstalled :: (M env m, PackageInstallInfo pii)
=> EnvOverride
-> GetInstalledOpts
-> Map PackageName pii -- ^ does not contain any installed information
-> m (InstalledMap, Map GhcPkgId PackageIdentifier)
-> m ( InstalledMap
, Map GhcPkgId PackageIdentifier -- globally installed
, Map GhcPkgId PackageIdentifier -- locally installed
)
getInstalled menv opts sourceMap = do
snapDBPath <- packageDatabaseDeps
localDBPath <- packageDatabaseLocal
Expand All @@ -75,11 +78,12 @@ getInstalled menv opts sourceMap = do
else return Nothing

let loadDatabase' = loadDatabase menv opts mcache sourceMap
(installedLibs', localInstalled) <-
loadDatabase' Nothing [] >>=
loadDatabase' (Just (Snap, snapDBPath)) . fst >>=
loadDatabase' (Just (Local, localDBPath)) . fst
let installedLibs = M.fromList $ map lhPair installedLibs'
(installedLibs0, globalInstalled) <- loadDatabase' Nothing []
(installedLibs1, _snapInstalled) <-
loadDatabase' (Just (Snap, snapDBPath)) installedLibs0
(installedLibs2, localInstalled) <-
loadDatabase' (Just (Local, localDBPath)) installedLibs1
let installedLibs = M.fromList $ map lhPair installedLibs2

case mcache of
Nothing -> return ()
Expand Down Expand Up @@ -107,7 +111,7 @@ getInstalled menv opts sourceMap = do
, installedLibs
]

return (installedMap, localInstalled)
return (installedMap, globalInstalled, localInstalled)

-- | Outputs both the modified InstalledMap and the Set of all installed packages in this database
--
Expand Down
5 changes: 4 additions & 1 deletion src/Stack/Dot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ createDependencyGraph dotOpts = do
(_,_,locals,_,sourceMap) <- loadSourceMap NeedTargets defaultBuildOpts
let graph = Map.fromList (localDependencies dotOpts locals)
menv <- getMinimalEnvOverride
installedMap <- fmap thrd . fst <$> getInstalled menv
installedMap <- fmap thrd . fst3 <$> getInstalled menv
(GetInstalledOpts False False)
sourceMap
withLoadPackage menv (\loader -> do
Expand All @@ -108,6 +108,9 @@ createDependencyGraph dotOpts = do
thrd :: (a,b,c) -> c
thrd (_,_,x) = x

fst3 :: (a,b,c) -> a
fst3 (x,_,_) = x

-- Given an 'Installed' try to get the 'Version'
libVersionFromInstalled :: Installed -> Maybe Version
libVersionFromInstalled (Library (PackageIdentifier _ v) _) = Just v
Expand Down
4 changes: 3 additions & 1 deletion src/Stack/SDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ getSDistFileList lp =
baseConfigOpts <- mkBaseConfigOpts bopts
(_, _mbp, locals, _extraToBuild, sourceMap) <- loadSourceMap NeedTargets bopts
runInBase <- liftBaseWith $ \run -> return (void . run)
withExecuteEnv menv bopts baseConfigOpts locals sourceMap $ \ee -> do
withExecuteEnv menv bopts baseConfigOpts locals
Set.empty -- provide empty list of globals. This is a hack around custom Setup.hs files
sourceMap $ \ee -> do
withSingleContext runInBase ac ee task Nothing (Just "sdist") $ \_package _cabalfp _pkgDir cabal _announce _console _mlogFile -> do
let outFile = tmpdir FP.</> "source-files-list"
cabal False ["sdist", "--list-sources", outFile]
Expand Down

0 comments on commit 6e12f46

Please sign in to comment.