Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend hs-source-dir to match-component #6622 #6623

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2117,12 +2117,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 @@ -360,8 +360,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
18 changes: 17 additions & 1 deletion cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,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",
Copy link
Collaborator

@phadej phadej May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add a test that Main.hs should be ambiguous?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, an ambiguous target selector makes sense, going to update it asap!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I am not sure I get what you are saying?
Do you mean to add a test for the case that Main.hs is ambiguous? Since it should be a filepath, I dont think it can be ambiguous?

":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 @@ -355,6 +361,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 Expand Up @@ -1330,7 +1346,7 @@ testExceptionInConfigureStep config = do
(_pkga1, failure) <- expectPackageFailed plan res pkgidA1
case buildFailureReason failure of
ConfigureFailed _ -> return ()
_ -> assertFailure $ "expected ConfigureFailed, got " ++ show failure
_ -> assertFailure $ "expected ConfigureFailed, got " ++ show failure
cleanProject testdir
where
testdir = "exception/configure"
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