cabal-auto-expose-0.1.0.0: Build time library that autodetects exposed modules
Safe HaskellNone
LanguageHaskell2010

Distribution.Simple.AutoExpose

Description

Import this module in your Setup.hs to auto detect library modules in your project The API does not conceal it's internals but in most cases you should only need the functions and datatype under 'Quick Start Functions' (Distribution.Simple.AutoExpose). For more granular access the ones under 'Internal Functions' (Distribution.Simple.AutoExpose) are available but subject to change.

Synopsis

Quick Start Functions

defaultMain :: IO () Source #

The common case top level function where this library is the only custom part of your project

import qualified Distribution.Simple.AutoExpose
main = AutoExpose.defaultMain

defaultMainWithHooks :: UserHooks -> IO () Source #

If you have already using custom UserHooks use this in your Setup.hs's main

import qualified Distribution.Simple.AutoExpose as AutoExpose
main = AutoExpose.defaultMainWithHooks myHooks

defaultMainGenerateCabal :: IO () Source #

The common case top level function where this library is the only custom part of your project

It also generates an explicit Cabal file at /system-temp-directory/package-name-package-version-generated.cabal

import qualified Distribution.Simple.AutoExpose
main = AutoExpose.defaultMainGenerateCabal

defaultMainWithHooksGenerateCabal :: WriteGeneratedCabal -> UserHooks -> IO () Source #

If you have already using custom UserHooks use this in your Setup.hs's main and also provide a way to generate an explicit Cabal file.

import qualified Distribution.Simple.AutoExpose as AutoExpose
main = do
  cabalWriter <- defaultWriteGeneratedCabal
  AutoExpose.defaultMainWithHooksGenerateCabal cabalWriter myHooks

data WriteGeneratedCabal Source #

A datatype that wraps a function that outputs the name of the explicity generated Cabal file and an absolute path to a directory into which to write it.

defaultWriteGeneratedCabal :: IO WriteGeneratedCabal Source #

Write the Cabal file to the system temp directory by default using defaultGeneratedCabalName for the filename.

Internal Functions

moduleNamesToExpose Source #

Arguments

:: [String]

File extensions of valid Haskell modules, includes pre-processor extensions

-> [FilePath]

File paths to search

-> [ModuleName] 

Search for file paths that look like valid modules and convert to the components to the Cabal internal ModuleName.

getDirectoryContents Source #

Arguments

:: HasCallStack 
=> FilePath

Directory to search (path must be absolute)

-> [FilePath]

Paths to ignore (paths must be absolute)

-> IO [FilePath]

File paths made relative to the search directory

Recursively collect the files in a directory, optionally excluding some files. Symlinks are ignored and collected paths are relative to the search directory, eg. if the search directory is /home/user/myproject/src the path /home/user/myproject/src/A/B/C.hs is returned as A/B/C.hs so it can converted by moduleNamesToExpose to a valid module name.

data ExposedLib Source #

Captures the detected Haskell modules and signatures in a library

Instances

Instances details
Show ExposedLib Source # 
Instance details

Defined in Distribution.Simple.AutoExpose

data PackageDescriptionSubset Source #

The common pieces of GenericPackageDescription and PackageDescription which we need to auto detect Haskell modules and signatures. We can't make do with just the PackageDescription because the confHook which instantiates the library with signatures only has access to GenericPackageDescription.

nonLibraryHsSourcePaths :: PackageDescriptionSubset -> [[FilePath]] Source #

Source directories for all non-library components (benchmarks, executables etc.) so that we can exclude their modules if they appear inside the library's source directory

indexWithNeighbors :: [a] -> [(a, [a])] Source #

Associate each item in a list will it's left and right elements, eg. > indexWithNeighbors [1,2,3,4] == [(1,[2,3,4]),(2,[1,3,4]),(3,[1,2,4]),(4,[1,2,3])]

Used to associate a source directory with possibly inner directories that should be ignored with searching for Haskell modules.

getExposedModules Source #

Arguments

:: HasCallStack 
=> [String]

Known Haskell and/or preprocessor extensions

-> [FilePath]

The source trees for this component

-> [[FilePath]]

The source trees for all the other components

-> IO [ModuleName]

Detect modules in this component

Drill into the source trees for a component and find modules excluding the source trees for other components

getExposedLib Source #

Arguments

:: HasCallStack 
=> PackageDescriptionSubset 
-> UserHooks

So we can grab the hookedPreProcessors extensions

-> IO ExposedLib 

Get a list of detected Haskell modules and signatures in the main library

withCabalFileDirectory Source #

Arguments

:: HasCallStack 
=> IO a

The IO action that auto detects modules & signatures

-> IO a 

Since the hs-source-dirs fields in a .cabal file take a source tree path relative to the .cabal file itself we need to make sure the current working directory in which to search for module detection is the directory in which the .cabal file resides.

updateLibrary :: ExposedLib -> Library -> Library Source #

Update the exposed modules and signatures of a Library

updatePackageDescription :: HasCallStack => PackageDescription -> UserHooks -> IO PackageDescription Source #

Update the PackageDescription of this package to include auto detected library modules. Also just to be nice fill in the .. module in otherModules field of the library's BuildInfo.

updateGenericPackageDescription :: HasCallStack => GenericPackageDescription -> UserHooks -> IO GenericPackageDescription Source #

Update the GenericPackageDescription of this package so the library can be properly instantiated with Backpack signatures at configure time when the confHook is run.

defaultGeneratedCabalName :: GenericPackageDescription -> FilePath Source #

The default name to use when generating an explicit Cabal file It defaults to package-name-package-version-generated.cabal

autoExposeHooks :: Maybe WriteGeneratedCabal -> UserHooks -> UserHooks Source #

Modify a set of UserHooks so that all relevant hooks see a PackageDescription or GenericPackageDescription with auto detected modules and signatures filled in.

Also optionally write an explicit Cabal file at confHook time.

sourceExtensions :: [String] Source #

The supported Haskell source extensions, currently hs and lhs

hsigExtensions :: [String] Source #

Backpack signature extensions, currently hsig and lhsig