Skip to content

Commit

Permalink
Merge pull request #6826 from phadej/pr-6623
Browse files Browse the repository at this point in the history
Prepend hs-source-dir to match-component
  • Loading branch information
phadej authored May 20, 2020
2 parents 10f33ba + ce1947a commit a4b1708
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 8 deletions.
15 changes: 12 additions & 3 deletions Cabal/doc/cabal-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ A target can take any of the following forms:
- ``tests``,
- ``benches``, ``benchmarks``.

- A module target: ``[package:][ctype:]module``, which specifies that the
component of which the given module is a part of will be built.

- A filepath target: ``[package:][ctype:]filepath``, which specifies that the
component of which the given filepath is a part of will be built.

In component targets, ``package:`` and ``ctype:`` (valid component types
are ``lib``, ``flib``, ``exe``, ``test`` and ``bench``) can be used to
disambiguate when multiple packages define the same component, or the
Expand All @@ -99,9 +105,12 @@ Some example targets:

$ cabal v2-build lib:foo-pkg # build the library named foo-pkg
$ cabal v2-build foo-pkg:foo-tests # build foo-tests in foo-pkg

(There is also syntax for specifying module and file targets, but it
doesn't currently do anything.)
$ cabal v2-build src/Lib.s # build the library component to
# which "src/Lib.hs" belongs
$ cabal v2-build app/Main.hs # build the executable component of
# "app/Main.hs"
$ cabal v2-build Lib # build the library component to
# which the module "Lib" belongs

Beyond a list of targets, ``cabal v2-build`` accepts all the flags that
``cabal v2-configure`` takes. Most of these flags are only taken into
Expand Down
12 changes: 7 additions & 5 deletions cabal-install/Distribution/Client/TargetSelector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2108,12 +2108,14 @@ matchComponentOtherFile :: [KnownComponent] -> String
-> Match (FilePath, KnownComponent)
matchComponentOtherFile cs =
matchFile
[ (file, c)
| c <- cs
, file <- cinfoHsFiles c
++ cinfoCFiles c
++ cinfoJsFiles c
[ (normalise (srcdir </> file), c)
| c <- cs
, srcdir <- cinfoSrcDirs c
, file <- cinfoHsFiles c
++ cinfoCFiles c
++ cinfoJsFiles c
]
. normalise


matchComponentModuleFile :: [KnownComponent] -> String
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ Extra-Source-Files:
tests/IntegrationTests2/targets/multiple-tests/cabal.project
tests/IntegrationTests2/targets/multiple-tests/p.cabal
tests/IntegrationTests2/targets/simple/P.hs
tests/IntegrationTests2/targets/simple/app/Main.hs
tests/IntegrationTests2/targets/simple/cabal.project
tests/IntegrationTests2/targets/simple/p.cabal
tests/IntegrationTests2/targets/simple/q/Q.hs
tests/IntegrationTests2/targets/simple/q/QQ.hs
tests/IntegrationTests2/targets/simple/q/q.cabal
tests/IntegrationTests2/targets/test-only/p.cabal
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/cabal-install.cabal.pp
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,10 @@
tests/IntegrationTests2/targets/multiple-tests/cabal.project
tests/IntegrationTests2/targets/multiple-tests/p.cabal
tests/IntegrationTests2/targets/simple/P.hs
tests/IntegrationTests2/targets/simple/app/Main.hs
tests/IntegrationTests2/targets/simple/cabal.project
tests/IntegrationTests2/targets/simple/p.cabal
tests/IntegrationTests2/targets/simple/q/Q.hs
tests/IntegrationTests2/targets/simple/q/QQ.hs
tests/IntegrationTests2/targets/simple/q/q.cabal
tests/IntegrationTests2/targets/test-only/p.cabal
Expand Down
16 changes: 16 additions & 0 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,15 @@ testTargetSelectors reportSubCase = do
":pkg:p:lib:p:file:P.y"
, "q/QQ.hs", "q:QQ.lhs", "lib:q:QQ.hsc", "q:q:QQ.hsc",
":pkg:q:lib:q:file:QQ.y"
, "q/Q.hs", "q:Q.lhs", "lib:q:Q.hsc", "q:q:Q.hsc",
":pkg:q:lib:q:file:Q.y"
, "app/Main.hs", "p:app/Main.hs", "exe:ppexe:app/Main.hs", "p:ppexe:app/Main.hs",
":pkg:p:exe:ppexe:file:app/Main.hs"
]
ts @?= replicate 5 (TargetComponent "p-0.1" (CLibName LMainLibName) (FileTarget "P"))
++ replicate 5 (TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "QQ"))
++ replicate 5 (TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "Q"))
++ replicate 5 (TargetComponent "p-0.1" (CExeName "ppexe") (FileTarget ("app" </> "Main.hs")))
-- Note there's a bit of an inconsistency here: for the single-part
-- syntax the target has to point to a file that exists, whereas for
-- all the other forms we don't require that.
Expand Down Expand Up @@ -356,6 +362,16 @@ testTargetSelectorAmbiguous reportSubCase = do
, mkexe "other2" `withCFiles` ["Foo"] ]
]

-- File target is ambiguous, part of multiple components
reportSubCase "ambiguous: file in multiple comps"
assertAmbiguous "Bar.hs"
[ mkTargetFile "foo" (CExeName "bar") "Bar"
, mkTargetFile "foo" (CExeName "bar2") "Bar"
]
[ mkpkg "foo" [ mkexe "bar" `withModules` ["Bar"]
, mkexe "bar2" `withModules` ["Bar"] ]
]

-- non-exact case packages and components are ambiguous
reportSubCase "ambiguous: non-exact-case pkg names"
assertAmbiguous "Foo"
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions cabal-install/tests/IntegrationTests2/targets/simple/p.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ library
executable pexe
main-is: Main.hs
other-modules: PMain

executable ppexe
main-is: Main.hs
hs-source-dirs: app
other-modules: PMain
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cabal-version: >= 1.2

library
exposed-modules: QQ
other-modules: Q
build-depends: base

executable qexe
Expand Down

0 comments on commit a4b1708

Please sign in to comment.