From 105e1721d665d8386afd47882020c51d6d97c522 Mon Sep 17 00:00:00 2001 From: Phlosioneer Date: Sun, 3 Mar 2019 21:59:57 -0500 Subject: Overhaul scaninc to work recursively This also fixes the bug where scaninc would ignore #include lines in assembly files. --- tools/scaninc/scaninc.cpp | 96 ++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 63 deletions(-) (limited to 'tools/scaninc/scaninc.cpp') diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index 3dc221479..0d55d11f6 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -25,8 +25,7 @@ #include #include #include "scaninc.h" -#include "asm_file.h" -#include "c_file.h" +#include "source_file.h" bool CanOpenFile(std::string path) { @@ -46,7 +45,7 @@ int main(int argc, char **argv) std::queue filesToProcess; std::set dependencies; - std::list includeDirs; + std::vector includeDirs; argc--; argv++; @@ -83,79 +82,50 @@ int main(int argc, char **argv) std::string initialPath(argv[0]); - std::size_t pos = initialPath.find_last_of('.'); + filesToProcess.push(initialPath); - if (pos == std::string::npos) - FATAL_ERROR("no file extension in path \"%s\"\n", initialPath.c_str()); - - std::string extension = initialPath.substr(pos + 1); - - std::string srcDir(""); - std::size_t slash = initialPath.rfind('/'); - if (slash != std::string::npos) - { - srcDir = initialPath.substr(0, slash + 1); - } - includeDirs.push_back(srcDir); - - if (extension == "c" || extension == "h") + while (!filesToProcess.empty()) { - filesToProcess.push(initialPath); + std::string filePath = filesToProcess.front(); + SourceFile file(filePath); + filesToProcess.pop(); - while (!filesToProcess.empty()) + includeDirs.push_back(file.GetSrcDir()); + for (auto incbin : file.GetIncbins()) { - CFile file(filesToProcess.front()); - filesToProcess.pop(); - - file.FindIncbins(); - for (auto incbin : file.GetIncbins()) - { - dependencies.insert(incbin); - } - for (auto include : file.GetIncludes()) + dependencies.insert(incbin); + } + for (auto include : file.GetIncludes()) + { + bool found = false; + for (auto includeDir : includeDirs) { - for (auto includeDir : includeDirs) + std::string path(includeDir + include); + if (CanOpenFile(path)) { - std::string path(includeDir + include); - if (CanOpenFile(path)) + bool inserted = dependencies.insert(path).second; + if (inserted) { - bool inserted = dependencies.insert(path).second; - if (inserted) - { - filesToProcess.push(path); - } - break; + filesToProcess.push(path); } + found = true; + break; } } - } - } - else if (extension == "s" || extension == "inc") - { - filesToProcess.push(initialPath); - - while (!filesToProcess.empty()) - { - AsmFile file(filesToProcess.front()); - - filesToProcess.pop(); - - IncDirectiveType incDirectiveType; - std::string path; - - while ((incDirectiveType = file.ReadUntilIncDirective(path)) != IncDirectiveType::None) + if (!found) { - bool inserted = dependencies.insert(path).second; - if (inserted - && incDirectiveType == IncDirectiveType::Include - && CanOpenFile(path)) - filesToProcess.push(path); + if (GetFileType(include) == SourceFileType::Header) + // We don't have any generated .h files... yet. + // Better to give a warning; debugging the makefile when a + // header is missing is very difficult. + fprintf(stderr, "scaninc: warning: C header file \"%s\" not found. (included from \"%s\")\n", + include.c_str(), filePath.c_str()); + + // It's probably a generated file. + dependencies.insert(include); } } - } - else - { - FATAL_ERROR("unknown extension \"%s\"\n", extension.c_str()); + includeDirs.pop_back(); } for (const std::string &path : dependencies) -- cgit v1.2.3 From b0c634d5318019f17547a758084fdcfb5a387c24 Mon Sep 17 00:00:00 2001 From: Phlosioneer Date: Mon, 4 Mar 2019 00:21:34 -0500 Subject: Support absolute paths --- tools/scaninc/scaninc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/scaninc/scaninc.cpp') diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index 0d55d11f6..696842dc9 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -62,7 +62,7 @@ int main(int argc, char **argv) argv++; includeDir = std::string(argv[0]); } - if (includeDir.back() != '/') + if (!includeDir.empty() && includeDir.back() != '/') { includeDir += '/'; } -- cgit v1.2.3 From bd157b301dea3526a4c373737dc8167d9a02b168 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Thu, 7 Mar 2019 09:46:14 -0600 Subject: Scaninc: Don't insert missing headers into dependencies --- tools/scaninc/scaninc.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'tools/scaninc/scaninc.cpp') diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index 696842dc9..b95cbd033 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -97,7 +97,6 @@ int main(int argc, char **argv) } for (auto include : file.GetIncludes()) { - bool found = false; for (auto includeDir : includeDirs) { std::string path(includeDir + include); @@ -108,22 +107,9 @@ int main(int argc, char **argv) { filesToProcess.push(path); } - found = true; break; } } - if (!found) - { - if (GetFileType(include) == SourceFileType::Header) - // We don't have any generated .h files... yet. - // Better to give a warning; debugging the makefile when a - // header is missing is very difficult. - fprintf(stderr, "scaninc: warning: C header file \"%s\" not found. (included from \"%s\")\n", - include.c_str(), filePath.c_str()); - - // It's probably a generated file. - dependencies.insert(include); - } } includeDirs.pop_back(); } -- cgit v1.2.3