Skip to content

Commit

Permalink
Downgrade NoLibraryFound from an error to a warning
Browse files Browse the repository at this point in the history
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 312a412)

# Conflicts:
#	Cabal/src/Distribution/Simple/Install.hs
  • Loading branch information
TeofilC authored and ulysses4ever committed Jun 7, 2024
1 parent a0a820f commit d3bba31
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions Cabal/src/Distribution/Simple/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions cabal-testsuite/PackageTests/OnlyTestSuite/OnlyTestSuite.cabal
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/OnlyTestSuite/cabal.cabal.out
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/OnlyTestSuite/cabal.out
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/OnlyTestSuite/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
withPackageDb $ do
setup "configure" []
setup "build" []
setup "copy" []
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/OnlyTestSuite/test/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main (main) where

main :: IO ()
main = putStrLn "Test suite not yet implemented."
13 changes: 13 additions & 0 deletions changelog.d/issue-6750
Original file line number Diff line number Diff line change
@@ -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.
}

0 comments on commit d3bba31

Please sign in to comment.