phadej / cabal-extras

A tool suite to aid Haskell development using `cabal-install`
80 stars 18 forks source link

cabal-bundler --openbsd prunes some used packages #85

Open blackgnezdo opened 3 years ago

blackgnezdo commented 3 years ago

Something is busted in CabalBundler.OpenBSD:

# This reports nothing
% cabal-bundler --openbsd stack-2.7.1 2>&1 | grep cmdargs
# This correctly lists cmdargs
% cabal-bundler --curl stack-2.7.1 2>&1 | grep cmdargs
f7d8ea5c4e6af368d9b5d2eb994fc29235406fbe91916a6dc63bd883025eca75  cmdargs-0.10.21.tar.gz
curl --silent --location --output cmdargs-0.10.21.tar.gz 'http://hackage.haskell.org/package/cmdargs-0.10.21/cmdargs-0.10.21.tar.gz'

More specifically, its bfs function seems to be to blame. Given this patch:

@@ -34,9 +35,12 @@ generateOpenBSD tracer packageName exeName' plan meta = do
     let units :: Map P.UnitId P.Unit
         units = P.pjUnits plan

+    flip traverse_ (M.keys units) $ \u -> putDebug tracer (show u)
     case findExe packageName exeName units of
         [(uid0, pkgId0)] -> do
             usedUnits <- bfs tracer units uid0
+            putDebug tracer "Used units"
+            flip traverse_ usedUnits $ \u -> putDebug tracer (show u)
             deps <- unitsToDeps meta usedUnits
             case partition ((pkgId0 == ) . depPkgId) deps of
                 (mainPackage : _, depUnits) -> do

I see that units contains cmdargs and usedUnits does not.

[  14.51226] debug: UnitId "cmdargs-0.10.21-4a200e2c22dceb11fcfc14a75b5ccfc97e5beabff692ce78854608622c5379d6"

@phadej if you happen to spot the bug, I'll happily skip the hunt. Otherwise I'll figure it out.

blackgnezdo commented 3 years ago

I believe cabal-bundler is doing the right thing here. The problematic dependency chains are:

  1. mustache:exe:haskell-mustache->cmdargs
  2. stack->mustache:lib:mustache

Now, cabal-bundler seems to correctly omit cmdargs as it is not a transitive dependency of stack. Yet, when I try to build stack with cabal in network-isolated environment which doesn't have cmdargs, cabal-install fails:

$ cabal v2-build --offline --disable-benchmarks --disable-tests -j1  --flags=""   exe:stack
Warning: No remote package servers have been specified. Usually you would have
one specified in the config file.
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: mustache-2.3.1 (user goal)
[__1] unknown package: cmdargs (dependency of mustache)
[__1] fail (backjumping, conflict set: cmdargs, mustache)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: mustache, cmdargs

I don't know why cabal wants cmdargs to exist, is this a known cabal limitation?

phadej commented 3 years ago

@blackgnezdo cmdargs is a dependency of an executable in mustache package. cabal doesn't have component solving, and solves for all components. See https://github.com/haskell/cabal/issues/4087

I'm :-1: in taking also executables into account, as it will make code a lot more complicated. Rather, we have yet another reason to figure out per component solving