danra
commented at 10:37 AM on September 8, 2017:
contributor
Create a wrapper header file which includes config/bitcoin-config.h only if it exists (according to a macro). Files can include this wrapper header directly instead of having each including file repeat the check-if-config-exists-and-only-include-if-it-does macros.
p.s. Open to suggestions if anyone has a better filename for the wrapper header.
dougstrong77 approved
fanquake added the label Refactoring on Sep 8, 2017
promag
commented at 11:18 AM on September 8, 2017:
member
How about just
#include "bitcoin-config.h"
which includes config/bitcoin-config.h.
danra
commented at 11:24 AM on September 8, 2017:
contributor
@promag I think that would be 1) confusing to readers 2) brittle to include paths changes
promag
commented at 11:34 AM on September 8, 2017:
member
brittle to include paths changes
I believe there is a plan to make all includes relative to src/ cc @laanwj.
Another option is to change the generated to, for instance
And always have config/bitcoin-config.h which checks for that.
danra
commented at 11:39 AM on September 8, 2017:
contributor
Another option is to change the generated to, for instance
AC_CONFIG_HEADERS([src/config/bitcoin-config-gen.h])
And always have config/bitcoin-config.h which checks for that.
That's fine with me if more people agree that's preferable.
Personally I think
"#include "config/bitcoin-config-if-exists.h"
or
"#include "bitcoin-config-if-exists.h"
reads nice and explicit, saying what we are actually doing - including the config file, but just in case it exists.
meshcollider
commented at 11:59 AM on September 8, 2017:
contributor
Other than refactoring, does this have any benefit? I'm not too keen on this idea tbh
danra
commented at 12:05 PM on September 8, 2017:
contributor
@MeshCollider In general, refactoring in order to DRY code has benefits.
Less overhead to reading and understanding the code. Especially important for security-conscious projects.
Less chance of being wrong when writing new code (e.g. see 3aa60b7ff9587637dcb3e646c2448bf75495a1f4)
And more. But I think that's enough.
Also, any particular reason why you are not keen on the idea?
meshcollider
commented at 12:57 PM on September 8, 2017:
contributor
@danra, not exactly sure, its just something about creating an entire new file just for 3 lines to import another file. IMO its clear enough as it is, because its just an if-statement, and anyone who would currently forget the ifdef would probably also forget to use this file, and just include bitcoin-config.h directly. Yes DRY is better, but I think this is taking it a bit far, that's all :)
danra
commented at 5:26 PM on September 8, 2017:
contributor
@MeshCollider In addition to the considerations I mentioned, it's a macro if, easy to either misspell or get wrong (checking for value instead of just being defined, etc.)
Better contain it to a single file and forget about it.
danra force-pushed on Sep 8, 2017
achow101
commented at 7:45 PM on September 8, 2017:
member
@danra can you do the bulk of this as a scripted diff? That would make review easier and also less likely for you to have accidentally missed an include.
danra force-pushed on Sep 8, 2017
danra
commented at 8:49 PM on September 8, 2017:
contributor
Seriously, I'm not sure a script would help very much, since there're subtle variations of the original ifdefs as you can see in the diff. So at best the script would show handling of some variations, and the rest of the code would have to be checked anyway for any other variations not covered by the script.
At best, the script would prove no misspellings of the new include, but that would be caught as a compile error anyway.
achow101
commented at 9:10 PM on September 8, 2017:
member
A scripted diff is easier to review and verify that the changes are correct, especially for such a change like this which is basically a scripted diff.
danra
commented at 10:40 AM on September 9, 2017:
contributor
DAK why Travis is failing to find "config/bitcoin-config-if-present.h" in the build? Is this some cache issue? It builds fine on my local machine.
MarcoFalke
commented at 2:42 AM on September 10, 2017:
member
@danra I haven't looked by it could be that out of tree builds are failing.
danra force-pushed on Sep 10, 2017
danra
commented at 8:22 PM on September 10, 2017:
contributor
@MarcoFalke Tested out of tree build on my local machine - works fine. Would appreciate any other pointers as to what else might be causing the travis build to fail.
sipa
commented at 8:23 PM on September 10, 2017:
member
Run make distcheck.
danra
commented at 8:49 PM on September 10, 2017:
contributor
@sipa That reproduced the build error locally. Thanks!
danra force-pushed on Sep 10, 2017
dcousens approved
danra force-pushed on Sep 29, 2017
danra
commented at 12:40 PM on September 29, 2017:
contributor
Create a wrapper header file which includes config/bitcoin-config.h only if it exists (according to a macro). Files can include this wrapper header directly instead of having each including file repeat the check-if-config-exists-and-only-include-if-it-does macros.dfa07f8f91
danra force-pushed on Sep 30, 2017
danra force-pushed on Sep 30, 2017
danra force-pushed on Sep 30, 2017
scripted-diff: DRY config header inclusion if one exists
danra
commented at 9:57 AM on September 30, 2017:
contributor
Does anyone know if GLOBIGNORE is supported in the shell on the Travis host which fails the scripted-diff check? It works on my local bash but I can't get it to work here, tried multiple variations.
laanwj
commented at 12:11 PM on November 28, 2017:
member
Closing this for now, I don't think there is agreement to do this, and rebasing it will be a ton of work.
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-04-22 06:15 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me