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

A brute-force script for automatic removal of superfluous includes from .cpp files #259

Open
geneotech opened this issue Apr 23, 2018 · 0 comments

Comments

@geneotech
Copy link
Member

geneotech commented Apr 23, 2018

  • Motivation: To speed up build times even more.
  • Input: a list of source files.
    • Could be easily specified with the ones we already specify in CMakeLists.txt, and passed to add_custom_target, named remove_superfluous_includes.
  • Approach: brute-force. I propose this algorithm:
    • For every input cpp file, comment out the n-th found include directive by prepending //.
      • Just match against ^#include.
    • Build the project as usual - the script can just call ninja all on a build directory passed as input.
    • Parse the error log to know which sources failed to build.
      • In the ones that failed, uncomment the just commented out include directive (literally just remove the first two characters).
    • (Optional) - build the project once again to ensure that everything is alright.
      • If not, halt and spout a beautiful error.
    • If no file has an (n+1)-th include directive, halt with success.
    • Otherwise repeat the algorithm with n = n + 1.
  • While we could simply anaylze each file one-by-one, we would then have to parallelize it by hand.
    • Instead we take advantage of the regular parallelism of builds.
    • As a bonus we actually get to know if the whole project builds.
    • Additionally, if we parallelized on file-level, we would have more i/o overhead due to necessary temporary file copies.
  • Problem: with #ifdef-ed code, shit may hit the fan when the defines change.
    • We'll just run it with all defines enabled.
    • We'll just remove platform-specific code and run it specifically on the game code - these should be alright.
@geneotech geneotech changed the title A brute-force script for automatic removal of superfluous C++ includes from .cpp files A brute-force script for automatic removal of superfluous includes from .cpp files Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant