- [FIX] Ignorar els #include en comentaris de bloc
- [FIX] Ara troba includes que se li atragantaven
This commit is contained in:
78
main.cpp
78
main.cpp
@@ -12,6 +12,7 @@ std::string libs = "";
|
||||
std::string cppflags = "";
|
||||
std::string executable = "out";
|
||||
std::string source_path = "";
|
||||
std::vector<std::string> source_paths;
|
||||
std::string build_path = "";
|
||||
#ifdef _WIN32
|
||||
std::string folder_char = "\\";
|
||||
@@ -164,45 +165,70 @@ const bool textFound(char *buffer, const char *text)
|
||||
return equal;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> getIncludes(const std::string &filename) {
|
||||
std::ifstream f(filename);
|
||||
if (!f) return {};
|
||||
|
||||
std::vector<std::string> includes;
|
||||
std::string line;
|
||||
bool inBlockComment = false;
|
||||
|
||||
while (std::getline(f, line)) {
|
||||
// Quitar comentarios de línea
|
||||
auto pos = line.find("//");
|
||||
if (pos != std::string::npos)
|
||||
line.resize(pos);
|
||||
std::string processed;
|
||||
processed.reserve(line.size());
|
||||
|
||||
// Buscar #include
|
||||
pos = line.find("#include");
|
||||
if (pos == std::string::npos)
|
||||
for (size_t i = 0; i < line.size(); ++i) {
|
||||
// Detectar inicio de comentario de bloque
|
||||
if (!inBlockComment && i + 1 < line.size() && line[i] == '/' && line[i+1] == '*') {
|
||||
inBlockComment = true;
|
||||
i++; // saltar '*'
|
||||
continue;
|
||||
}
|
||||
|
||||
// Detectar fin de comentario de bloque
|
||||
if (inBlockComment && i + 1 < line.size() && line[i] == '*' && line[i+1] == '/') {
|
||||
inBlockComment = false;
|
||||
i++; // saltar '/'
|
||||
continue;
|
||||
}
|
||||
|
||||
// Si estamos dentro de un bloque, ignorar todo
|
||||
if (inBlockComment)
|
||||
continue;
|
||||
|
||||
// Detectar comentario de línea
|
||||
if (i + 1 < line.size() && line[i] == '/' && line[i+1] == '/') {
|
||||
break; // ignorar el resto de la línea
|
||||
}
|
||||
|
||||
processed.push_back(line[i]);
|
||||
}
|
||||
|
||||
// Si la línea quedó vacía tras limpiar comentarios, saltar
|
||||
if (processed.find("#include") == std::string::npos)
|
||||
continue;
|
||||
|
||||
// Avanzar tras "#include"
|
||||
// Buscar #include
|
||||
size_t pos = processed.find("#include");
|
||||
pos += 8;
|
||||
|
||||
// Saltar espacios
|
||||
while (pos < line.size() && (line[pos] == ' ' || line[pos] == '\t'))
|
||||
while (pos < processed.size() && (processed[pos] == ' ' || processed[pos] == '\t'))
|
||||
pos++;
|
||||
|
||||
// Solo queremos includes con comillas
|
||||
if (pos >= line.size() || line[pos] != '"')
|
||||
// Solo includes con comillas
|
||||
if (pos >= processed.size() || processed[pos] != '"')
|
||||
continue;
|
||||
|
||||
pos++; // saltar la primera comilla
|
||||
pos++; // saltar comilla inicial
|
||||
size_t start = pos;
|
||||
|
||||
// Buscar la comilla de cierre
|
||||
while (pos < line.size() && line[pos] != '"')
|
||||
// Buscar comilla final
|
||||
while (pos < processed.size() && processed[pos] != '"')
|
||||
pos++;
|
||||
|
||||
if (pos < line.size())
|
||||
includes.push_back(line.substr(start, pos - start));
|
||||
if (pos < processed.size())
|
||||
includes.push_back(processed.substr(start, pos - start));
|
||||
}
|
||||
|
||||
return includes;
|
||||
@@ -216,8 +242,18 @@ bool HeadersNeedRecompile(std::string file, std::filesystem::file_time_type obje
|
||||
std::string src_path = path_without_filename.string();
|
||||
|
||||
std::string include_file = src_path + include;
|
||||
if (!std::filesystem::exists(include_file)) {
|
||||
std::cout << "WARNING: Include file '" << include_file << "' not found." << std::endl;
|
||||
bool found = std::filesystem::exists(include_file);
|
||||
if (!found) {
|
||||
for (auto path : source_paths) {
|
||||
include_file = path + "/" + include;
|
||||
if (std::filesystem::exists(include_file)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
std::cout << "WARNING: Include file '" << include << "' not found in '" << file << "'." << std::endl;
|
||||
} else {
|
||||
auto include_file_write_time = std::filesystem::last_write_time(include_file);
|
||||
if (include_file_write_time > object_file_write_time) {
|
||||
@@ -296,9 +332,9 @@ int main(int argc, char *argv[])
|
||||
std::chrono::steady_clock::time_point begin_all = std::chrono::steady_clock::now();
|
||||
|
||||
if (!std::filesystem::is_directory(build_path)) std::filesystem::create_directory(build_path);
|
||||
auto source_paths = split(source_path);
|
||||
source_paths = split(source_path);
|
||||
|
||||
for (auto src_path : source_paths) {
|
||||
for (auto &src_path : source_paths) {
|
||||
bool recursive = false;
|
||||
|
||||
if (!src_path.empty() && src_path.back() == '+') {
|
||||
|
||||
Reference in New Issue
Block a user