Skip to content

Commit 406a271

Browse files
authored
Merge pull request #3503 from commercialhaskell/2781-shadow-bug
Force reconfigure when deps are rebuilt #2781
2 parents 33854d7 + e06ab0b commit 406a271

File tree

13 files changed

+87
-3
lines changed

13 files changed

+87
-3
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ Bug fixes:
150150
[#3476](https://github.com/commercialhaskell/stack/issues/3476).
151151
* Properly handle relative paths stored in the precompiled cache files. See
152152
[#3431](https://github.com/commercialhaskell/stack/issues/3431).
153+
* In some cases, Cabal does not realize that it needs to reconfigure, and must
154+
be told to do so automatically. This would manifest as a "shadowed
155+
dependency" error message. We now force a reconfigure whenever a dependency is
156+
built, even if the package ID remained the same. See
157+
[#2781](https://github.com/commercialhaskell/stack/issues/2781).
153158

154159

155160
## 1.5.1

src/Stack/Build/ConstructPlan.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ addFinal lp package isAllInOne = do
354354
, taskType = TTFiles lp Local -- FIXME we can rely on this being Local, right?
355355
, taskAllInOne = isAllInOne
356356
, taskCachePkgSrc = CacheSrcLocal (toFilePath (lpDir lp))
357+
, taskAnyMissing = not $ Set.null missing
357358
}
358359
tell mempty { wFinals = Map.singleton (packageName package) res }
359360

@@ -562,6 +563,7 @@ installPackageGivenDeps isAllInOne ps package minstalled (missing, present, minL
562563
PSIndex loc _ _ pkgLoc -> TTIndex package (loc <> minLoc) pkgLoc
563564
, taskAllInOne = isAllInOne
564565
, taskCachePkgSrc = toCachePkgSrc ps
566+
, taskAnyMissing = not $ Set.null missing
565567
}
566568

567569
-- Update response in the lib map. If it is an error, and there's

src/Stack/Build/Execute.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,12 @@ ensureConfig :: HasEnvConfig env
787787
-> RIO env () -- ^ announce
788788
-> (ExcludeTHLoading -> [String] -> RIO env ()) -- ^ cabal
789789
-> Path Abs File -- ^ .cabal file
790+
-> Task
790791
-> RIO env Bool
791-
ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp = do
792+
ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task = do
792793
newCabalMod <- liftIO (fmap modTime (D.getModificationTime (toFilePath cabalfp)))
793794
needConfig <-
794-
if boptsReconfigure eeBuildOpts
795+
if boptsReconfigure eeBuildOpts || taskAnyMissing task
795796
then return True
796797
else do
797798
-- We can ignore the components portion of the config
@@ -1305,7 +1306,7 @@ singleBuild runInBase ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} in
13051306
("Building all executables for `" <> packageNameText (packageName package) <>
13061307
"' once. After a successful build of all of them, only specified executables will be rebuilt."))
13071308

1308-
_neededConfig <- ensureConfig cache pkgDir ee (announce ("configure" <> annSuffix executableBuildStatuses)) cabal cabalfp
1309+
_neededConfig <- ensureConfig cache pkgDir ee (announce ("configure" <> annSuffix executableBuildStatuses)) cabal cabalfp task
13091310

13101311
let installedMapHasThisPkg :: Bool
13111312
installedMapHasThisPkg =

src/Stack/SDist.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ getSDistFileList lp =
291291
, taskPresent = Map.empty
292292
, taskAllInOne = True
293293
, taskCachePkgSrc = CacheSrcLocal (toFilePath (lpDir lp))
294+
, taskAnyMissing = True
294295
}
295296

296297
normalizeTarballPaths :: HasRunner env => [FilePath] -> RIO env [FilePath]

src/Stack/Types/Build.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,17 @@ data Task = Task
404404
, taskAllInOne :: !Bool
405405
-- ^ indicates that the package can be built in one step
406406
, taskCachePkgSrc :: !CachePkgSrc
407+
, taskAnyMissing :: !Bool
408+
-- ^ Were any of the dependencies missing? The reason this is
409+
-- necessary is... hairy. And as you may expect, a bug in
410+
-- Cabal. See:
411+
-- <https://github.com/haskell/cabal/issues/4728#issuecomment-337937673>. The
412+
-- problem is that Cabal may end up generating the same package ID
413+
-- for a dependency, even if the ABI has changed. As a result,
414+
-- without this field, Stack would think that a reconfigure is
415+
-- unnecessary, when in fact we _do_ need to reconfigure. The
416+
-- details here suck. We really need proper hashes for package
417+
-- identifiers.
407418
}
408419
deriving Show
409420

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import StackTest
2+
import System.Directory
3+
4+
main :: IO ()
5+
main = do
6+
createDirectoryIfMissing True "foo/src"
7+
readFile "foo/v1/Foo.hs" >>= writeFile "foo/src/Foo.hs"
8+
stack ["bench"]
9+
readFile "foo/v2/Foo.hs" >>= writeFile "foo/src/Foo.hs"
10+
stack ["bench"]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: bar
2+
version: 0.1.0.0
3+
build-type: Simple
4+
cabal-version: >=1.10
5+
6+
library
7+
hs-source-dirs: src
8+
exposed-modules: Bar
9+
build-depends: base, foo
10+
default-language: Haskell2010
11+
12+
benchmark bench
13+
type: exitcode-stdio-1.0
14+
hs-source-dirs: bench
15+
main-is: bench.hs
16+
build-depends: base
17+
, bar
18+
default-language: Haskell2010
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main :: IO ()
2+
main = return ()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Bar
2+
( bar
3+
) where
4+
5+
import Foo
6+
7+
bar :: IO ()
8+
bar = foo
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: foo
2+
version: 0.1.0.0
3+
build-type: Simple
4+
cabal-version: >=1.10
5+
6+
library
7+
hs-source-dirs: src
8+
exposed-modules: Foo
9+
build-depends: base
10+
default-language: Haskell2010

0 commit comments

Comments
 (0)