From c6d4076089192adc6cdc7782d7a3190bb0923501 Mon Sep 17 00:00:00 2001 From: Gabriella Gonzalez Date: Sun, 2 Apr 2023 11:21:06 -0700 Subject: [PATCH] Fix `dhall freeze --cache --all` to be idempotent The fix in https://github.com/dhall-lang/dhall-haskell/pull/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. --- dhall/src/Dhall/Freeze.hs | 13 ++++++++++++- dhall/src/Dhall/Main.hs | 2 +- dhall/tests/freeze/cached/idempotentA.dhall | 5 +++++ dhall/tests/freeze/cached/idempotentB.dhall | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 dhall/tests/freeze/cached/idempotentA.dhall create mode 100644 dhall/tests/freeze/cached/idempotentB.dhall diff --git a/dhall/src/Dhall/Freeze.hs b/dhall/src/Dhall/Freeze.hs index b5433599c..5c1f1b068 100644 --- a/dhall/src/Dhall/Freeze.hs +++ b/dhall/src/Dhall/Freeze.hs @@ -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 @@ -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 diff --git a/dhall/src/Dhall/Main.hs b/dhall/src/Dhall/Main.hs index 53b6d6419..ce79f53c8 100644 --- a/dhall/src/Dhall/Main.hs +++ b/dhall/src/Dhall/Main.hs @@ -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 = diff --git a/dhall/tests/freeze/cached/idempotentA.dhall b/dhall/tests/freeze/cached/idempotentA.dhall new file mode 100644 index 000000000..c6d131a07 --- /dev/null +++ b/dhall/tests/freeze/cached/idempotentA.dhall @@ -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 diff --git a/dhall/tests/freeze/cached/idempotentB.dhall b/dhall/tests/freeze/cached/idempotentB.dhall new file mode 100644 index 000000000..44af7a6ce --- /dev/null +++ b/dhall/tests/freeze/cached/idempotentB.dhall @@ -0,0 +1,3 @@ + missing + sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70 +? ./True.dhall