Skip to content

Commit

Permalink
Merge branch 'master' into dedupe-more-include-and-linker-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
nh2 committed Jun 14, 2018
2 parents 02ab5ca + 4e0c701 commit e917e31
Show file tree
Hide file tree
Showing 72 changed files with 577 additions and 160 deletions.
1 change: 1 addition & 0 deletions Cabal/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* Options listed in `ghc-options`, `cc-options`, `ld-options`,
`cxx-options`, `cpp-options` are not deduplicated anymore
([#4449](https://github.com/haskell/cabal/issues/4449)).
* Deprecated `cabal hscolour` in favour of `cabal haddock --hyperlink-source` ([#5236](https://github.com/haskell/cabal/pull/5236/)).
* Cabal now dedupliates more `-I` and `-L` and flags to avoid `E2BIG`
(https://github.com/haskell/cabal/issues/5356)

Expand Down
18 changes: 18 additions & 0 deletions Cabal/Distribution/Simple/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ data HaddockArgs = HaddockArgs {
-- ^ (Template for modules, template for symbols, template for lines).
argLinkedSource :: Flag Bool,
-- ^ Generate hyperlinked sources
argQuickJump :: Flag Bool,
-- ^ Generate quickjump index
argCssFile :: Flag FilePath,
-- ^ Optional custom CSS file.
argContents :: Flag String,
Expand Down Expand Up @@ -156,6 +158,7 @@ haddock pkg_descr lbi suffixes flags' = do
, haddockHtmlLocation = Flag (pkg_url ++ "/docs")
, haddockContents = Flag (toPathTemplate pkg_url)
, haddockLinkedSource = Flag True
, haddockQuickJump = Flag True
}
pkg_url = "/package/$pkg-$version"
flag f = fromFlag $ f flags
Expand All @@ -176,6 +179,10 @@ haddock pkg_descr lbi suffixes flags' = do
&& version < mkVersion [2,2]) $
die' verbosity "haddock 2.0 and 2.1 do not support the --hoogle flag."

when ( flag haddockQuickJump
&& version < mkVersion [2,19]) $
die' verbosity "haddock prior to 2.19 does not support the --quickjump flag."

haddockGhcVersionStr <- getProgramOutput verbosity haddockProg
["--ghc-version"]
case (simpleParse haddockGhcVersionStr, compilerCompatVersion GHC comp) of
Expand Down Expand Up @@ -276,6 +283,7 @@ fromFlags env flags =
,"src/%{MODULE/./-}.html#line-%{LINE}")
else NoFlag,
argLinkedSource = haddockLinkedSource flags,
argQuickJump = haddockQuickJump flags,
argCssFile = haddockCss flags,
argContents = fmap (fromPathTemplate . substPathTemplate env)
(haddockContents flags),
Expand Down Expand Up @@ -545,6 +553,11 @@ renderPureArgs version comp platform args = concat
. fromFlag . argPackageName $ args
else []

, [ "--since-qual=external" | isVersion 2 20 ]

, [ "--quickjump" | isVersion 2 19
, fromFlag . argQuickJump $ args ]

, [ "--hyperlinked-source" | isVersion 2 17
, fromFlag . argLinkedSource $ args ]

Expand Down Expand Up @@ -751,6 +764,11 @@ hscolour' onNoHsColour haddockTarget pkg_descr lbi suffixes flags =
where
go :: ConfiguredProgram -> IO ()
go hscolourProg = do
warn verbosity $
"the 'cabal hscolour' command is deprecated in favour of 'cabal " ++
"haddock --hyperlink-source' and will be removed in the next major " ++
"release."

setupMessage verbosity "Running hscolour for" (packageId pkg_descr)
createDirectoryIfMissingVerbose verbosity True $
hscolourPref haddockTarget distPref pkg_descr
Expand Down
13 changes: 11 additions & 2 deletions Cabal/Distribution/Simple/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module Distribution.Simple.Setup (
buildOptions, haddockOptions, installDirsOptions,
programDbOptions, programDbPaths',
programConfigurationOptions, programConfigurationPaths',
programFlagsDescription,
splitArgs,

defaultDistPref, optionDistPref,
Expand Down Expand Up @@ -1220,7 +1221,8 @@ hscolourCommand = CommandUI
, commandSynopsis =
"Generate HsColour colourised code, in HTML format."
, commandDescription = Just (\_ -> "Requires the hscolour program.\n")
, commandNotes = Nothing
, commandNotes = Just $ \_ ->
"Deprecated in favour of 'cabal haddock --hyperlink-source'."
, commandUsage = \pname ->
"Usage: " ++ pname ++ " hscolour [FLAGS]\n"
, commandDefaultFlags = defaultHscolourFlags
Expand Down Expand Up @@ -1375,6 +1377,7 @@ data HaddockFlags = HaddockFlags {
haddockInternal :: Flag Bool,
haddockCss :: Flag FilePath,
haddockLinkedSource :: Flag Bool,
haddockQuickJump :: Flag Bool,
haddockHscolourCss :: Flag FilePath,
haddockContents :: Flag PathTemplate,
haddockDistPref :: Flag FilePath,
Expand All @@ -1400,6 +1403,7 @@ defaultHaddockFlags = HaddockFlags {
haddockInternal = Flag False,
haddockCss = NoFlag,
haddockLinkedSource = Flag False,
haddockQuickJump = Flag False,
haddockHscolourCss = NoFlag,
haddockContents = NoFlag,
haddockDistPref = NoFlag,
Expand Down Expand Up @@ -1512,11 +1516,16 @@ haddockOptions showOrParseArgs =
haddockCss (\v flags -> flags { haddockCss = v })
(reqArgFlag "PATH")

,option "" ["hyperlink-source","hyperlink-sources"]
,option "" ["hyperlink-source","hyperlink-sources","hyperlinked-source"]
"Hyperlink the documentation to the source code"
haddockLinkedSource (\v flags -> flags { haddockLinkedSource = v })
trueArg

,option "" ["quickjump"]
"Generate an index for interactive documentation navigation"
haddockQuickJump (\v flags -> flags { haddockQuickJump = v })
trueArg

,option "" ["hscolour-css"]
"Use PATH as the HsColour stylesheet"
haddockHscolourCss (\v flags -> flags { haddockHscolourCss = v })
Expand Down
9 changes: 7 additions & 2 deletions Cabal/doc/nix-local-build-overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ Nix-style Local Builds
======================

Nix-style local builds are a new build system implementation inspired by Nix.
The Nix-style local build system is commonly called "new-build" for short after the ``cabal new-*`` family of commands that control it.
However those names are only temporary until Nix-style local builds becomes the default.
The Nix-style local build system is commonly called "new-build" for short
after the ``cabal new-*`` family of commands that control it. However, those
names are only temporary until Nix-style local builds become the default.
This is expected to happen soon. For those who do not wish to use the new
functionality, the classic project style will not be removed immediately,
but these legacy commands will require the usage of the ``v1-`` prefix as of
Cabal 3.0 and will be removed in a future release.

Nix-style local builds combine the best of non-sandboxed and sandboxed Cabal:

Expand Down
11 changes: 11 additions & 0 deletions Cabal/doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ its ``cabal`` executable:
For libraries and local packages see
`Unsupported commands <#unsupported-commands>`__

cabal new-clean
---------------

``cabal new-clean [FLAGS]`` cleans up the temporary files and build artifacts
stored in the ``dist-newstyle`` folder.

By default, it removes the entire folder, but it can also spare the configuration
and caches if the ``--save-config`` option is given, in which case it only removes
the build artefacts (``.hi``, ``.o`` along with any other temporary files generated
by the compiler, along with the build output).

Unsupported commands
--------------------

Expand Down
107 changes: 107 additions & 0 deletions cabal-install/Distribution/Client/CmdClean.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{-# LANGUAGE RecordWildCards #-}
module Distribution.Client.CmdClean (cleanCommand, cleanAction) where

import Prelude ()
import Distribution.Client.Compat.Prelude

import Distribution.Client.DistDirLayout
( DistDirLayout(..), defaultDistDirLayout )
import Distribution.Client.ProjectConfig
( findProjectRoot )
import Distribution.Client.Setup
( GlobalFlags )
import Distribution.ReadE ( succeedReadE )
import Distribution.Simple.Setup
( Flag(..), toFlag, fromFlagOrDefault, flagToList, flagToMaybe
, optionDistPref, optionVerbosity, falseArg
)
import Distribution.Simple.Command
( CommandUI(..), option, reqArg )
import Distribution.Simple.Utils
( info, die', wrapText )
import Distribution.Verbosity
( Verbosity, normal )

import Control.Exception
( throwIO )
import System.Directory
( removeDirectoryRecursive, doesDirectoryExist )

data CleanFlags = CleanFlags
{ cleanSaveConfig :: Flag Bool
, cleanVerbosity :: Flag Verbosity
, cleanDistDir :: Flag FilePath
, cleanProjectFile :: Flag FilePath
} deriving (Eq)

defaultCleanFlags :: CleanFlags
defaultCleanFlags = CleanFlags
{ cleanSaveConfig = toFlag False
, cleanVerbosity = toFlag normal
, cleanDistDir = NoFlag
, cleanProjectFile = mempty
}

cleanCommand :: CommandUI CleanFlags
cleanCommand = CommandUI
{ commandName = "new-clean"
, commandSynopsis = "Clean the package store and remove temporary files."
, commandUsage = \pname ->
"Usage: " ++ pname ++ " new-clean [FLAGS]\n"
, commandDescription = Just $ \_ -> wrapText $
"Removes all temporary files created during the building process "
++ "(.hi, .o, preprocessed sources, etc.) and also empties out the "
++ "local caches (by default).\n\n"
, commandNotes = Nothing
, commandDefaultFlags = defaultCleanFlags
, commandOptions = \showOrParseArgs ->
[ optionVerbosity
cleanVerbosity (\v flags -> flags { cleanVerbosity = v })
, optionDistPref
cleanDistDir (\dd flags -> flags { cleanDistDir = dd })
showOrParseArgs
, option [] ["project-file"]
"Set the name of the cabal.project file to search for in parent directories"
cleanProjectFile (\pf flags -> flags {cleanProjectFile = pf})
(reqArg "FILE" (succeedReadE Flag) flagToList)
, option ['s'] ["save-config"]
"Save configuration, only remove build artifacts"
cleanSaveConfig (\sc flags -> flags { cleanSaveConfig = sc })
falseArg
]
}

cleanAction :: CleanFlags -> [String] -> GlobalFlags -> IO ()
cleanAction CleanFlags{..} extraArgs _ = do
let verbosity = fromFlagOrDefault normal cleanVerbosity
saveConfig = fromFlagOrDefault False cleanSaveConfig
mdistDirectory = flagToMaybe cleanDistDir
mprojectFile = flagToMaybe cleanProjectFile

unless (null extraArgs) $
die' verbosity $ "'clean' doesn't take any extra arguments: " ++ unwords extraArgs

projectRoot <- either throwIO return =<< findProjectRoot Nothing mprojectFile

let distLayout = defaultDistDirLayout projectRoot mdistDirectory

if saveConfig
then do
let buildRoot = distBuildRootDirectory distLayout
unpackedSrcRoot = distUnpackedSrcRootDirectory distLayout

buildRootExists <- doesDirectoryExist buildRoot
unpackedSrcRootExists <- doesDirectoryExist unpackedSrcRoot

when buildRootExists $ do
info verbosity ("Deleting build root (" ++ buildRoot ++ ")")
removeDirectoryRecursive buildRoot

when unpackedSrcRootExists $ do
info verbosity ("Deleting unpacked source root (" ++ unpackedSrcRoot ++ ")")
removeDirectoryRecursive unpackedSrcRoot
else do
let distRoot = distDirectory distLayout

info verbosity ("Deleting dist-newstyle (" ++ distRoot ++ ")")
removeDirectoryRecursive distRoot
109 changes: 109 additions & 0 deletions cabal-install/Distribution/Client/CmdLegacy.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
module Distribution.Client.CmdLegacy (legacyCmd) where

import Prelude ()
import Distribution.Client.Compat.Prelude

import qualified Distribution.Client.Setup as Client
import qualified Distribution.Simple.Setup as Setup
import Distribution.Simple.Command
import Distribution.Simple.Utils
( warn )
import Distribution.Verbosity
( Verbosity, normal )

import qualified Data.Text as T

-- Duplicated code (it's identical to Main.regularCmd), but makes things cleaner
-- and lets me keep how this happens a dirty little secret.
makeCmd :: CommandUI flags -> (flags -> [String] -> action) -> CommandSpec action
makeCmd ui action = CommandSpec ui ((flip commandAddAction) action) NormalCommand

deprecationNote :: String -> String
deprecationNote cmd =
"The " ++ cmd ++ " command is a part of the legacy v1 style of cabal usage.\n\n" ++

"Please switch to using either the new project style or the legacy v1-" ++ cmd ++ "\n" ++
"alias as new-style projects will become the default in the next version of\n" ++
"cabal-install. Please file a bug if you cannot replicate a working v1- use\n" ++
"case with the new-style commands.\n"

legacyNote :: String -> String
legacyNote cmd =
"The v1-" ++ cmd ++ " command is a part of the legacy v1 style of cabal usage.\n\n" ++

"It is a legacy feature and will be removed in a future release of cabal-install.\n" ++
"Please file a bug if you cannot replicate a working v1- use case with the new-style\n" ++
"commands.\n"

--

class HasVerbosity a where
verbosity :: a -> Verbosity

instance HasVerbosity (Setup.Flag Verbosity) where
verbosity = Setup.fromFlagOrDefault normal

instance (HasVerbosity a) => HasVerbosity (a, b) where
verbosity (a, _) = verbosity a

instance (HasVerbosity b) => HasVerbosity (a, b, c) where
verbosity (_ , b, _) = verbosity b

instance (HasVerbosity a) => HasVerbosity (a, b, c, d) where
verbosity (a, _, _, _) = verbosity a

instance HasVerbosity Setup.BuildFlags where
verbosity = verbosity . Setup.buildVerbosity

instance HasVerbosity Setup.ConfigFlags where
verbosity = verbosity . Setup.configVerbosity

instance HasVerbosity Setup.ReplFlags where
verbosity = verbosity . Setup.replVerbosity

instance HasVerbosity Client.FreezeFlags where
verbosity = verbosity . Client.freezeVerbosity

instance HasVerbosity Setup.HaddockFlags where
verbosity = verbosity . Setup.haddockVerbosity

instance HasVerbosity Client.ExecFlags where
verbosity = verbosity . Client.execVerbosity

instance HasVerbosity Client.UpdateFlags where
verbosity = verbosity . Client.updateVerbosity

instance HasVerbosity Setup.CleanFlags where
verbosity = verbosity . Setup.cleanVerbosity

--

legacyCmd :: (HasVerbosity flags) => CommandUI flags -> (flags -> [String] -> globals -> IO action) -> [CommandSpec (globals -> IO action)]
legacyCmd origUi@CommandUI{..} action = [makeCmd legUi action, makeCmd depUi depAction]
where
legacyMsg = T.unpack . T.replace "v1-" "" . T.pack

depNote = deprecationNote commandName
legNote = legacyNote commandName

depAction flags extra globals = warn (verbosity flags) (depNote ++ "\n") >> action flags extra globals

legUi = origUi
{ commandName = "v1-" ++ commandName
, commandNotes = Just $ \pname -> case commandNotes of
Just notes -> notes pname ++ "\n" ++ legNote
Nothing -> legNote
}

depUi = origUi
{ commandName = legacyMsg commandName
, commandUsage = legacyMsg . commandUsage
, commandDescription = (legacyMsg .) <$> commandDescription
, commandNotes = Just $ \pname -> case commandNotes of
Just notes -> legacyMsg (notes pname) ++ "\n" ++ depNote
Nothing -> depNote
}
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ instance Semigroup SavedConfig where
haddockInternal = combine haddockInternal,
haddockCss = combine haddockCss,
haddockLinkedSource = combine haddockLinkedSource,
haddockQuickJump = combine haddockQuickJump,
haddockHscolourCss = combine haddockHscolourCss,
haddockContents = combine haddockContents,
haddockDistPref = combine haddockDistPref,
Expand Down
Loading

0 comments on commit e917e31

Please sign in to comment.