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

Support for public sublibrary dependencies #6343

Merged
merged 18 commits into from
Dec 1, 2023
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
24 changes: 14 additions & 10 deletions .stan.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
id = "OBS-STAN-0102-luLR/n-522:30"
# ✦ Category: #Infinite #List
# ✦ File: src\Stack\New.hs
#
# 522 ┃
# 523 ┃ let isPkgSpec f = ".cabal" `L.isSuffixOf` f || "package.yaml" `L.isSuffixOf` f
# 524 ┃ ^^^^^^^^^^^^^^
Expand All @@ -38,6 +39,7 @@
id = "OBS-STAN-0102-luLR/n-522:65"
# ✦ Category: #Infinite #List
# ✦ File: src\Stack\New.hs
#
# 522 ┃
# 523 ┃ let isPkgSpec f = ".cabal" `L.isSuffixOf` f || "package.yaml" `L.isSuffixOf` f
# 524 ┃ ^^^^^^^^^^^^^^
Expand All @@ -52,31 +54,33 @@

# Anti-pattern: Data.ByteString.Char8.pack
[[ignore]]
id = "OBS-STAN-0203-fki0nd-1124:21"
id = "OBS-STAN-0203-fki0nd-1128:21"
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
# ✦ Category: #AntiPattern
# ✦ File: src\Stack\Build\Execute.hs
# ✦ Category: #AntiPattern
# ✦ File: src\Stack\Build\Execute.hs
#
# 1122
# 1123 ┃ newProjectRoot <- S8.pack . toFilePath <$> view projectRootL
# 1124 ┃ ^^^^^^^
# 1127
# 1128 ┃ newProjectRoot <- S8.pack . toFilePath <$> view projectRootL
# 1129 ┃ ^^^^^^^

# Anti-pattern: Data.ByteString.Char8.pack
[[ignore]]
id = "OBS-STAN-0203-fki0nd-2668:3"
id = "OBS-STAN-0203-fki0nd-2672:3"
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
# ✦ Category: #AntiPattern
# ✦ File: src\Stack\Build\Execute.hs
# 2673 ┃
# 2674 ┃ S8.pack . formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6Q"
# 2675 ┃ ^^^^^^^
#
# 2671 ┃
# 2672 ┃ S8.pack . formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6Q"
# 2673 ┃ ^^^^^^^

# Anti-pattern: Data.ByteString.Char8.pack
[[ignore]]
id = "OBS-STAN-0203-hTeu0Y-380:17"
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
# ✦ Category: #AntiPattern
# ✦ File: src\Stack\Init.hs
#
# 378 ┃
# 379 ┃ commentHelp = BC.pack . intercalate "\n" . map commentLine
# 380 ┃ ^^^^^^^
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Release notes:

* After an upgrade from an earlier version of Stack, on first use only,
Stack 2.14.0 may warn that it had trouble loading the CompilerPaths cache.
* The hash used as a key for Stack's pre-compiled package cache has changed,
following the dropping of support for Cabal versions older than `1.24.0.0`.

Expand All @@ -28,6 +30,8 @@ Behavior changes:
Other enhancements:

* Consider GHC 9.8 to be a tested compiler and remove warnings.
* Stack can build packages with dependencies on public sub-libraries of other
packages.
* Add flag `--no-init` to Stack's `new` command to skip the initialisation of
the newly-created project for use with Stack.
* The HTML file paths produced at the end of `stack haddock` are printed on
Expand Down
5 changes: 3 additions & 2 deletions doc/maintainers/stack_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,15 @@ to take stock of the errors that Stack itself can raise, by reference to the
- `Stack.Types.Build.BuildPrettyException`

~~~haskell
[S-4804] | ConstructPlanFailed [ConstructPlanException] (Path Abs File) (Path Abs Dir) ParentMap (Set PackageName) (Map PackageName [PackageName])
[S-4804] = ConstructPlanFailed [ConstructPlanException] (Path Abs File) (Path Abs Dir) ParentMap (Set PackageName) (Map PackageName [PackageName])
[S-7282] | ExecutionFailure [SomeException]
[S-7011] | CabalExitedUnsuccessfully ExitCode PackageIdentifier (Path Abs File) [String] (Maybe (Path Abs File)) [Text]
[S-6374] | SetupHsBuildFailure ExitCode (Maybe PackageIdentifier) (Path Abs File) [String] (Maybe (Path Abs File)) [Text]
[S-8506] | TargetParseException [StyleDoc]
[S-7086] | SomeTargetsNotBuildable [(PackageName, NamedComponent)]
[S-8664] | InvalidFlagSpecification (Set UnusedFlags)
[S-8100] = GHCProfOptionInvalid
[S-8100] | GHCProfOptionInvalid
[S-1727] | NotOnlyLocal [PackageName] [Text]
~~~

- `Stack.Types.Compiler.CompilerException`
Expand Down
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ library:
- Stack.Types.ApplyGhcOptions
- Stack.Types.ApplyProgOptions
- Stack.Types.Build
- Stack.Types.Build.ConstructPlan
- Stack.Types.Build.Exception
- Stack.Types.BuildConfig
- Stack.Types.BuildOpts
Expand All @@ -277,6 +278,7 @@ library:
- Stack.Types.CompilerPaths
- Stack.Types.Compiler
- Stack.Types.Component
- Stack.Types.ComponentUtils
- Stack.Types.Config
- Stack.Types.Config.Exception
- Stack.Types.ConfigMonoid
Expand Down
43 changes: 5 additions & 38 deletions src/Stack/Build.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

-- | Build the project.
Expand All @@ -19,8 +18,8 @@ import Data.List.Extra ( groupSort )
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Distribution.PackageDescription as C
import Distribution.Types.Dependency ( Dependency (..), depLibraries )
-- import qualified Distribution.PackageDescription as C
-- import Distribution.Types.Dependency ( Dependency (..), depLibraries )
import Distribution.Version ( mkVersion )
import RIO.NonEmpty ( nonEmpty )
import qualified RIO.NonEmpty as NE
Expand Down Expand Up @@ -63,11 +62,12 @@ import Stack.Types.GlobalOpts ( globalOptsBuildOptsMonoidL )
import Stack.Types.NamedComponent ( exeComponents )
import Stack.Types.Package
( InstallLocation (..), LocalPackage (..), Package (..)
, PackageConfig (..), lpFiles, lpFilesForComponents )
, PackageConfig (..), lpFiles, lpFilesForComponents
)
import Stack.Types.Platform ( HasPlatform (..) )
import Stack.Types.Runner ( Runner, globalOptsL )
import Stack.Types.SourceMap
( CommonPackage (..), ProjectPackage (..), SMTargets (..)
( SMTargets (..)
, SourceMap (..), Target (..) )
import System.Terminal ( fixCodePage )

Expand Down Expand Up @@ -138,8 +138,6 @@ build msetLocalFiles = do
depsLocals <- localDependencies
let allLocals = locals <> depsLocals

checkSubLibraryDependencies (Map.elems $ smProject sourceMap)

boptsCli <- view $ envConfigL.to envConfigBuildOptsCLI
-- Set local files, necessary for file watching
stackYaml <- view stackYamlL
Expand Down Expand Up @@ -371,34 +369,3 @@ checkComponentsBuildable lps =
| lp <- lps
, c <- Set.toList (lpUnbuildable lp)
]

-- | Find if any sub-library dependency (other than internal libraries) exists
-- in each project package.
checkSubLibraryDependencies :: HasTerm env => [ProjectPackage] -> RIO env ()
checkSubLibraryDependencies projectPackages =
forM_ projectPackages $ \projectPackage -> do
C.GenericPackageDescription pkgDesc _ _ lib subLibs foreignLibs exes tests benches <-
liftIO $ cpGPD . ppCommon $ projectPackage

let pName = pkgName . C.package $ pkgDesc
dependencies = concatMap getDeps subLibs <>
concatMap getDeps foreignLibs <>
concatMap getDeps exes <>
concatMap getDeps tests <>
concatMap getDeps benches <>
maybe [] C.condTreeConstraints lib
notInternal (Dependency pName' _ _) = pName' /= pName
publicDependencies = filter notInternal dependencies
publicLibraries = concatMap (toList . depLibraries) publicDependencies

when (subLibDepExist publicLibraries) $
prettyWarnS
"Sublibrary dependency is not supported, this will almost certainly \
\fail."
where
getDeps (_, C.CondNode _ dep _) = dep
subLibDepExist = any
( \case
C.LSubLibName _ -> True
C.LMainLibName -> False
)
67 changes: 37 additions & 30 deletions src/Stack/Build/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ import Stack.Types.EnvConfig
)
import Stack.Types.GhcPkgId ( GhcPkgId, ghcPkgIdString )
import Stack.Types.NamedComponent ( NamedComponent (..) )
import Stack.Types.Package
(InstalledLibraryInfo (..), installedGhcPkgId )
import Stack.Types.SourceMap ( smRelDir )
import System.PosixCompat.Files
( modificationTime, getFileStatus, setFileTimes )
Expand Down Expand Up @@ -262,14 +264,11 @@ flagCacheKey :: (HasEnvConfig env) => Installed -> RIO env ConfigCacheKey
flagCacheKey installed = do
installationRoot <- installationRootLocal
case installed of
Library _ gid _ ->
pure $
configCacheKey installationRoot (ConfigCacheTypeFlagLibrary gid)
Executable ident ->
pure $
configCacheKey
installationRoot
(ConfigCacheTypeFlagExecutable ident)
Library _ installedInfo -> do
let gid = iliId installedInfo
pure $ configCacheKey installationRoot (ConfigCacheTypeFlagLibrary gid)
Executable ident -> pure $
configCacheKey installationRoot (ConfigCacheTypeFlagExecutable ident)

-- | Loads the flag cache for the given installed extra-deps
tryGetFlagCache :: HasEnvConfig env
Expand Down Expand Up @@ -378,28 +377,36 @@ writePrecompiledCache ::
-> [GhcPkgId] -- ^ sub-libraries, in the GhcPkgId format
-> Set Text -- ^ executables
-> RIO env ()
writePrecompiledCache baseConfigOpts loc copts buildHaddocks mghcPkgId subLibs exes = do
key <- getPrecompiledCacheKey loc copts buildHaddocks
ec <- view envConfigL
let stackRootRelative = makeRelative (view stackRootL ec)
mlibpath <- case mghcPkgId of
Executable _ -> pure Nothing
Library _ ipid _ -> Just <$> pathFromPkgId stackRootRelative ipid
subLibPaths <- mapM (pathFromPkgId stackRootRelative) subLibs
exes' <- forM (Set.toList exes) $ \exe -> do
name <- parseRelFile $ T.unpack exe
stackRootRelative $ bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
let precompiled = PrecompiledCache
{ pcLibrary = mlibpath
, pcSubLibs = subLibPaths
, pcExes = exes'
}
savePrecompiledCache key precompiled
-- reuse precompiled cache with haddocks also in case when haddocks are not
-- required
when buildHaddocks $ do
key' <- getPrecompiledCacheKey loc copts False
savePrecompiledCache key' precompiled
writePrecompiledCache
baseConfigOpts
loc
copts
buildHaddocks
mghcPkgId
subLibs
exes
= do
key <- getPrecompiledCacheKey loc copts buildHaddocks
ec <- view envConfigL
let stackRootRelative = makeRelative (view stackRootL ec)
mlibpath <-
traverse (pathFromPkgId stackRootRelative) (installedGhcPkgId mghcPkgId)
subLibPaths <- mapM (pathFromPkgId stackRootRelative) subLibs
exes' <- forM (Set.toList exes) $ \exe -> do
name <- parseRelFile $ T.unpack exe
stackRootRelative $
bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
let precompiled = PrecompiledCache
{ pcLibrary = mlibpath
, pcSubLibs = subLibPaths
, pcExes = exes'
}
savePrecompiledCache key precompiled
-- reuse precompiled cache with haddocks also in case when haddocks are
-- not required
when buildHaddocks $ do
key' <- getPrecompiledCacheKey loc copts False
savePrecompiledCache key' precompiled
where
pathFromPkgId stackRootRelative ipid = do
ipid' <- parseRelFile $ ghcPkgIdString ipid ++ ".conf"
Expand Down
Loading