Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoftwareVersion: Add git hash suffix with git-version crate #6

Conversation

Enselic
Copy link
Contributor

@Enselic Enselic commented Mar 20, 2021

Since we add it to the bugreport!() macro, it will be evaluated in the
context of the dependant project, and give relevant git hash info.

Features:

  • Optional via Cargo feature "git_hash"
  • Prints <no git> as git hash if git is not on PATH
  • Triggers rebuild if git hash (or index) change [1]

Note that since the bugreport!() macro is evaluated in the context of
the dependent project, it is not possible to use #[cfg()] inside of it.
So we have to have two different definitions of it depending on feature
"git_hash".

[1] Via elegant include_bytes!() hack by git-version crate, see
https://github.com/fusion-engineering/rust-git-version/blob/v0.3.4/git-version-macro/src/lib.rs#L40

Example output

From below CI run

example 'simple'

#### Software version

bugreport 0.3.0 bf54af5

example 'simple' without git_hash feature

#### Software version

bugreport 0.3.0

bat using this version

From CI run for Enselic/bat@271db66

#### Software version

bat 0.18.0 271db66

bat using this version but with "git_hash" feature disabled

From CI run for Enselic/bat@65a3d81

#### Software version

bat 0.18.0

Since we add it to the bugreport!() macro, it will be evaluated in the
context of the dependant project, and give relevant git hash info.

Features:
* Optional via Cargo feature "git_hash"
* Prints '<no git>' as git hash if git is not on PATH
* Triggers rebuild if git hash (or index) change [1]

Note that since the bugreport!() macro is evaluated in the context of
the dependent project, it is not possible to use #[cfg()] inside of it.
So we have to have two different definitions of it depnding on feature
"git_hash".

[1] Via elegant include_bytes!() hack by git-version crate, see
https://github.com/fusion-engineering/rust-git-version/blob/v0.3.4/git-version-macro/src/lib.rs#L40
@Enselic Enselic force-pushed the software-version-add-git-hash-suffix-via-git-version-macro branch from 225925b to 643541f Compare March 21, 2021 09:00
src/collector.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@Enselic Enselic force-pushed the software-version-add-git-hash-suffix-via-git-version-macro branch from b4f9a77 to 643541f Compare March 28, 2021 11:50
Instead of defining different bugreport!() macros depending on the
git_hash feature, use a single macro definition but with differently
cfg:ed helper macros.
@sharkdp
Copy link
Owner

sharkdp commented Apr 3, 2021

Thank you for the updates. This looks great!

@sharkdp sharkdp merged commit 7e8c8a9 into sharkdp:master Apr 3, 2021
@sharkdp
Copy link
Owner

sharkdp commented Apr 3, 2021

Let me know if I should push a new version (in order for bat to depend on it).

@Enselic
Copy link
Contributor Author

Enselic commented Apr 3, 2021

Glad you liked it!

No rush with pushing a new bugreport version, but would be nice to get this included in the next bat release, whenever that ends up being.

@Enselic Enselic deleted the software-version-add-git-hash-suffix-via-git-version-macro branch April 3, 2021 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants