cabal-helper-1.0.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 QueryEnvI 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 :: ProjType) = Package' (NonEmpty (Unit pt)) #

pUnits :: Package' units -> units #

Cabal flags to set when configuring and building this package.

Unit queries

data Unit (pt :: ProjType) #

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) 
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 #

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 UnitId #

Instances
Eq UnitId 
Instance details

Defined in CabalHelper.Compiletime.Types

Methods

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

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

Ord UnitId 
Instance details

Defined in CabalHelper.Compiletime.Types

Read UnitId 
Instance details

Defined in CabalHelper.Compiletime.Types

Show UnitId 
Instance details

Defined in CabalHelper.Compiletime.Types

data UnitInfo #

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 :: ProjType) = QueryEnvI QueryCache pt #

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 :: ProjType -> Type) (pt :: ProjType) #

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 QueryEnvI. Sets fields qeProjLoc and qeDistDir to projdir and distdir respectively and provides sensible defaults for the other fields.

qeReadProcess :: QueryEnvI c pt -> ReadProcessWithCwdAndEnv #

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 () #

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

qePrograms :: QueryEnvI c pt -> Programs #

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

qeProjLoc :: QueryEnvI c pt -> ProjLoc pt #

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 #

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

GADTs

data ProjType #

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 #

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) 
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 #

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 :: forall (pt :: ProjType) (pt1 :: CabalProjType). !(SCabalProjType pt1) -> !FilePath -> DistDir (Cabal pt1)

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 :: forall (pt :: ProjType). !(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) 
Instance details

Defined in CabalHelper.Compiletime.Types

Methods

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

show :: DistDir pt -> String #

showList :: [DistDir pt] -> ShowS #

data SProjType (pt :: ProjType) where #

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 :: forall (pt :: ProjType) (pt1 :: CabalProjType). !(SCabalProjType pt1) -> SProjType (Cabal pt1) 
SStack :: forall (pt :: ProjType). SProjType Stack 
Instances
Show (SProjType pt) 
Instance details

Defined in CabalHelper.Compiletime.Types

Methods

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

show :: SProjType pt -> String #

showList :: [SProjType pt] -> ShowS #

data SCabalProjType (pt :: CabalProjType) where #

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.

Constructors

SCV1 :: forall (pt :: CabalProjType). SCabalProjType CV1 
SCV2 :: forall (pt :: CabalProjType). SCabalProjType CV2 
Instances
Show (SCabalProjType pt) 
Instance details

Defined in CabalHelper.Compiletime.Types

data Ex (a :: k -> Type) :: forall k. (k -> Type) -> Type where #

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 :: forall k (a :: k -> Type) (x :: k). a x -> Ex a 

Programs

data Programs #

Configurable paths to various programs we use.

Constructors

Programs 

Fields

Instances
Eq Programs 
Instance details

Defined in CabalHelper.Compiletime.Types

Ord Programs 
Instance details

Defined in CabalHelper.Compiletime.Types

Read Programs 
Instance details

Defined in CabalHelper.Compiletime.Types

Show Programs 
Instance details

Defined in CabalHelper.Compiletime.Types

Generic Programs 
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 
Instance details

Defined in CabalHelper.Compiletime.Types

defaultPrograms :: Programs #

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

data EnvOverride #

Instances
Eq EnvOverride 
Instance details

Defined in CabalHelper.Compiletime.Types

Ord EnvOverride 
Instance details

Defined in CabalHelper.Compiletime.Types

Read EnvOverride 
Instance details

Defined in CabalHelper.Compiletime.Types

Show EnvOverride 
Instance details

Defined in CabalHelper.Compiletime.Types

Generic EnvOverride 
Instance details

Defined in CabalHelper.Compiletime.Types

Associated Types

type Rep EnvOverride :: Type -> Type #

type Rep EnvOverride 
Instance details

Defined in CabalHelper.Compiletime.Types

type Rep EnvOverride = D1 (MetaData "EnvOverride" "CabalHelper.Compiletime.Types" "cabal-helper-1.0.0.0-3RovMtTNraDHCRO0uwfQKJ-c-h-internal" False) (C1 (MetaCons "EnvPrepend" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)) :+: (C1 (MetaCons "EnvAppend" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)) :+: C1 (MetaCons "EnvReplace" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String))))

Query result types

data ChComponentInfo #

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 #

Instances
Eq ChComponentName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Ord ChComponentName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChComponentName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChComponentName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChComponentName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChComponentName :: Type -> Type #

type Rep ChComponentName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

data ChLibraryName #

Instances
Eq ChLibraryName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Ord ChLibraryName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChLibraryName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChLibraryName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChLibraryName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChLibraryName :: Type -> Type #

type Rep ChLibraryName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

type Rep ChLibraryName = D1 (MetaData "ChLibraryName" "CabalHelper.Shared.InterfaceTypes" "cabal-helper-1.0.0.0-3RovMtTNraDHCRO0uwfQKJ-c-h-internal" 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 #

Constructors

ChModuleName 
Instances
Eq ChModuleName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Ord ChModuleName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChModuleName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChModuleName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChModuleName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChModuleName :: Type -> Type #

type Rep ChModuleName 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

type Rep ChModuleName = D1 (MetaData "ChModuleName" "CabalHelper.Shared.InterfaceTypes" "cabal-helper-1.0.0.0-3RovMtTNraDHCRO0uwfQKJ-c-h-internal" True) (C1 (MetaCons "ChModuleName" PrefixI True) (S1 (MetaSel (Just "unChModuleName") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)))

data ChPkgDb #

Instances
Eq ChPkgDb 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Methods

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

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

Ord ChPkgDb 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChPkgDb 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChPkgDb 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChPkgDb 
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 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

type Rep ChPkgDb = D1 (MetaData "ChPkgDb" "CabalHelper.Shared.InterfaceTypes" "cabal-helper-1.0.0.0-3RovMtTNraDHCRO0uwfQKJ-c-h-internal" 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 #

Instances
Eq ChEntrypoint 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Ord ChEntrypoint 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Read ChEntrypoint 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Show ChEntrypoint 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Generic ChEntrypoint 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

Associated Types

type Rep ChEntrypoint :: Type -> Type #

type Rep ChEntrypoint 
Instance details

Defined in CabalHelper.Shared.InterfaceTypes

type Rep ChEntrypoint = D1 (MetaData "ChEntrypoint" "CabalHelper.Shared.InterfaceTypes" "cabal-helper-1.0.0.0-3RovMtTNraDHCRO0uwfQKJ-c-h-internal" 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 #