Skip to content

Commit

Permalink
Merge pull request #142 from phadej/gen-includes
Browse files Browse the repository at this point in the history
Include `include-dirs` in build directory (for Configure generated headers)
  • Loading branch information
phadej authored Dec 19, 2023
2 parents 2a01753 + a7ede15 commit 1eb4198
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cabal-docspec/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 0.0.0.202312dd
# 0.0.0.20231219

- Pass `default-language` flag to GHC
- Fix issue with CPP defines without an explicit value (i.e. `-DFOO`, not `-DBAR=42`)
- Include `include-dirs` in build directory (for Configure generated headers)

# 0.0.0.20230406

Expand Down
4 changes: 2 additions & 2 deletions cabal-docspec/src/CabalDocspec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ testComponent tracer0 tracerTop dynOptsCli ghcInfo buildDir cabalCfg plan env pk
-- first phase: read modules and extract the comments
let pkgVer = C.packageVersion (pkgGpd pkg)
modules <- for modulePaths $ \(modname, modpath) ->
phase1 tracer ghcInfo pkgVer (pkgDir pkg) cppEnabled cppDirs pkgIds bi modname modpath
phase1 tracer ghcInfo (Just buildDir) (C.packageName (pkgGpd pkg)) pkgVer (pkgDir pkg) cppEnabled cppDirs pkgIds bi modname modpath

-- extract doctests from the modules.
let parsed :: [Module [Located DocTest]]
Expand Down Expand Up @@ -347,7 +347,7 @@ testComponentNo tracer0 tracerTop dynOptsCli ghcInfo cabalCfg dbG pkg = do
-- first phase: read modules and extract the comments
let pkgVer = C.packageVersion (pkgGpd pkg)
modules <- for modulePaths $ \(modname, modpath) ->
phase1 tracer ghcInfo pkgVer (pkgDir pkg) cppEnabled cppDirs pkgIds bi modname modpath
phase1 tracer ghcInfo Nothing (C.packageName (pkgGpd pkg)) pkgVer (pkgDir pkg) cppEnabled cppDirs pkgIds bi modname modpath

-- extract doctests from the modules.
let parsed :: [Module [Located DocTest]]
Expand Down
32 changes: 25 additions & 7 deletions cabal-docspec/src/CabalDocspec/Phase1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ import CabalDocspec.Trace
phase1
:: TracerPeu r Tr
-> GhcInfo
-> Version -- ^ package version
-> Path Absolute -- ^ package directory
-> Bool -- ^ cpp extension
-> [Path Absolute] -- ^ additional include directories
-> [PackageIdentifier] -- ^ dependencies
-> Maybe (Path Absolute) -- ^ builddir
-> PackageName -- ^ package name
-> Version -- ^ package version
-> Path Absolute -- ^ package directory
-> Bool -- ^ cpp extension
-> [Path Absolute] -- ^ additional include directories
-> [PackageIdentifier] -- ^ dependencies
-> C.BuildInfo
-> C.ModuleName
-> Path Absolute
-> Peu r (Module (Located String))
phase1 tracer ghcInfo pkgVer pkgDir cppEnabled cppDirs pkgIds bi modname modpath = do
phase1 tracer ghcInfo mbuildDir pkgName_ pkgVer pkgDir cppEnabled cppDirs pkgIds bi modname modpath = do
traceApp tracer $ TracePhase1 modname modpath

contents <- fromUTF8BS <$> readByteString modpath
Expand Down Expand Up @@ -59,7 +61,16 @@ phase1 tracer ghcInfo pkgVer pkgDir cppEnabled cppDirs pkgIds bi modname modpath
-- so may break
[ pkgDir </> fromUnrootedFilePath dir
| dir <- C.includeDirs bi
] ++ cppDirs
] ++
[ buildDir </>
fromUnrootedFilePath "build" </>
componentDir ghcInfo (PackageIdentifier pkgName_ pkgVer) </>
fromUnrootedFilePath "build" </>
fromUnrootedFilePath dir
| buildDir <- toList mbuildDir
, dir <- C.includeDirs bi
] ++
cppDirs

cppDefines :: [(String, String)]
cppDefines =
Expand All @@ -70,6 +81,13 @@ phase1 tracer ghcInfo pkgVer pkgDir cppEnabled cppDirs pkgIds bi modname modpath
, Just d' <- return (parseDefineFlag d)
]

-- x86_64-linux/ghc-9.8.1/streamly-0.10.0
componentDir :: GhcInfo -> PackageIdentifier -> Path Unrooted
componentDir ghcInfo pid =
fromUnrootedFilePath(ghcPlatform ghcInfo) </>
fromUnrootedFilePath ("ghc-" ++ prettyShow (ghcVersion ghcInfo)) </>
fromUnrootedFilePath (prettyShow pid)

cppGhcVersion :: Version -> String
cppGhcVersion v = case C.versionNumbers v of
[] -> "0"
Expand Down

0 comments on commit 1eb4198

Please sign in to comment.