Skip to content

Need a way to embed git revision into executable when running cabal install #7355

Open

Description

@newhoggy

Describe the bug
When cabal install is run, instead of building in place, it copies to source to some other location and builds from that location. For example on my Mac it builds from somewhere like this: /private/var/folders/zh/ln41q4zs52x2fd61rxccmq640000gn/T/cabal-install.-79645/dist-newstyle/tmp/src-79645/cardano-config-0.1.0.0

As a result, whilst libraries like gitrev allow you to embed the git revision when you run cabal build, this does not work with cabal install.

There needs to be some mechanism to allow the build to capture the git revision when cabal install is used.

To Reproduce
On any project that uses gitrev or some similar git revision embedding library, run cabal v2-install.

Then observe that the the git revision is not embedded.

Expected behavior
The git revision should be embedded, or if not, some other mechanism needs to be provided to make this possible

System information
cabal-3.4

Additional context
N/A

Activity

  1. newhoggy commented on Apr 12, 2021

    @newhoggy
    Author
  2. newhoggy commented on Apr 12, 2021

    @newhoggy
    Author

    The problem occurs here: IntersectMBO/cardano-node#1127

  3. typedrat commented on Apr 15, 2021

    @typedrat
    Collaborator

    This shouldn't work!

    As it stands, you have an undeclared data dependency on the .git folder, and cabal install is keeping you honest by only giving you access during installation build to the files that you have declared yourself to depend on, because it needs to know the set of dependencies that you have in order to be able to compute the hash of the current input state and know if it needs to reinstall the program!

    This is made somewhat inconvenient because Cabal fails to support globbing files without extensions or otherwise including the full contents of a directory in extra-source-files, but is easy enough to fix for the case of the master branch by adding

    extra-source-files: ../.git/HEAD
                      , ../.git/refs/heads/master

    to your cabal file.

  4. gbaz commented on Sep 2, 2021

    @gbaz
    Collaborator

    Does the above comment suffice to close this?

  5. DavSanchez commented on Oct 19, 2021

    @DavSanchez

    The solution proposed by @typedrat is unfortunately not working for me, although I think it makes sense that it should. I'll try to troubleshoot what could be happening under the hood but not sure if I'll reach something.

  6. added
    can-workaround
    on Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cabal-install: cmd/installcan-workaroundtype: user-question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions