-
Notifications
You must be signed in to change notification settings - Fork 38.8k
refactor: Make all #includes relative to project root #11053
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
Conversation
|
Concept ACK 👍 |
|
|
Concept ACK. Are you planing on squashing everything to a single commit? Intermediate commits are broken (eg 15d3a6d3343f27e8c01faa5674a2fe406488eac3 breaks building |
|
I think it is possible to do more of this as a scripted diff. I was looking into this this morning, and the following command seemed to work well for switching all include paths that don't depend on the current directory from for f in \
src/*.cpp \
src/*.h \
src/bench/*.cpp \
src/bench/*.h \
src/compat/*.cpp \
src/compat/*.h \
src/consensus/*.cpp \
src/consensus/*.h \
src/crypto/*.cpp \
src/crypto/*.h \
src/crypto/ctaes/*.h \
src/policy/*.cpp \
src/policy/*.h \
src/primitives/*.cpp \
src/primitives/*.h \
src/qt/*.cpp \
src/qt/*.h \
src/qt/test/*.cpp \
src/qt/test/*.h \
src/rpc/*.cpp \
src/rpc/*.h \
src/script/*.cpp \
src/script/*.h \
src/support/*.cpp \
src/support/*.h \
src/support/allocators/*.h \
src/test/*.cpp \
src/test/*.h \
src/wallet/*.cpp \
src/wallet/*.h \
src/wallet/test/*.cpp \
src/wallet/test/*.h \
src/zmq/*.cpp \
src/zmq/*.h
do
base=${f%/*} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base/'\\1'; then echo '#include \"\\1\"\\2'; else echo '#include <\\1>\\2'; fi:e" $f
done |
|
My branch is here (2 commits): https://github.com/ryanofsky/bitcoin/commits/pr/inc It also updates developer notes. Feel free to take anything there that might be useful |
Yes, before merging we could squash it. Before then, the current order of commits is easer to keep up to date with master.
I'm not entirely sure how to rebase on top of your changes, or how to combine it. My changes are more complete. For example I've changed I've cherry-picked the developer notes change, thanks. |
|
Great. |
|
@ryanofsky |
cbe3ac5 to
d4a0cc1
Compare
|
Changed the base commit to modified @ryanofsky's script. The rest of the changes is much smaller now. Also the individual commits should build because I moved the |
src/qt/test/compattests.cpp
Outdated
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.
The include is being lost here because of the apostophe in the comment. I think replacing echo '...' with echo \"...\" in the script should fix it.
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.
Seems to work, apparently we're nowhere using " in comment after include :-)
-BEGIN VERIFY SCRIPT-
for f in \
src/*.cpp \
src/*.h \
src/bench/*.cpp \
src/bench/*.h \
src/compat/*.cpp \
src/compat/*.h \
src/consensus/*.cpp \
src/consensus/*.h \
src/crypto/*.cpp \
src/crypto/*.h \
src/crypto/ctaes/*.h \
src/policy/*.cpp \
src/policy/*.h \
src/primitives/*.cpp \
src/primitives/*.h \
src/qt/*.cpp \
src/qt/*.h \
src/qt/test/*.cpp \
src/qt/test/*.h \
src/rpc/*.cpp \
src/rpc/*.h \
src/script/*.cpp \
src/script/*.h \
src/support/*.cpp \
src/support/*.h \
src/support/allocators/*.h \
src/test/*.cpp \
src/test/*.h \
src/wallet/*.cpp \
src/wallet/*.h \
src/wallet/test/*.cpp \
src/wallet/test/*.h \
src/zmq/*.cpp \
src/zmq/*.h
do
base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f
done
-END VERIFY SCRIPT-
This makes all include paths in the GUI absolute. Many changes are involved as every single source file in src/qt/ assumes to be able to use relative includes.
Remove -I from build system for everything but the project root, and built-in dependencies.
d4a0cc1 to
895330f
Compare
ryanofsky
left a comment
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.
ACK 895330f. I confirmed all the individual commits in the branch compile. This looks great! I had no idea all those obj and qt include paths were even there, and I'm glad you were able to get rid of them.
|
This makes me nervous without a subdir-as-a-namespace. gcc (i assume most others as well) searches -I's left-to-right, meaning that something with a generic name like "config.h" could end up including something from the system if we manage to add our "-I(builddir)" after some other path. Testing with Granted, that's pretty paranoid. Much more likely if there was an ordering bug though, would be a compilation failure. A subdir would at least save us from those. Would it make sense to use |
But isn't that true for Duplicated include files can lead to more confusion with relative includes as it can be ambiguous which one is included. At least with
I think on the longer run we should make sure all source files are in directories under I really dislike using top_builddir as an intermediate step though. It'd work, but feels dirty to add Regarding active paranoia, someone could still put a Only insanely disciplined relative inclusion (using explicit |
Do you know of any projects that do this? Closing this for now, on further thought, this creates more issues than it solves I guess. |
Is this only being closed because of the issue theuni raised? Or are there other problems? My earlier scripted diff (branch) is neutral with respect to the issue theuni is talking about because it leaves includes that are relative to the source directory intact, and only modifies includes that rely on the include path from <> to "". So for example, if an amount.h were added to an prepended include path, nothing different would happen than already happens now. More broadly though, it is hard to imagine taking this issue seriously, because the project already uses a mix of <> and "" includes, and all of the existing <> includes (as well as nearly all the "" includes in subdirectories below src/) are already relying on the configured include paths. And as laanwj pointed out this change is only removing include paths, not adding any, so it is strictly decreasing whatever ambiguities there may be in interpreting #include directives compared to what we are doing now. |
Because of the issue theuni raised. I don't see any way out of that, he's right and we're already screwed, and this doesn't make it better (though it does make things more consistent, if they mess up! I have to stand by that. You won't have file A including the right copy and file B including the wrong one, for instance.).
I did think about that, and that would be true if we weren't using subdirectories ourselves. However as soon as we |
|
In Qt I think each module uses "" for self headers and <> for other module headers and everything else. But public headers always use <>. |
I'm somewhat starting to like this idea. Make all includes relative and correct, then lose Edit: To answer this myself, I guess things can become ambiguous if you have chains of include files including each other. E.g.
Yep, and we don't have any public headers besides |
|
@laanwj I think it's too early to close this. I was thinking outloud about any potential drawbacks, but that's not to say that this creates more problems than it solves. As you mentioned, both of those potential issues are very unlikely. |
Could someone state clearly what two potential issues this PR causes? I think I might have missed that there is more than one issue... |
Again, I'm not at all convinced that those things are real issues. Just thinking through them. |
|
Thanks! Just to give my opinion, I think any of the following changes would be simple and minimally disruptive improvements on the status quo:
Slight preference for (1) over (2) over (3), but I think any of these could be good improvements and there may be other simple solutions as well (like using If more disruptive changes are ok, it'd also be nice to move headers in the src/ root to appropriate subdirectories. But I think that type of change would be better to handle separately and should not block simple improvements like the one implemented in this PR. |
|
This has acks from me, jonas, and promag, as well as concept acks from jnewbery and practicalswift and cory withdrew his objection. @laanwj can this be rebased and merged? |
|
I think this is open for grabs |
What does this mean? Maybe there should be a tag for PRs where author wants someone to take over or needs help with something. |
|
Ah. I think I meant "this is up for grabs". |
|
I'll rebase and open a new PR, I'm happy to maintain it since it already has so many ACKs |
|
Closing now that #11651 is open. |
…laanwj, MeshCollider, ryanofsky) 7b91b5f Remove trailing whitespace causing travis failure (MeshCollider) 434f5a2 Recommend #include<> syntax in developer notes (Russell Yanofsky) 96b9281 refactor: Include obj/build.h instead of build.h (Wladimir J. van der Laan) 138016b test: refactor: Use absolute include paths for test data files (Wladimir J. van der Laan) e7b3163 qt: refactor: Changes to make include paths absolute (Wladimir J. van der Laan) 0c71521 build: Remove -I for everything but project root (Wladimir J. van der Laan) 5b56ec9 qt: refactor: Use absolute include paths in .ui files (Wladimir J. van der Laan) 1a44534 scripted-diff: Replace #include "" with #include <> (ryanofsky) (MeshCollider) Pull request description: Rebase of #11053 Previously started by @laanwj, ACK'ed by promag, ryanofsky, jonasschnelli, and concept-ACK'ed by practicalswift and jnewbery. Thus should be almost RTM :) Tree-SHA512: d8d25248309deb06a54686c4a6bafd290ba69dcd0df391a50d1caed2c22ff2659be442459bdd9d1fc3b6a1360ba0804a907b1402d206df3e1cb6e8924e3c7f3e
(inspired by discussion here: #10976 (comment) and #10752 (comment))
This makes all includes in the project relative to the project root only.
There are some advantages to this, both for developers and for the compiler:
src/init.handsrc/wallet/init.hwithout potential confusion, as discussed in [MOVEONLY] Move some static functions out of wallet.h/cpp #10976)<...>includes the compiler doesn't have to look everywhere, resulting in less 'probing' before looking in the include path-Iwhich can affect compilation performance. For example right now whenprimitives/block.hincludes "primitives/transaction.h", it will look insrc/primitives/primitivesfirst.Most of the changes by number are in
src/qtas all the source files there assume that they can include from there. I've separated this out, so that we could decide to do this only for non-qt files first ,for example.Ping @theuni @ryanofsky