forked from haskell/cabal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve haskell#6369: Allow cabal v2-install pkgname:exename
- Loading branch information
Showing
4 changed files
with
79 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
cabal-install/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module Distribution.Client.CmdInstall.ClientInstallTargetSelector ( | ||
WithoutProjectTargetSelector (..), | ||
parseWithoutProjectTargetSelector, | ||
woPackageNames, | ||
woPackageTargets, | ||
woPackageSpecifiers, | ||
) where | ||
|
||
import Distribution.Client.Compat.Prelude | ||
import Prelude () | ||
|
||
import Distribution.Client.TargetSelector | ||
import Distribution.Client.Types | ||
import Distribution.Compat.CharParsing (char, optional) | ||
import Distribution.Package | ||
import Distribution.Parsec | ||
import Distribution.Simple.LocalBuildInfo (ComponentName (CExeName)) | ||
import Distribution.Simple.Utils (die') | ||
import Distribution.Solver.Types.PackageConstraint (PackageProperty (..)) | ||
import Distribution.Verbosity (Verbosity) | ||
import Distribution.Version | ||
|
||
data WithoutProjectTargetSelector | ||
= WoPackageId PackageId | ||
| WoPackageComponent PackageId ComponentName | ||
-- | WoURI URI | ||
deriving (Show) | ||
|
||
parseWithoutProjectTargetSelector :: Verbosity -> String -> IO WithoutProjectTargetSelector | ||
parseWithoutProjectTargetSelector verbosity input = | ||
case explicitEitherParsec parser input of | ||
Right ts -> return ts | ||
Left err -> die' verbosity $ "Invalid package ID: " ++ input ++ "\n" ++ err | ||
where | ||
parser :: ParsecParser WithoutProjectTargetSelector | ||
parser = do | ||
pid <- parsec | ||
cn <- optional (char ':' *> parsec) | ||
return $ case cn of | ||
Nothing -> WoPackageId pid | ||
Just cn' -> WoPackageComponent pid (CExeName cn') | ||
|
||
woPackageNames :: WithoutProjectTargetSelector -> [PackageName] | ||
woPackageNames (WoPackageId pid) = [pkgName pid] | ||
woPackageNames (WoPackageComponent pid _) = [pkgName pid] | ||
|
||
woPackageTargets :: WithoutProjectTargetSelector -> TargetSelector | ||
woPackageTargets (WoPackageId pid) = | ||
TargetPackageNamed (pkgName pid) Nothing | ||
woPackageTargets (WoPackageComponent pid cn) = | ||
TargetComponentUnknown (pkgName pid) (Right cn) WholeComponent | ||
|
||
woPackageSpecifiers :: WithoutProjectTargetSelector -> PackageSpecifier pkg | ||
woPackageSpecifiers (WoPackageId pid) = pidPackageSpecifiers pid | ||
woPackageSpecifiers (WoPackageComponent pid _) = pidPackageSpecifiers pid | ||
|
||
pidPackageSpecifiers :: PackageId -> PackageSpecifier pkg | ||
pidPackageSpecifiers pid | ||
| pkgVersion pid == nullVersion = NamedPackage (pkgName pid) [] | ||
| otherwise = NamedPackage (pkgName pid) | ||
[ PackagePropertyVersion (thisVersion (pkgVersion pid)) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters