Skip to content

Commit a4869ef

Browse files
committed
Avoid recomputing stack yaml path in #1340
1 parent 2798368 commit a4869ef

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/Stack/Config.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ configFromConfigMonoid
9494
:: (MonadLogger m, MonadIO m, MonadCatch m, MonadReader env m, HasHttpManager env)
9595
=> Path Abs Dir -- ^ stack root, e.g. ~/.stack
9696
-> Path Abs File -- ^ user config file path, e.g. ~/.stack/config.yaml
97-
-> Maybe Project
97+
-> Maybe (Project, Path Abs File)
9898
-> ConfigMonoid
9999
-> m Config
100100
configFromConfigMonoid configStackRoot configUserConfigPath mproject configMonoid@ConfigMonoid{..} = do
@@ -142,7 +142,7 @@ configFromConfigMonoid configStackRoot configUserConfigPath mproject configMonoi
142142

143143
configCompilerCheck = fromMaybe MatchMinor configMonoidCompilerCheck
144144

145-
configDocker <- dockerOptsFromMonoid mproject configStackRoot configMonoidDockerOpts
145+
configDocker <- dockerOptsFromMonoid (fmap fst mproject) configStackRoot configMonoidDockerOpts
146146

147147
rawEnv <- liftIO getEnvironment
148148
origEnv <- mkEnvOverride configPlatform
@@ -168,14 +168,16 @@ configFromConfigMonoid configStackRoot configUserConfigPath mproject configMonoi
168168
localDir <- liftIO (getAppUserDataDirectory "local") >>= parseAbsDir
169169
return $ localDir </> $(mkRelDir "bin")
170170
Just userPath ->
171-
(getProjectConfig Nothing >>= \case
172-
Nothing ->
173-
-- ^ Not in a project
174-
liftIO (canonicalizePath userPath >>= parseAbsDir)
175-
Just (parent -> sYamlDir) -> (resolveDir sYamlDir userPath))
176-
-- ^ Resolves to the project dir and appends the user path if it is relative
177-
`catchAll`
178-
const (throwM (NoSuchDirectory userPath))
171+
(case mproject of
172+
-- Not in a project
173+
Nothing -> parseRelAsAbsDir userPath
174+
-- Resolves to the project dir and appends the user path if it is relative
175+
Just (_, configYaml) -> resolveDir (parent configYaml) userPath)
176+
-- TODO: Either catch specific exceptions or add a
177+
-- parseRelAsAbsDirMaybe utility and use it along with
178+
-- resolveDirMaybe.
179+
`catchAll`
180+
const (throwM (NoSuchDirectory userPath))
179181

180182
configJobs <-
181183
case configMonoidJobs of
@@ -278,7 +280,8 @@ loadConfig configArgs mstackYaml = do
278280
(configMonoidDockerOpts c) {dockerMonoidDefaultEnable = False}})
279281
extraConfigs0
280282
mproject <- loadProjectConfig mstackYaml
281-
config <- configFromConfigMonoid stackRoot userConfigPath (fmap (\(proj, _, _) -> proj) mproject) $ mconcat $
283+
let mproject' = (\(project, stackYaml, _) -> (project, stackYaml)) <$> mproject
284+
config <- configFromConfigMonoid stackRoot userConfigPath mproject' $ mconcat $
282285
case mproject of
283286
Nothing -> configArgs : extraConfigs
284287
Just (_, _, projectConfig) -> configArgs : projectConfig : extraConfigs

0 commit comments

Comments
 (0)