mirror of
https://github.com/open-goal/jak-project
synced 2026-06-01 01:40:07 -04:00
1e33dcda4b
* Remove assets folder, use more std::filesystem * windows fix * another one for windows * another one * better system for different folders * rm debugging stuff * let extractor override everything * dont revert jak1 change
90 lines
2.5 KiB
C++
90 lines
2.5 KiB
C++
|
|
#include "Tool.h"
|
|
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
|
|
#include "common/util/FileUtil.h"
|
|
|
|
#include "third-party/fmt/core.h"
|
|
|
|
Tool::Tool(const std::string& name) : m_name(name) {}
|
|
|
|
bool Tool::needs_run(const ToolInput& task, const PathMap& path_map) {
|
|
// for this to return false, all outputs need to be newer than all inputs.
|
|
|
|
for (auto& in : task.input) {
|
|
auto in_file = std::filesystem::path(file_util::get_file_path({in}));
|
|
|
|
if (!std::filesystem::exists(in_file)) {
|
|
throw std::runtime_error(fmt::format("Input file {} does not exist.", in));
|
|
}
|
|
|
|
auto newest_input = std::filesystem::last_write_time(in_file);
|
|
for (auto& dep : task.deps) {
|
|
auto dep_path = std::filesystem::path(file_util::get_file_path({dep}));
|
|
if (std::filesystem::exists(dep_path)) {
|
|
auto dep_time = std::filesystem::last_write_time(dep_path);
|
|
if (dep_time > newest_input) {
|
|
newest_input = dep_time;
|
|
}
|
|
} else {
|
|
return true; // don't have a dep.
|
|
}
|
|
}
|
|
|
|
for (auto& dep : get_additional_dependencies(task, path_map)) {
|
|
auto dep_path = std::filesystem::path(file_util::get_file_path({dep}));
|
|
if (std::filesystem::exists(dep_path)) {
|
|
auto dep_time = std::filesystem::last_write_time(dep_path);
|
|
if (dep_time > newest_input) {
|
|
newest_input = dep_time;
|
|
}
|
|
} else {
|
|
return true; // don't have a dep.
|
|
}
|
|
}
|
|
|
|
for (auto& out : task.output) {
|
|
auto out_path = std::filesystem::path(file_util::get_file_path({out}));
|
|
if (std::filesystem::exists(out_path)) {
|
|
auto out_time = std::filesystem::last_write_time(out_path);
|
|
if (out_time < newest_input) {
|
|
return true;
|
|
}
|
|
} else {
|
|
return true; // don't have a dep.
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
std::string PathMap::apply_remaps(const std::string& input) const {
|
|
if (!input.empty() && input[0] == '$') {
|
|
std::string prefix = "$";
|
|
size_t i = 1;
|
|
for (; i < input.size(); i++) {
|
|
char c = input[i];
|
|
if (c == '/') {
|
|
break;
|
|
} else {
|
|
prefix.push_back(c);
|
|
}
|
|
}
|
|
const auto& it = path_remap.find(prefix);
|
|
if (it == path_remap.end()) {
|
|
return input;
|
|
} else {
|
|
std::string result = it->second;
|
|
while (!result.empty() && result.back() == '/') {
|
|
result.pop_back();
|
|
}
|
|
result.insert(result.end(), input.begin() + i, input.end());
|
|
return result;
|
|
}
|
|
} else {
|
|
return input;
|
|
}
|
|
} |