Skip to content

Commit 93b0258

Browse files
authored
Merge pull request #6037 from haskell/autogen-includes
Add autogen-includes field
2 parents 5dd260a + 7e27ae7 commit 93b0258

40 files changed

+160
-13
lines changed

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ checkLibrary pkg lib =
270270
"An 'autogen-module' is neither on 'exposed-modules' or "
271271
++ "'other-modules'."
272272

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

275281
where
@@ -282,6 +288,9 @@ checkLibrary pkg lib =
282288
moduleDuplicates = dups (explicitLibModules lib ++
283289
map moduleReexportName (reexportedModules lib))
284290

291+
allExplicitIncludes :: L.HasBuildInfo a => a -> [FilePath]
292+
allExplicitIncludes x = view L.includes x ++ view L.installIncludes x
293+
285294
checkExecutable :: PackageDescription -> Executable -> [PackageCheck]
286295
checkExecutable pkg exe =
287296
catMaybes [
@@ -315,6 +324,11 @@ checkExecutable pkg exe =
315324
PackageBuildImpossible $
316325
"On executable '" ++ prettyShow (exeName exe) ++ "' an 'autogen-module' is not "
317326
++ "on 'other-modules'"
327+
328+
-- check that all autogen-includes appear on includes
329+
, check
330+
(not $ and $ map (flip elem (view L.includes exe)) (view L.autogenIncludes exe)) $
331+
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'."
318332
]
319333
where
320334
moduleDuplicates = dups (exeModules exe)
@@ -355,13 +369,15 @@ checkTestSuite pkg test =
355369

356370
-- check that all autogen-modules appear on other-modules
357371
, check
358-
(not $ and $ map
359-
(flip elem (testModules test))
360-
(testModulesAutogen test)
361-
) $
372+
(not $ and $ map (flip elem (testModules test)) (testModulesAutogen test)) $
362373
PackageBuildImpossible $
363374
"On test suite '" ++ prettyShow (testName test) ++ "' an 'autogen-module' is not "
364375
++ "on 'other-modules'"
376+
377+
-- check that all autogen-includes appear on includes
378+
, check
379+
(not $ and $ map (flip elem (view L.includes test)) (view L.autogenIncludes test)) $
380+
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'."
365381
]
366382
where
367383
moduleDuplicates = dups $ testModules test
@@ -404,13 +420,15 @@ checkBenchmark _pkg bm =
404420

405421
-- check that all autogen-modules appear on other-modules
406422
, check
407-
(not $ and $ map
408-
(flip elem (benchmarkModules bm))
409-
(benchmarkModulesAutogen bm)
410-
) $
423+
(not $ and $ map (flip elem (benchmarkModules bm)) (benchmarkModulesAutogen bm)) $
411424
PackageBuildImpossible $
412425
"On benchmark '" ++ prettyShow (benchmarkName bm) ++ "' an 'autogen-module' is "
413426
++ "not on 'other-modules'"
427+
428+
-- check that all autogen-includes appear on includes
429+
, check
430+
(not $ and $ map (flip elem (view L.includes bm)) (view L.autogenIncludes bm)) $
431+
PackageBuildImpossible "An include in 'autogen-includes' is not in 'includes'."
414432
]
415433
where
416434
moduleDuplicates = dups $ benchmarkModules bm

Cabal/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ buildInfoFieldGrammar = BuildInfo
427427
<*> monoidalFieldAla "extra-lib-dirs" (alaList' FSep FilePathNT) L.extraLibDirs
428428
<*> monoidalFieldAla "include-dirs" (alaList' FSep FilePathNT) L.includeDirs
429429
<*> monoidalFieldAla "includes" (alaList' FSep FilePathNT) L.includes
430+
<*> monoidalFieldAla "autogen-includes" (alaList' FSep FilePathNT) L.autogenIncludes
431+
^^^ availableSince CabalSpecV3_0 []
430432
<*> monoidalFieldAla "install-includes" (alaList' FSep FilePathNT) L.installIncludes
431433
<*> optionsFieldGrammar
432434
<*> profOptionsFieldGrammar

Cabal/Distribution/Simple/SrcDist.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,13 @@ listPackageSourcesOrdinary verbosity pkg_descr pps =
226226
-- License file(s).
227227
, return (licenseFiles pkg_descr)
228228

229-
-- Install-include files.
229+
-- Install-include files, without autogen-include files
230230
, fmap concat
231231
. withAllLib $ \ l -> do
232-
let lbi = libBuildInfo l
232+
let lbi = libBuildInfo l
233+
incls = filter (`notElem` autogenIncludes lbi) (installIncludes lbi)
233234
relincdirs = "." : filter isRelative (includeDirs lbi)
234-
traverse (fmap snd . findIncludeFile verbosity relincdirs) (installIncludes lbi)
235+
traverse (fmap snd . findIncludeFile verbosity relincdirs) incls
235236

236237
-- Setup script, if it exists.
237238
, fmap (maybe [] (\f -> [f])) $ findSetupFile ""

Cabal/Distribution/Types/BuildInfo.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ data BuildInfo = BuildInfo {
9494
extraLibDirs :: [String],
9595
includeDirs :: [FilePath], -- ^directories to find .h files
9696
includes :: [FilePath], -- ^ The .h files to be found in includeDirs
97+
autogenIncludes :: [FilePath], -- ^ The .h files to be generated (e.g. by @autoconf@)
9798
installIncludes :: [FilePath], -- ^ .h files to install with the package
9899
options :: PerCompilerFlavor [String],
99100
profOptions :: PerCompilerFlavor [String],
@@ -147,6 +148,7 @@ instance Monoid BuildInfo where
147148
extraLibDirs = [],
148149
includeDirs = [],
149150
includes = [],
151+
autogenIncludes = [],
150152
installIncludes = [],
151153
options = mempty,
152154
profOptions = mempty,
@@ -194,6 +196,7 @@ instance Semigroup BuildInfo where
194196
extraLibDirs = combineNub extraLibDirs,
195197
includeDirs = combineNub includeDirs,
196198
includes = combineNub includes,
199+
autogenIncludes = combineNub autogenIncludes,
197200
installIncludes = combineNub installIncludes,
198201
options = combine options,
199202
profOptions = combine profOptions,

Cabal/Distribution/Types/BuildInfo/Lens.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ class HasBuildInfo a where
160160
includes = buildInfo . includes
161161
{-# INLINE includes #-}
162162

163+
autogenIncludes :: Lens' a [FilePath]
164+
autogenIncludes = buildInfo . autogenIncludes
165+
{-# INLINE autogenIncludes #-}
166+
163167
installIncludes :: Lens' a [FilePath]
164168
installIncludes = buildInfo . installIncludes
165169
{-# INLINE installIncludes #-}
@@ -299,6 +303,9 @@ instance HasBuildInfo BuildInfo where
299303
includes f s = fmap (\x -> s { T.includes = x }) (f (T.includes s))
300304
{-# INLINE includes #-}
301305

306+
autogenIncludes f s = fmap (\x -> s { T.autogenIncludes = x }) (f (T.autogenIncludes s))
307+
{-# INLINE autogenIncludes #-}
308+
302309
installIncludes f s = fmap (\x -> s { T.installIncludes = x }) (f (T.installIncludes s))
303310
{-# INLINE installIncludes #-}
304311

Cabal/doc/developing-packages.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,8 +3326,8 @@ is to distinguish ``Cabal < 2.0`` from ``Cabal >= 2.0``.
33263326
33273327
33283328
3329-
Autogenerated modules
3330-
---------------------
3329+
Autogenerated modules and includes
3330+
----------------------------------
33313331

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

3375+
.. pkg-field:: autogen-includes: filename list
3376+
:since: 3.0
3377+
3378+
A list of header files from this package which are autogenerated
3379+
(e.g. by a ``configure`` script). Autogenerated header files are not
3380+
packaged by ``sdist`` command.
3381+
33753382
Accessing data files from package code
33763383
--------------------------------------
33773384

Cabal/doc/file-format-changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ relative to the respective preceding *published* version.
6666
* Wildcards are disallowed in :pkg-field:`pkgconfig-depends`,
6767
Yet the pkgconfig format is relaxed to accept e.g. versions like ``1.1.0h``.
6868

69+
* New :pkg-field:`autogen-includes` for specifying :pkg-field:`install-includes`
70+
which are autogenerated (e.g. by a ``configure`` script).
71+
6972
``cabal-version: 2.4``
7073
----------------------
7174

Cabal/tests/ParserTests/regressions/Octree-0.5.expr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ GenericPackageDescription
2424
libBuildInfo = BuildInfo
2525
{asmOptions = [],
2626
asmSources = [],
27+
autogenIncludes = [],
2728
autogenModules = [],
2829
buildToolDepends = [],
2930
buildTools = [],
@@ -113,6 +114,7 @@ GenericPackageDescription
113114
{testBuildInfo = BuildInfo
114115
{asmOptions = [],
115116
asmSources = [],
117+
autogenIncludes = [],
116118
autogenModules = [],
117119
buildToolDepends = [],
118120
buildTools = [],
@@ -206,6 +208,7 @@ GenericPackageDescription
206208
{testBuildInfo = BuildInfo
207209
{asmOptions = [],
208210
asmSources = [],
211+
autogenIncludes = [],
209212
autogenModules = [],
210213
buildToolDepends = [],
211214
buildTools = [],

Cabal/tests/ParserTests/regressions/common-conditional.expr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ GenericPackageDescription
2323
libBuildInfo = BuildInfo
2424
{asmOptions = [],
2525
asmSources = [],
26+
autogenIncludes = [],
2627
autogenModules = [],
2728
buildToolDepends = [],
2829
buildTools = [],
@@ -99,6 +100,7 @@ GenericPackageDescription
99100
libBuildInfo = BuildInfo
100101
{asmOptions = [],
101102
asmSources = [],
103+
autogenIncludes = [],
102104
autogenModules = [],
103105
buildToolDepends = [],
104106
buildTools = [],
@@ -174,6 +176,7 @@ GenericPackageDescription
174176
libBuildInfo = BuildInfo
175177
{asmOptions = [],
176178
asmSources = [],
179+
autogenIncludes = [],
177180
autogenModules = [],
178181
buildToolDepends = [],
179182
buildTools = [],
@@ -237,6 +240,7 @@ GenericPackageDescription
237240
{testBuildInfo = BuildInfo
238241
{asmOptions = [],
239242
asmSources = [],
243+
autogenIncludes = [],
240244
autogenModules = [],
241245
buildToolDepends = [],
242246
buildTools = [],
@@ -308,6 +312,7 @@ GenericPackageDescription
308312
{testBuildInfo = BuildInfo
309313
{asmOptions = [],
310314
asmSources = [],
315+
autogenIncludes = [],
311316
autogenModules = [],
312317
buildToolDepends = [],
313318
buildTools = [],
@@ -379,6 +384,7 @@ GenericPackageDescription
379384
{testBuildInfo = BuildInfo
380385
{asmOptions = [],
381386
asmSources = [],
387+
autogenIncludes = [],
382388
autogenModules = [],
383389
buildToolDepends = [],
384390
buildTools = [],
@@ -454,6 +460,7 @@ GenericPackageDescription
454460
{testBuildInfo = BuildInfo
455461
{asmOptions = [],
456462
asmSources = [],
463+
autogenIncludes = [],
457464
autogenModules = [],
458465
buildToolDepends = [],
459466
buildTools = [],
@@ -528,6 +535,7 @@ GenericPackageDescription
528535
{testBuildInfo = BuildInfo
529536
{asmOptions = [],
530537
asmSources = [],
538+
autogenIncludes = [],
531539
autogenModules = [],
532540
buildToolDepends = [],
533541
buildTools = [],

Cabal/tests/ParserTests/regressions/common.expr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ GenericPackageDescription
1414
libBuildInfo = BuildInfo
1515
{asmOptions = [],
1616
asmSources = [],
17+
autogenIncludes = [],
1718
autogenModules = [],
1819
buildToolDepends = [],
1920
buildTools = [],
@@ -76,6 +77,7 @@ GenericPackageDescription
7677
{testBuildInfo = BuildInfo
7778
{asmOptions = [],
7879
asmSources = [],
80+
autogenIncludes = [],
7981
autogenModules = [],
8082
buildToolDepends = [],
8183
buildTools = [],

0 commit comments

Comments
 (0)