From 696987ca88b29c462dd845be59e5dcc15b638b13 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 29 Mar 2020 20:30:54 +0200 Subject: [PATCH 1/5] Prepend hs-source-dir to match-component --- cabal-install/Distribution/Client/TargetSelector.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cabal-install/Distribution/Client/TargetSelector.hs b/cabal-install/Distribution/Client/TargetSelector.hs index 23d92f580fd..407a98e51a7 100644 --- a/cabal-install/Distribution/Client/TargetSelector.hs +++ b/cabal-install/Distribution/Client/TargetSelector.hs @@ -2117,11 +2117,12 @@ 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 ] From 48e6759e65d5510bcf5d03138a3134dba7e80bf1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Mar 2020 17:49:33 +0200 Subject: [PATCH 2/5] Add Integration tests for File Target Selector Add Integration test for Target Selecetors for files that are part of other-modules in sub-directories. --- cabal-install/cabal-install.cabal | 2 ++ cabal-install/cabal-install.cabal.pp | 2 ++ cabal-install/tests/IntegrationTests2.hs | 8 +++++++- .../tests/IntegrationTests2/targets/simple/app/Main.hs | 0 .../tests/IntegrationTests2/targets/simple/p.cabal | 5 +++++ .../tests/IntegrationTests2/targets/simple/q/Q.hs | 0 .../tests/IntegrationTests2/targets/simple/q/q.cabal | 1 + 7 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 cabal-install/tests/IntegrationTests2/targets/simple/app/Main.hs create mode 100644 cabal-install/tests/IntegrationTests2/targets/simple/q/Q.hs diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 76be19b76ce..a8f3f43c205 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -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 diff --git a/cabal-install/cabal-install.cabal.pp b/cabal-install/cabal-install.cabal.pp index 740172173c2..8d2eb38a4e7 100644 --- a/cabal-install/cabal-install.cabal.pp +++ b/cabal-install/cabal-install.cabal.pp @@ -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 diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index ce3f614ff8c..b0319595278 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -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", + ":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. @@ -1330,7 +1336,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" diff --git a/cabal-install/tests/IntegrationTests2/targets/simple/app/Main.hs b/cabal-install/tests/IntegrationTests2/targets/simple/app/Main.hs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cabal-install/tests/IntegrationTests2/targets/simple/p.cabal b/cabal-install/tests/IntegrationTests2/targets/simple/p.cabal index 4f7f5e3847d..87797575f8c 100644 --- a/cabal-install/tests/IntegrationTests2/targets/simple/p.cabal +++ b/cabal-install/tests/IntegrationTests2/targets/simple/p.cabal @@ -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 diff --git a/cabal-install/tests/IntegrationTests2/targets/simple/q/Q.hs b/cabal-install/tests/IntegrationTests2/targets/simple/q/Q.hs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cabal-install/tests/IntegrationTests2/targets/simple/q/q.cabal b/cabal-install/tests/IntegrationTests2/targets/simple/q/q.cabal index d8a3609d127..788a23a4b2c 100644 --- a/cabal-install/tests/IntegrationTests2/targets/simple/q/q.cabal +++ b/cabal-install/tests/IntegrationTests2/targets/simple/q/q.cabal @@ -5,6 +5,7 @@ cabal-version: >= 1.2 library exposed-modules: QQ + other-modules: Q build-depends: base executable qexe From ff4d6e5489a81f81e7a5047ee05ee1484ab531ca Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2020 20:28:52 +0200 Subject: [PATCH 3/5] Normalise Filepaths for target matching --- cabal-install/Distribution/Client/TargetSelector.hs | 1 + cabal-install/tests/IntegrationTests2.hs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cabal-install/Distribution/Client/TargetSelector.hs b/cabal-install/Distribution/Client/TargetSelector.hs index 407a98e51a7..db5ace5cc92 100644 --- a/cabal-install/Distribution/Client/TargetSelector.hs +++ b/cabal-install/Distribution/Client/TargetSelector.hs @@ -2124,6 +2124,7 @@ matchComponentOtherFile cs = ++ cinfoCFiles c ++ cinfoJsFiles c ] + . normalise matchComponentModuleFile :: [KnownComponent] -> String diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index b0319595278..c294fe515af 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -255,7 +255,7 @@ testTargetSelectors reportSubCase = do 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")) + ++ 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. From 9fef1d63a11133e1c2165b1cc6749b90a4d02093 Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 30 Mar 2020 23:11:57 +0200 Subject: [PATCH 4/5] Add filepath and module target syntax to readthedocs --- Cabal/doc/cabal-commands.rst | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Cabal/doc/cabal-commands.rst b/Cabal/doc/cabal-commands.rst index c19df8b3570..8b119fd68ad 100644 --- a/Cabal/doc/cabal-commands.rst +++ b/Cabal/doc/cabal-commands.rst @@ -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 From 91998223d249ff07b0ce27312712892d17502077 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 17 May 2020 19:12:51 +0200 Subject: [PATCH 5/5] Add ambiguous file target test-case --- cabal-install/tests/IntegrationTests2.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index c294fe515af..e7af7d898e7 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -361,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"