Skip to content

Commit

Permalink
Add 'spago freeze' to compute hashes on the package set (purescript#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f authored Feb 15, 2019
1 parent b2116d5 commit 82ffb2e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ PureScript package manager and build tool powered by [Dhall][dhall] and
- [Adding and overriding dependencies in the Package Set](#adding-and-overriding-dependencies-in-the-package-set)
- [Verifying your additions and overrides](#verifying-your-additions-and-overrides)
- [Upgrading the Package Set](#upgrading-the-package-set)
- [Caching the Package Set](#caching-the-package-set)
- [Building, bundling and testing a project](#building-bundling-and-testing-a-project)
- [FAQ](#faq)
- [Hey wait we have a perfectly functional `pulp` right?](#hey-wait-we-have-a-perfectly-functional-pulp-right)
Expand Down Expand Up @@ -351,6 +352,32 @@ Fetching the new one and generating hashes.. (this might take some time)
Done. Updating the local package-set file..
```

#### Caching the Package Set

It is important to have the hashes set in your `packages.dhall`, like this:

```haskell
...

let mkPackage =
https://raw.githubusercontent.com/spacchetti/spacchetti/0.12.2-20190210/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57

let upstream =
https://raw.githubusercontent.com/spacchetti/spacchetti/0.12.2-20190210/src/packages.dhall sha256:1bee3f7608ca0f87a88b4b8807cb6722ab9ce3386b68325fbfa71d7211c1cf51

...
```

The reason why it's so important is that (apart from [the safety guarantees][dhall-hash-safety])
when your imports are protected by a hash they will be cached, considerably speeding up all
the config-related operations.

You can freeze the imports in your package set by running:

```bash
$ spago freeze
```

### Building, bundling and testing a project

We can build the project and its dependencies by running:
Expand Down Expand Up @@ -554,3 +581,4 @@ We have two commands for it:
[todomvc]: https://github.com/f-f/purescript-react-basic-todomvc
[purec]: https://github.com/pure-c/purec
[purerl]: https://github.com/purerl/purescript
[dhall-hash-safety]: https://github.com/dhall-lang/dhall-lang/wiki/Safety-guarantees#code-injection
9 changes: 9 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ data Command
-- | Upgrade the package-set to the latest release
| SpacchettiUpgrade

-- | Freeze the package-set so it will be cached
| Freeze

-- | ### Commands for working with Psc-Package
--
-- Do the boilerplate of the local project setup to override and add arbitrary packages
Expand Down Expand Up @@ -96,6 +99,7 @@ parser
T.<|> bundle
T.<|> makeModule
T.<|> spacchettiUpgrade
T.<|> freeze
T.<|> pscPackageLocalSetup
T.<|> pscPackageInsDhall
T.<|> pscPackageClean
Expand Down Expand Up @@ -176,6 +180,10 @@ parser
= T.subcommand "spacchetti-upgrade" "Upgrade the upstream in packages.dhall to the latest Spacchetti release"
$ pure SpacchettiUpgrade

freeze
= T.subcommand "freeze" "Add hashes to the package-set, so it will be cached"
$ pure Freeze

version
= T.subcommand "version" "Show spago version"
$ pure Version
Expand All @@ -201,6 +209,7 @@ main = do
Verify limitJobs package -> Spago.Packages.verify limitJobs (Just package)
VerifySet limitJobs -> Spago.Packages.verify limitJobs Nothing
SpacchettiUpgrade -> Spago.Packages.upgradeSpacchetti
Freeze -> Spago.Packages.freeze
Build limitJobs paths pursArgs -> Spago.Build.build limitJobs paths pursArgs
Test modName limitJobs paths pursArgs -> Spago.Build.test modName limitJobs paths pursArgs
Repl paths pursArgs -> Spago.Build.repl paths pursArgs
Expand Down
6 changes: 6 additions & 0 deletions app/Spago/Messages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ upgradingPackageSet newTag = makeMessage
, "Fetching the new one and generating hashes.. (this might take some time)"
]

freezePackageSet :: Text
freezePackageSet = makeMessage
[ "Generating hashes for the package-set so it will be cached."
, "This might take some time..."
]

packageSetVersionWarning :: Text
packageSetVersionWarning = makeMessage
[ "WARNING: the package-set version you're on doesn't check if the version of the"
Expand Down
8 changes: 8 additions & 0 deletions app/Spago/PackageSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Spago.PackageSet
( upgradeSpacchetti
, checkPursIsUpToDate
, makePackageSetFile
, freeze
, path
, pathText
, PackageSet
Expand Down Expand Up @@ -93,6 +94,13 @@ makePackageSetFile force = do
Dhall.Format.format Dhall.Pretty.Unicode (Just $ Text.unpack pathText)


-- | Freeze the package-set imports so they can be cached
freeze :: IO ()
freeze = do
echo Messages.freezePackageSet
Dhall.Freeze.freeze (Just $ Text.unpack pathText) False defaultStandardVersion


data RawPackageSet = RawPackageSet
{ mkPackage :: Dhall.Import
, upstream :: Dhall.Import
Expand Down
1 change: 1 addition & 0 deletions app/Spago/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Spago.Packages
, getGlobs
, getProjectDeps
, PackageSet.upgradeSpacchetti
, PackageSet.freeze
, PackageSet.PackageName(..)
, PackagesFilter(..)
) where
Expand Down

0 comments on commit 82ffb2e

Please sign in to comment.