Skip to content

Commit

Permalink
init: add ignored packages as commented in config
Browse files Browse the repository at this point in the history
Packages which are not compatible with the resolver are added to the
config but commented out.

See commercialhaskell#1621
  • Loading branch information
harendra-kumar committed Jan 19, 2016
1 parent fcfebe0 commit 58eb46c
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Control.Monad.Reader (MonadReader)
import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Char8 as BC
import qualified Data.HashMap.Strict as HM
import qualified Data.IntMap as IntMap
import qualified Data.Foldable as F
Expand Down Expand Up @@ -95,16 +96,19 @@ initProject currDir initOpts = do
, projectCompiler = Nothing
, projectExtraPackageDBs = []
}

makeRel dir =
case stripDir currDir dir of
Nothing
| currDir == dir -> "."
| otherwise -> assert False $ toFilePath dir
Just rel -> toFilePath rel

pkgs = map toPkg $ Map.elems (fmap fst rbundle)
toPkg dir = PackageEntry
{ peValidWanted = Nothing
, peExtraDepMaybe = Nothing
, peLocation = PLFilePath $
case stripDir currDir dir of
Nothing
| currDir == dir -> "."
| otherwise -> assert False $ toFilePath dir
Just rel -> toFilePath rel
, peLocation = PLFilePath $ makeRel dir
, peSubdirs = []
}

Expand All @@ -128,18 +132,21 @@ initProject currDir initOpts = do
(if exists then "Overwriting existing configuration file: "
else "Writing configuration to file: ")
<> T.pack reldest
liftIO $ L.writeFile dest' $ B.toLazyByteString $ renderStackYaml p
liftIO $ L.writeFile dest'
$ B.toLazyByteString
$ renderStackYaml p (Map.elems $ fmap (makeRel . fst) ignored)
$logInfo "All done."

-- | Render a stack.yaml file with comments, see:
-- https://github.com/commercialhaskell/stack/issues/226
renderStackYaml :: Project -> B.Builder
renderStackYaml p =
renderStackYaml :: Project -> [FilePath]-> B.Builder
renderStackYaml p ignoredPackages =
case Yaml.toJSON p of
Yaml.Object o -> renderObject o
_ -> assert False $ B.byteString $ Yaml.encode p
where
renderObject o =
B.byteString "# This file was automatically generated by stack init\n" <>
B.byteString "# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html\n\n" <>
F.foldMap (goComment o) comments <>
goOthers (o `HM.difference` HM.fromList comments) <>
Expand All @@ -158,9 +165,15 @@ renderStackYaml p =
\# Allow a newer minor version of GHC than the snapshot specifies\n\
\# compiler-check: newer-minor\n"

ignoredPackagesComment =
if ignoredPackages /= [] then
"\n# Some packages were found to be incompatible with the resolver and \
\have been commented out"
else ""

comments =
[ ("resolver", "Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)")
, ("packages", "Local packages, usually specified by relative directory name")
, ("packages", "Local packages, usually specified by relative directory name" <> ignoredPackagesComment)
, ("extra-deps", "Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)")
, ("flags", "Override default flag values for local packages and extra-deps")
, ("extra-package-dbs", "Extra package databases containing global packages")
Expand All @@ -174,6 +187,11 @@ renderStackYaml p =
B.byteString comment <>
B.byteString "\n" <>
B.byteString (Yaml.encode $ Yaml.object [(name, v)]) <>
if (name == "packages") then
B.byteString $ BC.pack $ concat
$ (map (\x -> "#- " ++ x ++ "\n")
ignoredPackages) ++ ["\n"]
else "" <>
B.byteString "\n"

goOthers o
Expand Down

0 comments on commit 58eb46c

Please # to comment.