From fdb94a695f24a9f3662c45acb79ecb65a5601492 Mon Sep 17 00:00:00 2001 From: Elliot Goodrich Date: Sun, 13 Oct 2024 06:01:25 +0100 Subject: [PATCH] Print out all attempted paths When trying to look up paths passed to `--affected` we attempt to convert to absolute and relative paths in case the Ninja input file does not match how files were passed in. When this fails, it would be nice to let the user know that other file paths were tried. It is a good reminder what base path is used when converting from relative to absolute paths. --- src/trimutil.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/trimutil.cpp b/src/trimutil.cpp index a111faf..17f1477 100644 --- a/src/trimutil.cpp +++ b/src/trimutil.cpp @@ -643,11 +643,14 @@ void TrimUtil::trim(std::ostream& output, } // Mark all files in `affected` as required + std::vector attempted; for (std::string line; std::getline(affected, line);) { if (line.empty()) { continue; } + attempted.clear(); + // First try the raw input { const std::optional index = graph.findPath(line); @@ -666,7 +669,8 @@ void TrimUtil::trim(std::ostream& output, std::filesystem::path p(line); if (!p.is_absolute()) { std::error_code okay; - const std::filesystem::path absolute = std::filesystem::absolute(p, okay); + const std::filesystem::path& absolute = + attempted.emplace_back(std::filesystem::absolute(p, okay)); if (okay) { std::string absoluteStr = absolute.string(); const std::optional index = graph.findPath(absoluteStr); @@ -686,7 +690,8 @@ void TrimUtil::trim(std::ostream& output, // file if (!p.is_relative()) { std::error_code okay; - const std::filesystem::path relative = std::filesystem::relative(p, okay); + const std::filesystem::path& relative = + attempted.emplace_back(std::filesystem::relative(p, okay)); if (okay) { std::string relativeStr = relative.string(); const std::optional index = graph.findPath(relativeStr); @@ -702,7 +707,17 @@ void TrimUtil::trim(std::ostream& output, } } - std::cerr << "'" << line << "' not found in input file" << std::endl; + std::cerr << "'" << line << "' not found in input file"; + if (!attempted.empty()) { + std::cerr << " (also tried "; + const char* separator = ""; + for (const std::filesystem::path& path : attempted) { + std::cerr << separator << "'" << path.string() << "'"; + separator = ", "; + } + std::cerr << ')'; + } + std::cerr << std::endl; } std::vector seen(graph.size());