-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
packages: . | ||
|
||
source-repository-package | ||
type: git | ||
location: https://github.com/fendor/cabal-build-info | ||
tag: d28c94d08d6fb8996225bfc127ebcc6e7e80e46a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
module HIE.Bios.Cabal.BuildInfo where | ||
|
||
import qualified Data.Aeson.Combinators.Decode as ACD | ||
import Data.Maybe | ||
import Data.Either | ||
import Cabal.BuildInfo | ||
import Control.Monad | ||
import System.FilePath | ||
import Data.Foldable (foldr') | ||
import System.Directory | ||
|
||
collectBuildInfo :: FilePath -> IO (Maybe BuildInfo) | ||
collectBuildInfo builddir = do | ||
let planJson = builddir </> "cache" </> "plan.json" | ||
buildInfos <- ACD.decodeFileStrict buildInfoPathDecoder planJson | ||
case buildInfos of | ||
Nothing -> error "TODO: failed to decode plan.json" | ||
Just bi -> do | ||
existing <- filterM doesFileExist bi | ||
realBuildInfos <- mapM decodeBuildInfoFile existing | ||
case partitionEithers realBuildInfos of | ||
(errs@(_:_), _) -> error $ "TODO: failed to build-info.json: " ++ unlines errs | ||
(_, infos) -> pure $ merge infos | ||
where | ||
merge :: [BuildInfo] -> Maybe BuildInfo | ||
merge [] = Nothing | ||
merge (x:xs) = Just $ foldr' go x xs | ||
|
||
go :: BuildInfo -> BuildInfo -> BuildInfo | ||
go b1 b2 = b1 { components = components b1 ++ components b2 } | ||
|
||
buildInfoPathDecoder :: ACD.Decoder [FilePath] | ||
buildInfoPathDecoder = do | ||
let buildInfoDecoder = ACD.maybe $ ACD.key "build-info" ACD.string | ||
catMaybes <$> ACD.key "install-plan" (ACD.list buildInfoDecoder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters