Skip to content

Commit

Permalink
Fix dhall freeze --cache --all to be idempotent (dhall-lang#2500)
Browse files Browse the repository at this point in the history
The fix in dhall-lang#2350
introduced a new problem: now `dhall freeze --cache --all` is not
idempotent and will fail if you run it a second time on the same due to
trying to resolve the `missing` import.  This change fixes that.
  • Loading branch information
Gabriella439 authored and locallycompact committed Apr 26, 2023
1 parent e1ed817 commit ab40e47
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dhall/src/Dhall/Freeze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ freezeRemoteImportWithSettings settings directory import_ =
Remote {} -> freezeImportWithSettings settings directory import_
_ -> return import_

-- | See 'freezeRemoteImport'.
freezeNonMissingImportWithSettings
:: EvaluateSettings
-> FilePath
-> Import
-> IO Import
freezeNonMissingImportWithSettings settings directory import_ =
case importType (importHashed import_) of
Missing -> return import_
_ -> freezeImportWithSettings settings directory import_

-- | See 'freeze'.
freezeWithSettings
:: EvaluateSettings
Expand Down Expand Up @@ -322,7 +333,7 @@ freezeExpressionWithSettings
freezeExpressionWithSettings settings directory scope intent expression = do
let freezeScope =
case scope of
AllImports -> freezeImportWithSettings
AllImports -> freezeNonMissingImportWithSettings
OnlyRemoteImports -> freezeRemoteImportWithSettings

let freezeFunction = freezeScope settings directory
Expand Down
2 changes: 1 addition & 1 deletion dhall/src/Dhall/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ parseMode =
parseAllFlag =
Options.Applicative.switch
( Options.Applicative.long "all"
<> Options.Applicative.help "Add integrity checks to all imports (not just remote imports)"
<> Options.Applicative.help "Add integrity checks to all imports (not just remote imports) except for missing imports"
)

parseCacheFlag =
Expand Down
5 changes: 5 additions & 0 deletions dhall/tests/freeze/cached/idempotentA.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- The purpose of this test is to verify that `dhall freeze --cached` is
-- idempotent and doesn't attempt to resolve the `missing` import
missing
sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70
? ./True.dhall
3 changes: 3 additions & 0 deletions dhall/tests/freeze/cached/idempotentB.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
missing
sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70
? ./True.dhall

0 comments on commit ab40e47

Please sign in to comment.