diff options
-rw-r--r-- | hadrian/hadrian.cabal | 1 | ||||
-rw-r--r-- | hadrian/src/Main.hs | 2 | ||||
-rw-r--r-- | hadrian/src/Rules/Docspec.hs | 57 | ||||
-rw-r--r-- | libraries/base/Data/List/NonEmpty.hs | 3 |
4 files changed, 63 insertions, 0 deletions
diff --git a/hadrian/hadrian.cabal b/hadrian/hadrian.cabal index 3bca30ff23..0b54bed039 100644 --- a/hadrian/hadrian.cabal +++ b/hadrian/hadrian.cabal @@ -68,6 +68,7 @@ executable hadrian , Rules.Compile , Rules.Configure , Rules.Dependencies + , Rules.Docspec , Rules.Documentation , Rules.Generate , Rules.Gmp diff --git a/hadrian/src/Main.hs b/hadrian/src/Main.hs index d75bc743a7..db808f5a57 100644 --- a/hadrian/src/Main.hs +++ b/hadrian/src/Main.hs @@ -11,6 +11,7 @@ import qualified CommandLine import qualified Environment import qualified Rules import qualified Rules.Clean +import qualified Rules.Docspec import qualified Rules.Documentation import qualified Rules.Lint import qualified Rules.Nofib @@ -83,6 +84,7 @@ main = do rules :: Rules () rules = do Rules.buildRules + Rules.Docspec.docspecRules Rules.Documentation.documentationRules Rules.Clean.cleanRules Rules.Lint.lintRules diff --git a/hadrian/src/Rules/Docspec.hs b/hadrian/src/Rules/Docspec.hs new file mode 100644 index 0000000000..e5f8eb66c4 --- /dev/null +++ b/hadrian/src/Rules/Docspec.hs @@ -0,0 +1,57 @@ +module Rules.Docspec + ( docspecRules + ) where + +import System.Directory (findExecutable) + +import Base +import Context.Path +import Settings.Builders.Common +import qualified Packages as P + +docspecRules :: Rules () +docspecRules = do + "docspec:base" ~> docspec base + +docspec :: Action () -> Action () +docspec lintAction = do + isExecutablePresent <- isJust <$> liftIO (findExecutable "cabal-docspec") + if isExecutablePresent + then do + putBuild "| Running cabal-docspec…" + lintAction + putSuccess "| Done." + else + putFailure "| Please make sure you have the `cabal-docspec` executable in your $PATH" + +base :: Action () +base = do + topDir <- topDirectory + let context = vanillaContext Stage1 P.base + stage1GHCPath <- P.programPath (vanillaContext Stage1 P.ghc) + let stage1GHC = topDir </> stage1GHCPath + stage1Lib <- stageLibPath Stage1 + let cabalFile = pkgCabalFile P.base + let topIncludes = topDir </> "includes" + includeDeps' <- includesDependencies Stage1 + buildPath' <- buildPath context + let buildIncludesPath = topDir </> buildPath' </> "include" + let includeDeps = fmap (topDir </>) includeDeps' + mtlConfFile <- pkgConfFile $ vanillaContext Stage1 P.mtl + deepseqConfFile <- pkgConfFile $ vanillaContext Stage1 P.deepseq + bytestringConfFile <- pkgConfFile $ vanillaContext Stage1 P.bytestring + let neededIncludes = includeDeps ++ [mtlConfFile, deepseqConfFile, bytestringConfFile] + need neededIncludes + + command_ [] "cabal-docspec" [ "-w", stage1GHC + , "--no-cabal-plan" + , "--strip-comments" + , "--timeout", "2" + , "--ghci-rtsopts=-K500K" + , "--extra-package=mtl", "--extra-package=deepseq", "--extra-package=bytestring" + , "-XNoImplicitPrelude" + , "-I", topIncludes + , "-I", buildIncludesPath + , "-I", stage1Lib + , cabalFile + ] diff --git a/libraries/base/Data/List/NonEmpty.hs b/libraries/base/Data/List/NonEmpty.hs index d66d9c6a92..84e909a25a 100644 --- a/libraries/base/Data/List/NonEmpty.hs +++ b/libraries/base/Data/List/NonEmpty.hs @@ -113,6 +113,9 @@ import GHC.Base (NonEmpty(..)) infixr 5 <| +-- $setup +-- >>> import Prelude (negate) + -- | Number of elements in 'NonEmpty' list. length :: NonEmpty a -> Int length (_ :| xs) = 1 + Prelude.length xs |