cabal-helper-1.1.0.0: Give Haskell development tools access to Cabal project environment

LicenseApache-2.0
Maintainercabal-helper@dxld.at
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Distribution.Helper

Contents

Description

 
Synopsis

Type Variable Naming Conventions

Throughout the API we use the following conventions for type variables:

  • pt stands for "project type", when instantiated it is always of kind ProjType.
  • c stands for "cache". It is used internally to make the cache inaccessible for some parts of the implementation. Users of the API may completely ignore this parameter. See the internal qeCacheRef field accessor of QueryEnv for details.

Running Queries

data Query pt a Source #

A query against a package's Cabal configuration. Use runQuery to execute it.

Instances
Monad (Query pt) Source # 
Instance details

Defined in Distribution.Helper

Methods

(>>=) :: Query pt a -> (a -> Query pt b) -> Query pt b #

(>>) :: Query pt a -> Query pt b -> Query pt b #

return :: a -> Query pt a #

fail :: String -> Query pt a #

Functor (Query pt) Source # 
Instance details

Defined in Distribution.Helper

Methods

fmap :: (a -> b) -> Query pt a -> Query pt b #

(<$) :: a -> Query pt b -> Query pt a #

Applicative (Query pt) Source # 
Instance details

Defined in Distribution.Helper

Methods

pure :: a -> Query pt a #

(<*>) :: Query pt (a -> b) -> Query pt a -> Query pt b #

liftA2 :: (a -> b -> c) -> Query pt a -> Query pt b -> Query pt c #

(*>) :: Query pt a -> Query pt b -> Query pt b #

(<*) :: Query pt a -> Query pt b -> Query pt a #

runQuery :: Query pt a -> QueryEnv pt -> IO a Source #

Queries against Cabal's on disk state

Project queries

compilerVersion :: Query pt (String, Version) Source #

The version of GHC the project is configured to use for compilation.

projectPackages :: Query pt (NonEmpty (Package pt)) Source #

All local packages currently active in a project's build plan.

Package queries

type Package pt = Package' (NonEmpty (Unit pt)) Source #

pPackageName :: Package' units -> String Source #

pSourceDir :: Package' units -> FilePath Source #

pUnits :: Package' units -> units Source #

Cabal flags to set when configuring and building this package.

Unit queries

data Unit pt Source #

A Unit is essentially a "build target". It is used to refer to a set of components (exes, libs, tests etc.) which are managed by a certain instance of the Cabal build-system[1]. We may get information on the components in a unit by retriving the corresponding UnitInfo.

[1]: No I'm not talking about the cabal-install build-tool, I'm talking about the Cabal build-system. Note the distinction. Both cabal-install and Stack use the Cabal build-system (aka lib:Cabal) underneath.

Note that a Unit value is only valid within the QueryEnv context it was created in, this is however this is not enforced by the API. Furthermore if the user changes the underlying project configuration while your application is running even a properly scoped Unit could become invalid because the component it belongs to was removed from the cabal file.

Instances
Show (Unit pt) Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Methods

showsPrec :: Int -> Unit pt -> ShowS #

show :: Unit pt -> String #

showList :: [Unit pt] -> ShowS #

uComponentName :: Unit pt -> Maybe ChComponentName Source #

This returns the component a Unit corresponds to. This information is only available if the correspondence happens to be unique and known before querying setup-config for the respective project type. Currently this only applies to pt=V2.

This is intended to be used as an optimization, to allow reducing the number of helper invocations for clients that don't need to know the entire project structure.

data UnitInfo Source #

The information extracted from a 'Unit'\'s on-disk configuration cache.

Constructors

UnitInfo 

Fields

unitInfo :: Unit pt -> Query pt UnitInfo Source #

Get the UnitInfo for a given Unit. To get a Unit see projectUnits.

Convenience Queries

allUnits :: (UnitInfo -> a) -> Query pt (NonEmpty a) Source #

Get information on all units in a project.

Query environment

type QueryEnv pt = QueryEnvI QueryCache pt Source #

Environment for running a Query. The constructor is not exposed in the API to allow extending it with more fields without breaking user code.

To create a QueryEnv use the mkQueryEnv smart constructor instead. Some field accessors are exported and may be used to override the defaults filled in by mkQueryEnv. See below.

Note that this environment contains an IORef used as a cache. If you want to take advantage of this you should not simply discard the value returned by the smart constructor after one use.

data QueryEnvI c (pt :: ProjType) Source #

mkQueryEnv Source #

Arguments

:: ProjLoc pt

Location of the project.

-> DistDir pt

Path to the dist/ or dist-newstyle/ directory, called builddir in Cabal terminology.

-> IO (QueryEnv pt) 

mkQueryEnv projdir distdir. Smart constructor for QueryEnv. Sets fields qeProjLoc and qeDistDir to projdir and distdir respectively and provides sensible defaults for the other fields.

qeReadProcess :: QueryEnvI c pt -> ReadProcessWithCwdAndEnv Source #

Field accessor for QueryEnv. Function used to to start processes and capture output. Useful if you need to, for example, redirect standard error output of programs started by cabal-helper.

qeCallProcess :: QueryEnvI c pt -> CallProcessWithCwdAndEnv () Source #

Field accessor for QueryEnv. Function used to to start processes without capturing output. See also qeReadProcess.

qePrograms :: QueryEnvI c pt -> Programs Source #

Field accessor for QueryEnv. Paths to various programs we use.

qeProjLoc :: QueryEnvI c pt -> ProjLoc pt Source #

Field accessor for QueryEnv. Defines path to the project directory, i.e. a directory containing a cabal.project file

qeDistDir :: QueryEnvI c pt -> DistDir pt Source #

Field accessor for QueryEnv. Defines path to the dist/ or dist-newstyle/ directory, aka. builddir in Cabal terminology.

GADTs

data ProjType Source #

The kind of project being managed by a QueryEnv (pun intended). Used as a phantom-type variable throughout to make the project type being passed into various functions correspond to the correct implementation.

Constructors

Cabal CabalProjType

cabal project.

Stack

stack project.

data ProjLoc (pt :: ProjType) where Source #

Location of a project context. This is usually just the path project's top-level source code directory together with an optional project-type specific config file path.

To find any recognized default project contexts in a given directory use findProjects.

Build tools usually allow the user to specify the location of their project config files manually, so we also support passing this path here with the *File constructors.

Correspondence between Project and Package Source Directories

Note that the project's source directory does not necessarily correspond to the directory containing the project config file, though in some cases it does.

For example cabal v2-build allows the cabal.project file to be positively anywhere in the filesystem when specified via the --cabal-project command-line flag, corresponding to the ProjLocV2File constructor here. This config file can then refer to package directories with absolute paths in the packages: declaration.

Hence it isn't actually possible to find one directory which contains the whole project's source code but rather we have to consider each package's source directory individually, see pSourceDir

Constructors

ProjLocV1CabalFile

A fully specified cabal v1-build project context. Here you can specify both the path to the .cabal file and the source directory of the package. The cabal file path corresponds to the --cabal-file=PATH flag on the cabal command line.

Note that more than one such files existing in a package directory is a user error and while cabal will still complain about that we won't.

Also note that for this project type the concepts of project and package coincide.

Fields

ProjLocV1Dir

A cabal v1-build project context. Essentially the same as ProjLocV1CabalFile but this will dynamically search for the cabal file for you as cabal-install does by default.

If more than one .cabal file is found in the given directory we will shamelessly throw a obscure exception so prefer ProjLocV1CabalFile if you don't want that to happen. This mainly exists for easy upgrading from the cabal-helper-0.8 series.

Fields

ProjLocV2File

A cabal v2-build project context. The path to the cabal.project file, though you can call it whatever you like. This configuration file then points to the packages that make up this project. This corresponds to the --cabal-project=PATH flag on the cabal command line.

Fields

ProjLocV2Dir

This is equivalent to ProjLocV2File but using the default cabal.project file name in the given directory.

Fields

ProjLocStackYaml

A stack project context. Specify the path to the stack.yaml file here. This configuration file then points to the packages that make up this project. Corresponds to stack's --stack-yaml=PATH command line flag if different from the default name, stack.yaml.

Note: with Stack the invariant takeDirectory plStackYaml == projdir holds.

Fields

Instances
Show (ProjLoc pt) Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Methods

showsPrec :: Int -> ProjLoc pt -> ShowS #

show :: ProjLoc pt -> String #

showList :: [ProjLoc pt] -> ShowS #

data DistDir (pt :: ProjType) where Source #

A build directory for a certain project type. The pt type variable must be compatible with the ProjLoc used. This is enforced by the type system so you can't get this wrong.

Constructors

DistDirCabal :: !(SCabalProjType pt) -> !FilePath -> DistDir (Cabal pt)

A build-directory for cabal, aka. dist-dir in Cabal terminology. SCabalProjType specifies whether we should use v2-build or v1-build. This choice must correspond to ProjLoc 's project type.

DistDirStack :: !(Maybe RelativePath) -> DistDir Stack

A build-directory for stack, aka. work-dir. Optionally override Stack's work-dir. If you just want to use Stack's default set to Nothing

Instances
Show (DistDir pt) Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Methods

showsPrec :: Int -> DistDir pt -> ShowS #

show :: DistDir pt -> String #

showList :: [DistDir pt] -> ShowS #

data SProjType pt where Source #

A "singleton" datatype for ProjType which allows us to establish a correspondence between a runtime representation of ProjType to the compile-time value at the type level.

If you just want to know the runtime ProjType use demoteSProjType to convert to that.

Constructors

SCabal :: !(SCabalProjType pt) -> SProjType (Cabal pt) 
SStack :: SProjType Stack 
Instances
Show (SProjType pt) Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Methods

showsPrec :: Int -> SProjType pt -> ShowS #

show :: SProjType pt -> String #

showList :: [SProjType pt] -> ShowS #

data SCabalProjType pt where Source #

This is a singleton, like SProjType, but restricted to just the Cabal project types. We use this to restrict some functions which don't make sense for Stack to just the Cabal project types.

Instances
Show (SCabalProjType pt) Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

data Ex a Source #

General purpose existential wrapper. Useful for hiding a phantom type argument.

Say you have:

{-# LANGUAGE DataKinds, GADTS #-}
data K = A | B | ...
data Q k where
  QA :: ... -> Q 'A
  QB :: ... -> Q 'B

and you want a list of Q. You can use Ex to hide the phantom type argument and recover it later by matching on the GADT constructors:

qa :: Q A
qa = QA

qb :: Q B
qb = QB

mylist :: [Ex Q]
mylist = [Ex qa, Ex qb]

Constructors

Ex (a x) 

Programs

data Programs Source #

Configurable paths to various programs we use.

Constructors

Programs 

Fields

Instances
Eq Programs Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Ord Programs Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Read Programs Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Show Programs Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Generic Programs Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Associated Types

type Rep Programs :: Type -> Type #

Methods

from :: Programs -> Rep Programs x #

to :: Rep Programs x -> Programs #

type Rep Programs Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

defaultPrograms :: Programs Source #

By default all programs use their unqualified names, i.e. they will be searched for on PATH.

data EnvOverride Source #

Instances
Eq EnvOverride Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Ord EnvOverride Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Read EnvOverride Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Show EnvOverride Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Generic EnvOverride Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Associated Types

type Rep EnvOverride :: Type -> Type #

type Rep EnvOverride Source # 
Instance details

Defined in CabalHelper.Compiletime.Types

Query result types

data ChComponentInfo Source #

Constructors

ChComponentInfo 

Fields

  • ciComponentName :: ChComponentName

    The component's type and name

  • ciGhcOptions :: [String]

    Full set of GHC options, ready for loading this component into GHCi.

  • ciSourceDirs :: [String]

    A component's hs-source-dirs field, note that this only contains the directories specified by the cabal file, however cabal also adds the output directory of preprocessors to GHC's search path when building. TODO: make this easier to use.

  • ciEntrypoints :: ChEntrypoint

    Modules or files Cabal would have the compiler build directly. Can be used to compute the home module closure for a component.

data ChComponentName Source #

Instances
Eq ChComponentName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Ord ChComponentName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChComponentName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChComponentName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChComponentName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChComponentName :: Type -> Type #

type Rep ChComponentName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

data ChLibraryName Source #

Instances
Eq ChLibraryName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Ord ChLibraryName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChLibraryName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChLibraryName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChLibraryName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChLibraryName :: Type -> Type #

type Rep ChLibraryName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

type Rep ChLibraryName = D1 (MetaData "ChLibraryName" "CabalHelper.Shared.InterfaceTypes" "cabal-helper-1.1.0.0-8hQYifbIUuK6Vc5oLdO5q5" False) (C1 (MetaCons "ChMainLibName" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "ChSubLibName" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)))

newtype ChModuleName Source #

Constructors

ChModuleName 
Instances
Eq ChModuleName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Ord ChModuleName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChModuleName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChModuleName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChModuleName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChModuleName :: Type -> Type #

type Rep ChModuleName Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

type Rep ChModuleName = D1 (MetaData "ChModuleName" "CabalHelper.Shared.InterfaceTypes" "cabal-helper-1.1.0.0-8hQYifbIUuK6Vc5oLdO5q5" True) (C1 (MetaCons "ChModuleName" PrefixI True) (S1 (MetaSel (Just "unChModuleName") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)))

data ChPkgDb Source #

Instances
Eq ChPkgDb Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Methods

(==) :: ChPkgDb -> ChPkgDb -> Bool #

(/=) :: ChPkgDb -> ChPkgDb -> Bool #

Ord ChPkgDb Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChPkgDb Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChPkgDb Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChPkgDb Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChPkgDb :: Type -> Type #

Methods

from :: ChPkgDb -> Rep ChPkgDb x #

to :: Rep ChPkgDb x -> ChPkgDb #

type Rep ChPkgDb Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

type Rep ChPkgDb = D1 (MetaData "ChPkgDb" "CabalHelper.Shared.InterfaceTypes" "cabal-helper-1.1.0.0-8hQYifbIUuK6Vc5oLdO5q5" False) (C1 (MetaCons "ChPkgGlobal" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "ChPkgUser" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "ChPkgSpecific" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 FilePath))))

data ChEntrypoint Source #

Instances
Eq ChEntrypoint Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Ord ChEntrypoint Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChEntrypoint Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChEntrypoint Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChEntrypoint Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChEntrypoint :: Type -> Type #

type Rep ChEntrypoint Source # 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

type Rep ChEntrypoint = D1 (MetaData "ChEntrypoint" "CabalHelper.Shared.InterfaceTypes" "cabal-helper-1.1.0.0-8hQYifbIUuK6Vc5oLdO5q5" False) (C1 (MetaCons "ChSetupEntrypoint" PrefixI True) (S1 (MetaSel (Just "chMainIs") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 FilePath)) :+: (C1 (MetaCons "ChLibEntrypoint" PrefixI True) (S1 (MetaSel (Just "chExposedModules") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [ChModuleName]) :*: (S1 (MetaSel (Just "chOtherModules") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [ChModuleName]) :*: S1 (MetaSel (Just "chSignatures") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [ChModuleName]))) :+: C1 (MetaCons "ChExeEntrypoint" PrefixI True) (S1 (MetaSel (Just "chMainIs") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 FilePath) :*: S1 (MetaSel (Just "chOtherModules") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [ChModuleName]))))

General information

Legacy v1-build helpers

getSandboxPkgDb Source #

Arguments

:: String

Cabal build platform, i.e. buildPlatform

-> GhcVersion

GHC version (cProjectVersion is your friend)

-> FilePath

Path to the project directory, i.e. a directory containing a cabal.sandbox.config file

-> IO (Maybe FilePath) 

Get the path to the sandbox package-db in a project

Build actions

prepare :: Query pt () Source #

Make sure the appropriate helper executable for the given project is installed and ready to run queries.

The idea is you can run this at a convinient time instead of having the helper compilation happen during a time-sensitive user interaction. This will however happen automatically as needed if you don't run it first.

writeAutogenFiles :: Unit pt -> Query pt () Source #

Create cabal_macros.h, Paths_<pkg>.hs and other generated files in the usual place. See initialBuildSteps.

This is usually only needed on the first load of a unit or after the cabal file changes.

buildUnits :: [Unit pt] -> Query pt () Source #