Skip to content

Commit

Permalink
Radical approach - don't use such a long name for the wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
lukel97 committed Jun 15, 2020
1 parent 4219d51 commit 579e259
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 52 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ jobs:


- name: Build Server
run: cabal build exe:haskell-language-server -O2 --builddir=../b --disable-documentation
run: cabal build exe:haskell-language-server -O2 --disable-documentation

- name: Find Server Binary
id: find_server_binary
shell: bash
run: |
HLS=$(find ../b \( -name 'haskell-language-server' -o -name 'haskell-language-server.exe' \) -type f)
HLS=$(find dist-newstyle \( -name 'haskell-language-server' -o -name 'haskell-language-server.exe' \) -type f)
echo ::set-output name=hls_binary::$HLS
- name: Upload Server Binary
Expand All @@ -55,14 +55,14 @@ jobs:

- name: Build Wrapper
if: matrix.ghc == '8.10.1'
run: cabal build exe:haskell-language-server-wrapper -O2 --builddir=../b --disable-documentation -v
run: cabal build exe:hls-wrapper -O2 --disable-documentation

- name: Find Wrapper Binary
if: matrix.ghc == '8.10.1'
id: find_wrapper_binary
shell: bash
run: |
HLS_WRAPPER=$(find ../b \( -name 'haskell-language-server-wrapper' -o -name 'haskell-language-server-wrapper.exe' \) -type f)
HLS_WRAPPER=$(find dist-newstyle \( -name 'hls-wrapper' -o -name 'hls-wrapper.exe' \) -type f)
echo ::set-output name=hls_wrapper_binary::$HLS_WRAPPER
- name: Upload Wrapper
Expand Down
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/bubba/hie-bios.git
tag: c9411178
tag: 6df34cb7df3d380a2ef245d4fe54c18ce6874f48

tests: true
documentation: true
Expand Down
17 changes: 0 additions & 17 deletions exe/Arguments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,13 @@ module Arguments
( Arguments(..)
, getArguments
, ghcideVersion
, getGhcLibDir
) where

import Data.Char
import Data.List
import Data.Maybe
import Data.Version
import Development.GitRev
import qualified GHC.Paths
import HIE.Bios.Types
import Options.Applicative
import Paths_haskell_language_server
import System.Environment
import System.Process

-- ---------------------------------------------------------------------

Expand Down Expand Up @@ -89,16 +82,6 @@ arguments exeName = Arguments
<> help "Work out the project GHC version and print it")

-- ---------------------------------------------------------------------
-- Set the GHC libdir to the nix libdir if it's present.
getGhcLibDir :: ComponentOptions -> IO FilePath
getGhcLibDir opts = do
nixLibDir <- lookupEnv "NIX_GHC_LIBDIR"
-- We want to avoid using ghc-paths, as it is not portable
-- in the static binary sense - it just bakes in the path to the
-- libraries at compile time! This is ok if the user built from
-- source, but if they downloaoded a binary then this will return
-- some path that doesn't exist on their computer.
return $ fromMaybe GHC.Paths.libdir (nixLibDir <|> ghcLibDir opts)

ghcideVersion :: IO String
ghcideVersion = do
Expand Down
21 changes: 10 additions & 11 deletions exe/Wrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Ide.Version
import System.Directory
import System.Environment
import System.Exit
import System.FilePath
import System.IO
import System.Info
import System.Process
Expand All @@ -36,9 +35,17 @@ main = do
-- WARNING: If you write to stdout before runLanguageServer
-- then the language server will not work
Arguments{..} <- getArguments "haskell-language-server-wrapper"

d <- getCurrentDirectory

-- Get the cabal directory from the cradle
cradle <- findLocalCradle d
let dir = cradleRootDir cradle
setCurrentDirectory dir

ghcVersion <- getProjectGhcVersion cradle

when argsProjectGhcVersion $
getCurrentDirectory >>= loadImplicitCradle >>= getProjectGhcVersion >>= putStrLn >> exitSuccess
when argsProjectGhcVersion $ putStrLn ghcVersion >> exitSuccess

if argsVersion then ghcideVersion >>= putStrLn >> exitSuccess
else hPutStrLn stderr {- see WARNING above -} =<< ghcideVersion
Expand All @@ -61,19 +68,11 @@ main = do
progName <- getProgName
logm $ "run entered for haskell-language-server-wrapper(" ++ progName ++ ") "
++ hlsVersion
d <- getCurrentDirectory
logm $ "Current directory:" ++ d
logm $ "Operating system:" ++ os
args <- getArgs
logm $ "args:" ++ show args

-- Get the cabal directory from the cradle
cradle <- findLocalCradle d
let dir = cradleRootDir cradle
logm $ "Cradle directory:" ++ dir
setCurrentDirectory dir

ghcVersion <- getProjectGhcVersion cradle
logm $ "Project GHC version:" ++ ghcVersion

let
Expand Down
2 changes: 1 addition & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ executable haskell-language-server
, unordered-containers
default-language: Haskell2010

executable haskell-language-server-wrapper
executable hls-wrapper
import: agpl
main-is: Wrapper.hs
hs-source-dirs:
Expand Down
28 changes: 10 additions & 18 deletions src/Ide/Cradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ findLocalCradle fp = do
debugm $ "Found \"" ++ yaml ++ "\" for \"" ++ fp ++ "\""
crdl <- Bios.loadCradle yaml
return $ fmap (const CabalNone) crdl
Nothing -> Bios.loadImplicitCradle fp -- cabalHelperCradle fp
Nothing -> Bios.loadImplicitCradle (fp </> "Foo.hs") -- cabalHelperCradle fp
logm $ "Module \"" ++ fp ++ "\" is loaded by Cradle: " ++ show crdl
return crdl

Expand Down Expand Up @@ -100,7 +100,7 @@ data CabalHelper
execProjectGhc :: Cradle CabalHelper -> [String] -> IO (Maybe String)
execProjectGhc crdl args = do
isStackInstalled <- isJust <$> findExecutable "stack"
-- isCabalInstalled <- isJust <$> findExecutable "cabal"
isCabalInstalled <- isJust <$> findExecutable "cabal"
ghcOutput <- if isStackCradle crdl && isStackInstalled
then do
logm $ "Executing Stack GHC with args: " <> unwords args
Expand All @@ -112,11 +112,11 @@ execProjectGhc crdl args = do
-- This command must work though before the project is build.
-- Therefore, fallback to "ghc" on the path.
--
-- else if isCabalCradle crdl && isCabalInstalled then do
-- let cmd = "cabal v2-exec -v0 ghc -- " ++ unwords args
-- catch (Just <$> tryCommand crdl cmd) $ \(_ ::IOException) -> do
-- errorm $ "Command `" ++ cmd ++ "` failed."
-- return Nothing
else if isCabalCradle crdl && isCabalInstalled then do
let cmd = "cabal v2-exec -v0 ghc -- " ++ unwords args
catch (Just <$> tryCommand crdl cmd) $ \(_ ::IOException) -> do
errorm $ "Command `" ++ cmd ++ "` failed."
return Nothing
else do
logm $ "Executing GHC on path with args: " <> unwords args
execWithGhc
Expand Down Expand Up @@ -153,15 +153,6 @@ tryCommand crdl cmd = do
ExitSuccess -> return $ T.unpack . T.strip . head . T.lines $ T.pack sout


-- | Get the directory of the libdir based on the project ghc.
getProjectGhcLibDir :: Cradle CabalHelper -> IO (Maybe FilePath)
getProjectGhcLibDir crdl =
execProjectGhc crdl ["--print-libdir"] >>= \case
Nothing -> do
errorm "Could not obtain the libdir."
return Nothing
mlibdir -> return mlibdir

-- ---------------------------------------------------------------------


Expand Down Expand Up @@ -469,8 +460,8 @@ cabalHelperCradle file = do
{ componentOptions = [file, fixImportDirs cwd "-i."]
, componentRoot = cwd
, componentDependencies = []
, ghcLibDir = Nothing
}
, runGhcLibDir = pure Nothing
}
}
Just (Ex proj) -> do
Expand Down Expand Up @@ -498,6 +489,7 @@ cabalHelperCradle file = do
, cradleOptsProg =
CradleAction { actionName = Bios.Other (projectNoneType proj)
, runCradle = \_ _ -> return CradleNone
, runGhcLibDir = pure Nothing
}
}
Just realPackage -> do
Expand All @@ -518,6 +510,7 @@ cabalHelperCradle file = do
realPackage
normalisedPackageLocation
fp
, runGhcLibDir = pure Nothing
}
}

Expand Down Expand Up @@ -555,7 +548,6 @@ cabalHelperAction proj env package root fp = do
ComponentOptions { componentOptions = ghcOptions
, componentRoot = root
, componentDependencies = []
, ghcLibDir = Nothing
}
Left err -> return
$ CradleFail
Expand Down

0 comments on commit 579e259

Please sign in to comment.