@@ -42,6 +42,7 @@ import Data.Array.IArray ( (!), (//) )
4242import qualified Data.ByteString as S
4343import Data.ByteString.Builder ( byteString )
4444import Data.Coerce ( coerce )
45+ import qualified Data.Either.Extra as EE
4546import qualified Data.IntMap as IntMap
4647import qualified Data.Map as Map
4748import qualified Data.Map.Merge.Strict as MS
@@ -272,15 +273,16 @@ getLatestSnapshot = do
272273configFromConfigMonoid ::
273274 (HasRunner env , HasTerm env )
274275 => Path Abs Dir -- ^ Stack root, e.g. ~/.stack
275- -> Path Abs File -- ^ user config file path, e.g. ~/.stack/config.yaml
276+ -> Path Abs File
277+ -- ^ User-specific global configuration file.
276278 -> Maybe AbstractSnapshot
277279 -> ProjectConfig (Project , Path Abs File )
278280 -> ConfigMonoid
279281 -> (Config -> RIO env a )
280282 -> RIO env a
281283configFromConfigMonoid
282284 stackRoot
283- userConfigPath
285+ userGlobalConfigFile
284286 snapshot
285287 project
286288 configMonoid
@@ -565,7 +567,7 @@ configFromConfigMonoid
565567 (stackRoot </> relFileStorage)
566568 ( \ userStorage -> inner Config
567569 { workDir
568- , userConfigPath
570+ , userGlobalConfigFile
569571 , build
570572 , docker
571573 , nix
@@ -771,16 +773,16 @@ withBuildConfig inner = do
771773 <> " specified on command line"
772774 makeConcreteSnapshot aSnapshot
773775
774- (project', stackYaml ) <- case config. project of
776+ (project', configFile ) <- case config. project of
775777 PCProject (project, fp) -> do
776778 forM_ project. userMsg prettyWarnS
777- pure (project, fp)
779+ pure (project, Right fp)
778780 PCNoProject extraDeps -> do
779781 p <-
780782 case mSnapshot of
781783 Nothing -> throwIO NoSnapshotWhenUsingNoProject
782784 Just _ -> getEmptyProject mSnapshot extraDeps
783- pure (p, config. userConfigPath )
785+ pure (p, Left config. userGlobalConfigFile )
784786 PCGlobalProject -> do
785787 logDebug " Run from outside a project, using implicit global project config"
786788 destDir <- getImplicitGlobalProjectDir config
@@ -803,7 +805,7 @@ withBuildConfig inner = do
803805 <> " from implicit global project's config file: "
804806 <> fromString dest'
805807 Just _ -> pure ()
806- pure (project, dest)
808+ pure (project, Right dest)
807809 else do
808810 prettyInfoL
809811 [ flow " Writing the configuration file for the implicit \
@@ -816,10 +818,10 @@ withBuildConfig inner = do
816818 p <- getEmptyProject mSnapshot []
817819 liftIO $ do
818820 writeBinaryFileAtomic dest $ byteString $ S. concat
819- [ " # This is the implicit global project's config file, which is only used when \n "
820- , " # 'stack' is run outside of a real project. Settings here do _not_ act as\n "
821+ [ " # This is the implicit global project's configuration file, which is only used\n "
822+ , " # when 'stack' is run outside of a real project. Settings here do _not_ act as\n "
821823 , " # defaults for all projects. To change Stack's default settings, edit\n "
822- , " # '" , encodeUtf8 (T. pack $ toFilePath config. userConfigPath ), " ' instead.\n "
824+ , " # '" , encodeUtf8 (T. pack $ toFilePath config. userGlobalConfigFile ), " ' instead.\n "
823825 , " #\n "
824826 , " # For more information about Stack's configuration, see\n "
825827 , " # http://docs.haskellstack.org/en/stable/yaml_configuration/\n "
@@ -829,29 +831,31 @@ withBuildConfig inner = do
829831 " This is the implicit global project, which is " <>
830832 " used only when 'stack' is run\n outside of a " <>
831833 " real project.\n "
832- pure (p, dest)
834+ pure (p, Right dest)
833835 mcompiler <- view $ globalOptsL . to (. compiler)
834836 let project :: Project
835837 project = project'
836838 { Project. compiler = mcompiler <|> project'. compiler
837839 , Project. snapshot = fromMaybe project'. snapshot mSnapshot
838840 }
841+ -- We are indifferent as to whether the configuration file is a
842+ -- user-specific global or a project-level one.
843+ eitherConfigFile = EE. fromEither configFile
839844 extraPackageDBs <- mapM resolveDir' project. extraPackageDBs
840845
841- smWanted <- lockCachedWanted stackYaml project. snapshot $
842- fillProjectWanted stackYaml config project
846+ smWanted <- lockCachedWanted eitherConfigFile project. snapshot $
847+ fillProjectWanted eitherConfigFile config project
843848
844- -- Unfortunately redoes getProjectWorkDir, since we don't have a BuildConfig
845- -- yet
849+ -- Unfortunately redoes getWorkDir, since we don't have a BuildConfig yet
846850 workDir <- view workDirL
847- let projectStorageFile = parent stackYaml </> workDir </> relFileStorage
851+ let projectStorageFile = parent eitherConfigFile </> workDir </> relFileStorage
848852
849853 initProjectStorage projectStorageFile $ \ projectStorage -> do
850854 let bc = BuildConfig
851855 { config
852856 , smWanted
853857 , extraPackageDBs
854- , stackYaml
858+ , configFile
855859 , curator = project. curator
856860 , projectStorage
857861 }
@@ -891,18 +895,20 @@ withBuildConfig inner = do
891895
892896fillProjectWanted ::
893897 (HasLogFunc env , HasPantryConfig env , HasProcessContext env )
894- => Path Abs t
898+ => Path Abs File
899+ -- ^ Location of the configuration file, which may be either a
900+ -- user-specific global or a project-level one.
895901 -> Config
896902 -> Project
897903 -> Map RawPackageLocationImmutable PackageLocationImmutable
898904 -> WantedCompiler
899905 -> Map PackageName (Bool -> RIO env DepPackage )
900906 -> RIO env (SMWanted , [CompletedPLI ])
901- fillProjectWanted stackYamlFP config project locCache snapCompiler snapPackages = do
907+ fillProjectWanted configFile config project locCache snapCompiler snapPackages = do
902908 let bopts = config. build
903909
904910 packages0 <- for project. packages $ \ fp@ (RelFilePath t) -> do
905- abs' <- resolveDir (parent stackYamlFP ) (T. unpack t)
911+ abs' <- resolveDir (parent configFile ) (T. unpack t)
906912 let resolved = ResolvedPath fp abs'
907913 pp <- mkProjectPackage YesPrintWarnings resolved bopts. buildHaddocks
908914 pure (pp. projectCommon. name, pp)
0 commit comments