Skip to content

Commit 9ddf6f1

Browse files
kk-hainqphilderbeast
authored andcommitted
wip: Support sub-library dependencies
1 parent 5a5149b commit 9ddf6f1

File tree

9 files changed

+40
-62
lines changed

9 files changed

+40
-62
lines changed

src/Stack/Build.hs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import qualified Data.Text.IO as TIO
3232
import Data.Text.Read (decimal)
3333
import qualified Data.Vector as V
3434
import qualified Data.Yaml as Yaml
35-
import qualified Distribution.PackageDescription as C
36-
import Distribution.Types.Dependency (depLibraries)
3735
import Distribution.Version (mkVersion)
3836
import Path (parent)
3937
import Stack.Build.ConstructPlan
@@ -69,8 +67,6 @@ build msetLocalFiles = do
6967
depsLocals <- localDependencies
7068
let allLocals = locals <> depsLocals
7169

72-
checkSubLibraryDependencies (Map.elems $ smProject sourceMap)
73-
7470
boptsCli <- view $ envConfigL.to envConfigBuildOptsCLI
7571
-- Set local files, necessary for file watching
7672
stackYaml <- view stackYamlL
@@ -353,29 +349,4 @@ checkComponentsBuildable lps =
353349
[ (packageName (lpPackage lp), c)
354350
| lp <- lps
355351
, c <- Set.toList (lpUnbuildable lp)
356-
]
357-
358-
-- | Find if sublibrary dependency exist in each project
359-
checkSubLibraryDependencies :: HasLogFunc env => [ProjectPackage] -> RIO env ()
360-
checkSubLibraryDependencies proj = do
361-
forM_ proj $ \p -> do
362-
C.GenericPackageDescription _ _ _ lib subLibs foreignLibs exes tests benches <- liftIO $ cpGPD . ppCommon $ p
363-
364-
let dependencies = concatMap getDeps subLibs <>
365-
concatMap getDeps foreignLibs <>
366-
concatMap getDeps exes <>
367-
concatMap getDeps tests <>
368-
concatMap getDeps benches <>
369-
maybe [] C.condTreeConstraints lib
370-
libraries = concatMap (toList . depLibraries) dependencies
371-
372-
when (subLibDepExist libraries)
373-
(logWarn "SubLibrary dependency is not supported, this will almost certainly fail")
374-
where
375-
getDeps (_, C.CondNode _ dep _) = dep
376-
subLibDepExist lib =
377-
any (\x ->
378-
case x of
379-
C.LSubLibName _ -> True
380-
C.LMainLibName -> False
381-
) lib
352+
]

src/Stack/Package.hs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE CPP #-}
3-
{-# LANGUAGE DataKinds #-}
4-
{-# LANGUAGE DeriveDataTypeable #-}
5-
{-# LANGUAGE FlexibleContexts #-}
6-
{-# LANGUAGE FlexibleInstances #-}
7-
{-# LANGUAGE OverloadedStrings #-}
8-
{-# LANGUAGE RankNTypes #-}
9-
{-# LANGUAGE RecordWildCards #-}
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE NoImplicitPrelude #-}
3+
{-# LANGUAGE TupleSections #-}
104
{-# LANGUAGE ScopedTypeVariables #-}
11-
{-# LANGUAGE TupleSections #-}
5+
{-# LANGUAGE FlexibleContexts #-}
6+
{-# LANGUAGE DataKinds #-}
7+
{-# LANGUAGE DeriveDataTypeable #-}
8+
{-# LANGUAGE FlexibleInstances #-}
9+
{-# LANGUAGE OverloadedStrings #-}
10+
{-# LANGUAGE RankNTypes #-}
11+
{-# LANGUAGE RecordWildCards #-}
12+
{-# LANGUAGE LambdaCase #-}
1213

1314
-- | Dealing with Cabal.
1415

@@ -32,6 +33,7 @@ import Data.List (find, isPrefixOf, unzip)
3233
import qualified Data.Map.Strict as M
3334
import qualified Data.Set as S
3435
import qualified Data.Text as T
36+
import qualified Distribution.Compat.NonEmptySet as NES
3537
import Distribution.CabalSpecVersion
3638
import Distribution.Compiler
3739
import Distribution.ModuleName (ModuleName)
@@ -144,6 +146,7 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
144146
, packageDefaultFlags = M.fromList
145147
[(flagName flag, flagDefault flag) | flag <- pkgFlags]
146148
, packageAllDeps = S.fromList (M.keys deps)
149+
, packageSubLibDeps = subLibDeps
147150
, packageLibraries =
148151
let mlib = do
149152
lib <- library pkg
@@ -258,6 +261,13 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
258261
(M.fromList . map (depPkgName &&& depVerRange) . setupDepends)
259262
(setupBuildInfo pkg)
260263

264+
-- TODO: Should merge this calculation with deps.
265+
subLibDeps = S.fromList $ concatMap
266+
(\(Dependency n _ libs) -> mapMaybe (getSubLibName n) (NES.toList libs))
267+
(concatMap targetBuildDepends (allBuildInfo' pkg))
268+
getSubLibName pn (LSubLibName cn) = Just (T.pack (unPackageName pn <> ":" <> Cabal.unUnqualComponentName cn))
269+
getSubLibName _ _ = Nothing
270+
261271
asLibrary range = DepValue
262272
{ dvVersionRange = range
263273
, dvType = AsLibrary

src/Stack/Types/Build.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import Database.Persist.Sql (PersistField(..)
6060
import Distribution.PackageDescription (TestSuiteInterface)
6161
import Distribution.System (Arch)
6262
import qualified Distribution.Text as C
63+
import Distribution.Types.PackageName (mkPackageName, unPackageName)
6364
import Distribution.Version (mkVersion)
6465
import Path (parseRelDir, (</>), parent)
6566
import Path.Extra (toFilePathNoTrailingSep)
@@ -692,7 +693,14 @@ configureOptsNoDir econfig bco deps isLocal package = concat
692693
-- with --exact-configuration.
693694
flags = packageFlags package `Map.union` packageDefaultFlags package
694695

695-
depOptions = map (uncurry toDepOption) $ Map.toList deps
696+
-- FIXME: drunk code
697+
sublibDeps = flip mapMaybe (Set.toList (packageSubLibDeps package)) $ \sublib ->
698+
let subname = T.unpack sublib
699+
in case find (\(PackageIdentifier pn _, _) -> unPackageName pn == takeWhile (/= ':') subname) (Map.toList deps) of
700+
Just (PackageIdentifier _ v, gid) -> Just (PackageIdentifier (mkPackageName subname) v, gid)
701+
_ -> Nothing
702+
703+
depOptions = map (uncurry toDepOption) (Map.toList deps <> sublibDeps)
696704
where
697705
toDepOption = if newerCabal then toDepOption1_22 else toDepOption1_18
698706

src/Stack/Types/Package.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ data Package =
102102
,packageDeps :: !(Map PackageName DepValue) -- ^ Packages that the package depends on, both as libraries and build tools.
103103
,packageUnknownTools :: !(Set ExeName) -- ^ Build tools specified in the legacy manner (build-tools:) that failed the hard-coded lookup.
104104
,packageAllDeps :: !(Set PackageName) -- ^ Original dependencies (not sieved).
105+
-- FIXME: Having `packageDeps`, `packageAllDeps`, and `packageSubLibDeps` seem redundant.
106+
,packageSubLibDeps :: !(Set Text) -- ^ Original sub-library dependencies (not sieved).
105107
,packageGhcOptions :: ![Text] -- ^ Ghc options used on package.
106108
,packageCabalConfigOpts :: ![Text] -- ^ Additional options passed to ./Setup.hs configure
107109
,packageFlags :: !(Map FlagName Bool) -- ^ Flags used on package.

stack.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# GHC 9.2.4
23
resolver: nightly-2022-08-02
34

@@ -34,7 +35,5 @@ ghc-options:
3435
user-message: |
3536
If building Stack on macOS, you are advised to use stack-macos.yaml as the
3637
project-level configuration file, and command:
37-
3838
stack --stack-yaml stack-macos.yaml build
39-
4039
See that configuration file for further information.

stack.yaml.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ packages:
77
- completed:
88
hackage: hi-file-parser-0.1.3.0@sha256:b868e1bcb73fffe5963de6879f0a0a4c5ced97e08fc09c2c9428af884cdcaa74,2488
99
pantry-tree:
10-
sha256: 43b8556254dde11c40335bf05e3f8ae5fa6e198fcf37d2cf51da141fe218be31
1110
size: 1929
11+
sha256: 43b8556254dde11c40335bf05e3f8ae5fa6e198fcf37d2cf51da141fe218be31
1212
original:
1313
hackage: hi-file-parser-0.1.3.0@sha256:b868e1bcb73fffe5963de6879f0a0a4c5ced97e08fc09c2c9428af884cdcaa74,2488
1414
- completed:
1515
hackage: pantry-0.5.7@sha256:f96119ad2cc3771fe0891939d8a29c7f089fb333a70646e8deb2ec60532ea948,3914
1616
pantry-tree:
17-
sha256: c96fe10d96d1b1a9439c473bf27eeb2d94ad2fdbb93ccc4d9f0c69643b868c6d
1817
size: 2524
18+
sha256: c96fe10d96d1b1a9439c473bf27eeb2d94ad2fdbb93ccc4d9f0c69643b868c6d
1919
original:
2020
hackage: pantry-0.5.7@sha256:f96119ad2cc3771fe0891939d8a29c7f089fb333a70646e8deb2ec60532ea948,3914
2121
snapshots:
2222
- completed:
23-
sha256: ce4257dd36ba3b96eeee64cfb08884ddb46dd73f81f8b25a71658834edc607e2
2423
size: 619227
2524
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/8/2.yaml
25+
sha256: ce4257dd36ba3b96eeee64cfb08884ddb46dd73f81f8b25a71658834edc607e2
2626
original: nightly-2022-08-02
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import Control.Monad (unless)
2-
import Data.List (isInfixOf)
31
import StackTest
42

53
main :: IO ()
6-
main = do
7-
putStrLn "Disabled: CI doesn't have GHC 8.8.1"
8-
{-
9-
stackErrStderr ["build"] $ \str ->
10-
let msg = "SubLibrary dependency is not supported, this will almost certainly fail" in
11-
12-
unless (msg `isInfixOf` str) $
13-
error $ "Expected a warning: \n" ++ show msg
14-
-}
4+
main = stack ["build", "--install-ghc"]
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
resolver: nightly-2020-01-17
1+
resolver: nightly-2021-06-19
22
packages:
33
- .
44
- subproject
5-
extra-deps:
6-
- github: snoyberg/filelock
7-
commit: 4f080496d8bf153fbe26e64d1f52cf73c7db25f6

test/integration/tests/cabal-sublibrary-dependency/files/subproject/subproject.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
cabal-version: 3.0
12
name: subproject
23
version: 0.1.0.0
34
build-type: Simple
4-
cabal-version: >=1.10
55

66
library
77
hs-source-dirs: src
@@ -10,6 +10,7 @@ library
1010
default-language: Haskell2010
1111

1212
library sub
13+
visibility: public
1314
hs-source-dirs: src
1415
exposed-modules: SubLib
1516
build-depends: base >= 4.7 && < 5

0 commit comments

Comments
 (0)