Commit ce1947a9 authored by fendor's avatar fendor Committed by Oleg Grenrus

Prepend hs-source-dir to match-component

Add Integration tests for File Target Selector

Add Integration test for Target Selecetors for files that
are part of other-modules in sub-directories.

Normalise Filepaths for target matching

Add filepath and module target syntax to readthedocs

Add ambiguous file target test-case
parent 10f33bad
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -365,8 +365,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
......
......@@ -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.
......@@ -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"
......
......@@ -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
\ No newline at end of file
......@@ -5,6 +5,7 @@ cabal-version: >= 1.2
library
exposed-modules: QQ
other-modules: Q
build-depends: base
executable qexe
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment