Created
April 18, 2023 19:54
-
-
Save RFullum/16134600c979fd18bdc4f1a85a87d7a0 to your computer and use it in GitHub Desktop.
Find header files in Juce app that don't have an #include anywhere other than their corresponding source file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Put somewhere in Juce app (ie. ctor of MainComponent) and run app. Will | |
print to console the name of the header files that don't have an #include | |
in the code other than in their corresponding .cpp file. | |
*/ | |
DBG(" "); | |
auto sourceDir = juce::File("~/Rode/RodeCentral/rode_central/RODE Central/Source"); | |
std::vector<juce::File> codeFiles; // .h and .cpp | |
std::vector<juce::File> headerFiles; // just .h | |
std::vector<juce::File> unusedHeaderFiles; | |
for (juce::DirectoryEntry entry : juce::RangedDirectoryIterator(sourceDir, true)) | |
{ | |
auto file = entry.getFile(); | |
auto headerExt = juce::String(".h"); | |
auto sourceExt = juce::String(".cpp"); | |
if (file.getFileExtension() == headerExt || file.getFileExtension() == sourceExt) | |
{ | |
codeFiles.emplace_back(file); | |
if (file.getFileExtension() == headerExt) | |
headerFiles.emplace_back(file); | |
} | |
} | |
unusedHeaderFiles = headerFiles; | |
for (auto header : headerFiles) | |
{ | |
for (auto codeFile : codeFiles) | |
{ | |
const auto headerNameNoExt = header.getFileNameWithoutExtension(); | |
const auto codeNameNoExt = codeFile.getFileNameWithoutExtension(); | |
if (headerNameNoExt != codeNameNoExt) | |
{ | |
auto fileText = codeFile.loadFileAsString(); | |
auto headerName = header.getFileName(); | |
if (fileText.contains(headerName)) | |
{ | |
for (int i = 0; i < unusedHeaderFiles.size(); ++i) | |
{ | |
if (unusedHeaderFiles[i] == header) | |
unusedHeaderFiles.erase(unusedHeaderFiles.begin() + i); | |
} | |
} | |
} | |
} | |
} | |
for (auto unused : unusedHeaderFiles) | |
DBG(unused.getFileName()); | |
DBG(" "); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment