@@ -15,6 +15,7 @@ module Test.Hls.Util
15
15
, setupBuildToolFiles
16
16
, withFileLogging
17
17
, findExe
18
+ , withCurrentDirectoryInTmp
18
19
-- , makeRequest
19
20
-- , runIGM
20
21
-- , runIGM'
@@ -46,13 +47,15 @@ import System.Directory
46
47
import System.Environment
47
48
import System.FilePath
48
49
import qualified System.Log.Logger as L
50
+ import System.IO.Temp
49
51
-- import Test.Hspec
50
52
import Test.Hspec.Runner
51
53
import Test.Hspec.Core.Formatters
52
54
import Text.Blaze.Renderer.String (renderMarkup )
53
55
import Text.Blaze.Internal
54
56
-- import qualified Haskell.Ide.Engine.PluginApi as HIE (BiosOptions, defaultOptions)
55
57
-- import HIE.Bios.Types
58
+ import System.Process
56
59
57
60
-- testOptions :: HIE.BiosOptions
58
61
-- testOptions = HIE.defaultOptions { cradleOptsVerbosity = Verbose }
@@ -332,6 +335,36 @@ findExeRecursive exe dir = do
332
335
findExe :: String -> IO FilePath
333
336
findExe name = do
334
337
fp <- fmap fromJust $ runMaybeT $
335
- MaybeT (findExecutable name) <|>
338
+ MaybeT (findExecutable name) <|>
336
339
MaybeT (findExeRecursive name " dist-newstyle" )
337
340
makeAbsolute fp
341
+
342
+ -- | Like 'withCurrentDirectory', but will copy the directory over to the system
343
+ -- temporary directory first to avoid haskell-language-server's source tree from
344
+ -- interfering with the cradle
345
+ withCurrentDirectoryInTmp :: FilePath -> IO a -> IO a
346
+ withCurrentDirectoryInTmp dir f =
347
+ withTempCopy dir $ \ newDir ->
348
+ withCurrentDirectory newDir $ do
349
+ _ <- system " stack path"
350
+ _ <- system " stack exec env"
351
+ f
352
+
353
+ withTempCopy :: FilePath -> (FilePath -> IO a ) -> IO a
354
+ withTempCopy srcDir f = do
355
+ withSystemTempDirectory " hls-test" $ \ newDir -> do
356
+ copyDir srcDir newDir
357
+ f newDir
358
+
359
+ copyDir :: FilePath -> FilePath -> IO ()
360
+ copyDir src dst = do
361
+ cnts <- listDirectory src
362
+ forM_ cnts $ \ file -> do
363
+ unless (file `elem` ignored) $ do
364
+ let srcFp = src </> file
365
+ dstFp = dst </> file
366
+ isDir <- doesDirectoryExist srcFp
367
+ if isDir
368
+ then createDirectory dstFp >> copyDir srcFp dstFp
369
+ else copyFile srcFp dstFp
370
+ where ignored = [" dist" , " dist-newstyle" , " .stack-work" ]
0 commit comments