- [FIX] Estava mirant en el buffer equivocat i nomes veïa com a molt el primer include
- [NEW] Ara també mira els includes dels includes recursivament, per a recompilar si canvien.
This commit is contained in:
80
main.cpp
80
main.cpp
@@ -134,7 +134,7 @@ std::vector<std::string> getIncludes(std::string filename)
|
|||||||
|
|
||||||
if (*p=='#')
|
if (*p=='#')
|
||||||
{
|
{
|
||||||
if (textFound(buffer, "#include"))
|
if (textFound(p, "#include"))
|
||||||
{
|
{
|
||||||
p+=8;
|
p+=8;
|
||||||
while(strchr(" \t", *p)) p++; // Ignore whitespace (spaces and tabs)
|
while(strchr(" \t", *p)) p++; // Ignore whitespace (spaces and tabs)
|
||||||
@@ -180,17 +180,44 @@ std::vector<std::string> split(std::string str)
|
|||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaybeRecompile(std::string source_file)
|
bool HeadersNeedRecompile(std::string file, std::filesystem::file_time_type object_file_write_time)
|
||||||
|
{
|
||||||
|
auto include_files = getIncludes(file);
|
||||||
|
for (auto include : include_files)
|
||||||
|
{
|
||||||
|
std::filesystem::path fullpath(file);
|
||||||
|
auto path_without_filename = fullpath.remove_filename();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto include_file_write_time = std::filesystem::last_write_time(include_file);
|
||||||
|
if (include_file_write_time > object_file_write_time)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (HeadersNeedRecompile(include_file, object_file_write_time)) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MustRecompile(std::string source_file)
|
||||||
{
|
{
|
||||||
bool must_recompile = false;
|
|
||||||
std::string object_file = build_path + "/" + getFileNameWithoutExtension(source_file)+".o";
|
std::string object_file = build_path + "/" + getFileNameWithoutExtension(source_file)+".o";
|
||||||
|
|
||||||
// si el objecte no existeix, fa falta recompilar
|
// si el objecte no existeix, fa falta recompilar
|
||||||
if (!std::filesystem::exists(object_file))
|
if (!std::filesystem::exists(object_file))
|
||||||
{
|
{
|
||||||
must_recompile = true;
|
return true;
|
||||||
//std::cout << "'" << object_file << "' No existeix. ";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -201,42 +228,23 @@ void MaybeRecompile(std::string source_file)
|
|||||||
auto source_file_write_time = std::filesystem::last_write_time(source_file);
|
auto source_file_write_time = std::filesystem::last_write_time(source_file);
|
||||||
if (source_file_write_time > object_file_write_time)
|
if (source_file_write_time > object_file_write_time)
|
||||||
{
|
{
|
||||||
//std::cout << "'" << source_file << "' es més nou. ";
|
return true;
|
||||||
must_recompile = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Sino, mirem els includes
|
if (HeadersNeedRecompile(source_file, object_file_write_time))
|
||||||
auto include_files = getIncludes(source_file);
|
return true;
|
||||||
for (auto include : include_files)
|
}
|
||||||
{
|
}
|
||||||
std::filesystem::path fullpath(source_file);
|
return false;
|
||||||
auto path_without_filename = fullpath.remove_filename();
|
}
|
||||||
std::string src_path = path_without_filename.string();
|
|
||||||
|
|
||||||
std::string include_file = src_path + "/" + include;
|
void MaybeRecompile(std::string source_file)
|
||||||
if (!std::filesystem::exists(include_file))
|
{
|
||||||
{
|
if (MustRecompile(source_file))
|
||||||
std::cout << "WARNING: Include file '" << include_file << "' not found." << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto include_file_write_time = std::filesystem::last_write_time(include_file);
|
|
||||||
if (include_file_write_time > object_file_write_time)
|
|
||||||
{
|
|
||||||
//std::cout << "El include '" << include_file << "' es més nou. ";
|
|
||||||
must_recompile = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (must_recompile)
|
|
||||||
{
|
{
|
||||||
|
std::string object_file = build_path + "/" + getFileNameWithoutExtension(source_file)+".o";
|
||||||
must_link = true;
|
must_link = true;
|
||||||
//std::cout << object_file << " s'ha de reompilar" << std::endl;
|
|
||||||
std::string command = "g++ " + source_file + " " + cppflags + " -c -o " + object_file;
|
std::string command = "g++ " + source_file + " " + cppflags + " -c -o " + object_file;
|
||||||
std::cout << command << std::endl;
|
std::cout << command << std::endl;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user