Search code examples
haskellhaskell-stack

How to build and modify source code locally of a package from Hackage using the `Haskell Stack`?


Background

I downloaded the source files of package (e.g. test-framework) to have a closer look in it's architecture, to modify it for experiments, and may be to contribute later on.

I downloaded the source code and got stuck in incompatibilities and lots of compiler errors.

Question

Is there a step by step procedure, of how to obtain the source code properly and to setup such a project using the Haskell Stack?


Solution

  • Procedures

    We can choose out of the following two opportunities:

    • without use of tarball files
    • with use of tarball files

    Procedure - without use of tarball files

    Thanks to the "Cigarette Smoking Man"...

    1. Setup your main project

    2. unpack the package that should be obtained as source code

      stack unpack

    3. change current directory to the created folder

      cd <package>

    4. initialise the folder (creates file stack.yaml)

      stack init

    5. modify stack.yaml of the main project, to add package with relative path to section packages!!!

    6. modify package.yaml of main project, to add dependency to package with constraint (e.g. == 1.2.1) to section dependencies

    7. delete cabal-file (here local-from-hackage-without-tarball.cabal), if any

    8. in the main folder build the main project stack build

    NOTE: This setup can be even used in ghci, by typing stack ghci and :reload.

    Procedure - with use of tarball files

    1. Setup your main project

    2. unpack the package that should be obtained as source code

      stack unpack

    3. change current directory to the created folder

      cd <package>

    4. initialise the folder (creates file stack.yaml)

      stack init

    5. generate a tarball file of the package code

      stack sdist

    6. modify stack.yaml of the main project, to add package with relative path to section extra-deps!!!

    7. modify package.yaml of main project, to add dependency to package with constraint (e.g. == 1.2.1) to section dependencies

    8. delete cabal-file (here local-from-hackage-by-tarball.cabal), if any

    9. in the main folder build the main project stack build

    More detailed procedures

    For more details check source: Building a package locally from source using "stack"

    Example projects

    Additonally, for both alternatives, here you can find a complete projects, where the module Random exports an additional function.

    GitHub:

    local-from-hackage-by-tarball

    local-from-hackage-without-tarball