Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to v2-install both library and executable #6480

Open
elliottslaughter opened this issue Jan 15, 2020 · 4 comments
Open

How to v2-install both library and executable #6480

elliottslaughter opened this issue Jan 15, 2020 · 4 comments

Comments

@elliottslaughter
Copy link

Describe the bug
If I install a library followed by its executable, both seem to get rebuilt. This could be avoided if there were an easy way (e.g. --exe --lib) to build both in the first place, or if the command were smart enough to avoid the duplicate build.

To Reproduce
Steps to reproduce the behavior:

$ cabal v2-install --lib pandoc
$ cabal v2-install pandoc

Expected behavior
My original build (with --lib) already built the executable. It would be nice if it didn't have to be rebuilt, or failing that, if there were a way to explicitly request both to be installed.

System information

  • Operating system: macOS 10.14
  • cabal 3.0.0.0, ghc 8.8.1

Additional context
Sample output:

$ cabal v2-install --lib pandoc
Resolving dependencies...
[ ... ]
 - pandoc-2.9.1.1 (lib) (requires download & build)
 - pandoc-2.9.1.1 (exe:pandoc) (requires download & build)
[ ... ]
Installing   pandoc-2.9.1.1 (exe:pandoc)
Completed    pandoc-2.9.1.1 (exe:pandoc)
$ cabal v2-install pandoc
Resolving dependencies...
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
 - process-1.6.7.0 (lib:process) (requires download & build)
 - hsc2hs-0.68.6 (exe:hsc2hs) (requires build)
 - network-3.1.1.1 (lib:network) (requires build)
 - tls-1.5.3 (lib) (requires build)
 - streaming-commons-0.2.1.2 (lib) (requires build)
 - socks-0.6.1 (lib) (requires build)
 - HTTP-4000.3.14 (lib) (requires build)
 - http-client-0.6.4 (lib) (requires build)
 - connection-0.3.1 (lib:connection) (requires build)
 - http-client-tls-0.3.5.3 (lib) (requires build)
 - pandoc-2.9.1.1 (lib) (requires build)
 - pandoc-2.9.1.1 (exe:pandoc) (requires build)
[ ... ]

It's not quite as bad as a full rebuild, but it still requires extra time if you build the library and executable multiple times.

@phadej
Copy link
Collaborator

phadej commented Jan 15, 2020

This is weird. cabal install --lib pandoc should not build an executable. And I don't see a reason in pandoc.cabal why it would do so. (it's not build-type: Custom, e.g.)

@fgaz do you know what may be the cause?

@fgaz
Copy link
Member

fgaz commented Jan 17, 2020

I can't think of any reason why it should do that. @typedrat?

@fgaz
Copy link
Member

fgaz commented Jan 17, 2020

I looked a bit at the code and it seems that on the installLibraries branch the component-type filtering is only done after the building and before the installation in the env file:

entriesForLibraryComponents :: TargetsMap -> [GhcEnvironmentFileEntry]
entriesForLibraryComponents = Map.foldrWithKey' (\k v -> mappend (go k v)) []
where
hasLib :: (ComponentTarget, [TargetSelector]) -> Bool
hasLib (ComponentTarget (CLibName _) _, _) = True
hasLib _ = False
go :: UnitId
-> [(ComponentTarget, [TargetSelector])]
-> [GhcEnvironmentFileEntry]
go unitId targets
| any hasLib targets = [GhcEnvFilePackageId unitId]
| otherwise = []

@fgaz
Copy link
Member

fgaz commented Jan 17, 2020

Which explains why install --lib <package-with-no-libs> succeeds:

> cabal v2-install yabi
Resolving dependencies...
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - word8-0.1.3 (lib) (requires download & build)
 - yabi-0.2.0.0 (exe:yabi) (requires download & build)
Downloading  word8-0.1.3
Downloaded   word8-0.1.3
Downloading  yabi-0.2.0.0
Configuring library for word8-0.1.3..
Downloaded   yabi-0.2.0.0
Preprocessing library for word8-0.1.3..
Building library for word8-0.1.3..
[1 of 2] Compiling Data.Char8       ( Data/Char8.hs, dist/build/Data/Char8.o )
[2 of 2] Compiling Data.Word8       ( Data/Word8.hs, dist/build/Data/Word8.o )
Installing library in /home/fgaz/.cabal/store/ghc-8.6.5/incoming/new-13710/home/fgaz/.cabal/store/ghc-8.6.5/word8-0.1.3-a2b361dcca69866e4747c1dcdd9edce50bfcf06017e9a9e3253f16436e28d4e4/lib
Configuring executable 'yabi' for yabi-0.2.0.0..
Preprocessing executable 'yabi' for yabi-0.2.0.0..
Building executable 'yabi' for yabi-0.2.0.0..
[1 of 1] Compiling Main             ( yabi.hs, dist/build/yabi/yabi-tmp/Main.o )
Linking dist/build/yabi/yabi ...
Installing executable yabi in /home/fgaz/.cabal/store/ghc-8.6.5/incoming/new-13710/home/fgaz/.cabal/store/ghc-8.6.5/yabi-0.2.0.0-66c5bafad0f1822c8fed4992e9136d3e02ef01c505ca3ca0a76404c71449ac75/bin
Warning: The directory
/home/fgaz/.cabal/store/ghc-8.6.5/incoming/new-13710/home/fgaz/.cabal/store/ghc-8.6.5/yabi-0.2.0.0-66c5bafad0f1822c8fed4992e9136d3e02ef01c505ca3ca0a76404c71449ac75/bin
is not in the system search path.

(the warning is bogus and has nothing to do with the issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants