From 82ffb2ecb52f750de1e505642a0bef051f5f979b Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Fri, 15 Feb 2019 16:09:24 +0200 Subject: [PATCH] Add 'spago freeze' to compute hashes on the package set (#113) --- README.md | 28 ++++++++++++++++++++++++++++ app/Main.hs | 9 +++++++++ app/Spago/Messages.hs | 6 ++++++ app/Spago/PackageSet.hs | 8 ++++++++ app/Spago/Packages.hs | 1 + 5 files changed, 52 insertions(+) diff --git a/README.md b/README.md index 272e18f59..7e3e17740 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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: @@ -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 diff --git a/app/Main.hs b/app/Main.hs index 63bf4f735..2e41a284b 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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 @@ -96,6 +99,7 @@ parser T.<|> bundle T.<|> makeModule T.<|> spacchettiUpgrade + T.<|> freeze T.<|> pscPackageLocalSetup T.<|> pscPackageInsDhall T.<|> pscPackageClean @@ -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 @@ -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 diff --git a/app/Spago/Messages.hs b/app/Spago/Messages.hs index e09ac9db1..31d380b5b 100644 --- a/app/Spago/Messages.hs +++ b/app/Spago/Messages.hs @@ -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" diff --git a/app/Spago/PackageSet.hs b/app/Spago/PackageSet.hs index 80bcc41f7..2aa690938 100644 --- a/app/Spago/PackageSet.hs +++ b/app/Spago/PackageSet.hs @@ -2,6 +2,7 @@ module Spago.PackageSet ( upgradeSpacchetti , checkPursIsUpToDate , makePackageSetFile + , freeze , path , pathText , PackageSet @@ -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 diff --git a/app/Spago/Packages.hs b/app/Spago/Packages.hs index 48ff966f1..e67b36706 100644 --- a/app/Spago/Packages.hs +++ b/app/Spago/Packages.hs @@ -7,6 +7,7 @@ module Spago.Packages , getGlobs , getProjectDeps , PackageSet.upgradeSpacchetti + , PackageSet.freeze , PackageSet.PackageName(..) , PackagesFilter(..) ) where