Daniel Díaz Casanueva | 3 Jul 03:20 2013
Picon

Custom Setup.hs and Paths module

Hi everyone.

I am writing a package where I am using the Paths module that cabal generates automatically. After adding the Paths module to the "other-modules" section in my cabal file everything worked just fine, until I wanted to write a custom Setup.hs. This Setup.hs just writes a couple of files in the system and then calls "defaultMain". The thing is that now "cabal install" does not find the Paths module, so the package is broken.

Any thoughts? I need your help, people!

Thank you,
Daniel Díaz.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Erik de Castro Lopo | 3 Jul 03:39 2013

Re: Custom Setup.hs and Paths module

Daniel Díaz Casanueva wrote:

> Hi everyone.
> 
> I am writing a package where I am using the Paths module that cabal
> generates automatically. After adding the Paths module to the
> "other-modules" section in my cabal file everything worked just fine, until
> I wanted to write a custom Setup.hs. This Setup.hs just writes a couple of
> files in the system and then calls "defaultMain". The thing is that now
> "cabal install" does not find the Paths module, so the package is broken.

I ran into the same problem. I ended up fixing it by *not* using the auto
generated Paths module and instead parsing the cabal file in Setup.hs.

This is not has horrible as it sounds as I used the Cabal insfrastructure
to do it. Basically something like this:

    import Distribution.Simple
    import Distribution.PackageDescription
    import Distribution.PackageDescription.Parse (readPackageDescription)
    import Distribution.Verbosity (silent)

    version <- fmap (showVersion . pkgVersion . package . packageDescription)
                    $ readPackageDescription silent "my-package.cabal"

and then used that version String to write a trivial 5 line file Version.hs.

HTH,
Erik
--

-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Daniel Díaz Casanueva | 3 Jul 14:56 2013
Picon

Re: Custom Setup.hs and Paths module

Hello Erik.

Yes, that solution may work, but seems ad-hoc to me. I would like to see a way to actually import the Paths module. In the meanwhile, I will be using your idea. Thank you for the response.

Anybody knows how to hack the Setup.hs so I can use the real Paths module?


On Wed, Jul 3, 2013 at 3:39 AM, Erik de Castro Lopo <mle+hs <at> mega-nerd.com> wrote:
Daniel Díaz Casanueva wrote:

> Hi everyone.
>
> I am writing a package where I am using the Paths module that cabal
> generates automatically. After adding the Paths module to the
> "other-modules" section in my cabal file everything worked just fine, until
> I wanted to write a custom Setup.hs. This Setup.hs just writes a couple of
> files in the system and then calls "defaultMain". The thing is that now
> "cabal install" does not find the Paths module, so the package is broken.

I ran into the same problem. I ended up fixing it by *not* using the auto
generated Paths module and instead parsing the cabal file in Setup.hs.

This is not has horrible as it sounds as I used the Cabal insfrastructure
to do it. Basically something like this:

    import Distribution.Simple
    import Distribution.PackageDescription
    import Distribution.PackageDescription.Parse (readPackageDescription)
    import Distribution.Verbosity (silent)

    version <- fmap (showVersion . pkgVersion . package . packageDescription)
                    $ readPackageDescription silent "my-package.cabal"

and then used that version String to write a trivial 5 line file Version.hs.

HTH,
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Erik de Castro Lopo | 3 Jul 22:24 2013

Re: Custom Setup.hs and Paths module

Daniel Díaz Casanueva wrote:

> Hello Erik.
> 
> Yes, that solution may work, but seems ad-hoc to me. I would like to see a
> way to actually import the Paths module. In the meanwhile, I will be using
> your idea. Thank you for the response.
> 
> Anybody knows how to hack the Setup.hs so I can use the real Paths module?

I'm almost certain it can't be done.

The problem is that the Paths module is generated by the 'cabal configure'
process and the configure process needs to run Setup.hs which needs the
Paths module etc etc.

That's what you might call a circular dependency :-).

Erik
--

-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane