Skip to content

Commit dd312ec

Browse files
authored
Merge pull request #8234 from mgsium/tabular-help
pretty-print run targets on failure
2 parents b2c3de3 + bd998ce commit dd312ec

File tree

12 files changed

+71
-111
lines changed

12 files changed

+71
-111
lines changed

.docker/validate-8.0.2.dockerfile

Lines changed: 0 additions & 69 deletions
This file was deleted.

.github/workflows/validate.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
strategy:
3939
matrix:
4040
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
41-
ghc: ["9.2.3", "9.0.2", "8.10.7", "8.8.4", "8.6.5", "8.4.4", "8.0.2"]
41+
ghc: ["9.2.3", "9.0.2", "8.10.7", "8.8.4", "8.6.5", "8.4.4"]
4242
exclude:
4343
# lot of segfaults caused by ghc bugs
4444
- os: "windows-latest"
@@ -49,16 +49,6 @@ jobs:
4949
# it often randomly does "C:\Users\RUNNER~1\AppData\Local\Temp\ghcFEDE.c: DeleteFile "\\\\?\\C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\ghcFEDE.c": permission denied (Access is denied.)"
5050
- os: "windows-latest"
5151
ghc: "8.6.5"
52-
include:
53-
- os: "ubuntu-latest"
54-
ghc: "8.0.2"
55-
cli: "false"
56-
- os: "macos-latest"
57-
ghc: "8.0.2"
58-
cli: "false"
59-
- os: "windows-latest"
60-
ghc: "8.0.2"
61-
cli: "false"
6252

6353
steps:
6454

Cabal-syntax/src/Distribution/Types/ComponentName.hs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
22
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE PatternSynonyms #-}
34

45
module Distribution.Types.ComponentName (
5-
ComponentName(..),
6+
ComponentName(.., CFLibName, CExeName, CTestName, CBenchName),
67
showComponentName,
8+
componentNameRaw,
79
componentNameStanza,
810
componentNameString,
911
) where
@@ -21,12 +23,32 @@ import qualified Distribution.Compat.CharParsing as P
2123

2224
-- Libraries live in a separate namespace, so must distinguish
2325
data ComponentName = CLibName LibraryName
24-
| CFLibName UnqualComponentName
25-
| CExeName UnqualComponentName
26-
| CTestName UnqualComponentName
27-
| CBenchName UnqualComponentName
26+
| CNotLibName NotLibComponentName
2827
deriving (Eq, Generic, Ord, Read, Show, Typeable)
2928

29+
data NotLibComponentName
30+
= CNLFLibName { toCompName :: UnqualComponentName }
31+
| CNLExeName { toCompName :: UnqualComponentName }
32+
| CNLTestName { toCompName :: UnqualComponentName }
33+
| CNLBenchName { toCompName :: UnqualComponentName }
34+
deriving (Eq, Generic, Ord, Read, Show, Typeable)
35+
36+
pattern CFLibName :: UnqualComponentName -> ComponentName
37+
pattern CFLibName n = CNotLibName (CNLFLibName n)
38+
39+
pattern CExeName :: UnqualComponentName -> ComponentName
40+
pattern CExeName n = CNotLibName (CNLExeName n)
41+
42+
pattern CTestName :: UnqualComponentName -> ComponentName
43+
pattern CTestName n = CNotLibName (CNLTestName n)
44+
45+
pattern CBenchName :: UnqualComponentName -> ComponentName
46+
pattern CBenchName n = CNotLibName (CNLBenchName n)
47+
{-# COMPLETE CLibName, CFLibName, CExeName, CTestName, CBenchName #-}
48+
49+
instance Binary NotLibComponentName
50+
instance Structured NotLibComponentName
51+
3052
instance Binary ComponentName
3153
instance Structured ComponentName
3254

@@ -59,6 +81,10 @@ showComponentName (CExeName name) = "executable '" ++ prettyShow name ++ "'"
5981
showComponentName (CTestName name) = "test suite '" ++ prettyShow name ++ "'"
6082
showComponentName (CBenchName name) = "benchmark '" ++ prettyShow name ++ "'"
6183

84+
componentNameRaw :: ComponentName -> String
85+
componentNameRaw l@(CLibName _) = showComponentName l
86+
componentNameRaw (CNotLibName x) = prettyShow $ toCompName x
87+
6288
componentNameStanza :: ComponentName -> String
6389
componentNameStanza (CLibName lib) = libraryNameStanza lib
6490
componentNameStanza (CFLibName name) = "foreign-library " ++ prettyShow name
@@ -71,8 +97,5 @@ componentNameStanza (CBenchName name) = "benchmark " ++ prettyShow name
7197
-- @Nothing@ if the 'ComponentName' was for the public
7298
-- library.
7399
componentNameString :: ComponentName -> Maybe UnqualComponentName
74-
componentNameString (CLibName lib) = libraryNameString lib
75-
componentNameString (CFLibName n) = Just n
76-
componentNameString (CExeName n) = Just n
77-
componentNameString (CTestName n) = Just n
78-
componentNameString (CBenchName n) = Just n
100+
componentNameString (CLibName lib) = libraryNameString lib
101+
componentNameString (CNotLibName x) = Just $ toCompName x

Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tests = testGroup "Distribution.Utils.Structured"
2929
, testCase "GenericPackageDescription" $
3030
md5Check (Proxy :: Proxy GenericPackageDescription) 0xaf3d4c667a8f019c98a45451419ad71c
3131
, testCase "LocalBuildInfo" $
32-
md5Check (Proxy :: Proxy LocalBuildInfo) 0x6d132d3f99c869b678468256f24b6241
32+
md5Check (Proxy :: Proxy LocalBuildInfo) 0x8ef5a39cb640e4340cf5c43a8300ff94
3333
#endif
3434
]
3535

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ cabal-install-test-accept:
126126
#
127127
# make validate-via-docker-all -j4 -O
128128
#
129-
validate-via-docker-all : validate-via-docker-8.0.2
130129
validate-via-docker-all : validate-via-docker-8.2.2
131130
validate-via-docker-all : validate-via-docker-8.4.4
132131
validate-via-docker-all : validate-via-docker-8.6.5
@@ -147,9 +146,6 @@ validate-dockerfiles : .docker/validate-8.6.5.dockerfile
147146
# and we have a test relying on this limit being sufficiently small
148147
DOCKERARGS:=--ulimit nofile=1024:1024
149148

150-
validate-via-docker-8.0.2:
151-
docker build $(DOCKERARGS) -t cabal-validate:8.0.2 -f .docker/validate-8.0.2.dockerfile .
152-
153149
validate-via-docker-8.2.2:
154150
docker build $(DOCKERARGS) -t cabal-validate:8.2.2 -f .docker/validate-8.2.2.dockerfile .
155151

cabal-dev-scripts/src/GenValidateDockerfile.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ params = Map.fromList
4545
, pair "8.6.5" $ Z "ghc-8.6.5" "8.6.5-bionic" False True False True ""
4646
, pair "8.4.4" $ Z "ghc-8.4.4" "8.4.4-bionic" False True False True ""
4747
, pair "8.2.2" $ Z "ghc-8.2.2" "8.2.2-bionic" True True False True ""
48-
, pair "8.0.2" $ Z "ghc-8.0.2" "8.0.2-bionic" True True False True ""
4948
]
5049
where
5150
pair = (,)

cabal-install/src/Distribution/Client/CmdErrorMessages.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ renderListCommaAnd [x] = x
7272
renderListCommaAnd [x,x'] = x ++ " and " ++ x'
7373
renderListCommaAnd (x:xs) = x ++ ", " ++ renderListCommaAnd xs
7474

75+
renderListTabular :: [String] -> String
76+
renderListTabular = ("\n"++) . unlines . map ("| * "++)
77+
78+
renderListPretty :: [String] -> String
79+
renderListPretty xs = if length xs > 5 then renderListTabular xs
80+
else renderListCommaAnd xs
81+
7582
-- | Render a list of things in the style @blah blah; this that; and the other@
7683
renderListSemiAnd :: [String] -> String
7784
renderListSemiAnd [] = ""

cabal-install/src/Distribution/Client/CmdRun.hs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import Distribution.Client.CmdErrorMessages
2727
( renderTargetSelector, showTargetSelector,
2828
renderTargetProblem,
2929
renderTargetProblemNoTargets, plural, targetSelectorPluralPkgs,
30-
targetSelectorFilter, renderListCommaAnd )
30+
targetSelectorFilter, renderListCommaAnd,
31+
renderListPretty )
3132
import Distribution.Client.TargetProblem
3233
( TargetProblem (..) )
3334

@@ -42,11 +43,11 @@ import Distribution.Simple.Flag
4243
import Distribution.Simple.Command
4344
( CommandUI(..), usageAlternatives )
4445
import Distribution.Types.ComponentName
45-
( showComponentName )
46+
( componentNameRaw )
4647
import Distribution.Verbosity
4748
( normal, silent )
4849
import Distribution.Simple.Utils
49-
( wrapText, die', info, notice )
50+
( wrapText, die', info, notice, safeHead )
5051
import Distribution.Client.ProjectPlanning
5152
( ElaboratedConfiguredPackage(..)
5253
, ElaboratedInstallPlan, binDirectoryFor )
@@ -64,6 +65,7 @@ import Distribution.Types.UnitId
6465
import Distribution.Client.ScriptUtils
6566
( AcceptNoTargets(..), withContextAndSelectors, updateContextAndWriteProjectFile, TargetContext(..) )
6667

68+
import Data.List (group)
6769
import qualified Data.Set as Set
6870
import System.Directory
6971
( doesFileExist )
@@ -424,14 +426,13 @@ renderRunProblem :: RunProblem -> String
424426
renderRunProblem (TargetProblemMatchesMultiple targetSelector targets) =
425427
"The run command is for running a single executable at once. The target '"
426428
++ showTargetSelector targetSelector ++ "' refers to "
427-
++ renderTargetSelector targetSelector ++ " which includes "
428-
++ renderListCommaAnd ( ("the "++) <$>
429-
showComponentName <$>
430-
availableTargetComponentName <$>
431-
foldMap
432-
(\kind -> filterTargetsKind kind targets)
433-
[ExeKind, TestKind, BenchKind] )
434-
++ "."
429+
++ renderTargetSelector targetSelector ++ " which includes \n"
430+
++ unlines ((\(label, xs) -> "- " ++ label ++ ": " ++ renderListPretty xs)
431+
<$> (zip ["executables", "test-suites", "benchmarks"]
432+
$ filter (not . null) . map removeDuplicates
433+
$ map (componentNameRaw . availableTargetComponentName)
434+
<$> (flip filterTargetsKind $ targets) <$> [ExeKind, TestKind, BenchKind] ))
435+
where removeDuplicates = catMaybes . map safeHead . group . sort
435436

436437
renderRunProblem (TargetProblemMultipleTargets selectorMap) =
437438
"The run command is for running a single executable at once. The targets "

cabal-install/tests/UnitTests/Distribution/Client/Init/Utils.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ baseVersion' "8.8.4" = [4,13,0,0]
6767
baseVersion' "8.6.5" = [4,12,0,0]
6868
baseVersion' "8.4.4" = [4,11,1,0]
6969
baseVersion' "8.2.2" = [4,10,1,0]
70-
baseVersion' "8.0.2" = [4,10,0,0]
7170
baseVersion' "7.10.3" = [4,9,0,0]
7271
baseVersion' "7.8.4" = [4,8,0,0]
7372
baseVersion' "7.6.3" = [4,7,0,0]

cabal-testsuite/PackageTests/NewBuild/CmdRun/MultipleExes/cabal.out

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Building executable 'bar' for MultipleExes-1.0..
1616
# cabal v2-run
1717
Up to date
1818
# cabal v2-run
19-
Error: cabal: The run command is for running a single executable at once. The target '' refers to the package MultipleExes-1.0 which includes the executable 'foo' and the executable 'bar'.
19+
Error: cabal: The run command is for running a single executable at once. The target '' refers to the package MultipleExes-1.0 which includes
20+
- executables: bar and foo
2021
# cabal v2-run
21-
Error: cabal: The run command is for running a single executable at once. The target 'MultipleExes' refers to the package MultipleExes-1.0 which includes the executable 'foo' and the executable 'bar'.
22+
Error: cabal: The run command is for running a single executable at once. The target 'MultipleExes' refers to the package MultipleExes-1.0 which includes
23+
- executables: bar and foo

cabal-testsuite/PackageTests/NewBuild/CmdRun/MultiplePackages/cabal.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Building executable 'foo-exe' for bar-1.0..
2525
# cabal v2-run
2626
Error: cabal: No targets given and there is no package in the current directory. Specify packages or components by name or location. See 'cabal build --help' for more details on target options.
2727
# cabal v2-run
28-
Error: cabal: The run command is for running a single executable at once. The target 'bar' refers to the package bar-1.0 which includes the executable 'foo-exe' and the executable 'bar-exe'.
28+
Error: cabal: The run command is for running a single executable at once. The target 'bar' refers to the package bar-1.0 which includes
29+
- executables: bar-exe and foo-exe
2930
# cabal v2-run
3031
Error: cabal: Ambiguous target 'foo-exe'. It could be:
3132
bar:foo-exe (component)

changelog.d/issue-8189

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
synopsis: Pretty-print run targets on failure
2+
packages: cabal-install
3+
prs: #8234
4+
issues: #8189
5+
6+
description: {
7+
8+
- Targets of the `run` command are pretty-printed when failing due to multiple targets.
9+
- Duplicate targets are removed in the output.
10+
11+
}

0 commit comments

Comments
 (0)