diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2018-12-02 18:26:39 +0100 |
---|---|---|
committer | Daniel Gröber <dxld@darkboxed.org> | 2019-01-22 03:06:51 +0100 |
commit | b7177f8b7f972258eb4fa72217d2896d8a45849a (patch) | |
tree | 9ecb0655ac220d8e588f2cc528eb1e4f38945c9d /cabal-plan/src | |
parent | 158af7acfa54ad3f4a18cd8e697efb1341cd7e05 (diff) |
Add cabal target-selector compatible pretty printer for CompName
Currently `dispCompName CompNameLib` would just print `"lib"` however this
syntax is neither accepted by `cabal v1-build` nor `v2-build` as a valid target
selector making it somewhat useless for that use-case.
To specify a main library as a target selector one has to use the
`<namespace>:<component name>` syntax where `<component name>` is the name of
the respective package for unqualified libraries.
Hence this commit adds new function `dispCompName` with an additional `PkgName`
argument.
Diffstat (limited to 'cabal-plan/src')
-rwxr-xr-x | cabal-plan/src/Cabal/Plan.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/cabal-plan/src/Cabal/Plan.hs b/cabal-plan/src/Cabal/Plan.hs index 63be81b..d65c581 100755 --- a/cabal-plan/src/Cabal/Plan.hs +++ b/cabal-plan/src/Cabal/Plan.hs @@ -14,6 +14,7 @@ module Cabal.Plan , Unit(..) , CompName(..) , dispCompName + , dispCompNameTarget , CompInfo(..) , UnitType(..) @@ -300,7 +301,16 @@ parseCompName t0 = case T.splitOn ":" t0 of ["setup"] -> Just CompNameSetup _ -> Nothing --- | Pretty print 'CompName' +-- | Pretty print 'CompName' in cabal's target-selector syntax. +dispCompNameTarget :: PkgName -> CompName -> Text +dispCompNameTarget (PkgName pkg) cn = case cn of + CompNameLib -> "lib:" <> pkg + _ -> dispCompName cn + +-- | Pretty print 'CompName' in the same syntax that is used in +-- @plan.json@. Note that this string can not be used as a target-selector on +-- the cabal command-line. See 'dispCompNameTarget' for a target-selector +-- compatible pretty printer. dispCompName :: CompName -> Text dispCompName cn = case cn of CompNameLib -> "lib" |