Skip to content

Commit

Permalink
Merge branch 'master' into gb/build-reports-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaz authored Aug 23, 2021
2 parents 1c0dd92 + bea894a commit da7be57
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 13 deletions.
5 changes: 5 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
-*-change-log-*-
3.6.0.0 Emily Pillmore <emilypi@cohomolo.gy> 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 <oleg.grenrus@iki.fi> 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 <hvr@gnu.org> April 2020
* `v2-build` (and other `v2-`prefixed commands) now accept the
Expand Down
29 changes: 22 additions & 7 deletions cabal-install/src/Distribution/Client/CmdHaddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
18 changes: 15 additions & 3 deletions cabal-install/src/Distribution/Client/ProjectBuilding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ resolveBuildTimeSettings verbosity
buildSettingReportPlanningFailure
= fromFlag projectConfigReportPlanningFailure
buildSettingProgPathExtra = fromNubList projectConfigProgPathExtra
buildSettingHaddockOpen = False

ProjectConfigBuildOnly{..} = defaults
<> projectConfigBuildOnly
Expand Down
3 changes: 2 additions & 1 deletion cabal-install/src/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,6 @@ data BuildTimeSettings
buildSettingCacheDir :: FilePath,
buildSettingHttpTransport :: Maybe String,
buildSettingIgnoreExpiry :: Bool,
buildSettingProgPathExtra :: [FilePath]
buildSettingProgPathExtra :: [FilePath],
buildSettingHaddockOpen :: Bool
}
24 changes: 23 additions & 1 deletion cabal-install/src/Distribution/Client/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Distribution.Client.Utils
, moreRecentFile, existsAndIsMoreRecentThan
, tryFindAddSourcePackageDesc
, tryFindPackageDesc
, findOpenProgramLocation
, relaxEncodingErrors
, ProgressPhase (..)
, progressMessage
Expand All @@ -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 )
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/pr-7550
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: Add --open flag to `cabal haddock`
packages: cabal-install
prs: #7550
issues: #7366
9 changes: 8 additions & 1 deletion doc/cabal-project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
-------------------------------------

Expand Down
43 changes: 43 additions & 0 deletions release-notes/cabal-install-3.6.0.0.md
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit da7be57

Please sign in to comment.