11

I'm working on a website using Yesod I have the normal build running but I can't seem to populate my database reliably. I have a second haskell program that populates the database and I've added it to my cabal file like this:

executable         program
  if flag(library-only)
    Buildable: False

  main-is:           ../main.hs
  hs-source-dirs:    dist
  build-depends:     base
                   , myproject
                   , yesod-default

executable         init
  if flag(library-only)
    Buildable: False

  main-is:           init.hs
  hs-source-dirs:    Init
  build-depends:     base
                   , directory
                   , persistent
                   , persistent-sqlite
                   , text
                   , myproject
                   , yesod-default

The problem is that when I run 'cabal build' it does not rebuild init when init.hs changes. What do I have to do to make this happen?

Here's an example terminal session (after editing init.hs):

$ cabal build
Building myproject-0.0.0...
Preprocessing library myproject-0.0.0...
Registering myproject-0.0.0...
$ rm -rf dist/build/myproject/init
$ cabal build
Building myproject-0.0.0...
Preprocessing library myproject-0.0.0...
Registering myproject-0.0.0...

Thank you.

Gregory
  • 1,205
  • 10
  • 17
  • The question title mentions multiple executables. Is there another executable stanza that doesn't have this problem in the same cabal file? – Heatsink Jul 31 '12 at 17:49
  • Are you sure `init` doesn't get rebuilt? You'll have to look under `dist/build` to see the new executable, or run `cabal install` if you want the new executable put somewhere else. – Daniel Wagner Jul 31 '12 at 18:51
  • I've updated the cabal snippet above. When I modify init.hs (which is located inside the Init/ directory) it doesn't recompile anything. cabal runs and exits without any ghc invocations. I have a symlink to the executable in dist/build that I am using to run the code. – Gregory Aug 01 '12 at 02:42
  • 3
    I probably don't really understand what you are doing here: For `executable program`, why do you have `hs-source-dirs` to be set to cabal's `dist/` folder but then say that `main-is` is outside of that folder, in your current folder? I've never seen this before and dont understand what the intention is. – nh2 Sep 08 '13 at 07:35

1 Answers1

7

You can manage multiple executables by passing them as arguments to cabal build and cabal run. For example, cabal build init. The first executable is the default if no target name is given.

Anthony
  • 3,771
  • 23
  • 16