Skip to content

Commit 8355d8c

Browse files
committed
Reconfigure on new PATH env var (fixes #3138)
1 parent 65c987c commit 8355d8c

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ Behavior changes:
105105
can be disabled via the `hide-source-paths` configuration option in
106106
`stack.yaml`. See [#3784](https://github.com/commercialhaskell/stack/issues/3784)
107107

108+
* Stack will reconfigure a package if you modify your `PATH` environment
109+
variable. See
110+
[#3138](https://github.com/commercialhaskell/stack/issues/3138).
111+
108112
Other enhancements:
109113

110114
* Defer loading up of files for local packages. This allows us to get

src/Stack/Build/ConstructPlan.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import Stack.Types.NamedComponent
4949
import Stack.Types.Package
5050
import Stack.Types.SourceMap
5151
import Stack.Types.Version
52+
import System.Environment (lookupEnv)
5253
import System.IO (putStrLn)
5354
import RIO.PrettyPrint
5455
import RIO.Process (findExecutable, HasProcessContext (..))
@@ -124,6 +125,7 @@ data Ctx = Ctx
124125
, wanted :: !(Set PackageName)
125126
, localNames :: !(Set PackageName)
126127
, mcurator :: !(Maybe Curator)
128+
, pathEnvVar :: !Text
127129
}
128130

129131
instance HasPlatform Ctx
@@ -187,7 +189,8 @@ constructPlan baseConfigOpts0 localDumpPkgs loadPackage0 sourceMap installedMap
187189

188190
let onTarget = void . addDep
189191
let inner = mapM_ onTarget $ Map.keys (smtTargets $ smTargets sourceMap)
190-
let ctx = mkCtx econfig globalCabalVersion sources mcur
192+
pathEnvVar' <- liftIO $ maybe mempty T.pack <$> lookupEnv "PATH"
193+
let ctx = mkCtx econfig globalCabalVersion sources mcur pathEnvVar'
191194
((), m, W efinals installExes dirtyReason warnings parents) <-
192195
liftIO $ runRWST inner ctx M.empty
193196
mapM_ (logWarn . RIO.display) (warnings [])
@@ -226,7 +229,7 @@ constructPlan baseConfigOpts0 localDumpPkgs loadPackage0 sourceMap installedMap
226229
where
227230
hasBaseInDeps = Map.member (mkPackageName "base") (smDeps sourceMap)
228231

229-
mkCtx econfig globalCabalVersion sources mcur = Ctx
232+
mkCtx econfig globalCabalVersion sources mcur pathEnvVar' = Ctx
230233
{ baseConfigOpts = baseConfigOpts0
231234
, loadPackage = \x y z -> runRIO econfig $
232235
applyForceCustomBuild globalCabalVersion <$> loadPackage0 x y z
@@ -236,6 +239,7 @@ constructPlan baseConfigOpts0 localDumpPkgs loadPackage0 sourceMap installedMap
236239
, wanted = Map.keysSet (smtTargets $ smTargets sourceMap)
237240
, localNames = Map.keysSet (smProject sourceMap)
238241
, mcurator = mcur
242+
, pathEnvVar = pathEnvVar'
239243
}
240244

241245
prunedGlobalDeps = flip Map.mapMaybe (smGlobal sourceMap) $ \gp ->
@@ -788,6 +792,7 @@ checkDirtiness ps installed package present = do
788792
PSFilePath lp -> Set.map (encodeUtf8 . renderComponent) $ lpComponents lp
789793
PSRemote{} -> Set.empty
790794
, configCachePkgSrc = toCachePkgSrc ps
795+
, configCachePathEnvVar = pathEnvVar ctx
791796
}
792797
config = view configL ctx
793798
mreason <-

src/Stack/Build/Execute.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import Stack.Types.NamedComponent
8282
import Stack.Types.Package
8383
import Stack.Types.Version
8484
import qualified System.Directory as D
85-
import System.Environment (getExecutablePath)
85+
import System.Environment (getExecutablePath, lookupEnv)
8686
import System.Exit (ExitCode (..))
8787
import qualified System.FilePath as FP
8888
import System.IO (stderr, stdout)
@@ -209,6 +209,8 @@ data ExecuteEnv = ExecuteEnv
209209
-- Setup.hs built.
210210
, eeLargestPackageName :: !(Maybe Int)
211211
-- ^ For nicer interleaved output: track the largest package name size
212+
, eePathEnvVar :: !Text
213+
-- ^ Value of the PATH environment variable
212214
}
213215

214216
buildSetupArgs :: [String]
@@ -341,6 +343,7 @@ withExecuteEnv bopts boptsCli baseConfigOpts locals globalPackages snapshotPacka
341343
localPackagesTVar <- liftIO $ newTVarIO (toDumpPackagesByGhcPkgId localPackages)
342344
logFilesTChan <- liftIO $ atomically newTChan
343345
let totalWanted = length $ filter lpWanted locals
346+
pathEnvVar <- liftIO $ maybe mempty T.pack <$> lookupEnv "PATH"
344347
inner ExecuteEnv
345348
{ eeBuildOpts = bopts
346349
, eeBuildOptsCLI = boptsCli
@@ -366,6 +369,7 @@ withExecuteEnv bopts boptsCli baseConfigOpts locals globalPackages snapshotPacka
366369
, eeLogFiles = logFilesTChan
367370
, eeCustomBuilt = customBuiltRef
368371
, eeLargestPackageName = mlargestPackageName
372+
, eePathEnvVar = pathEnvVar
369373
} `finally` dumpLogs logFilesTChan totalWanted
370374
where
371375
toDumpPackagesByGhcPkgId = Map.fromList . map (\dp -> (dpGhcPkgId dp, dp))
@@ -824,6 +828,7 @@ getConfigCache ExecuteEnv {..} task@Task {..} installedMap enableTest enableBenc
824828
TTLocalMutable lp -> Set.map (encodeUtf8 . renderComponent) $ lpComponents lp
825829
TTRemotePackage{} -> Set.empty
826830
, configCachePkgSrc = taskCachePkgSrc
831+
, configCachePathEnvVar = eePathEnvVar
827832
}
828833
allDepsMap = Map.union missing' taskPresent
829834
return (allDepsMap, cache)

src/Stack/Storage.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ConfigCacheParent sql="config_cache"
6464
type ConfigCacheType default=''
6565
pkgSrc CachePkgSrc default=''
6666
active Bool default=0
67+
pathEnvVar Text default=''
6768
UniqueConfigCacheParent directory type sql="unique_config_cache"
6869
deriving Show
6970

@@ -199,6 +200,7 @@ readConfigCache (Entity parentId ConfigCacheParent {..}) = do
199200
configCacheComponents <-
200201
Set.fromList . map (configCacheComponentValue . entityVal) <$>
201202
selectList [ConfigCacheComponentParent ==. parentId] []
203+
let configCachePathEnvVar = configCacheParentPathEnvVar
202204
return ConfigCache {..}
203205

204206
-- | Load 'ConfigCache' from the database.
@@ -235,6 +237,7 @@ saveConfigCache key@(UniqueConfigCacheParent dir type_) new =
235237
, configCacheParentType = type_
236238
, configCacheParentPkgSrc = configCachePkgSrc new
237239
, configCacheParentActive = True
240+
, configCacheParentPathEnvVar = configCachePathEnvVar new
238241
}
239242
Just parentEntity@(Entity parentId _) -> do
240243
old <- readConfigCache parentEntity

src/Stack/Types/Build.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ data ConfigCache = ConfigCache
391391
-- here, as it's not a configure option (just a build option), but this
392392
-- is a convenient way to force compilation when the components change.
393393
, configCachePkgSrc :: !CachePkgSrc
394+
, configCachePathEnvVar :: !Text
395+
-- ^ Value of the PATH env var, see <https://github.com/commercialhaskell/stack/issues/3138>
394396
}
395397
deriving (Generic, Eq, Show, Data, Typeable)
396398
instance NFData ConfigCache

0 commit comments

Comments
 (0)