-
Notifications
You must be signed in to change notification settings - Fork 89
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
Generate version header #1920
Generate version header #1920
Conversation
By putting the #define in a header rather than a compile-line definition, and using that header only in the file that needs it, CMake doesn't need to recompile every file on commit
Note that for the makefile build system, BOUT_REVISION is still a preprocessor macro passed on the command line
I guess this is a breaking change. People probably not using |
Yes, probably wise! |
bout.hxx ends up included in a bunch of library files, so will still trigger some compilation cascade on commit
Makefile-build system now also configures this file to include the commit from configure-time, so that bout::version::revision will always have a meaningful value even if -DBOUT_REVISION is not passed on command line
Possible gotcha: if you build with I'm now happy that this does what we want for CMake: on commit
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This works for me. Will save lots of time compiling when I have to commit everything to debug Travis runs...
Would be nice to add a section to the manual listing the breaking changes, and the scripts available to apply the necessary updates.
Would it be worth adding some warnings to flag up any uses that weren't fixed? The compiler should give errors there anyway, but I think it would be friendlier if this script gave a warning. |
Good point. We're now not defining those macros, so |
This now takes care of situations like the contrived: -#ifndef BOUT_VERSION_STRING
-#ifdef REVISION
- output_progress.write(_("BOUT++ version {:s}\n"), BUILDFLAG(REVISION));
-#else
- output_progress.write(_("BOUT++ version {:s}\n"), "Unknown");
-#endif
-#else
- output_progress.write(_("BOUT++ version {:s}\n"), BOUT_VERSION_STRING);
-#endif
-#ifdef REVISION
- output_progress.write(_("Revision {:s}\n"), BUILDFLAG(REVISION));
-#endif
-#ifndef REVISION
- output_progress.write(_("Revision {:s}\n"), "Unknown");
-#endif
+ output_progress.write(_("BOUT++ version {:s}\n"), bout::version::full);
+ output_progress.write(_("Revision {:s}\n"), BUILDFLAG(bout::version::revision)); I consider all these upgrader scripts as "best effort only" and somewhat dangerous. The output must be checked by the users, so there's no specific warning for this one. When I get them all into a single framework type thing, it'll have a big flashing warning. |
This solves a problem with the CMake system: everything gets rebuilt on every commit because
-DBOUT_VERSION*
are passed on the command line to every file, and CMake knows that if the preprocessor macros for a file change then the file needs to be rebuilt.This is solved by adding
include/bout/version.hxx
which is generated by the build system frominclude/bout/version.hxx.in
. This header containsconstexpr
variables in thebout::version::
namespace, and replaces the preprocessor macrosBOUT_VERSION
,REVISION
,BOUT_VERSION_STRING
andBOUT_VERSION_DOUBLE
.It might be nice to mark those macros as deprecated somehow. Not found a nice portable way so far!
There's a little funkiness with the makefile build system:
BOUT_REVISION
(renamed fromREVISION
) is still passed to each file via the command line. I couldn't see a way round this, which is whyversion.hxx.in
still has an#ifndef
in it.Also, there is a potential issue here: if in one cxx file you take the address of a
constexpr
variable defined in a header, you may/will get a different address than in another cxx file. C++17 solves this withinline
variables.Mostly we shouldn't be taking the address of
constexpr
variables, but unfortunately, this is howDatafile::add
works. Basically, don't callDatafile::add
on the samebout::version
variable twice in different files, or it will throw. But you probably shouldn't be doing that anyway!Lastly, there's a bunch of unrelated changes to
configure
because I think the gettext macro has been updated on my system. Happy to pull those changes out into a separate PR.