diff --git a/bant/frontend/elaboration.cc b/bant/frontend/elaboration.cc index 71891c8..e37432f 100644 --- a/bant/frontend/elaboration.cc +++ b/bant/frontend/elaboration.cc @@ -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 glob_result = MultiGlob(root_dir, query::ExtractStringList(include_list), query::ExtractStringList(exclude_list)); diff --git a/bant/tool/BUILD b/bant/tool/BUILD index b5a1c9e..7c1e36b 100644 --- a/bant/tool/BUILD +++ b/bant/tool/BUILD @@ -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", diff --git a/bant/tool/compilation-db.cc b/bant/tool/compilation-db.cc index d24dd73..f2944ba 100644 --- a/bant/tool/compilation-db.cc +++ b/bant/tool/compilation-db.cc @@ -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"; @@ -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"; } diff --git a/bant/tool/dwyu.cc b/bant/tool/dwyu.cc index 2f35740..91a947c 100644 --- a/bant/tool/dwyu.cc +++ b/bant/tool/dwyu.cc @@ -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 @@ -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> DWYUGenerator::DependenciesNeededBySources( const BazelTarget &target, const ParsedBuildFile &build_file, @@ -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 source_content; { const ScopedTimer timer(&source_read_stats.duration); diff --git a/bant/types-bazel.cc b/bant/types-bazel.cc index d56746f..01e0da2 100644 --- a/bant/types-bazel.cc +++ b/bant/types-bazel.cc @@ -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); diff --git a/bant/types-bazel.h b/bant/types-bazel.h index 4fa92a3..6aed201 100644 --- a/bant/types-bazel.h +++ b/bant/types-bazel.h @@ -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;