Skip to content

Commit

Permalink
Assemble paths for sources for dwyu even outside the current project.
Browse files Browse the repository at this point in the history
Not that it is typically needed, but it makes it well-rounded.
  • Loading branch information
hzeller committed May 25, 2024
1 parent c2e229c commit e544df9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions bant/tool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ cc_library(
"//bant:session",
"//bant:types",
"//bant:types-bazel",
"//bant:workspace",
"//bant/explore:header-providers",
"//bant/explore:query-utils",
"//bant/frontend:named-content",
Expand Down
18 changes: 17 additions & 1 deletion bant/tool/dwyu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "bant/types.h"
#include "bant/util/file-utils.h"
#include "bant/util/stat.h"
#include "bant/workspace.h"
#include "re2/re2.h"

// Used for messages that are a little bit too noisy right now.
Expand Down Expand Up @@ -269,6 +270,20 @@ bool DWYUGenerator::CanSee(const BazelTarget &target,
return false;
}

// TODO: this needs to be in a central place. Also needed in elaboration.
static std::string MakeFullyQualified(const BazelWorkspace &workspace,
const BazelPackage &package,
std::string_view filename) {
std::string result;
auto package_path = workspace.FindPathByProject(package.project);
if (package_path.has_value()) {
result = package_path->path();
}
if (!result.empty()) result.append("/");
result.append(package.QualifiedFile(filename));
return result;
}

std::vector<absl::btree_set<BazelTarget>>
DWYUGenerator::DependenciesNeededBySources(
const BazelTarget &target, const ParsedBuildFile &build_file,
Expand Down Expand Up @@ -315,7 +330,8 @@ DWYUGenerator::DependenciesNeededBySources(
};

for (const std::string_view src_name : sources) {
const std::string source_file = build_file.package.QualifiedFile(src_name);
const std::string source_file =
MakeFullyQualified(project_.workspace(), build_file.package, src_name);
auto source_content = TryOpenFile(source_file);
if (!source_content.has_value()) {
project_.Loc(info_out, src_name)
Expand Down

0 comments on commit e544df9

Please sign in to comment.