Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal custom setup #2866

Merged
merged 3 commits into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Other enhancements:
closing [#877](https://github.com/commercialhaskell/stack/issues/877).
* `stack haddock` now shows index.html paths when documentation is alread up to
date. Resolved [#781](https://github.com/commercialhaskell/stack/issues/781)
* Respects the `custom-setup` field introduced in Cabal 1.24. This
supercedes any `explicit-setup-deps` settings in your `stack.yaml`
and trusts the package's `.cabal` file to explicitly state all its
dependencies.

Bug fixes:

Expand Down
5 changes: 5 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ explicit-setup-deps:
entropy: false # override the new default for one package
```

NOTE: since 1.4.0, Stack has support for Cabal's `custom-setup` block
(introduced in Cabal 1.24). If a `custom-setup` block is provided in a `.cabal`
file, it will override the setting of `explicit-setup-deps`, and instead rely
on the stated dependencies.

### allow-newer

(Since 0.1.7)
Expand Down
64 changes: 49 additions & 15 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -933,29 +933,58 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
["-package=" ++ packageIdentifierString
(PackageIdentifier cabalPackageName
eeCabalPkgVer)]
packageArgs =
case mdeps of
packageDBArgs =
( "-clear-package-db"
: "-global-package-db"
: map (("-package-db=" ++) . toFilePathNoTrailingSep) (bcoExtraDBs eeBaseConfigOpts)
) ++
( ("-package-db=" ++ toFilePathNoTrailingSep (bcoSnapDB eeBaseConfigOpts))
: ("-package-db=" ++ toFilePathNoTrailingSep (bcoLocalDB eeBaseConfigOpts))
: ["-hide-all-packages"]
)

getPackageArgs =
case (packageSetupDeps package, mdeps) of
-- The package is using the Cabal custom-setup
-- configuration introduced in Cabal 1.24. In
-- this case, the package is providing an
-- explicit list of dependencies, and we
-- should simply use all of them.
(Just customSetupDeps, _) -> do
allDeps <-
case mdeps of
Just x -> return x
Nothing -> do
$logWarn "In getPackageArgs: custom-setup in use, but no dependency map present"
return Map.empty
depsArgs <- forM (Map.toList customSetupDeps) $ \(name, range) -> do
let matches (PackageIdentifier name' version) =
name == name' &&
version `withinRange` range
case map snd (filter (matches . fst) (Map.toList allDeps)) of
x:xs -> do
unless (null xs)
($logWarn (T.pack ("Found multiple installed packages for custom-setup dep: " ++ packageNameString name)))
return ("-package-id=" ++ ghcPkgIdString x)
[] -> do
$logWarn (T.pack ("Could not find custom-setup dep: " ++ packageNameString name))
return ("--package=" ++ packageNameString name)
return (packageDBArgs ++ depsArgs)

-- This branch is taken when
-- 'explicit-setup-deps' is requested in your
-- stack.yaml file.
Just deps | explicitSetupDeps (packageName package) config ->
(Nothing, Just deps) | explicitSetupDeps (packageName package) config ->
-- Stack always builds with the global Cabal for various
-- reproducibility issues.
let depsMinusCabal
= map ghcPkgIdString
$ Set.toList
$ addGlobalPackages deps (Map.elems eeGlobalDumpPkgs)
in
( "-clear-package-db"
: "-global-package-db"
: map (("-package-db=" ++) . toFilePathNoTrailingSep) (bcoExtraDBs eeBaseConfigOpts)
) ++
( ("-package-db=" ++ toFilePathNoTrailingSep (bcoSnapDB eeBaseConfigOpts))
: ("-package-db=" ++ toFilePathNoTrailingSep (bcoLocalDB eeBaseConfigOpts))
: ["-hide-all-packages"]
) ++
in return (
packageDBArgs ++
cabalPackageArg ++
map ("-package-id=" ++) depsMinusCabal
map ("-package-id=" ++) depsMinusCabal)
-- This branch is usually taken for builds, and
-- is always taken for `stack sdist`.
--
Expand All @@ -973,12 +1002,16 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
-- Currently, this branch is only taken via `stack
-- sdist` or when explicitly requested in the
-- stack.yaml file.
_ ->
(Nothing, _) -> return (
cabalPackageArg ++
-- NOTE: This is different from
-- packageDBArgs above inthat it does not
-- include the local database and does not
-- pass in the -hide-all-packages argument
("-clear-package-db"
: "-global-package-db"
: map (("-package-db=" ++) . toFilePathNoTrailingSep) (bcoExtraDBs eeBaseConfigOpts)
++ ["-package-db=" ++ toFilePathNoTrailingSep (bcoSnapDB eeBaseConfigOpts)])
++ ["-package-db=" ++ toFilePathNoTrailingSep (bcoSnapDB eeBaseConfigOpts)]))

setupArgs = ("--builddir=" ++ toFilePathNoTrailingSep distRelativeDir') : args
runExe exeName fullArgs =
Expand Down Expand Up @@ -1027,6 +1060,7 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
case compiler of
Ghc -> getGhcPath
Ghcjs -> getGhcjsPath
packageArgs <- getPackageArgs
runExe compilerPath $
[ "--make"
, "-odir", toFilePathNoTrailingSep setupDir
Expand Down
21 changes: 12 additions & 9 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ packageFromPackageDescription packageConfig gpkg pkg =
(not . null . exposedModules)
(library pkg)
, packageSimpleType = buildType pkg == Just Simple
, packageSetupDeps = msetupDeps
}
where
pkgFiles = GetPackageFiles $
Expand Down Expand Up @@ -271,7 +272,17 @@ packageFromPackageDescription packageConfig gpkg pkg =
return (componentModules, componentFiles, buildFiles <> dataFiles', warnings)
pkgId = package pkg
name = fromCabalPackageName (pkgName pkgId)
deps = M.filterWithKey (const . (/= name)) (packageDependencies pkg)
deps = M.filterWithKey (const . (/= name)) (M.union
(packageDependencies pkg)
-- We include all custom-setup deps - if present - in the
-- package deps themselves. Stack always works with the
-- invariant that there will be a single installed package
-- relating to a package name, and this applies at the setup
-- dependency level as well.
(fromMaybe M.empty msetupDeps))
msetupDeps = fmap
(M.fromList . map (depName &&& depRange) . setupDepends)
(setupBuildInfo pkg)

-- | Generate GHC options for the package's components, and a list of
-- options which apply generally to the package, not one specific
Expand Down Expand Up @@ -758,11 +769,7 @@ buildOtherSources build =

-- | Get the target's JS sources.
targetJsSources :: BuildInfo -> [FilePath]
#if MIN_VERSION_Cabal(1, 22, 0)
targetJsSources = jsSources
#else
targetJsSources = const []
#endif

-- | Get all dependencies of a package, including library,
-- executables, tests, benchmarks.
Expand Down Expand Up @@ -868,11 +875,7 @@ resolveConditions rc addDeps (CondNode lib deps cs) = basic <> children
case (flavor, rcCompilerVersion rc) of
(GHC, GhcVersion vghc) -> vghc `withinRange` range
(GHC, GhcjsVersion _ vghc) -> vghc `withinRange` range
#if MIN_VERSION_Cabal(1, 22, 0)
(GHCJS, GhcjsVersion vghcjs _) ->
#else
(OtherCompiler "ghcjs", GhcjsVersion vghcjs _) ->
#endif
vghcjs `withinRange` range
_ -> False

Expand Down
2 changes: 2 additions & 0 deletions src/Stack/Types/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ data Package =
,packageOpts :: !GetPackageOpts -- ^ Args to pass to GHC.
,packageHasExposedModules :: !Bool -- ^ Does the package have exposed modules?
,packageSimpleType :: !Bool -- ^ Does the package of build-type: Simple
,packageSetupDeps :: !(Maybe (Map PackageName VersionRange))
-- ^ If present: custom-setup dependencies
}
deriving (Show,Typeable)

Expand Down
3 changes: 3 additions & 0 deletions src/test/Stack/GhciSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ packages_singlePackage =
, packageOpts = GetPackageOpts undefined
, packageHasExposedModules = True
, packageSimpleType = True
, packageSetupDeps = Nothing
}
}
]
Expand Down Expand Up @@ -255,6 +256,7 @@ packages_multiplePackages =
, packageOpts = GetPackageOpts undefined
, packageHasExposedModules = True
, packageSimpleType = True
, packageSetupDeps = Nothing
}
}
, GhciPkgInfo
Expand Down Expand Up @@ -285,6 +287,7 @@ packages_multiplePackages =
, packageOpts = GetPackageOpts undefined
, packageHasExposedModules = True
, packageSimpleType = True
, packageSetupDeps = Nothing
}
}
]
2 changes: 1 addition & 1 deletion stack-7.8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extra-deps:
# For deepseq-1.4
- deepseq-1.4.1.2
- bytestring-0.10.6.0
- Cabal-1.18.1.6
- Cabal-1.24.2.0
- containers-0.5.6.3
- hpc-0.6.0.2
- process-1.2.1.0
Expand Down
2 changes: 1 addition & 1 deletion stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ library
System.Process.PagerEditor
System.Process.Read
System.Process.Run
build-depends: Cabal >= 1.18.1.5 && < 1.25
build-depends: Cabal >= 1.24 && < 1.25
, aeson (>= 1.0 && < 1.1)
, ansi-terminal >= 0.6.2.3
, async >= 2.0.2 && < 2.2
Expand Down
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ nix:
packages:
- zlib
extra-deps:
- Cabal-1.24.2.0
- th-utilities-0.2.0.1
- store-0.3
- store-core-0.3
Expand Down