Skip to content

Commit 644478f

Browse files
committed
Workaround for broken Setup.hs files #370
1 parent ba1075a commit 644478f

File tree

8 files changed

+72
-3
lines changed

8 files changed

+72
-3
lines changed

src/Stack/Build/Execute.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ withSingleContext :: M env m
455455
withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} inner0 =
456456
withPackage $ \package cabalfp pkgDir ->
457457
withLogFile package $ \mlogFile ->
458-
withCabal pkgDir mlogFile $ \cabal ->
458+
withCabal package pkgDir mlogFile $ \cabal ->
459459
inner0 package cabalfp pkgDir cabal announce console mlogFile
460460
where
461461
announce x = $logInfo $ T.concat
@@ -499,15 +499,21 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} inner0 =
499499
(liftIO . hClose)
500500
$ \h -> inner (Just (logPath, h))
501501

502-
withCabal pkgDir mlogFile inner = do
502+
withCabal package pkgDir mlogFile inner = do
503503
config <- asks getConfig
504504
menv <- liftIO $ configEnvOverride config EnvSettings
505505
{ esIncludeLocals = taskLocation task == Local
506506
, esIncludeGhcPackagePath = False
507507
}
508508
exeName <- liftIO $ join $ findExecutable menv "runhaskell"
509509
distRelativeDir' <- distRelativeDir
510-
msetuphs <- liftIO $ getSetupHs pkgDir
510+
msetuphs <-
511+
-- Avoid broken Setup.hs files causing problems for simple build
512+
-- types, see:
513+
-- https://github.com/commercialhaskell/stack/issues/370
514+
if packageSimpleType package
515+
then return Nothing
516+
else liftIO $ getSetupHs pkgDir
511517
let setuphs = fromMaybe eeSetupHs msetuphs
512518
inner $ \stripTHLoading args -> do
513519
let fullArgs =

src/Stack/Package.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ data Package =
122122
,packageExes :: !(Set Text) -- ^ names of executables
123123
,packageOpts :: !GetPackageOpts -- ^ Args to pass to GHC.
124124
,packageHasExposedModules :: !Bool -- ^ Does the package have exposed modules?
125+
,packageSimpleType :: !Bool -- ^ Does the package of build-type: Simple
125126
}
126127
deriving (Show,Typeable)
127128

@@ -245,6 +246,7 @@ resolvePackage packageConfig gpkg = Package
245246
, packageOpts = GetPackageOpts $ \cabalfp ->
246247
generatePkgDescOpts cabalfp pkg
247248
, packageHasExposedModules = maybe False (not . null . exposedModules) (library pkg)
249+
, packageSimpleType = buildType (packageDescription gpkg) == Just Simple
248250
}
249251

250252
where
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import StackTest
2+
3+
main :: IO ()
4+
main = stack ["build"]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2015
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Your name here nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Make (defaultMain)
2+
main = defaultMain
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: new-template
2+
version: 0.1.0.0
3+
synopsis: Initial project template from stack
4+
description: Please see README.md
5+
homepage: http://github.com/name/project
6+
license: BSD3
7+
license-file: LICENSE
8+
author: Your name here
9+
maintainer: [email protected]
10+
category: Web
11+
build-type: Simple
12+
cabal-version: >=1.10
13+
14+
library
15+
hs-source-dirs: src
16+
exposed-modules: Lib
17+
build-depends: base >= 4.7 && < 5
18+
default-language: Haskell2010
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Lib
2+
( someFunc
3+
) where
4+
5+
someFunc :: IO ()
6+
someFunc = putStrLn "someFunc"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
resolver: ghc-7.8

0 commit comments

Comments
 (0)