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

Improve includes #6320

Merged
merged 11 commits into from
Mar 2, 2022
Merged

Improve includes #6320

merged 11 commits into from
Mar 2, 2022

Conversation

JohannesLorenz
Copy link
Contributor

As requested in #5592 .

The last commit has been done using iwyu (see commit for details) and a lot of manual refactoring. The commits before it are preparation.

@LmmsBot
Copy link

LmmsBot commented Feb 28, 2022

🤖 Hey, I'm @LmmsBot from github.com/lmms/bot and I made downloads for this pull request, click me to make them magically appear! 🎩

Linux

Windows

macOS

🤖
{"platform_name_to_artifacts": {"Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://15834-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.182%2Bg7d1c982ab-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/15834?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "Windows": [{"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://15833-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.182%2Bg7d1c982ab-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/15833?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://15836-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.182%2Bg7d1c982ab-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/15836?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/citejhkk2uxx1rh2/artifacts/build/lmms-1.3.0-alpha-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/42749613"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/o1nrj7qqo0r9itws/artifacts/build/lmms-1.3.0-alpha-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/42749613"}], "macOS": [{"artifact": {"title": {"title": "", "platform_name": "macOS"}, "link": {"link": "https://15835-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.182%2Bg7d1c982ab-mac10.14.dmg"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/15835?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}]}, "commit_sha": "ddcdc256a1b0d675e355a0f1ddfd5d1b0b6c589b"}

This improves the include structure by elliminating includes that are
not used. Most of this was done by using `include-what-you-use` with
`CMAKE_C_INCLUDE_WHAT_YOU_USE` and `CMAKE_CXX_INCLUDE_WHAT_YOU_USE`
set to (broken down here):

```
include-what-you-use;
    -Xiwyu;--mapping_file=/usr/share/include-what-you-use/qt5_11.imp;
    -Xiwyu;--keep=*/xmmintrin.h;
    -Xiwyu;--keep=*/lmmsconfig.h;
    -Xiwyu;--keep=*/weak_libjack.h;
    -Xiwyu;--keep=*/sys/*;
    -Xiwyu;--keep=*/debug.h;
    -Xiwyu;--keep=*/SDL/*;
    -Xiwyu;--keep=*/alsa/*;
    -Xiwyu;--keep=*/FL/x.h;
    -Xiwyu;--keep=*/MidiApple.h;
    -Xiwyu;--keep=*/MidiWinMM.h;
    -Xiwyu;--keep=*/AudioSoundIo.h
```
@JohannesLorenz
Copy link
Contributor Author

I reworked your comments and pushed.

For some headers, I think this PR can damage more than it should. For example, if you remove "lmmsconfig.h" accidentally, the code might still compile, but be configured wrong. Though, I didn't notice more headers with that issue, and at least for this one, the worst case seems to be "LMMS compiles more than I wanted".

Another point (already mentioned in one comment): The include order in this PR is not too crucial, as clang-format will reorder all of this - except if there are #if... or (FWIR) comments in between.

Copy link
Member

@DomClark DomClark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some headers, I think this PR can damage more than it should. For example, if you remove "lmmsconfig.h" accidentally, the code might still compile, but be configured wrong. Though, I didn't notice more headers with that issue, and at least for this one, the worst case seems to be "LMMS compiles more than I wanted".

I'm not sure if there's an easy way to check for this. CI is passing, which is the main thing, so I'd say we merge this and fix up any issues later.

@PhysSong
Copy link
Member

PhysSong commented Mar 2, 2022

I've also checked with more compilers, and it's working. 👍

@JohannesLorenz JohannesLorenz merged commit 7db3fa9 into LMMS:master Mar 2, 2022
@zonkmachine
Copy link
Contributor

@JohannesLorenz I'm on a brand new laptop now and Ubuntu 21.10, fresh install.
7db3fa9 generates this error. The commit prior to this builds just fine.

Building CXX object src/CMakeFiles/lmmsobjs.dir/core/MixHelpers.cpp.o
/home/zonkmachine/builds/lmms/src/core/MixHelpers.cpp: In function ‘bool MixHelpers::sanitize(sampleFrame*, int)’:
/home/zonkmachine/builds/lmms/src/core/MixHelpers.cpp:105:41: error: ‘printf’ was not declared in this scope
  105 |                                         printf("Bad data, clearing buffer. frame: ");
      |                                         ^~~~~~
/home/zonkmachine/builds/lmms/src/core/MixHelpers.cpp:32:1: note: ‘printf’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’?
   31 | #include "ValueBuffer.h"
  +++ |+#include <cstdio>
   32 | 
make[2]: *** [src/CMakeFiles/lmmsobjs.dir/build.make:652: src/CMakeFiles/lmmsobjs.dir/core/MixHelpers.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2319: src/CMakeFiles/lmmsobjs.dir/all] Error 2
make: *** [Makefile:171: all] Error 2

@PhysSong
Copy link
Member

PhysSong commented Mar 4, 2022

It seems like debug builds(with LMMS_DEBUG) wasn't checked properly. Also, there might be some chances where the code won't build without some optional dependencies due to missing headers.

@PhysSong
Copy link
Member

PhysSong commented Mar 4, 2022

Confirmed that it's the only build error, at least on Linux with GCC 11 and Qt 5.15.

@DomClark
Copy link
Member

DomClark commented Mar 4, 2022

When added back, that include ought to be wrapped in #ifdef LMMS_DEBUG so it isn't erroneously removed again. Also, we shouldn't be calling printf from a real-time thread, even in debug mode.

@JohannesLorenz
Copy link
Contributor Author

Sorry, I really have problems with my notifications lately, but luckily, @PhysSong already fixed it in 80a6672 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants