Skip to content

fix list-bin to only choose the selected component #7791

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

Merged
merged 5 commits into from
Feb 25, 2022
Merged
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
24 changes: 15 additions & 9 deletions cabal-install/src/Distribution/Client/CmdListBin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
elaboratedPlan
return (elaboratedPlan', targets)

(selectedUnitId, _selectedComponent) <-
(selectedUnitId, selectedComponent) <-
-- Slight duplication with 'runProjectPreBuildPhase'.
singleComponentOrElse
(die' verbosity $ "No or multiple targets given, but the run "
Expand All @@ -128,12 +128,13 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
Nothing -> die' verbosity "No or multiple targets given..."
Just gpp -> return $ IP.foldPlanPackage
(const []) -- IPI don't have executables
(elaboratedPackage (distDirLayout baseCtx) (elaboratedShared buildCtx))
(elaboratedPackage (distDirLayout baseCtx) (elaboratedShared buildCtx) selectedComponent)
gpp

case binfiles of
[] -> die' verbosity "No target found"
[exe] -> putStrLn exe
_ -> die' verbosity "No or multiple targets given"
_ -> die' verbosity "Multiple targets found"
where
defaultVerbosity = verboseStderr silent
verbosity = fromFlagOrDefault defaultVerbosity (configVerbosity configFlags)
Expand All @@ -142,9 +143,10 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
elaboratedPackage
:: DistDirLayout
-> ElaboratedSharedConfig
-> UnqualComponentName
-> ElaboratedConfiguredPackage
-> [FilePath]
elaboratedPackage distDirLayout elaboratedSharedConfig elab = case elabPkgOrComp elab of
elaboratedPackage distDirLayout elaboratedSharedConfig selectedComponent elab = case elabPkgOrComp elab of
ElabPackage pkg ->
[ bin
| (c, _) <- CD.toList $ CD.zip (pkgLibDependencies pkg)
Expand All @@ -156,11 +158,15 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
dist_dir = distBuildDirectory distDirLayout (elabDistDirParams elaboratedSharedConfig elab)

bin_file c = case c of
CD.ComponentExe s -> [bin_file' s]
CD.ComponentTest s -> [bin_file' s]
CD.ComponentBench s -> [bin_file' s]
CD.ComponentFLib s -> [flib_file' s]
_ -> []
CD.ComponentExe s
| s == selectedComponent -> [bin_file' s]
CD.ComponentTest s
| s == selectedComponent -> [bin_file' s]
CD.ComponentBench s
| s == selectedComponent -> [bin_file' s]
CD.ComponentFLib s
| s == selectedComponent -> [flib_file' s]
_ -> []

plat :: Platform
plat = pkgConfigPlatform elaboratedSharedConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cabal-version: 2.2
name: SelectedComponent
version: 1.0.0

executable testexe

executable setup

custom-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cabal list-bin
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- SelectedComponent-1.0.0 (exe:testexe) (first run)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Test.Cabal.Prelude

-- https://github.com/haskell/cabal/issues/7679
main = cabalTest . void $ do
res <- cabal' "list-bin" ["exe:testexe"]

assertOutputContains "SelectedComponent-1.0.0" res
assertOutputContains "testexe" res
4 changes: 4 additions & 0 deletions changelog.d/issue-7679
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: Fix list-bin to only choose the selected component
packages: cabal-install
issues: #7679
prs: #7791