Skip to content

Commit

Permalink
Print out all attempted paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elliotgoodrich committed Oct 13, 2024
1 parent e2d9945 commit fdb94a6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/trimutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,14 @@ void TrimUtil::trim(std::ostream& output,
}

// Mark all files in `affected` as required
std::vector<std::filesystem::path> attempted;
for (std::string line; std::getline(affected, line);) {
if (line.empty()) {
continue;
}

attempted.clear();

// First try the raw input
{
const std::optional<std::size_t> index = graph.findPath(line);
Expand All @@ -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<std::size_t> index = graph.findPath(absoluteStr);
Expand All @@ -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<std::size_t> index = graph.findPath(relativeStr);
Expand All @@ -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<bool> seen(graph.size());
Expand Down

0 comments on commit fdb94a6

Please sign in to comment.