diff --git a/cabal-install/changelog b/cabal-install/changelog index bf1f18f9153..068a26db510 100644 --- a/cabal-install/changelog +++ b/cabal-install/changelog @@ -1,4 +1,9 @@ -*-change-log-*- +3.6.0.0 Emily Pillmore August 2021 + * See https://github.com/haskell/cabal/blob/master/release-notes/cabal-install-3.6.0.0.md + +3.4.0.0 Oleg Grenrus February 2021 + * See https://github.com/haskell/cabal/blob/master/release-notes/cabal-install-3.4.0.0.md 3.2.0.0 Herbert Valerio Riedel April 2020 * `v2-build` (and other `v2-`prefixed commands) now accept the diff --git a/cabal-install/src/Distribution/Client/CmdHaddock.hs b/cabal-install/src/Distribution/Client/CmdHaddock.hs index d179873f127..f7a26dfad89 100644 --- a/cabal-install/src/Distribution/Client/CmdHaddock.hs +++ b/cabal-install/src/Distribution/Client/CmdHaddock.hs @@ -24,15 +24,18 @@ import Distribution.Client.NixStyleOptions import Distribution.Client.Setup ( GlobalFlags, ConfigFlags(..) ) import Distribution.Simple.Setup - ( HaddockFlags(..), fromFlagOrDefault ) + ( HaddockFlags(..), fromFlagOrDefault, trueArg ) import Distribution.Simple.Command - ( CommandUI(..), usageAlternatives ) + ( CommandUI(..), usageAlternatives, ShowOrParseArgs, OptionField, option ) import Distribution.Verbosity ( normal ) import Distribution.Simple.Utils ( wrapText, die' ) +import Distribution.Simple.Flag (Flag(..)) -haddockCommand :: CommandUI (NixStyleFlags ()) +newtype ClientHaddockFlags = ClientHaddockFlags { openInBrowser :: Flag Bool } + +haddockCommand :: CommandUI (NixStyleFlags ClientHaddockFlags) haddockCommand = CommandUI { commandName = "v2-haddock", commandSynopsis = "Build Haddock documentation", @@ -58,20 +61,32 @@ haddockCommand = CommandUI { "Examples:\n" ++ " " ++ pname ++ " v2-haddock pkgname" ++ " Build documentation for the package named pkgname\n" - , commandOptions = nixStyleOptions (const []) - , commandDefaultFlags = defaultNixStyleFlags () + , commandOptions = nixStyleOptions haddockOptions + , commandDefaultFlags = defaultNixStyleFlags (ClientHaddockFlags (Flag False)) } --TODO: [nice to have] support haddock on specific components, not just -- whole packages and the silly --executables etc modifiers. +haddockOptions :: ShowOrParseArgs -> [OptionField ClientHaddockFlags] +haddockOptions _ = + [ option [] ["open"] "Open generated documentation in the browser" + openInBrowser (\v f -> f { openInBrowser = v}) trueArg + ] + -- | The @haddock@ command is TODO. -- -- For more details on how this works, see the module -- "Distribution.Client.ProjectOrchestration" -- -haddockAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO () +haddockAction :: NixStyleFlags ClientHaddockFlags -> [String] -> GlobalFlags -> IO () haddockAction flags@NixStyleFlags {..} targetStrings globalFlags = do - baseCtx <- establishProjectBaseContext verbosity cliConfig HaddockCommand + projCtx <- establishProjectBaseContext verbosity cliConfig HaddockCommand + + let baseCtx + | fromFlagOrDefault False (openInBrowser extraFlags) + = projCtx { buildSettings = (buildSettings projCtx) { buildSettingHaddockOpen = True } } + | otherwise + = projCtx targetSelectors <- either (reportTargetSelectorProblems verbosity) return =<< readTargetSelectors (localPackages baseCtx) Nothing targetStrings diff --git a/cabal-install/src/Distribution/Client/ProjectBuilding.hs b/cabal-install/src/Distribution/Client/ProjectBuilding.hs index f11d14913db..6e96c459fe7 100644 --- a/cabal-install/src/Distribution/Client/ProjectBuilding.hs +++ b/cabal-install/src/Distribution/Client/ProjectBuilding.hs @@ -68,7 +68,7 @@ import Distribution.Client.Setup import Distribution.Client.SourceFiles import Distribution.Client.SrcDist (allPackageSourceFiles) import Distribution.Client.Utils - ( ProgressPhase(..), progressMessage, removeExistingFile ) + ( ProgressPhase(..), findOpenProgramLocation, progressMessage, removeExistingFile ) import Distribution.Compat.Lens import Distribution.Package @@ -1201,11 +1201,12 @@ buildInplaceUnpackedPackage verbosity distPackageCacheDirectory, distDirectory } - BuildTimeSettings{buildSettingNumJobs} + BuildTimeSettings{buildSettingNumJobs, buildSettingHaddockOpen} registerLock cacheLock pkgshared@ElaboratedSharedConfig { pkgConfigCompiler = compiler, - pkgConfigCompilerProgs = progdb + pkgConfigCompilerProgs = progdb, + pkgConfigPlatform = platform } plan rpkg@(ReadyPackage pkg) @@ -1321,6 +1322,17 @@ buildInplaceUnpackedPackage verbosity Tar.createTarGzFile dest docDir name notice verbosity $ "Documentation tarball created: " ++ dest + when (buildSettingHaddockOpen && haddockTarget /= Cabal.ForHackage) $ do + let dest = docDir name "index.html" + name = haddockDirName haddockTarget (elabPkgDescription pkg) + docDir = distBuildDirectory distDirLayout dparams + "doc" "html" + exe <- findOpenProgramLocation platform + case exe of + Right open -> runProgramInvocation verbosity (simpleProgramInvocation open [dest]) + Left err -> die' verbosity err + + return BuildResult { buildResultDocs = docsResult, buildResultTests = testsResult, diff --git a/cabal-install/src/Distribution/Client/ProjectConfig.hs b/cabal-install/src/Distribution/Client/ProjectConfig.hs index 8835ee27c07..17c0435035d 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig.hs @@ -324,6 +324,7 @@ resolveBuildTimeSettings verbosity buildSettingReportPlanningFailure = fromFlag projectConfigReportPlanningFailure buildSettingProgPathExtra = fromNubList projectConfigProgPathExtra + buildSettingHaddockOpen = False ProjectConfigBuildOnly{..} = defaults <> projectConfigBuildOnly diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs index e5d18273dca..92850b27925 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs @@ -457,5 +457,6 @@ data BuildTimeSettings buildSettingCacheDir :: FilePath, buildSettingHttpTransport :: Maybe String, buildSettingIgnoreExpiry :: Bool, - buildSettingProgPathExtra :: [FilePath] + buildSettingProgPathExtra :: [FilePath], + buildSettingHaddockOpen :: Bool } diff --git a/cabal-install/src/Distribution/Client/Utils.hs b/cabal-install/src/Distribution/Client/Utils.hs index 5c37ab35266..f9021803c7d 100644 --- a/cabal-install/src/Distribution/Client/Utils.hs +++ b/cabal-install/src/Distribution/Client/Utils.hs @@ -18,6 +18,7 @@ module Distribution.Client.Utils , moreRecentFile, existsAndIsMoreRecentThan , tryFindAddSourcePackageDesc , tryFindPackageDesc + , findOpenProgramLocation , relaxEncodingErrors , ProgressPhase (..) , progressMessage @@ -38,6 +39,7 @@ import Distribution.Compat.Time ( getModTime ) import Distribution.Simple.Setup ( Flag(..) ) import Distribution.Version import Distribution.Simple.Utils ( die', findPackageDesc, noticeNoWrap ) +import Distribution.System ( Platform (..), OS(..)) import qualified Data.ByteString.Lazy as BS import Data.Bits ( (.|.), shiftL, shiftR ) @@ -50,7 +52,7 @@ import Foreign.C.Types ( CInt(..) ) import qualified Control.Exception as Exception ( finally, bracket ) import System.Directory - ( canonicalizePath, doesFileExist, getCurrentDirectory + ( canonicalizePath, doesFileExist, findExecutable, getCurrentDirectory , removeFile, setCurrentDirectory, getDirectoryContents, doesDirectoryExist ) import System.IO ( Handle, hClose, openTempFile @@ -344,6 +346,26 @@ tryFindPackageDesc verbosity depPath err = do Right file -> return file Left _ -> die' verbosity err +findOpenProgramLocation :: Platform -> IO (Either String FilePath) +findOpenProgramLocation (Platform _ os) = + let + locate name = do + exe <- findExecutable name + case exe of + Just s -> pure (Right s) + Nothing -> pure (Left ("Couldn't find file-opener program `" <> name <> "`")) + xdg = locate "xdg-open" + in case os of + Windows -> pure (Right "start") + OSX -> locate "open" + Linux -> xdg + FreeBSD -> xdg + OpenBSD -> xdg + NetBSD -> xdg + DragonFly -> xdg + _ -> pure (Left ("Couldn't determine file-opener program for " <> show os)) + + -- | Phase of building a dependency. Represents current status of package -- dependency processing. See #4040 for details. data ProgressPhase diff --git a/changelog.d/pr-7550 b/changelog.d/pr-7550 new file mode 100644 index 00000000000..e95e220acdc --- /dev/null +++ b/changelog.d/pr-7550 @@ -0,0 +1,4 @@ +synopsis: Add --open flag to `cabal haddock` +packages: cabal-install +prs: #7550 +issues: #7366 diff --git a/doc/cabal-project.rst b/doc/cabal-project.rst index f4c39513992..cbb41eeeb87 100644 --- a/doc/cabal-project.rst +++ b/doc/cabal-project.rst @@ -497,7 +497,7 @@ The following settings control the behavior of the dependency solver: active repositories are merged. When searching for a certain version of a certain package name, the list of - active repositories is searched last-to-first. + active repositories is searched last-to-first. For example, suppose hackage.haskell.org has versions 1.0 and 2.0 of package X, and my-repository has version 2.0 of a similarly named package. @@ -1406,6 +1406,13 @@ running ``setup haddock``. (TODO: Where does the documentation get put.) The command line variant of this flag is ``--keep-temp-files`` (for the ``haddock`` subcommand). +.. cfg-field:: open: boolean + :synopsis: Open generated documentation in-browser. + + When generating HTML documentation, attempt to open it in a browser + when complete. This will use ``xdg-open`` on Linux and BSD systems, + ``open`` on macOS, and ``start`` on Windows. + Advanced global configuration options ------------------------------------- diff --git a/release-notes/cabal-install-3.6.0.0.md b/release-notes/cabal-install-3.6.0.0.md new file mode 100644 index 00000000000..c4692787ec9 --- /dev/null +++ b/release-notes/cabal-install-3.6.0.0.md @@ -0,0 +1,43 @@ +### Backports + +- Backported to 3.4 [#6964](https://github.com/haskell/cabal/pull/6964) [#6968](https://github.com/haskell/cabal/pull/6968) +- CI setup [#6959](https://github.com/haskell/cabal/pull/6959) + + - Remove travis scripts + +### Significant Changes + +- Add post-checkout-command to source-package-repository [#6664](https://github.com/haskell/cabal/issues/6664) [#7047](https://github.com/haskell/cabal/pull/7047) +- Assume list-bin target selectors are for executables [#7326](https://github.com/haskell/cabal/issues/7326) [#7335](https://github.com/haskell/cabal/pull/7335) +- Add a --only-download flag [#7323](https://github.com/haskell/cabal/issues/7323) [#7347](https://github.com/haskell/cabal/pull/7347) +- Add `hsc2hs-options`, for specifying additional options to pass to `hsc2hs` [#6295](https://github.com/haskell/cabal/pull/6295) +- Make extra-packages work properly [#6972](https://github.com/haskell/cabal/pull/6972) +- Bugfix - stop creating spurious dirs on `init` [#6772](https://github.com/haskell/cabal/issues/6772) [#7262](https://github.com/haskell/cabal/pull/7262) +- Avoid resource exhaustion in `cabal init` [#5115](https://github.com/haskell/cabal/issues/5115) [#7283](https://github.com/haskell/cabal/pull/7283) + + - Read file contents strictly to avoid resource exhaustion in `cabal init`. + - Ignore UTF-8 decoding errors. + +- Add language extensions for GHC 9.2 [#7312](https://github.com/haskell/cabal/issues/7312) +- --dry-run and --only-download effect v2-configure, v2-freeze, v2-run, and v2-exec [#7379](https://github.com/haskell/cabal/issues/7379) +- Fix instantiating an indefinite Backpack from Hackage with an inplace package [#6835](https://github.com/haskell/cabal/issues/6835) [#7413](https://github.com/haskell/cabal/pull/7413) + + Previously, cabal-install would always attempt to put instantiations of indefinite packages from Hackage in + the global package store, even if they were instantiated with inplace packages. This would not work + and GHC would complain about packages being missing from the package database. We have fixed the + instantiation algorithm to correctly inplace packages in these situations, removing one of the last + blockers to widespread use of Backpack packages on Hackage. + +- removes the warnings for extraneous versions [#7286](https://github.com/haskell/cabal/issues/7286) [#7470](https://github.com/haskell/cabal/pull/7470) +- Alert user and suggest command on spelling mistakes + +### Other improvements + +- Code organization [#6960](https://github.com/haskell/cabal/pull/6960) [#6963](https://github.com/haskell/cabal/pull/6963) [#6970](https://github.com/haskell/cabal/pull/6970) [#6974](https://github.com/haskell/cabal/pull/6974) [#6975](https://github.com/haskell/cabal/pull/6975) + + - Move Cabal sources into Cabal/src + - Move cabal-install sources to cabal-install/src/ + - Move doc/ to the top-level of the repository + - Add stylish-haskell config. + +- Documentation improvements [#6813](https://github.com/haskell/cabal/issues/6813) [#6971](https://github.com/haskell/cabal/pull/6971) [#7047](https://github.com/haskell/cabal/pull/7047)