Skip to content

Commit

Permalink
Detect implicit cabal cradle in the absence of cabal.project (#221)
Browse files Browse the repository at this point in the history
* Detect implicit cabal cradle in the absence of cabal.project

A cabal cradle doesn't need a cabal.project file and isn't guaranteed to
have one either. This improves the implicit cradle search for cabal by
falling back to finding .cabal files if hie-bios couldn't find any
cabal.project files.
Because it falls back, if hie-bios tries to query a multi-package cabal
project with a nested cabal package, it will still find use the "larger"
cradle with the upper cabal.project file. See the
implicit-cabal-deep-project test project for an example of this.

* Copy test projects over to temporary directory

This prevents the cabal.project/hie.yaml of hie-bios's source tree from
interfering with the cradle stuff
  • Loading branch information
lukel97 authored Jul 7, 2020
1 parent cacebd4 commit f1dbfc1
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
key: ${{ runner.OS }}-${{ matrix.ghc }}-cabal-0

- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
uses: ludeeus/action-shellcheck@2f2aa0d
if: matrix.os == 'ubuntu-latest'
with:
ignore: tests
Expand Down
9 changes: 9 additions & 0 deletions hie-bios.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ Extra-Source-Files: ChangeLog
tests/projects/implicit-cabal/cabal.project
tests/projects/implicit-cabal/implicit-cabal.cabal
tests/projects/implicit-cabal/Main.hs
tests/projects/implicit-cabal-no-project/implicit-cabal-no-project.cabal
tests/projects/implicit-cabal-no-project/Main.hs
tests/projects/implicit-cabal-deep-project/README
tests/projects/implicit-cabal-deep-project/implicit-cabal-deep-project.cabal
tests/projects/implicit-cabal-deep-project/Main.hs
tests/projects/implicit-cabal-deep-project/cabal.project
tests/projects/implicit-cabal-deep-project/foo/foo.cabal
tests/projects/implicit-cabal-deep-project/foo/Main.hs
tests/projects/implicit-stack/Setup.hs
tests/projects/implicit-stack/implicit-stack.cabal
tests/projects/implicit-stack/Main.hs
Expand Down Expand Up @@ -229,6 +237,7 @@ test-suite bios-tests
hie-bios,
filepath,
directory,
temporary,
ghc

hs-source-dirs: tests/
Expand Down
6 changes: 3 additions & 3 deletions src/HIE/Bios/Cradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ removeVerbosityOpts = filter ((&&) <$> (/= "-v0") <*> (/= "-w"))


cabalWorkDir :: FilePath -> MaybeT IO FilePath
cabalWorkDir = findFileUpwards isCabal
where
isCabal name = name == "cabal.project"
cabalWorkDir wdir =
findFileUpwards (== "cabal.project") wdir
<|> findFileUpwards (\fp -> takeExtension fp == ".cabal") wdir

------------------------------------------------------------------------
-- | Stack Cradle
Expand Down
186 changes: 113 additions & 73 deletions tests/BiosTests.hs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/projects/failing-cabal/failing-cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-type: Simple

library
exposed-modules: MyLib
build-depends: base >=4.13 && <4.14,
build-depends: base >=4,
containers < 1 && > 1
-- ^^^^^^^^^^ <<< Invalid constraint
default-language: Haskell2010
1 change: 1 addition & 0 deletions tests/projects/implicit-cabal-deep-project/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = pure ()
3 changes: 3 additions & 0 deletions tests/projects/implicit-cabal-deep-project/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Here we are testing that if we have a nested cabal package but a cabal.project
a directory above it, hie-bios will implicitly pick up the cabal.project and
NOT the nested cabal package
2 changes: 2 additions & 0 deletions tests/projects/implicit-cabal-deep-project/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .
foo
1 change: 1 addition & 0 deletions tests/projects/implicit-cabal-deep-project/foo/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = pure ()
9 changes: 9 additions & 0 deletions tests/projects/implicit-cabal-deep-project/foo/foo.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cabal-version: >=1.10
name: foo
version: 0.1.0.0
build-type: Simple

executable foo
main-is: Main.hs
build-depends: base >=4
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cabal-version: >=1.10
name: implicit-cabal-deep-project
version: 0.1.0.0
build-type: Simple
executable foo
main-is: Main.hs
build-depends: base >=4
default-language: Haskell2010
1 change: 1 addition & 0 deletions tests/projects/implicit-cabal-no-project/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = pure ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cabal-version: >=1.10
name: implicit-cabal-no-project
version: 0.1.0.0
build-type: Simple
executable foo
main-is: Main.hs
build-depends: base >=4
default-language: Haskell2010

0 comments on commit f1dbfc1

Please sign in to comment.