From d3bba3143cfe1f9ad8d15f7b3fbee419822bdcbe Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Wed, 24 Apr 2024 11:47:53 +0100 Subject: [PATCH] Downgrade NoLibraryFound from an error to a warning This makes Setup copy/install succeed if there's nothing to do because the package doesn't contain a library or executable. This allows downstream users of Cabal to avoid having to add workarounds for this edge case. Resolves #6750 (cherry picked from commit 312a4124e3e197e3525f60d5b9684e208e1c8df4) # Conflicts: # Cabal/src/Distribution/Simple/Install.hs --- Cabal/src/Distribution/Simple/Errors.hs | 3 ++- Cabal/src/Distribution/Simple/Install.hs | 25 +++++++++++++++++++ .../OnlyTestSuite/OnlyTestSuite.cabal | 15 +++++++++++ .../OnlyTestSuite/cabal.cabal.out | 6 +++++ .../PackageTests/OnlyTestSuite/cabal.out | 6 +++++ .../PackageTests/OnlyTestSuite/cabal.test.hs | 6 +++++ .../PackageTests/OnlyTestSuite/test/Main.hs | 4 +++ changelog.d/issue-6750 | 13 ++++++++++ 8 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 cabal-testsuite/PackageTests/OnlyTestSuite/OnlyTestSuite.cabal create mode 100644 cabal-testsuite/PackageTests/OnlyTestSuite/cabal.cabal.out create mode 100644 cabal-testsuite/PackageTests/OnlyTestSuite/cabal.out create mode 100644 cabal-testsuite/PackageTests/OnlyTestSuite/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/OnlyTestSuite/test/Main.hs create mode 100644 changelog.d/issue-6750 diff --git a/Cabal/src/Distribution/Simple/Errors.hs b/Cabal/src/Distribution/Simple/Errors.hs index 2c5af36a04b..b57d97d6679 100644 --- a/Cabal/src/Distribution/Simple/Errors.hs +++ b/Cabal/src/Distribution/Simple/Errors.hs @@ -48,7 +48,8 @@ data CabalException | EnableBenchMark | BenchMarkNameDisabled String | NoBenchMark String - | NoLibraryFound + | -- | @NoLibraryFound@ has been downgraded to a warning, and is therefore no longer emitted. + NoLibraryFound | CompilerNotInstalled CompilerFlavor | CantFindIncludeFile String | UnsupportedTestSuite String diff --git a/Cabal/src/Distribution/Simple/Install.hs b/Cabal/src/Distribution/Simple/Install.hs index 7a6c49e0d48..b3a1f93b1da 100644 --- a/Cabal/src/Distribution/Simple/Install.hs +++ b/Cabal/src/Distribution/Simple/Install.hs @@ -112,9 +112,34 @@ install pkg_descr lbi flags = do verbosity = fromFlag (copyVerbosity flags) copydest = fromFlag (copyDest flags) +<<<<<<< HEAD checkHasLibsOrExes = unless (hasLibs pkg_descr || hasForeignLibs pkg_descr || hasExes pkg_descr) $ dieWithException verbosity NoLibraryFound +======= + -- It's not necessary to do these in build-order, but it's harmless + withNeededTargetsInBuildOrder' pkg_descr lbi (map nodeKey targets) $ \target -> do + let comp = targetComponent target + clbi = targetCLBI target + copyComponent verbosity pkg_descr lbi comp clbi copydest + for_ installComponentHook $ \instAction -> + let inputs = + SetupHooks.InstallComponentInputs + { copyFlags = flags + , localBuildInfo = lbi + , targetInfo = target + } + in instAction inputs + where + common = copyCommonFlags flags + distPref = fromFlag $ setupDistPref common + verbosity = fromFlag $ setupVerbosity common + copydest = fromFlag (copyDest flags) + + checkHasLibsOrExes = + unless (hasLibs pkg_descr || hasForeignLibs pkg_descr || hasExes pkg_descr) $ + warn verbosity "No executables and no library found. Nothing to do." +>>>>>>> 312a4124e (Downgrade NoLibraryFound from an error to a warning) -- | Copy package global files. copyPackage diff --git a/cabal-testsuite/PackageTests/OnlyTestSuite/OnlyTestSuite.cabal b/cabal-testsuite/PackageTests/OnlyTestSuite/OnlyTestSuite.cabal new file mode 100644 index 00000000000..c449f91998c --- /dev/null +++ b/cabal-testsuite/PackageTests/OnlyTestSuite/OnlyTestSuite.cabal @@ -0,0 +1,15 @@ +cabal-version: 3.0 +name: OnlyTestSuite +version: 0.1.0.0 +build-type: Simple + +common warnings + ghc-options: -Wall + +test-suite OnlyTestSuite-test + import: warnings + default-language: Haskell2010 + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + build-depends: base diff --git a/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.cabal.out b/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.cabal.out new file mode 100644 index 00000000000..829de87b0cc --- /dev/null +++ b/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.cabal.out @@ -0,0 +1,6 @@ +# Setup configure +Configuring OnlyTestSuite-0.1.0.0... +# Setup build +Building OnlyTestSuite-0.1.0.0... +# Setup copy +Warning: No executables and no library found. Nothing to do. diff --git a/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.out b/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.out new file mode 100644 index 00000000000..829de87b0cc --- /dev/null +++ b/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.out @@ -0,0 +1,6 @@ +# Setup configure +Configuring OnlyTestSuite-0.1.0.0... +# Setup build +Building OnlyTestSuite-0.1.0.0... +# Setup copy +Warning: No executables and no library found. Nothing to do. diff --git a/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.test.hs b/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.test.hs new file mode 100644 index 00000000000..6e715d370e8 --- /dev/null +++ b/cabal-testsuite/PackageTests/OnlyTestSuite/cabal.test.hs @@ -0,0 +1,6 @@ +import Test.Cabal.Prelude +main = setupAndCabalTest $ do + withPackageDb $ do + setup "configure" [] + setup "build" [] + setup "copy" [] diff --git a/cabal-testsuite/PackageTests/OnlyTestSuite/test/Main.hs b/cabal-testsuite/PackageTests/OnlyTestSuite/test/Main.hs new file mode 100644 index 00000000000..3e2059e31f5 --- /dev/null +++ b/cabal-testsuite/PackageTests/OnlyTestSuite/test/Main.hs @@ -0,0 +1,4 @@ +module Main (main) where + +main :: IO () +main = putStrLn "Test suite not yet implemented." diff --git a/changelog.d/issue-6750 b/changelog.d/issue-6750 new file mode 100644 index 00000000000..e392258267b --- /dev/null +++ b/changelog.d/issue-6750 @@ -0,0 +1,13 @@ +synopsis: Make Setup copy/install succeed when there's no executable or library +packages: Cabal +prs: #9926 +issues: #6750 + +description: { + Historically the Setup copy and install steps would fail if the package didn't + contain an executable or library component. In this case there's nothing to do. + + This required workarounds for downstream users of Cabal to handle this edge case. + Now that this error has been downgraded to a warning, Cabal will succeed if + there's nothing to do. +}