Skip to content

Commit

Permalink
Merge pull request #6037 from haskell/autogen-includes
Browse files Browse the repository at this point in the history
Add autogen-includes field
  • Loading branch information
phadej authored May 8, 2019
2 parents 5dd260a + 7e27ae7 commit 93b0258
Show file tree
Hide file tree
Showing 40 changed files with 160 additions and 13 deletions.
34 changes: 26 additions & 8 deletions Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ checkLibrary pkg lib =
"An 'autogen-module' is neither on 'exposed-modules' or "
++ "'other-modules'."

-- check that all autogen-includes appear on includes or install-includes
, check
(not $ and $ map (flip elem (allExplicitIncludes lib)) (view L.autogenIncludes lib)) $
PackageBuildImpossible $
"An include in 'autogen-includes' is neither in 'includes' or "
++ "'install-includes'."
]

where
Expand All @@ -282,6 +288,9 @@ checkLibrary pkg lib =
moduleDuplicates = dups (explicitLibModules lib ++
map moduleReexportName (reexportedModules lib))

allExplicitIncludes :: L.HasBuildInfo a => a -> [FilePath]
allExplicitIncludes x = view L.includes x ++ view L.installIncludes x

checkExecutable :: PackageDescription -> Executable -> [PackageCheck]
checkExecutable pkg exe =
catMaybes [
Expand Down Expand Up @@ -315,6 +324,11 @@ checkExecutable pkg exe =
PackageBuildImpossible $
"On executable '" ++ prettyShow (exeName exe) ++ "' an 'autogen-module' is not "
++ "on 'other-modules'"

-- check that all autogen-includes appear on includes
, check
(not $ and $ map (flip elem (view L.includes exe)) (view L.autogenIncludes exe)) $
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'."
]
where
moduleDuplicates = dups (exeModules exe)
Expand Down Expand Up @@ -355,13 +369,15 @@ checkTestSuite pkg test =

-- check that all autogen-modules appear on other-modules
, check
(not $ and $ map
(flip elem (testModules test))
(testModulesAutogen test)
) $
(not $ and $ map (flip elem (testModules test)) (testModulesAutogen test)) $
PackageBuildImpossible $
"On test suite '" ++ prettyShow (testName test) ++ "' an 'autogen-module' is not "
++ "on 'other-modules'"

-- check that all autogen-includes appear on includes
, check
(not $ and $ map (flip elem (view L.includes test)) (view L.autogenIncludes test)) $
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'."
]
where
moduleDuplicates = dups $ testModules test
Expand Down Expand Up @@ -404,13 +420,15 @@ checkBenchmark _pkg bm =

-- check that all autogen-modules appear on other-modules
, check
(not $ and $ map
(flip elem (benchmarkModules bm))
(benchmarkModulesAutogen bm)
) $
(not $ and $ map (flip elem (benchmarkModules bm)) (benchmarkModulesAutogen bm)) $
PackageBuildImpossible $
"On benchmark '" ++ prettyShow (benchmarkName bm) ++ "' an 'autogen-module' is "
++ "not on 'other-modules'"

-- check that all autogen-includes appear on includes
, check
(not $ and $ map (flip elem (view L.includes bm)) (view L.autogenIncludes bm)) $
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'."
]
where
moduleDuplicates = dups $ benchmarkModules bm
Expand Down
2 changes: 2 additions & 0 deletions Cabal/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ buildInfoFieldGrammar = BuildInfo
<*> monoidalFieldAla "extra-lib-dirs" (alaList' FSep FilePathNT) L.extraLibDirs
<*> monoidalFieldAla "include-dirs" (alaList' FSep FilePathNT) L.includeDirs
<*> monoidalFieldAla "includes" (alaList' FSep FilePathNT) L.includes
<*> monoidalFieldAla "autogen-includes" (alaList' FSep FilePathNT) L.autogenIncludes
^^^ availableSince CabalSpecV3_0 []
<*> monoidalFieldAla "install-includes" (alaList' FSep FilePathNT) L.installIncludes
<*> optionsFieldGrammar
<*> profOptionsFieldGrammar
Expand Down
7 changes: 4 additions & 3 deletions Cabal/Distribution/Simple/SrcDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,13 @@ listPackageSourcesOrdinary verbosity pkg_descr pps =
-- License file(s).
, return (licenseFiles pkg_descr)

-- Install-include files.
-- Install-include files, without autogen-include files
, fmap concat
. withAllLib $ \ l -> do
let lbi = libBuildInfo l
let lbi = libBuildInfo l
incls = filter (`notElem` autogenIncludes lbi) (installIncludes lbi)
relincdirs = "." : filter isRelative (includeDirs lbi)
traverse (fmap snd . findIncludeFile verbosity relincdirs) (installIncludes lbi)
traverse (fmap snd . findIncludeFile verbosity relincdirs) incls

-- Setup script, if it exists.
, fmap (maybe [] (\f -> [f])) $ findSetupFile ""
Expand Down
3 changes: 3 additions & 0 deletions Cabal/Distribution/Types/BuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ data BuildInfo = BuildInfo {
extraLibDirs :: [String],
includeDirs :: [FilePath], -- ^directories to find .h files
includes :: [FilePath], -- ^ The .h files to be found in includeDirs
autogenIncludes :: [FilePath], -- ^ The .h files to be generated (e.g. by @autoconf@)
installIncludes :: [FilePath], -- ^ .h files to install with the package
options :: PerCompilerFlavor [String],
profOptions :: PerCompilerFlavor [String],
Expand Down Expand Up @@ -147,6 +148,7 @@ instance Monoid BuildInfo where
extraLibDirs = [],
includeDirs = [],
includes = [],
autogenIncludes = [],
installIncludes = [],
options = mempty,
profOptions = mempty,
Expand Down Expand Up @@ -194,6 +196,7 @@ instance Semigroup BuildInfo where
extraLibDirs = combineNub extraLibDirs,
includeDirs = combineNub includeDirs,
includes = combineNub includes,
autogenIncludes = combineNub autogenIncludes,
installIncludes = combineNub installIncludes,
options = combine options,
profOptions = combine profOptions,
Expand Down
7 changes: 7 additions & 0 deletions Cabal/Distribution/Types/BuildInfo/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ class HasBuildInfo a where
includes = buildInfo . includes
{-# INLINE includes #-}

autogenIncludes :: Lens' a [FilePath]
autogenIncludes = buildInfo . autogenIncludes
{-# INLINE autogenIncludes #-}

installIncludes :: Lens' a [FilePath]
installIncludes = buildInfo . installIncludes
{-# INLINE installIncludes #-}
Expand Down Expand Up @@ -299,6 +303,9 @@ instance HasBuildInfo BuildInfo where
includes f s = fmap (\x -> s { T.includes = x }) (f (T.includes s))
{-# INLINE includes #-}

autogenIncludes f s = fmap (\x -> s { T.autogenIncludes = x }) (f (T.autogenIncludes s))
{-# INLINE autogenIncludes #-}

installIncludes f s = fmap (\x -> s { T.installIncludes = x }) (f (T.installIncludes s))
{-# INLINE installIncludes #-}

Expand Down
11 changes: 9 additions & 2 deletions Cabal/doc/developing-packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3326,8 +3326,8 @@ is to distinguish ``Cabal < 2.0`` from ``Cabal >= 2.0``.
Autogenerated modules
---------------------
Autogenerated modules and includes
----------------------------------

Modules that are built automatically at setup, created with a custom
setup script, must appear on :pkg-field:`other-modules` for the library,
Expand Down Expand Up @@ -3372,6 +3372,13 @@ Right now :pkg-field:`executable:main-is` modules are not supported on
autogen-modules:
MyExeHelperModule

.. pkg-field:: autogen-includes: filename list
:since: 3.0

A list of header files from this package which are autogenerated
(e.g. by a ``configure`` script). Autogenerated header files are not
packaged by ``sdist`` command.

Accessing data files from package code
--------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions Cabal/doc/file-format-changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ relative to the respective preceding *published* version.
* Wildcards are disallowed in :pkg-field:`pkgconfig-depends`,
Yet the pkgconfig format is relaxed to accept e.g. versions like ``1.1.0h``.

* New :pkg-field:`autogen-includes` for specifying :pkg-field:`install-includes`
which are autogenerated (e.g. by a ``configure`` script).

``cabal-version: 2.4``
----------------------

Expand Down
3 changes: 3 additions & 0 deletions Cabal/tests/ParserTests/regressions/Octree-0.5.expr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ GenericPackageDescription
libBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -113,6 +114,7 @@ GenericPackageDescription
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -206,6 +208,7 @@ GenericPackageDescription
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down
8 changes: 8 additions & 0 deletions Cabal/tests/ParserTests/regressions/common-conditional.expr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ GenericPackageDescription
libBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -99,6 +100,7 @@ GenericPackageDescription
libBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -174,6 +176,7 @@ GenericPackageDescription
libBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -237,6 +240,7 @@ GenericPackageDescription
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -308,6 +312,7 @@ GenericPackageDescription
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -379,6 +384,7 @@ GenericPackageDescription
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -454,6 +460,7 @@ GenericPackageDescription
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -528,6 +535,7 @@ GenericPackageDescription
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down
2 changes: 2 additions & 0 deletions Cabal/tests/ParserTests/regressions/common.expr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ GenericPackageDescription
libBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down Expand Up @@ -76,6 +77,7 @@ GenericPackageDescription
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
Expand Down
Loading

0 comments on commit 93b0258

Please sign in to comment.