I have an embedded C project that builds with CMake, Ninja, and gcc-arm-none-eabi.
I want to capture the output (string) of a git describe --dirty ... command as (1) a string variable in my program, and (2) in the generated executable filename. I think the sensible way to do this would be with a pre-build event, which ninja does not appear to support.
Without the --dirty argument, I have it working using this git_describe CMake function. But that is only run by CMake at configure time (and it hard codes the output strings in build.ninja). So for example, if I just add the --dirty arg in my current setup, then CMake configure (on a clean git working tree), then modify a source file (making the worktree dirty), then build again, it does not re-run CMake configure, and does not re-run the git describe command, and so does not detect the dirty.
Questions:
Ideally, I think, I'd want to be able to make ninja execute and check the output of my preferred git describe command on every build, and trigger the dependent targets to rebuild if it changes.
---
Originally posted on GitHub (#2500). I was advised to post it here.
I have an embedded C project that builds with CMake, Ninja, and gcc-arm-none-eabi.
I want to capture the output (string) of a git describe --dirty ... command as (1) a string variable in my program, and (2) in the generated executable filename. I think the sensible way to do this would be with a pre-build event, which ninja does not appear to support.
Without the --dirty argument, I have it working using this git_describe CMake function. But that is only run by CMake at configure time (and it hard codes the output strings in build.ninja). So for example, if I just add the --dirty arg in my current setup, then CMake configure (on a clean git working tree), then modify a source file (making the worktree dirty), then build again, it does not re-run CMake configure, and does not re-run the git describe command, and so does not detect the dirty.
Questions:
- Am I correct that ninja does not support pre-build events?
- Is it possible to use ninja to reliably do what I'm describing here? On every build, without requiring the user to manually trigger a CMake configure before triggering the build.
Ideally, I think, I'd want to be able to make ninja execute and check the output of my preferred git describe command on every build, and trigger the dependent targets to rebuild if it changes.
rule generate_git_dirtycommand = git describe --dirty --always > $out.tmp && if ! cmp --quiet $out $out.tmp; then cp $out.tmp $out; firestat = 1
build git_dirty.txt: generate_git_dirty .git/HEAD
rule generate_git_dirty_header
command = printf "const char kGitDirty[] = \"%s\";\n" $$(< $in) > $out
build git_dirty.h: generate_git_dirty_header git_dirty.txt
---
Originally posted on GitHub (#2500). I was advised to post it here.
--
You received this message because you are subscribed to the Google Groups "ninja-build" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ninja-build...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ninja-build/c0654782-e69b-46c2-9bdf-f48eb658c2c9n%40googlegroups.com.
...
On the other hand, changing the name of the output based on build command is not supported, and generally not desirable.
David, Eli, and Ben,Thanks for your quick and informative responses. I will dig into your suggestions when I get back onto this task.David and Eli, I'd welcome any additional pointers about how to implement your suggestions from CMake.Meanwhile, a meta question for David below.On Tue, Oct 1, 2024 at 10:42 AM David Turner <di...@google.com> wrote:...On the other hand, changing the name of the output based on build command is not supported, and generally not desirable.Why do you think it's not desirable? Including a version number in the filename of an installer program seems like a pretty common practice, and I generally prefer that as a user. In an embedded context (e.g. using gcc-arm-none-eabi), the executable essentially is the installer, too.