Skip to content

Commit

Permalink
Rename QualifiedFile() that incorporates workspace FullyQualifiedFile()
Browse files Browse the repository at this point in the history
Also remove a helper function that now is covered by FullyQualifiedFile().

Use in compilation-db for the FQN of the sources to compile.
  • Loading branch information
hzeller committed Jul 7, 2024
1 parent a32e114 commit 1a6c094
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bant/frontend/elaboration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class SimpleElaborator : public BaseNodeReplacementVisitor {

// Find directory to start the glob()-ing.
const std::string root_dir =
package_.QualifiedFile(project_->workspace(), ".");
package_.FullyQualifiedFile(project_->workspace(), ".");
const std::vector<FilesystemPath> glob_result =
MultiGlob(root_dir, query::ExtractStringList(include_list),
query::ExtractStringList(exclude_list));
Expand Down
1 change: 0 additions & 1 deletion bant/tool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ 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
5 changes: 3 additions & 2 deletions bant/tool/compilation-db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ static void WriteCompilationDBEntry(const ParsedProject &project,
query::AppendStringList(details.hdrs_list, sources);

for (const auto src : sources) {
const std::string abs_src = package.QualifiedFile(src);
const std::string abs_src =
package.FullyQualifiedFile(project.workspace(), src);
out << " {\n";
out << " " << q{"file"} << ": " << q{abs_src} << ",\n";
out << " " << q{"arguments"} << ": [\n";
Expand Down Expand Up @@ -123,7 +124,7 @@ static std::string CollectGlobalFlagsAndIncDirs(const ParsedProject &project) {
const auto inc_dirs = query::ExtractStringList(details.includes_list);
for (const std::string_view inc_dir : inc_dirs) {
const std::string inc_path =
current_package.QualifiedFile(workspace, inc_dir);
current_package.FullyQualifiedFile(workspace, inc_dir);
if (!already_seen.insert(inc_path).second) continue;
out << kIndent << q{"-iquote"} << ", " << q{inc_path} << ",\n";
}
Expand Down
17 changes: 1 addition & 16 deletions bant/tool/dwyu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "bant/types.h"
#include "bant/util/file-utils.h"
#include "bant/util/stat.h"
#include "bant/workspace.h"
#include "re2/re2.h"

// Looking for source files directly in the source tree, but if not found
Expand Down Expand Up @@ -306,20 +305,6 @@ bool DWYUGenerator::CanSee(const BazelTarget &target,
return !any_valid_visiblity_pattern;
}

// 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 @@ -379,7 +364,7 @@ DWYUGenerator::DependenciesNeededBySources(

for (const std::string_view src_name : sources) {
const std::string source_file =
MakeFullyQualified(project_.workspace(), build_file.package, src_name);
build_file.package.FullyQualifiedFile(project_.workspace(), src_name);
std::optional<DWYUGenerator::SourceFile> source_content;
{
const ScopedTimer timer(&source_read_stats.duration);
Expand Down
4 changes: 2 additions & 2 deletions bant/types-bazel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ std::string BazelPackage::QualifiedFile(std::string_view relative_file) const {
return absl::StrCat(path, "/", relative_file);
}

std::string BazelPackage::QualifiedFile(const BazelWorkspace &workspace,
std::string_view relative_file) const {
std::string BazelPackage::FullyQualifiedFile(
const BazelWorkspace &workspace, std::string_view relative_file) const {
std::string root_dir;
if (!project.empty()) {
auto package_path = workspace.FindPathByProject(project);
Expand Down
7 changes: 5 additions & 2 deletions bant/types-bazel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ struct BazelPackage {

// Assemble filename relative to the path.
std::string QualifiedFile(std::string_view relative_file) const;
std::string QualifiedFile(const BazelWorkspace &workspace,
std::string_view relative_file) const;

// Assemble filename including potential prefix if it is located in an
// external project.
std::string FullyQualifiedFile(const BazelWorkspace &workspace,
std::string_view relative_file) const;

auto operator<=>(const BazelPackage &o) const = default;
bool operator<(const BazelPackage &) const = default;
Expand Down

0 comments on commit 1a6c094

Please sign in to comment.