Skip to content

Commit

Permalink
Merge pull request #7827 from brandonchinn178/chinn/haddock
Browse files Browse the repository at this point in the history
Fix haddock via Setup.hs with internal libraries
  • Loading branch information
mergify[bot] authored Jan 30, 2022
2 parents c976c0a + bd47cd7 commit 4879ae1
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 29 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Here are some other useful variations on the commands:

~~~~
cabal v2-build Cabal # build library only
cabal v2-build Cabal:unit-tests # build Cabal's unit test suite
cabal v2-build Cabal-tests:unit-tests # build Cabal's unit test suite
cabal v2-build cabal-tests # etc...
~~~~

Expand Down Expand Up @@ -91,7 +91,7 @@ run without it).

There are also other test suites:

* `Cabal:unit-tests` are small, quick-running unit tests
* `Cabal-tests:unit-tests` are small, quick-running unit tests
on small pieces of functionality in Cabal. If you are working
on some utility functions in the Cabal library you should run this
test suite.
Expand Down
2 changes: 1 addition & 1 deletion Cabal-syntax/src/Distribution/Compat/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ instance Functor (Pretext a b) where
--
-- First start a repl
--
-- > cabal new-repl Cabal:hackage-tests
-- > cabal new-repl Cabal-tests:hackage-tests
--
-- Because @--extra-package@ isn't yet implemented, we use a test-suite
-- with @generics-sop@ dependency.
Expand Down
2 changes: 1 addition & 1 deletion Cabal-syntax/src/Distribution/Types/VersionInterval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Distribution.Types.VersionRange.Internal

-- To test this module, and to run version range normalisation benchmarks:
--
-- cabal run Cabal:unit-tests -- -p Distribution.Version
-- cabal run Cabal-tests:unit-tests -- -p Distribution.Version
-- cabal run cabal-benchmarks -- -o bench.html normaliseVersionRange

-------------------------------------------------------------------------------
Expand Down
38 changes: 17 additions & 21 deletions Cabal/src/Distribution/Simple/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,27 +279,23 @@ haddock pkg_descr lbi suffixes flags' = do
let libArgs' = commonArgs `mappend` libArgs
runHaddock verbosity tmpFileOpts comp platform haddockProg libArgs'

case libName lib of
LMainLibName ->
pure index
LSubLibName _ -> do
pwd <- getCurrentDirectory

let
ipi = inplaceInstalledPackageInfo
pwd (flag haddockDistPref) pkg_descr
(mkAbiHash "inplace") lib lbi' clbi

debug verbosity $ "Registering inplace:\n"
++ (InstalledPackageInfo.showInstalledPackageInfo ipi)

registerPackage verbosity (compiler lbi') (withPrograms lbi')
(withPackageDB lbi') ipi
HcPkg.defaultRegisterOptions {
HcPkg.registerMultiInstance = True
}

return $ PackageIndex.insert ipi index
pwd <- getCurrentDirectory

let
ipi = inplaceInstalledPackageInfo
pwd (flag haddockDistPref) pkg_descr
(mkAbiHash "inplace") lib lbi' clbi

debug verbosity $ "Registering inplace:\n"
++ (InstalledPackageInfo.showInstalledPackageInfo ipi)

registerPackage verbosity (compiler lbi') (withPrograms lbi')
(withPackageDB lbi') ipi
HcPkg.defaultRegisterOptions {
HcPkg.registerMultiInstance = True
}

return $ PackageIndex.insert ipi index

CFLib flib -> (when (flag haddockForeignLibs) $ do
withTempDirectoryEx verbosity tmpFileOpts (buildDir lbi') "tmp" $
Expand Down
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/InternalLibraries/Haddock/Foo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Foo where

import InternalBefore

foo :: Int
foo = internalBefore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module InternalAfter where

import Foo

internalAfter :: Int
internalAfter = foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module InternalBefore where

internalBefore :: Int
internalBefore = 42
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/InternalLibraries/Haddock/foo.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: foo
version: 0.1.0.0
build-type: Simple
cabal-version: 1.24

library foo-internal-before
build-depends: base
exposed-modules: InternalBefore
default-language: Haskell2010

library
build-depends: base, foo-internal-before
exposed-modules: Foo
default-language: Haskell2010

library foo-internal-after
build-depends: base, foo
exposed-modules: InternalAfter
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Setup configure
Configuring foo-0.1.0.0...
# Setup build
Preprocessing library 'foo-internal-before' for foo-0.1.0.0..
Building library 'foo-internal-before' for foo-0.1.0.0..
Preprocessing library for foo-0.1.0.0..
Building library for foo-0.1.0.0..
Preprocessing library 'foo-internal-after' for foo-0.1.0.0..
Building library 'foo-internal-after' for foo-0.1.0.0..
# Setup copy
Installing internal library foo-internal-before in <PATH>
Installing library in <PATH>
Installing internal library foo-internal-after in <PATH>
# Setup register
Registering library 'foo-internal-before' for foo-0.1.0.0..
Registering library for foo-0.1.0.0..
Registering library 'foo-internal-after' for foo-0.1.0.0..
# Setup haddock
Preprocessing library 'foo-internal-before' for foo-0.1.0.0..
Running Haddock on library 'foo-internal-before' for foo-0.1.0.0..
Documentation created: haddock.cabal.dist/work/dist/doc/html/foo/index.html
Preprocessing library for foo-0.1.0.0..
Running Haddock on library for foo-0.1.0.0..
Documentation created: haddock.cabal.dist/work/dist/doc/html/foo/index.html
Preprocessing library 'foo-internal-after' for foo-0.1.0.0..
Running Haddock on library 'foo-internal-after' for foo-0.1.0.0..
Documentation created: haddock.cabal.dist/work/dist/doc/html/foo/index.html
27 changes: 27 additions & 0 deletions cabal-testsuite/PackageTests/InternalLibraries/Haddock/haddock.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Setup configure
Configuring foo-0.1.0.0...
# Setup build
Preprocessing library 'foo-internal-before' for foo-0.1.0.0..
Building library 'foo-internal-before' for foo-0.1.0.0..
Preprocessing library for foo-0.1.0.0..
Building library for foo-0.1.0.0..
Preprocessing library 'foo-internal-after' for foo-0.1.0.0..
Building library 'foo-internal-after' for foo-0.1.0.0..
# Setup copy
Installing internal library foo-internal-before in <PATH>
Installing library in <PATH>
Installing internal library foo-internal-after in <PATH>
# Setup register
Registering library 'foo-internal-before' for foo-0.1.0.0..
Registering library for foo-0.1.0.0..
Registering library 'foo-internal-after' for foo-0.1.0.0..
# Setup haddock
Preprocessing library 'foo-internal-before' for foo-0.1.0.0..
Running Haddock on library 'foo-internal-before' for foo-0.1.0.0..
Documentation created: haddock.dist/work/dist/doc/html/foo/index.html
Preprocessing library for foo-0.1.0.0..
Running Haddock on library for foo-0.1.0.0..
Documentation created: haddock.dist/work/dist/doc/html/foo/index.html
Preprocessing library 'foo-internal-after' for foo-0.1.0.0..
Running Haddock on library 'foo-internal-after' for foo-0.1.0.0..
Documentation created: haddock.dist/work/dist/doc/html/foo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test.Cabal.Prelude
-- https://github.com/haskell/cabal/issues/1919
main = setupAndCabalTest $
withPackageDb $ do
setup_install []
setup "haddock" []
4 changes: 4 additions & 0 deletions changelog.d/issue-1919
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: Fix haddock command via Setup.hs for internal libraries
packages: Cabal
issues: #1919
prs: #7827
2 changes: 1 addition & 1 deletion doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ example, to build a test suite named ``package-tests``, use the command:

Targets can be qualified with package names. So to request
``package-tests`` *from* the ``Cabal`` package, use
``Cabal:package-tests``.
``Cabal-tests:package-tests``.

Unlike sandboxes, there is no need to setup a sandbox or ``add-source``
projects; just check in ``cabal.project`` to your repository and
Expand Down
17 changes: 14 additions & 3 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
resolver: lts-11.6
resolver: lts-18.17

packages:
- Cabal-syntax/
- Cabal/
- Cabal-described
- Cabal-QuickCheck/
- Cabal-tests/
- Cabal-tree-diff/
- cabal-benchmarks/
- cabal-install-solver/
- cabal-install/
- cabal-testsuite/
- solver-benchmarks/

extra-deps:
- resolv-0.1.1.1
- QuickCheck-2.11.3
- rere-0.2@sha256:ec1d87554c03755d89f3401c5e5c27827e61dde835c54cbdaf509136ce8f6f2b,4079

allow-newer: true

nix:
packages:
- autoconf
Expand Down

0 comments on commit 4879ae1

Please sign in to comment.