Ticket #217 (closed defect: fixed)

Opened 10 months ago

Last modified 10 months ago

Main modules in .hsc files are not included in sdist

Reported by: gwern Assigned to:
Priority: normal Milestone: Cabal-1.4
Component: Cabal library Version: 1.2.3.0
Severity: normal Keywords:
Cc: Difficulty: normal
GHC Version: 6.8.2 Platform:

Description (Last modified by duncan)

I've been working on a darcs repo of tools for XMonad, and I ran into a problem with making an sdist tarball.

The repo is pretty standard: in a src/ directory, it contains 7 files, of which 6 are executables with 'module Main where' headers. The cabal file looks like this: http://hpaste.org/5239

name:               xmonad-utils
version:            0.1
homepage:           http://www.haskell.org/haskellwiki/Xmonad-utils
synopsis:           A small collection of X utilities
description:        A small collection of X utilities useful when
                    running XMonad. It includes: hxsel, which returns
                    the text currently in the X selection; hslock, a
                    simple X screen lock; hmanage: an utility to
                    toggle the override-redirect property of any
                    window; and hhp, a simple utility to hide the
                    pointer, similar to unclutter.
category:           System
license:            BSD3
license-file:       LICENSE
author:             Andrea Rossato
maintainer:         andrea.rossato@unibz.it
build-depends:      base>=2.0, X11>=1.3, ghc>=6.8, unix, random>=1.0
build-type:         Simple
tested-with:        GHC==6.8.2
extra-source-files: src/Heval.hs, src/Hhp.hs, src/Hmanage.hs,
                    src/Hxput.hs, src/Hxsel.hs, src/Utils.hs

executable:         hxsel
main-is:            Hxsel.hs
hs-source-dirs:     src/
ghc-options:        -funbox-strict-fields -O2 -Wall -optl-Wl,-s
ghc-prof-options:   -prof -auto-all

executable:         hxput
main-is:            Hxput.hs
hs-source-dirs:     src/
ghc-options:        -funbox-strict-fields -O2 -Wall -optl-Wl,-s
ghc-prof-options:   -prof -auto-all

executable:         hslock
main-is:            Hslock.hsc
other-modules:      Hslock
extensions:         ForeignFunctionInterface
hs-source-dirs:     src/
ghc-options:        -funbox-strict-fields -O2 -Wall -lcrypt -optl-Wl,-s
ghc-prof-options:   -prof -auto-all

executable:         hmanage
main-is:            Hmanage.hs
hs-source-dirs:     src/
ghc-options:        -funbox-strict-fields -O2 -Wall -optl-Wl,-s
ghc-prof-options:   -prof -auto-all

executable:         hhp
main-is:            Hhp.hs
hs-source-dirs:     src/
ghc-options:        -funbox-strict-fields -O2 -Wall -optl-Wl,-s
ghc-prof-options:   -prof -auto-all

executable:         heval
main-is:            Heval.hs
hs-source-dirs:     src/
ghc-options:        -funbox-strict-fields -O2 -Wall -optl-Wl,-s
ghc-prof-options:   -prof -auto-all
gwern@localhost:1008~/bin/xmonad-utils>ls src                                                                                       
Heval.hs  Hhp.hs  Hmanage.hs  Hslock.hsc  Hxput.hs  Hxsel.hs  Utils.hs

This package compiles fine, the binaries run fine, but if you should then try to create an sdist tarball, it errors and cannot find Hslock.hs (which is generated by hsc2hs from src/Hslock.hsc:

gwern@localhost:1010~/bin/xmonad-utils>haskell                                                                                      
cleaning...
Configuring xmonad-utils-0.1...
Dependency base>=2.0: using base-3.0.1.0
Dependency X11>=1.3: using X11-1.4.1
Dependency ghc>=6.8: using ghc-6.8.2
Dependency unix-any: using unix-2.3.0.0
Dependency random>=1.0: using random-1.0.0.0
Pulling from "http://gorgias.mine.nu/repos/xmonad-utils"...
We have the following new (to them) patches:
Sat Jan 26 12:10:12 EST 2008  gwern0@gmail.com
  * .cabal: small tweak for faster installation via cabal install
They have the following patches to pull:
No remote changes to pull in!
Using compiler: ghc-6.8.2
Using install prefix: /home/gwern/bin
Binaries installed in: /home/gwern/bin/bin
Libraries installed in: /home/gwern/bin/lib/xmonad-utils-0.1/ghc-6.8.2
Private binaries installed in: /home/gwern/bin/libexec
Data files installed in: /home/gwern/bin/share/xmonad-utils-0.1
Documentation installed in: /home/gwern/bin/share/doc/xmonad-utils-0.1
Using alex version 2.2 found on system at: /usr/bin/alex
Using ar found on system at: /usr/bin/ar
Using c2hs version 0.15.1 found on system at: /usr/bin/c2hs
Using cpphs version 1.5 found on system at: /usr/bin/cpphs
No ffihugs found
Using ghc version 6.8.2 found on system at: /usr/bin/ghc
Using ghc-pkg version 6.8.2 found on system at: /usr/bin/ghc-pkg
No greencard found
Using haddock version 2.0.0.0 found on system at: /usr/bin/haddock
Using happy version 1.17 found on system at: /usr/bin/happy
No hmake found
Using hsc2hs version 0.66-ghc found on system at: /usr/bin/hsc2hs
Using hscolour version 1.9 found on system at: /usr/bin/HsColour
No hugs found
No jhc found
Using ld found on system at: /usr/bin/ld
No nhc98 found
No pfesetup found
Using pkg-config version 0.22 found on system at: /usr/bin/pkg-config
Using ranlib found on system at: /usr/bin/ranlib
Using tar found on system at: /bin/tar
Preprocessing executables for xmonad-utils-0.1...
Building xmonad-utils-0.1...
[1 of 1] Compiling Main             ( src/Hxsel.hs, dist/build/hxsel/hxsel-tmp/Main.o )
Linking dist/build/hxsel/hxsel ...
[1 of 1] Compiling Main             ( src/Hxput.hs, dist/build/hxput/hxput-tmp/Main.o )
Linking dist/build/hxput/hxput ...
[1 of 2] Compiling Utils            ( src/Utils.hs, dist/build/hslock/hslock-tmp/Utils.o )
[2 of 2] Compiling Main             ( dist/build/hslock/hslock-tmp/Hslock.hs, dist/build/hslock/hslock-tmp/Main.o )
Linking dist/build/hslock/hslock ...
[1 of 1] Compiling Main             ( src/Hmanage.hs, dist/build/hmanage/hmanage-tmp/Main.o )
Linking dist/build/hmanage/hmanage ...
[1 of 2] Compiling Utils            ( src/Utils.hs, dist/build/hhp/hhp-tmp/Utils.o )
[2 of 2] Compiling Main             ( src/Hhp.hs, dist/build/hhp/hhp-tmp/Main.o )
Linking dist/build/hhp/hhp ...
[1 of 1] Compiling Main             ( src/Heval.hs, dist/build/heval/heval-tmp/Main.o )
Linking dist/build/heval/heval ...
Installing: /home/gwern/bin/bin
Building source dist for xmonad-utils-0.1.20080126...
Setup: Hslock.hs doesn't exist

Somewhat related pages might be #14 or #161.

Change History

01/26/08 10:06:03 changed by duncan

  • description changed.
  • reporter changed from guest to gwern.

01/26/08 10:17:04 changed by ross@soi.city.ac.uk

  • status changed from new to closed.
  • resolution set to invalid.

You shouldn't be using extra-source-files, but listing the modules in each executable section using something like

other-modules: Heval Hhp Hmanage Hxput Hxsel Utils

Putting the output of hsc2hs in a source tarball would be inappropriate, as it is system-dependent.

01/26/08 10:28:09 changed by guest

Including or not including extra-source-files makes no difference, as far as I can tell. It still builds fine and doesn't sdist fine.

other-modules: would not be useful, I don't think, since as I mentioned, each file is the module Main. If I add in the line "other-modules: Heval Hhp Hmanage Hxput Hxsel Utils" into each executable section - nothing changes. If I modify it to read "other-modules: Main" - nothing changes.

01/26/08 10:39:42 changed by duncan

  • status changed from closed to reopened.
  • platform deleted.
  • resolution deleted.
  • milestone set to Cabal-1.4.

Certainly putting .hs files in the extra-source-files is incorrect.

There is a bug here however. The original description is inaccurate as it specifies

main-is:            Hslock.hsc

where the actual source at http://gorgias.mine.nu/repos/xmonad-utils uses

main-is:            Hslock.hs

This explains why the error message above is:

Setup: Hslock.hs doesn't exist

So, main-is: should always be a .hs or .lhs file and is relative to the hs-source-dirs:. When building we correctly find the src/Hslock.hsc and pre-process it. The bug is that in sdist we just look for Hslock.hs directly in the hs-source-dirs without considering pre-processors at all.

The current Distribution/Simple/SrcDist.hs code just does:

  withExe pkg_descr $ \ (Executable _ mainPath exeBi) -> do
    prepareDir verbosity targetDir pps [] exeBi
    srcMainFile <- findFile (hsSourceDirs exeBi) mainPath

So the mainPath is ignored for pre-processing purposes.

(follow-up: ↓ 6 ) 01/26/08 10:43:21 changed by ross@soi.city.ac.uk

  • summary changed from .hsc files do not get processed for cabal sdist? to Main modules in .hsc files are not included in sdist.

Sorry, I missed that.

It looks like the fix for #14 is incomplete, as Duncan says. I think that the .hs source files will be included in the source bundle without needing to be mentioned in extra-source-files. The bug is that the .hsc source file is not also included. I suppose you can work around that with

extra-source-files: src/Hslock.hsc

(in reply to: ↑ 5 ) 01/26/08 10:51:26 changed by ross@soi.city.ac.uk

Replying to ross@soi.city.ac.uk:

I suppose you can work around that with {{{ extra-source-files: src/Hslock.hsc }}}

Hmm, no that won't work: it will still be looking for the missing .hs file. Main modules that need preprocessing don't work. There's the unpleasant workaround of having a trivial Main.hs that calls the other module, I guess.

(follow-up: ↓ 10 ) 01/26/08 12:10:07 changed by ross@soi.city.ac.uk

I think it would be most intuitive if main-is always named the source file containing the Main module, i.e. if

main-is:  Hslock.hsc

worked for both build and sdist.

(follow-up: ↓ 9 ) 01/26/08 13:04:42 changed by duncan

Main modules that need pre-processing half work. :-) The half that does not work is including them into the src tarball.

Perhaps we are free to change the interpretation of main-is when using pre-processors since due to the sdist bug it would have been hard for any existing packages to use that feature.

I think main-is is a bit of a wart. It specifies some kind of file name where all the other bits us a module name. This is reflected internally in the code where most of this stuff works in terms of module names and the main-is has to be hacked in. :-(

(in reply to: ↑ 8 ) 01/26/08 13:47:55 changed by ross@soi.city.ac.uk

Replying to duncan:

Perhaps we are free to change the interpretation of main-is when using pre-processors since due to the sdist bug it would have been hard for any existing packages to use that feature.

The User's Guide describes the meaning I was proposing, so build must be buggy :-P

(in reply to: ↑ 7 ) 01/26/08 17:29:35 changed by duncan

Replying to ross@soi.city.ac.uk:

I think it would be most intuitive if main-is always named the source file containing the Main module, i.e. if {{{ main-is: Hslock.hsc }}} worked for both build and sdist.

On reflection, I'm not so sure. In general when we have arbitrary pre-processors there may be a tree of files used to generate a source module/file. So it's right to name the module or ultimate file rather than one of the files used to generate it (if indeed it is generated from another file at all). So in the general case it is the only thing we can name.

It's also a good deal easier in the code, it means we do not have to pass into the per-compiler code where the pre-processed .hs/.lhs file is to be found (something we do not do for exposed/other-modules). It means the per-compiler build code can just assume the file has been generated and can be found in the search path.

So I'll take a look at fixing the src dist side of things, so that it finds the stuff used to generate the main .hs/.lhs and includes that into the tarball. It should be just a minor adaption on what the code does already for the other-modules.

01/31/08 07:02:54 changed by duncan

Fixed but not yet documented.

Thu Jan 31 11:49:09 GMT 2008  Duncan Coutts <duncan@haskell.org>
  * Find original sources for main-is when creating sdist
  Also add a package sanity check that main-is must specify a .hs or .lhs file.
  So the bahaviour is now that main-is specifies the main source file, even if
  that is generated by a pre-processor. This isn't really a change in behaviour
  since previously if you specified main-is: main.hsc then it would try to
  pass the .hsc file to ghc dirctly which would not work. For ticket #14 things
  were fixed to that it would look for main.hsc if you used main-is: main.hs an
  that file did not exist directy. This completes the other half, of actually
  being able to make a src distribution. So this should fix bug #217.
  Note that this still needs some work, we do not run platform-independent
  preprocessors and put the result into the tarball for main-is files.
  Generally, main-is has been the second class citizen compared to normal
  modules. We should try and refactor so both use the same code paths.

02/11/08 08:50:49 changed by duncan

  • status changed from reopened to closed.
  • resolution set to fixed.

Now documented too.