Skip to content

Commit a4b1708

Browse files
authored
Merge pull request #6826 from phadej/pr-6623
Prepend hs-source-dir to match-component
2 parents 10f33ba + ce1947a commit a4b1708

File tree

9 files changed

+45
-8
lines changed

9 files changed

+45
-8
lines changed

Cabal/doc/cabal-commands.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ A target can take any of the following forms:
8686
- ``tests``,
8787
- ``benches``, ``benchmarks``.
8888

89+
- A module target: ``[package:][ctype:]module``, which specifies that the
90+
component of which the given module is a part of will be built.
91+
92+
- A filepath target: ``[package:][ctype:]filepath``, which specifies that the
93+
component of which the given filepath is a part of will be built.
94+
8995
In component targets, ``package:`` and ``ctype:`` (valid component types
9096
are ``lib``, ``flib``, ``exe``, ``test`` and ``bench``) can be used to
9197
disambiguate when multiple packages define the same component, or the
@@ -99,9 +105,12 @@ Some example targets:
99105

100106
$ cabal v2-build lib:foo-pkg # build the library named foo-pkg
101107
$ cabal v2-build foo-pkg:foo-tests # build foo-tests in foo-pkg
102-
103-
(There is also syntax for specifying module and file targets, but it
104-
doesn't currently do anything.)
108+
$ cabal v2-build src/Lib.s # build the library component to
109+
# which "src/Lib.hs" belongs
110+
$ cabal v2-build app/Main.hs # build the executable component of
111+
# "app/Main.hs"
112+
$ cabal v2-build Lib # build the library component to
113+
# which the module "Lib" belongs
105114

106115
Beyond a list of targets, ``cabal v2-build`` accepts all the flags that
107116
``cabal v2-configure`` takes. Most of these flags are only taken into

cabal-install/Distribution/Client/TargetSelector.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,12 +2108,14 @@ matchComponentOtherFile :: [KnownComponent] -> String
21082108
-> Match (FilePath, KnownComponent)
21092109
matchComponentOtherFile cs =
21102110
matchFile
2111-
[ (file, c)
2112-
| c <- cs
2113-
, file <- cinfoHsFiles c
2114-
++ cinfoCFiles c
2115-
++ cinfoJsFiles c
2111+
[ (normalise (srcdir </> file), c)
2112+
| c <- cs
2113+
, srcdir <- cinfoSrcDirs c
2114+
, file <- cinfoHsFiles c
2115+
++ cinfoCFiles c
2116+
++ cinfoJsFiles c
21162117
]
2118+
. normalise
21172119

21182120

21192121
matchComponentModuleFile :: [KnownComponent] -> String

cabal-install/cabal-install.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ Extra-Source-Files:
8080
tests/IntegrationTests2/targets/multiple-tests/cabal.project
8181
tests/IntegrationTests2/targets/multiple-tests/p.cabal
8282
tests/IntegrationTests2/targets/simple/P.hs
83+
tests/IntegrationTests2/targets/simple/app/Main.hs
8384
tests/IntegrationTests2/targets/simple/cabal.project
8485
tests/IntegrationTests2/targets/simple/p.cabal
86+
tests/IntegrationTests2/targets/simple/q/Q.hs
8587
tests/IntegrationTests2/targets/simple/q/QQ.hs
8688
tests/IntegrationTests2/targets/simple/q/q.cabal
8789
tests/IntegrationTests2/targets/test-only/p.cabal

cabal-install/cabal-install.cabal.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,10 @@
365365
tests/IntegrationTests2/targets/multiple-tests/cabal.project
366366
tests/IntegrationTests2/targets/multiple-tests/p.cabal
367367
tests/IntegrationTests2/targets/simple/P.hs
368+
tests/IntegrationTests2/targets/simple/app/Main.hs
368369
tests/IntegrationTests2/targets/simple/cabal.project
369370
tests/IntegrationTests2/targets/simple/p.cabal
371+
tests/IntegrationTests2/targets/simple/q/Q.hs
370372
tests/IntegrationTests2/targets/simple/q/QQ.hs
371373
tests/IntegrationTests2/targets/simple/q/q.cabal
372374
tests/IntegrationTests2/targets/test-only/p.cabal

cabal-install/tests/IntegrationTests2.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,15 @@ testTargetSelectors reportSubCase = do
248248
":pkg:p:lib:p:file:P.y"
249249
, "q/QQ.hs", "q:QQ.lhs", "lib:q:QQ.hsc", "q:q:QQ.hsc",
250250
":pkg:q:lib:q:file:QQ.y"
251+
, "q/Q.hs", "q:Q.lhs", "lib:q:Q.hsc", "q:q:Q.hsc",
252+
":pkg:q:lib:q:file:Q.y"
253+
, "app/Main.hs", "p:app/Main.hs", "exe:ppexe:app/Main.hs", "p:ppexe:app/Main.hs",
254+
":pkg:p:exe:ppexe:file:app/Main.hs"
251255
]
252256
ts @?= replicate 5 (TargetComponent "p-0.1" (CLibName LMainLibName) (FileTarget "P"))
253257
++ replicate 5 (TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "QQ"))
258+
++ replicate 5 (TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "Q"))
259+
++ replicate 5 (TargetComponent "p-0.1" (CExeName "ppexe") (FileTarget ("app" </> "Main.hs")))
254260
-- Note there's a bit of an inconsistency here: for the single-part
255261
-- syntax the target has to point to a file that exists, whereas for
256262
-- all the other forms we don't require that.
@@ -356,6 +362,16 @@ testTargetSelectorAmbiguous reportSubCase = do
356362
, mkexe "other2" `withCFiles` ["Foo"] ]
357363
]
358364

365+
-- File target is ambiguous, part of multiple components
366+
reportSubCase "ambiguous: file in multiple comps"
367+
assertAmbiguous "Bar.hs"
368+
[ mkTargetFile "foo" (CExeName "bar") "Bar"
369+
, mkTargetFile "foo" (CExeName "bar2") "Bar"
370+
]
371+
[ mkpkg "foo" [ mkexe "bar" `withModules` ["Bar"]
372+
, mkexe "bar2" `withModules` ["Bar"] ]
373+
]
374+
359375
-- non-exact case packages and components are ambiguous
360376
reportSubCase "ambiguous: non-exact-case pkg names"
361377
assertAmbiguous "Foo"

cabal-install/tests/IntegrationTests2/targets/simple/app/Main.hs

Whitespace-only changes.

cabal-install/tests/IntegrationTests2/targets/simple/p.cabal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ library
1010
executable pexe
1111
main-is: Main.hs
1212
other-modules: PMain
13+
14+
executable ppexe
15+
main-is: Main.hs
16+
hs-source-dirs: app
17+
other-modules: PMain

cabal-install/tests/IntegrationTests2/targets/simple/q/Q.hs

Whitespace-only changes.

cabal-install/tests/IntegrationTests2/targets/simple/q/q.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cabal-version: >= 1.2
55

66
library
77
exposed-modules: QQ
8+
other-modules: Q
89
build-depends: base
910

1011
executable qexe

0 commit comments

Comments
 (0)