Copyright | (c) Duncan Coutts 2012 2015 2016 |
---|---|
License | BSD-like |
Maintainer | duncan@community.haskell.org |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Handling for user-specified target selectors.
Synopsis
- data TargetSelector
- = TargetPackage TargetImplicitCwd [PackageId] (Maybe ComponentKindFilter)
- | TargetPackageNamed PackageName (Maybe ComponentKindFilter)
- | TargetAllPackages (Maybe ComponentKindFilter)
- | TargetComponent PackageId ComponentName SubComponentTarget
- | TargetComponentUnknown PackageName (Either UnqualComponentName ComponentName) SubComponentTarget
- data TargetImplicitCwd
- data ComponentKind
- type ComponentKindFilter = ComponentKind
- data SubComponentTarget
- data QualLevel
- componentKind :: ComponentName -> ComponentKind
- readTargetSelectors :: [PackageSpecifier (SourcePackage (PackageLocation a))] -> Maybe ComponentKindFilter -> [String] -> IO (Either [TargetSelectorProblem] [TargetSelector])
- data TargetSelectorProblem
- = TargetSelectorExpected TargetString [String] String
- | TargetSelectorNoSuch TargetString [(Maybe (String, String), String, String, [String])]
- | TargetSelectorAmbiguous TargetString [(TargetString, TargetSelector)]
- | MatchingInternalError TargetString TargetSelector [(TargetString, [TargetSelector])]
- | TargetSelectorUnrecognised String
- | TargetSelectorNoCurrentPackage TargetString
- | TargetSelectorNoTargetsInCwd Bool
- | TargetSelectorNoTargetsInProject
- | TargetSelectorNoScript TargetString
- reportTargetSelectorProblems :: Verbosity -> [TargetSelectorProblem] -> IO a
- showTargetSelector :: TargetSelector -> String
- data TargetString
- showTargetString :: TargetString -> String
- parseTargetString :: String -> Maybe TargetString
- readTargetSelectorsWith :: (Applicative m, Monad m) => DirActions m -> [PackageSpecifier (SourcePackage (PackageLocation a))] -> Maybe ComponentKindFilter -> [String] -> m (Either [TargetSelectorProblem] [TargetSelector])
- data DirActions m = DirActions {
- doesFileExist :: FilePath -> m Bool
- doesDirectoryExist :: FilePath -> m Bool
- canonicalizePath :: FilePath -> m FilePath
- getCurrentDirectory :: m FilePath
- defaultDirActions :: DirActions IO
Target selectors
data TargetSelector Source #
A target selector is expression selecting a set of components (as targets
for a actions like build
, run
, test
etc). A target selector
corresponds to the user syntax for referring to targets on the command line.
From the users point of view a target can be many things: packages, dirs, component names, files etc. Internally we consider a target to be a specific component (or module/file within a component), and all the users' notions of targets are just different ways of referring to these component targets.
So target selectors are expressions in the sense that they are interpreted
to refer to one or more components. For example a TargetPackage
gets
interpreted differently by different commands to refer to all or a subset
of components within the package.
The syntax has lots of optional parts:
[ package name | package dir | package .cabal file ] [ [lib:|exe:] component name ] [ module name | source file ]
TargetPackage TargetImplicitCwd [PackageId] (Maybe ComponentKindFilter) | One (or more) packages as a whole, or all the components of a particular kind within the package(s). These are always packages that are local to the project. In the case that there is more than one, they all share the same directory location. |
TargetPackageNamed PackageName (Maybe ComponentKindFilter) | A package specified by name. This may refer to |
TargetAllPackages (Maybe ComponentKindFilter) | All packages, or all components of a particular kind in all packages. |
TargetComponent PackageId ComponentName SubComponentTarget | A specific component in a package within the project. |
TargetComponentUnknown PackageName (Either UnqualComponentName ComponentName) SubComponentTarget | A component in a package, but where it cannot be verified that the package has such a component, or because the package is itself not known. |
Instances
data TargetImplicitCwd Source #
Does this TargetPackage
selector arise from syntax referring to a
package in the current directory (e.g. tests
or no giving no explicit
target at all) or does it come from syntax referring to a package name
or location.
Instances
data ComponentKind Source #
Instances
type ComponentKindFilter = ComponentKind Source #
data SubComponentTarget Source #
Either the component as a whole or detail about a file or module target within a component.
WholeComponent | The component as a whole |
ModuleTarget ModuleName | A specific module within a component. |
FileTarget FilePath | A specific file within a component. Note that this does not carry the file extension. |
Instances
Qualification levels. Given the filepath src/F, executable component A, and package foo:
Instances
Enum QualLevel Source # | |
Defined in Distribution.Client.TargetSelector succ :: QualLevel -> QualLevel # pred :: QualLevel -> QualLevel # fromEnum :: QualLevel -> Int # enumFrom :: QualLevel -> [QualLevel] # enumFromThen :: QualLevel -> QualLevel -> [QualLevel] # enumFromTo :: QualLevel -> QualLevel -> [QualLevel] # enumFromThenTo :: QualLevel -> QualLevel -> QualLevel -> [QualLevel] # | |
Show QualLevel Source # | |
Eq QualLevel Source # | |
Reading target selectors
:: [PackageSpecifier (SourcePackage (PackageLocation a))] | |
-> Maybe ComponentKindFilter | This parameter is used when there are ambiguous selectors.
If it is |
-> [String] | |
-> IO (Either [TargetSelectorProblem] [TargetSelector]) |
Parse a bunch of command line args as TargetSelector
s, failing with an
error if any are unrecognised. The possible target selectors are based on
the available packages (and their locations).
data TargetSelectorProblem Source #
The various ways that trying to resolve a TargetString
to a
TargetSelector
can fail.
TargetSelectorExpected TargetString [String] String |
|
TargetSelectorNoSuch TargetString [(Maybe (String, String), String, String, [String])] |
|
TargetSelectorAmbiguous TargetString [(TargetString, TargetSelector)] | |
MatchingInternalError TargetString TargetSelector [(TargetString, [TargetSelector])] | |
TargetSelectorUnrecognised String | Syntax error when trying to parse a target string. |
TargetSelectorNoCurrentPackage TargetString | |
TargetSelectorNoTargetsInCwd Bool | bool that flags when it is acceptable to suggest "all" as a target |
TargetSelectorNoTargetsInProject | |
TargetSelectorNoScript TargetString |
Instances
Show TargetSelectorProblem Source # | |
Defined in Distribution.Client.TargetSelector showsPrec :: Int -> TargetSelectorProblem -> ShowS # show :: TargetSelectorProblem -> String # showList :: [TargetSelectorProblem] -> ShowS # | |
Eq TargetSelectorProblem Source # | |
Defined in Distribution.Client.TargetSelector (==) :: TargetSelectorProblem -> TargetSelectorProblem -> Bool # (/=) :: TargetSelectorProblem -> TargetSelectorProblem -> Bool # |
reportTargetSelectorProblems :: Verbosity -> [TargetSelectorProblem] -> IO a Source #
Throw an exception with a formatted message if there are any problems.
data TargetString Source #
The outline parse of a target selector. It takes one of the forms:
str1 str1:str2 str1:str2:str3 str1:str2:str3:str4
Instances
Show TargetString Source # | |
Defined in Distribution.Client.TargetSelector showsPrec :: Int -> TargetString -> ShowS # show :: TargetString -> String # showList :: [TargetString] -> ShowS # | |
Eq TargetString Source # | |
Defined in Distribution.Client.TargetSelector (==) :: TargetString -> TargetString -> Bool # (/=) :: TargetString -> TargetString -> Bool # |
showTargetString :: TargetString -> String Source #
Render a TargetString
back as the external syntax. This is mainly for
error messages.
non-IO
readTargetSelectorsWith :: (Applicative m, Monad m) => DirActions m -> [PackageSpecifier (SourcePackage (PackageLocation a))] -> Maybe ComponentKindFilter -> [String] -> m (Either [TargetSelectorProblem] [TargetSelector]) Source #
data DirActions m Source #
DirActions | |
|