Distribution.Client.ScriptUtils

cabal-install-3.12.1.0: The command-line interface for Cabal and Hackage.

Safe Haskell | None
Language | Haskell2010

Distribution.Client.ScriptUtils

Description

Utilities to help commands with scripts

Synopsis

- getScriptHash :: FilePath -> IO String
- getScriptCacheDirectory :: FilePath -> IO FilePath
- ensureScriptCacheDirectory :: Verbosity -> FilePath -> IO FilePath
- withContextAndSelectors :: AcceptNoTargets -> Maybe ComponentKind -> NixStyleFlags a -> [String] -> GlobalFlags -> CurrentCommand -> (TargetContext -> ProjectBaseContext -> [TargetSelector] -> IO b) -> IO b
- data AcceptNoTargets
  - = RejectNoTargets
  - | AcceptNoTargets
- data TargetContext
  - = ProjectContext
  - | GlobalContext
  - | ScriptContext FilePath Executable
- updateContextAndWriteProjectFile :: ProjectBaseContext -> FilePath -> Executable -> IO ProjectBaseContext
- updateContextAndWriteProjectFile' :: ProjectBaseContext -> SourcePackage (PackageLocation (Maybe FilePath)) -> IO ProjectBaseContext
- fakeProjectSourcePackage :: FilePath -> SourcePackage (PackageLocation loc)
- lSrcpkgDescription :: forall loc f. Functor f => LensLike f (SourcePackage loc) (SourcePackage loc) GenericPackageDescription GenericPackageDescription
- movedExePath :: UnqualComponentName -> DistDirLayout -> ElaboratedSharedConfig -> ElaboratedConfiguredPackage -> Maybe FilePath

# Documentation

getScriptHash :: FilePath -> IO String #

Get the hash of a script's absolute path.

Two hashes will be the same as long as the absolute paths are the same.

getScriptCacheDirectory :: FilePath -> IO FilePath #

Get the directory for caching a script build.

The only identity of a script is it's absolute path, so append the hashed path to the `script-builds` dir to get the cache directory.

ensureScriptCacheDirectory :: Verbosity -> FilePath -> IO FilePath #

Get the directory for caching a script build and ensure it exists.

The only identity of a script is it's absolute path, so append the hashed path to the `script-builds` dir to get the cache directory.

withContextAndSelectors #

Arguments

:: AcceptNoTargets | What your command should do when no targets are found.
-> Maybe ComponentKind | A target filter
-> NixStyleFlags a | Command line flags
-> [String] | Target strings or a script and args.
-> GlobalFlags | Global flags.
-> CurrentCommand | Current Command (usually for error reporting).
-> (TargetContext -> ProjectBaseContext -> [TargetSelector] -> IO b) | The body of your command action.
-> IO b |

Determine whether the targets represent regular targets or a script and return the proper context and target selectors. Die with an error message if selectors are valid as neither regular targets or as a script.

In the case that the context refers to a temporary directory, delete it after the action finishes.

data AcceptNoTargets #

What your command should do when no targets are found.

Constructors

RejectNoTargets | die on `TargetSelectorNoTargetsInProject`
AcceptNoTargets | return a default `TargetSelector`

#### Instances

Instances details

Show AcceptNoTargets # |
Instance details Defined in Distribution.Client.ScriptUtils Methods showsPrec :: Int -> AcceptNoTargets -> ShowS # show :: AcceptNoTargets -> String # showList :: [AcceptNoTargets] -> ShowS #
Eq AcceptNoTargets # |
Instance details Defined in Distribution.Client.ScriptUtils Methods (==) :: AcceptNoTargets -> AcceptNoTargets -> Bool # (/=) :: AcceptNoTargets -> AcceptNoTargets -> Bool #

data TargetContext #

Information about the context in which we found the `TargetSelector`s.

Constructors

ProjectContext | The target selectors are part of a project.
GlobalContext | The target selectors are from the global context.
ScriptContext FilePath Executable | The target selectors refer to a script. Contains the path to the script and the executable metadata parsed from the script

#### Instances

Instances details

Show TargetContext # |
Instance details Defined in Distribution.Client.ScriptUtils Methods showsPrec :: Int -> TargetContext -> ShowS # show :: TargetContext -> String # showList :: [TargetContext] -> ShowS #
Eq TargetContext # |
Instance details Defined in Distribution.Client.ScriptUtils Methods (==) :: TargetContext -> TargetContext -> Bool # (/=) :: TargetContext -> TargetContext -> Bool #

updateContextAndWriteProjectFile :: ProjectBaseContext -> FilePath -> Executable -> IO ProjectBaseContext #

Add add the executable metadata to the context and write a .cabal file.

updateContextAndWriteProjectFile' :: ProjectBaseContext -> SourcePackage (PackageLocation (Maybe FilePath)) -> IO ProjectBaseContext #

Add the `SourcePackage` to the context and use it to write a .cabal file.

fakeProjectSourcePackage :: FilePath -> SourcePackage (PackageLocation loc) #

The base for making a `SourcePackage` for a fake project. It needs a `Library` or `Executable` depending on the command.

lSrcpkgDescription :: forall loc f. Functor f => LensLike f (SourcePackage loc) (SourcePackage loc) GenericPackageDescription GenericPackageDescription #

A lens for the `srcpkgDescription` field of `SourcePackage`

movedExePath :: UnqualComponentName -> DistDirLayout -> ElaboratedSharedConfig -> ElaboratedConfiguredPackage -> Maybe FilePath #

Find the path of an exe that has been relocated with a "-o" option