Skip to content

Commit

Permalink
Use cabal-helper 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Oct 4, 2019
1 parent 15037a4 commit ed9bf88
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 559 deletions.
9 changes: 5 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@

[submodule "submodules/HaRe"]
path = submodules/HaRe
# url = https://github.com/bubba/HaRe.git
url = https://github.com/wz1000/HaRe.git
url = https://github.com/bubba/HaRe.git
# url = https://github.com/wz1000/HaRe.git

[submodule "submodules/cabal-helper"]
path = submodules/cabal-helper
# url = https://github.com/arbor/cabal-helper.git
url = https://github.com/alanz/cabal-helper.git
# url = https://github.com/alanz/cabal-helper.git
# url = https://github.com/DanielG/cabal-helper.git
url = https://github.com/wz1000/cabal-helper.git

[submodule "submodules/ghc-mod"]
path = submodules/ghc-mod
# url = https://github.com/arbor/ghc-mod.git
url = https://github.com/alanz/ghc-mod.git
url = https://github.com/bubba/ghc-mod.git
#url = https://github.com/mpickering/ghc-mod.git

[submodule "hie-bios"]
Expand Down
2 changes: 0 additions & 2 deletions app/MainHie.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import System.IO
import Haskell.Ide.Engine.Plugin.ApplyRefact
import Haskell.Ide.Engine.Plugin.Base
import Haskell.Ide.Engine.Plugin.Brittany
import Haskell.Ide.Engine.Plugin.Build
import Haskell.Ide.Engine.Plugin.Example2
import Haskell.Ide.Engine.Plugin.Bios
import Haskell.Ide.Engine.Plugin.HaRe
Expand All @@ -55,7 +54,6 @@ plugins includeExamples = pluginDescToIdePlugins allPlugins
[ applyRefactDescriptor "applyrefact"
, baseDescriptor "base"
, brittanyDescriptor "brittany"
, buildPluginDescriptor "build"
-- , ghcmodDescriptor "ghcmod"
, haddockDescriptor "haddock"
, hareDescriptor "hare"
Expand Down
3 changes: 1 addition & 2 deletions haskell-ide-engine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ library
Haskell.Ide.Engine.Options
Haskell.Ide.Engine.Plugin.ApplyRefact
Haskell.Ide.Engine.Plugin.Brittany
Haskell.Ide.Engine.Plugin.Build
Haskell.Ide.Engine.Plugin.Example2
Haskell.Ide.Engine.Plugin.Floskell
Haskell.Ide.Engine.Plugin.Bios
Expand Down Expand Up @@ -58,7 +57,7 @@ library
, brittany
, bytestring
, Cabal
, cabal-helper >= 0.8.0.4
, cabal-helper >= 1.0 && < 1.1
, containers
, data-default
, directory
Expand Down
70 changes: 69 additions & 1 deletion hie-plugin-api/Haskell/Ide/Engine/Cradle.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,79 @@
{-# LANGUAGE TupleSections #-}
module Haskell.Ide.Engine.Cradle (findLocalCradle) where

import HIE.Bios as BIOS
import HIE.Bios.Types

import Haskell.Ide.Engine.MonadFunctions

import Distribution.Helper
import Distribution.Helper.Discover

import System.FilePath
import System.Directory

import qualified Data.Map as M
import Data.Foldable (toList)
import Data.List (inits, sortOn)
import Data.Maybe (listToMaybe)
import Data.Ord
import System.Exit

findLocalCradle :: FilePath -> IO Cradle
findLocalCradle fp = do
-- Get the cabal directory from the cradle
cradleConf <- BIOS.findCradle fp
case cradleConf of
Just yaml -> BIOS.loadCradle yaml
Nothing -> BIOS.loadImplicitCradle fp
Nothing -> cabalHelperCradle fp

cabalHelperCradle :: FilePath -> IO Cradle
cabalHelperCradle file' = do
-- TODO find cradle
root' <- getCurrentDirectory
root <- canonicalizePath root'
return Cradle
{ cradleRootDir = root
, cradleOptsProg = CradleAction
{ actionName = "Cabal-Helper"
, runCradle = cabalHelperAction root
}
}

where
cabalHelperAction :: FilePath -> FilePath -> IO (CradleLoadResult ComponentOptions)
cabalHelperAction root fp = do
file <- canonicalizePath fp
let file_dir = makeRelative root $ takeDirectory file
debugm $ "Cabal Helper dirs: " ++ show [root, file, file_dir]
projs <- findProjects root
case projs of
(Ex proj:_) -> do
let [dist_dir] = findDistDirs proj
env <- mkQueryEnv proj dist_dir
units <- runQuery (allUnits id) env

case getFlags file_dir $ toList units of
Just fs -> do
debugm $ "Flags for \"" ++ fp ++ "\": " ++ show fs
return $ CradleSuccess
ComponentOptions
{ componentOptions = fs ++ [file]
, componentDependencies = []
}

Nothing -> return $ CradleFail $ CradleError (ExitFailure 2) ("Could not obtain flags for " ++ fp)
_ -> return $ CradleFail $ CradleError (ExitFailure 1) ("Could not find project from: " ++ fp)

getFlags :: FilePath -> [UnitInfo] -> Maybe [String]
getFlags dir uis
= listToMaybe
$ map (ciGhcOptions . snd)
$ filter (hasParent dir . fst)
$ sortOn (Down . length . fst)
$ concatMap (\ci -> map (,ci) (ciSourceDirs ci))
$ concat
$ M.elems . uiComponents <$> uis

hasParent :: FilePath -> FilePath -> Bool
hasParent child parent = any (equalFilePath parent) (map joinPath $ inits $ splitPath child)
1 change: 1 addition & 0 deletions hie-plugin-api/hie-plugin-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ library
, ghc
, hie-bios
, ghc-project-types >= 5.9.0.0
, cabal-helper
, haskell-lsp == 0.15.*
, hslogger
, unliftio
Expand Down
Loading

0 comments on commit ed9bf88

Please sign in to comment.