From c08a1c983ce47f7fdfab70d61f2da061361f4bdb Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Tue, 19 Sep 2023 17:18:59 +0700 Subject: [PATCH] Desugar local build tools to `build-tool-depends` (fixes #516) --- src/Hpack/Config.hs | 12 ++++-------- src/Hpack/Render.hs | 1 - test/EndToEndSpec.hs | 14 +++++++------- test/Hpack/ConfigSpec.hs | 8 ++------ 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/Hpack/Config.hs b/src/Hpack/Config.hs index dae657a7..0d5a998c 100644 --- a/src/Hpack/Config.hs +++ b/src/Hpack/Config.hs @@ -983,7 +983,7 @@ data Executable = Executable { , executableGeneratedModules :: [Module] } deriving (Eq, Show) -data BuildTool = BuildTool String String | LocalBuildTool String +data BuildTool = BuildTool String String deriving (Show, Eq, Ord) data Section a = Section { @@ -1517,14 +1517,11 @@ toSection packageName_ executableNames = go type SystemBuildTool = (String, VersionConstraint) -toBuildTool :: Monad m => String -> [String] -> (ParseBuildTool, DependencyVersion) - -> Warnings m (Either SystemBuildTool (BuildTool, DependencyVersion)) +toBuildTool :: Monad m => String -> [String] -> (ParseBuildTool, DependencyVersion) -> Warnings m (Either SystemBuildTool (BuildTool, DependencyVersion)) toBuildTool packageName_ executableNames = \ case - (QualifiedBuildTool pkg executable, v) - | pkg == packageName_ && executable `elem` executableNames -> localBuildTool executable v - | otherwise -> buildTool pkg executable v + (QualifiedBuildTool pkg executable, v) -> buildTool pkg executable v (UnqualifiedBuildTool executable, v) - | executable `elem` executableNames -> localBuildTool executable v + | executable `elem` executableNames -> buildTool packageName_ executable v | Just pkg <- lookup executable legacyTools -> legacyBuildTool pkg executable v | executable `elem` legacySystemTools, DependencyVersion Nothing c <- v -> legacySystemBuildTool executable c | otherwise -> buildTool executable executable v @@ -1533,7 +1530,6 @@ toBuildTool packageName_ executableNames = \ case systemBuildTool = return . Left - localBuildTool executable v = return . Right $ (LocalBuildTool executable, v) legacyBuildTool pkg executable v = warnLegacyTool pkg executable >> buildTool pkg executable v legacySystemBuildTool executable c = warnLegacySystemTool executable >> systemBuildTool (executable, c) diff --git a/src/Hpack/Render.hs b/src/Hpack/Render.hs index 239139fa..f38d027a 100644 --- a/src/Hpack/Render.hs +++ b/src/Hpack/Render.hs @@ -351,7 +351,6 @@ data RenderBuildTool = BuildTools String | BuildToolDepends String renderBuildTool :: (BuildTool, DependencyVersion) -> RenderBuildTool renderBuildTool (buildTool, renderVersion -> version) = case buildTool of - LocalBuildTool executable -> BuildTools (executable ++ version) BuildTool pkg executable | pkg == executable && executable `elem` knownBuildTools -> BuildTools (executable ++ version) | otherwise -> BuildToolDepends (pkg ++ ":" ++ executable ++ version) diff --git a/test/EndToEndSpec.hs b/test/EndToEndSpec.hs index 73611fcb..d48d561b 100644 --- a/test/EndToEndSpec.hs +++ b/test/EndToEndSpec.hs @@ -668,15 +668,15 @@ spec = around_ (inTempDirectoryNamed "my-package") $ do } context "when the name of a build tool matches an executable from the same package" $ do - it "adds it to build-tools" $ do + it "adds it to build-tool-depends" $ do [i| executables: bar: build-tools: - bar |] `shouldRenderTo` executable_ "bar" [i| - build-tools: - bar + build-tool-depends: + my-package:bar |] it "gives per-section unqualified names precedence over global qualified names" $ do @@ -688,8 +688,8 @@ spec = around_ (inTempDirectoryNamed "my-package") $ do build-tools: - bar == 0.2.0 |] `shouldRenderTo` executable_ "bar" [i| - build-tools: - bar ==0.2.0 + build-tool-depends: + my-package:bar ==0.2.0 |] it "gives per-section qualified names precedence over global unqualified names" $ do @@ -701,8 +701,8 @@ spec = around_ (inTempDirectoryNamed "my-package") $ do build-tools: - my-package:bar == 0.2.0 |] `shouldRenderTo` executable_ "bar" [i| - build-tools: - bar ==0.2.0 + build-tool-depends: + my-package:bar ==0.2.0 |] context "when the name of a build tool matches a legacy system build tool" $ do diff --git a/test/Hpack/ConfigSpec.hs b/test/Hpack/ConfigSpec.hs index 1842b249..ab4ffd7f 100644 --- a/test/Hpack/ConfigSpec.hs +++ b/test/Hpack/ConfigSpec.hs @@ -157,8 +157,8 @@ spec = do toBuildTool_ (UnqualifiedBuildTool "bar") `shouldBe` (Right (BuildTool "bar" "bar", anyVersion), []) context "when name matches a local executable" $ do - it "returns a LocalBuildTool" $ do - toBuildTool_ (UnqualifiedBuildTool "foo") `shouldBe` (Right (LocalBuildTool "foo", anyVersion), []) + it "uses the current package name" $ do + toBuildTool_ (UnqualifiedBuildTool "foo") `shouldBe` (Right (BuildTool "my-package" "foo", anyVersion), []) context "when name matches a legacy executable" $ do it "warns" $ do @@ -177,10 +177,6 @@ spec = do it "returns a BuildTool" $ do toBuildTool_ (QualifiedBuildTool "other-package" "foo") `shouldBe` (Right (BuildTool "other-package" "foo", anyVersion), []) - context "when both package matches the current package and executable matches a local executable" $ do - it "returns a LocalBuildTool" $ do - toBuildTool_ (QualifiedBuildTool "my-package" "foo") `shouldBe` (Right (LocalBuildTool "foo", anyVersion), []) - describe "readPackageConfig" $ do it "warns on missing name" $ do withPackageWarnings_ [i|