-
Notifications
You must be signed in to change notification settings - Fork 841
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
[WIP] stack freeze
command
#4220
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
79ce2ac
`stack freeze` command
qrilka 288131d
Pin revision to prevent test breakage
qrilka b108f02
More verbose and easy to understand output
qrilka 230237e
Docs for stack freeze
qrilka 238a9ee
Merge remote-tracking branch 'origin/pantry' into pantry
qrilka 2f2b751
New output format in tests
qrilka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Dependency freezing | ||
|
||
To make builds reproducible it makes sense to pin project dependencies to some | ||
exact versions and this is what is stack's `freeze` command is about. | ||
|
||
## Project freezing | ||
|
||
The default mode of its invocation: | ||
|
||
``` | ||
$ stack freeze | ||
``` | ||
freezes the following fields from the project's `stack.yaml` | ||
|
||
* packages in `extra-deps` which do not include sha256 of their cabal files and | ||
which do not specify pantry tree pointer of the package archive | ||
* `resolver` if it references a remote snapshot and if it does not specify | ||
pantry tree pointer of its contents | ||
|
||
The command outputs to standard output new project's `stack.yaml` with these | ||
changes included. | ||
|
||
If a project is specified precisely enough stack tells about it and exits. | ||
|
||
## Snapshot freezing | ||
|
||
When a project uses some custom snapshot freezing dependencies defined in | ||
the project is not enough as a snapshot could also contain not precisely | ||
specified package references. To prevent this from happening `--snapshot` flag | ||
(or `-s` in its short form) of the `freeze` command could be used: | ||
|
||
``` | ||
$ stack freeze --snapshot | ||
``` | ||
|
||
In this mode `freeze` command works almost like in the default mode, the main | ||
differenc is that it works with the projects snapshot definition and thus it | ||
pins packages from its `packages` field and not from the project's `extra-deps`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Stack.Freeze | ||
( freeze | ||
, FreezeOpts (..) | ||
, FreezeMode (..) | ||
) where | ||
|
||
import qualified Data.Yaml as Yaml | ||
import qualified RIO.ByteString as B | ||
import Stack.Prelude | ||
import Stack.Types.BuildPlan | ||
import Stack.Types.Config | ||
|
||
data FreezeMode = FreezeProject | FreezeSnapshot | ||
|
||
data FreezeOpts = FreezeOpts | ||
{ freezeMode :: FreezeMode | ||
} | ||
|
||
freeze :: HasEnvConfig env => FreezeOpts -> RIO env () | ||
freeze (FreezeOpts FreezeProject) = do | ||
mproject <- view $ configL.to configMaybeProject | ||
case mproject of | ||
Just (p, _) -> do | ||
let deps = projectDependencies p | ||
resolver = projectResolver p | ||
completePackageLocation' pl = | ||
case pl of | ||
PLImmutable pli -> PLImmutable <$> completePackageLocation pli | ||
plm@(PLMutable _) -> pure plm | ||
resolver' <- completeSnapshotLocation resolver | ||
deps' <- mapM completePackageLocation' deps | ||
if deps' == deps && resolver' == resolver | ||
then | ||
logInfo "No freezing is required for this project" | ||
else | ||
liftIO $ B.putStr $ Yaml.encode p{ projectDependencies = deps' | ||
, projectResolver = resolver' | ||
} | ||
Nothing -> logWarn "No project was found: nothing to freeze" | ||
|
||
freeze (FreezeOpts FreezeSnapshot) = do | ||
msnapshot <- view $ buildConfigL.to bcSnapshotDef.to sdSnapshot | ||
case msnapshot of | ||
Just (snap, _) -> do | ||
snap' <- completeSnapshot snap | ||
if snap' == snap | ||
then | ||
logInfo "No freezing is required for the snapshot of this project" | ||
else | ||
liftIO $ B.putStr $ Yaml.encode snap' | ||
Nothing -> | ||
logWarn "No snapshot was found: nothing to freeze" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module Stack.Options.FreezeParser where | ||
|
||
import Data.Semigroup ((<>)) | ||
import Options.Applicative | ||
import Stack.Freeze | ||
|
||
|
||
-- | Parser for arguments to `stack freeze` | ||
freezeOptsParser :: Parser FreezeOpts | ||
freezeOptsParser = | ||
FreezeOpts <$> flag FreezeProject FreezeSnapshot | ||
( long "snapshot" | ||
<> short 's' | ||
<> help "Freeze snapshot definition instead of project's stack.yaml" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Control.Monad (unless) | ||
import StackTest | ||
|
||
main :: IO () | ||
main = do | ||
stackCheckStdout ["freeze"] $ \stdOut -> do | ||
let expected = unlines | ||
[ "packages:" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem with this approach, but you can sort of get multiline strings in Haskell with: "foo\n\
\bar\n\
\baz" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know but |
||
, "- ." | ||
, "extra-deps:" | ||
, "- hackage: a50-0.5@sha256:b8dfcc13dcbb12e444128bb0e17527a2a7a9bd74ca9450d6f6862c4b394ac054,1491" | ||
, " pantry-tree:" | ||
, " size: 409" | ||
, " sha256: a7c6151a18b04afe1f13637627cad4deff91af51d336c4f33e95fc98c64c40d3" | ||
, "resolver:" | ||
, " size: 527165" | ||
, " url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/11/19.yaml" | ||
, " sha256: 0116ad1779b20ad2c9d6620f172531f13b12bb69867e78f4277157e28865dfd4" | ||
] | ||
unless (stdOut == expected) $ | ||
error $ concat [ "Expected: " | ||
, show expected | ||
, "\nActual: " | ||
, show stdOut | ||
] |
12 changes: 12 additions & 0 deletions
12
test/integration/tests/4220-freeze-command/files/freeze-command.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: freeze-command | ||
version: 0.1.0.0 | ||
build-type: Simple | ||
cabal-version: >= 2.0 | ||
|
||
library | ||
exposed-modules: Src | ||
hs-source-dirs: src | ||
build-depends: base | ||
, rio | ||
, vector | ||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Src where | ||
|
||
-- | A function of the main library | ||
funMainLib :: Int -> Int | ||
funMainLib = succ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resolver: lts-11.19 | ||
packages: | ||
- . | ||
extra-deps: | ||
- a50-0.5@rev:0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to
git add
the new modules.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, forgot the main part of it