Skip to content

Commit 2b5cd8b

Browse files
committed
[Driver] Remove InstallDir and getInstalledDir. NFC
Follow-up to #80527.
1 parent 9606655 commit 2b5cd8b

18 files changed

+32
-59
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ class Driver {
160160
/// Target and driver mode components extracted from clang executable name.
161161
ParsedClangName ClangNameParts;
162162

163-
/// TODO: Remove this in favor of Dir.
164-
std::string InstalledDir;
165-
166163
/// The path to the compiler resource directory.
167164
std::string ResourceDir;
168165

@@ -429,8 +426,6 @@ class Driver {
429426

430427
/// Get the path to where the clang executable was installed.
431428
const char *getInstalledDir() const {
432-
if (!InstalledDir.empty())
433-
return InstalledDir.c_str();
434429
return Dir.c_str();
435430
}
436431

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,10 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
209209

210210
Name = std::string(llvm::sys::path::filename(ClangExecutable));
211211
Dir = std::string(llvm::sys::path::parent_path(ClangExecutable));
212-
InstalledDir = Dir; // Provide a sensible default installed dir.
213212

214213
if ((!SysRoot.empty()) && llvm::sys::path::is_relative(SysRoot)) {
215214
// Prepend InstalledDir if SysRoot is relative
216-
SmallString<128> P(InstalledDir);
215+
SmallString<128> P(Dir);
217216
llvm::sys::path::append(P, SysRoot);
218217
SysRoot = std::string(P);
219218
}
@@ -1337,7 +1336,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
13371336
if (const Arg *A = Args.getLastArg(options::OPT_target))
13381337
TargetTriple = A->getValue();
13391338
if (const Arg *A = Args.getLastArg(options::OPT_ccc_install_dir))
1340-
Dir = InstalledDir = A->getValue();
1339+
Dir = Dir = A->getValue();
13411340
for (const Arg *A : Args.filtered(options::OPT_B)) {
13421341
A->claim();
13431342
PrefixDirs.push_back(A->getValue(0));
@@ -2000,7 +1999,7 @@ void Driver::PrintVersion(const Compilation &C, raw_ostream &OS) const {
20001999
OS << '\n';
20012000

20022001
// Print out the install directory.
2003-
OS << "InstalledDir: " << InstalledDir << '\n';
2002+
OS << "InstalledDir: " << Dir << '\n';
20042003

20052004
// If configuration files were used, print their paths.
20062005
for (auto ConfigFile : ConfigFiles)

clang/lib/Driver/ToolChains/AIX.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
342342
/// AIX - AIX tool chain which can call as(1) and ld(1) directly.
343343
AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
344344
: ToolChain(D, Triple, Args) {
345-
getProgramPaths().push_back(getDriver().getInstalledDir());
346-
if (getDriver().getInstalledDir() != getDriver().Dir)
347-
getProgramPaths().push_back(getDriver().Dir);
345+
getProgramPaths().push_back(getDriver().Dir);
348346

349347
ParseInlineAsmUsingAsmParser = Args.hasFlag(
350348
options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ RocmInstallationDetector::getInstallationPathCandidates() {
209209
}
210210

211211
// Try to find relative to the compiler binary.
212-
const char *InstallDir = D.getInstalledDir();
212+
StringRef InstallDir = D.Dir;
213213

214214
// Check both a normal Unix prefix position of the clang binary, as well as
215215
// the Windows-esque layout the ROCm packages use with the host architecture

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ static bool findRISCVMultilibs(const Driver &D,
100100
BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
101101
const ArgList &Args)
102102
: ToolChain(D, Triple, Args) {
103-
getProgramPaths().push_back(getDriver().getInstalledDir());
104-
if (getDriver().getInstalledDir() != getDriver().Dir)
105-
getProgramPaths().push_back(getDriver().Dir);
103+
getProgramPaths().push_back(getDriver().Dir);
106104

107105
findMultilibs(D, Triple, Args);
108106
SmallString<128> SysRoot(computeSysRoot());

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11091109
if ((getToolChain().getTriple().isNVPTX() ||
11101110
getToolChain().getTriple().isAMDGCN()) &&
11111111
C.getActiveOffloadKinds() == Action::OFK_None) {
1112-
SmallString<128> P(llvm::sys::path::parent_path(D.InstalledDir));
1112+
SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
11131113
llvm::sys::path::append(P, "include");
11141114
llvm::sys::path::append(P, getToolChain().getTripleString());
11151115
CmdArgs.push_back("-internal-isystem");

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,7 @@ void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA,
925925
MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
926926
: ToolChain(D, Triple, Args) {
927927
// We expect 'as', 'ld', etc. to be adjacent to our install dir.
928-
getProgramPaths().push_back(getDriver().getInstalledDir());
929-
if (getDriver().getInstalledDir() != getDriver().Dir)
930-
getProgramPaths().push_back(getDriver().Dir);
928+
getProgramPaths().push_back(getDriver().Dir);
931929
}
932930

933931
/// Darwin - Darwin tool chain for i386 and x86_64.
@@ -2534,7 +2532,7 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
25342532
// Note that InstallBin can be relative, so we use '..' instead of
25352533
// parent_path.
25362534
llvm::SmallString<128> InstallBin =
2537-
llvm::StringRef(getDriver().getInstalledDir()); // <install>/bin
2535+
llvm::StringRef(getDriver().Dir); // <install>/bin
25382536
llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
25392537
if (getVFS().exists(InstallBin)) {
25402538
addSystemInclude(DriverArgs, CC1Args, InstallBin);
@@ -2545,7 +2543,7 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
25452543
}
25462544

25472545
// (2) Check for the folder where the executable is located, if different.
2548-
if (getDriver().getInstalledDir() != getDriver().Dir) {
2546+
if (getDriver().Dir != getDriver().Dir) {
25492547
InstallBin = llvm::StringRef(getDriver().Dir);
25502548
llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
25512549
if (getVFS().exists(InstallBin)) {

clang/lib/Driver/ToolChains/DragonFly.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,8 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
205205
DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple,
206206
const ArgList &Args)
207207
: Generic_ELF(D, Triple, Args) {
208-
209208
// Path mangling to find libexec
210-
getProgramPaths().push_back(getDriver().getInstalledDir());
211-
if (getDriver().getInstalledDir() != getDriver().Dir)
212-
getProgramPaths().push_back(getDriver().Dir);
209+
getProgramPaths().push_back(getDriver().Dir);
213210

214211
getFilePaths().push_back(getDriver().Dir + "/../lib");
215212
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));

clang/lib/Driver/ToolChains/Fuchsia.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ void fuchsia::StaticLibTool::ConstructJob(Compilation &C, const JobAction &JA,
251251
Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
252252
const ArgList &Args)
253253
: ToolChain(D, Triple, Args) {
254-
getProgramPaths().push_back(getDriver().getInstalledDir());
255-
if (getDriver().getInstalledDir() != D.Dir)
256-
getProgramPaths().push_back(D.Dir);
254+
getProgramPaths().push_back(getDriver().Dir);
257255

258256
if (!D.SysRoot.empty()) {
259257
SmallString<128> P(D.SysRoot);

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,7 @@ void Generic_GCC::GCCInstallationDetector::init(
22852285
}
22862286

22872287
// Then look for gcc installed alongside clang.
2288-
Prefixes.push_back(D.InstalledDir + "/..");
2288+
Prefixes.push_back(D.Dir + "/..");
22892289

22902290
// Next, look for prefix(es) that correspond to distribution-supplied gcc
22912291
// installations.
@@ -3054,9 +3054,7 @@ Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
30543054
const ArgList &Args)
30553055
: ToolChain(D, Triple, Args), GCCInstallation(D),
30563056
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args) {
3057-
getProgramPaths().push_back(getDriver().getInstalledDir());
3058-
if (getDriver().getInstalledDir() != getDriver().Dir)
3059-
getProgramPaths().push_back(getDriver().Dir);
3057+
getProgramPaths().push_back(getDriver().Dir);
30603058
}
30613059

30623060
Generic_GCC::~Generic_GCC() {}

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
411411
const std::string MCpuSuffix = "/" + CpuVer.str();
412412
const std::string MCpuG0Suffix = MCpuSuffix + "/G0";
413413
const std::string RootDir =
414-
HTC.getHexagonTargetDir(D.InstalledDir, D.PrefixDirs) + "/";
414+
HTC.getHexagonTargetDir(D.Dir, D.PrefixDirs) + "/";
415415
const std::string StartSubDir =
416416
"hexagon/lib" + (UseG0 ? MCpuG0Suffix : MCpuSuffix);
417417

@@ -569,8 +569,7 @@ void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args,
569569
std::copy(D.PrefixDirs.begin(), D.PrefixDirs.end(),
570570
std::back_inserter(RootDirs));
571571

572-
std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(),
573-
D.PrefixDirs);
572+
std::string TargetDir = getHexagonTargetDir(D.Dir, D.PrefixDirs);
574573
if (!llvm::is_contained(RootDirs, TargetDir))
575574
RootDirs.push_back(TargetDir);
576575

@@ -597,8 +596,7 @@ void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args,
597596
HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple,
598597
const llvm::opt::ArgList &Args)
599598
: Linux(D, Triple, Args) {
600-
const std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(),
601-
D.PrefixDirs);
599+
const std::string TargetDir = getHexagonTargetDir(D.Dir, D.PrefixDirs);
602600

603601
// Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to
604602
// program paths
@@ -728,8 +726,7 @@ void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
728726

729727
if (HasSysRoot)
730728
return;
731-
std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(),
732-
D.PrefixDirs);
729+
std::string TargetDir = getHexagonTargetDir(D.Dir, D.PrefixDirs);
733730
addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include");
734731
}
735732

@@ -744,7 +741,7 @@ void HexagonToolChain::addLibCxxIncludePaths(
744741
addLibStdCXXIncludePaths("/usr/include/c++/v1", "", "", DriverArgs,
745742
CC1Args);
746743
else {
747-
std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs);
744+
std::string TargetDir = getHexagonTargetDir(D.Dir, D.PrefixDirs);
748745
addLibStdCXXIncludePaths(TargetDir + "/hexagon/include/c++/v1", "", "",
749746
DriverArgs, CC1Args);
750747
}
@@ -753,7 +750,7 @@ void HexagonToolChain::addLibStdCxxIncludePaths(
753750
const llvm::opt::ArgList &DriverArgs,
754751
llvm::opt::ArgStringList &CC1Args) const {
755752
const Driver &D = getDriver();
756-
std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs);
753+
std::string TargetDir = getHexagonTargetDir(D.Dir, D.PrefixDirs);
757754
addLibStdCXXIncludePaths(TargetDir + "/hexagon/include/c++", "", "",
758755
DriverArgs, CC1Args);
759756
}

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ std::string Linux::computeSysRoot() const {
384384
if (getTriple().isAndroid()) {
385385
// Android toolchains typically include a sysroot at ../sysroot relative to
386386
// the clang binary.
387-
const StringRef ClangDir = getDriver().getInstalledDir();
387+
const StringRef ClangDir = getDriver().Dir;
388388
std::string AndroidSysRootPath = (ClangDir + "/../sysroot").str();
389389
if (getVFS().exists(AndroidSysRootPath))
390390
return AndroidSysRootPath;

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,7 @@ MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
423423
const ArgList &Args)
424424
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
425425
RocmInstallation(D, Triple, Args) {
426-
getProgramPaths().push_back(getDriver().getInstalledDir());
427-
if (getDriver().getInstalledDir() != getDriver().Dir)
428-
getProgramPaths().push_back(getDriver().Dir);
426+
getProgramPaths().push_back(getDriver().Dir);
429427

430428
std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;
431429
if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir))

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ findClangRelativeSysroot(const Driver &D, const llvm::Triple &LiteralTriple,
463463
Subdirs.back() += "-w64-mingw32";
464464
Subdirs.emplace_back(T.getArchName());
465465
Subdirs.back() += "-w64-mingw32ucrt";
466-
StringRef ClangRoot = llvm::sys::path::parent_path(D.getInstalledDir());
466+
StringRef ClangRoot = llvm::sys::path::parent_path(D.Dir);
467467
StringRef Sep = llvm::sys::path::get_separator();
468468
for (StringRef CandidateSubdir : Subdirs) {
469469
if (llvm::sys::fs::is_directory(ClangRoot + Sep + CandidateSubdir)) {
@@ -487,10 +487,10 @@ toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple,
487487
const ArgList &Args)
488488
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
489489
RocmInstallation(D, Triple, Args) {
490-
getProgramPaths().push_back(getDriver().getInstalledDir());
490+
getProgramPaths().push_back(getDriver().Dir);
491491

492492
std::string InstallBase =
493-
std::string(llvm::sys::path::parent_path(getDriver().getInstalledDir()));
493+
std::string(llvm::sys::path::parent_path(getDriver().Dir));
494494
// The sequence for detecting a sysroot here should be kept in sync with
495495
// the testTriple function below.
496496
llvm::Triple LiteralTriple = getLiteralTriple(D, getTriple());
@@ -796,8 +796,7 @@ static bool testTriple(const Driver &D, const llvm::Triple &Triple,
796796
if (D.SysRoot.size())
797797
return true;
798798
llvm::Triple LiteralTriple = getLiteralTriple(D, Triple);
799-
std::string InstallBase =
800-
std::string(llvm::sys::path::parent_path(D.getInstalledDir()));
799+
std::string InstallBase = std::string(llvm::sys::path::parent_path(D.Dir));
801800
if (llvm::ErrorOr<std::string> TargetSubdir =
802801
findClangRelativeSysroot(D, LiteralTriple, Triple, SubdirName))
803802
return true;

clang/lib/Driver/ToolChains/MipsLinux.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ void MipsLLVMToolChain::AddClangSystemIncludeArgs(
5757
const auto &Callback = Multilibs.includeDirsCallback();
5858
if (Callback) {
5959
for (const auto &Path : Callback(SelectedMultilibs.back()))
60-
addExternCSystemIncludeIfExists(DriverArgs, CC1Args,
61-
D.getInstalledDir() + Path);
60+
addExternCSystemIncludeIfExists(DriverArgs, CC1Args, D.Dir + Path);
6261
}
6362
}
6463

@@ -70,7 +69,7 @@ std::string MipsLLVMToolChain::computeSysRoot() const {
7069
if (!getDriver().SysRoot.empty())
7170
return getDriver().SysRoot + SelectedMultilibs.back().osSuffix();
7271

73-
const std::string InstalledDir(getDriver().getInstalledDir());
72+
const std::string InstalledDir(getDriver().Dir);
7473
std::string SysRootPath =
7574
InstalledDir + "/../sysroot" + SelectedMultilibs.back().osSuffix();
7675
if (llvm::sys::fs::exists(SysRootPath))
@@ -97,7 +96,7 @@ void MipsLLVMToolChain::addLibCxxIncludePaths(
9796
llvm::opt::ArgStringList &CC1Args) const {
9897
if (const auto &Callback = Multilibs.includeDirsCallback()) {
9998
for (std::string Path : Callback(SelectedMultilibs.back())) {
100-
Path = getDriver().getInstalledDir() + Path + "/c++/v1";
99+
Path = getDriver().Dir + Path + "/c++/v1";
101100
if (llvm::sys::fs::exists(Path)) {
102101
addSystemInclude(DriverArgs, CC1Args, Path);
103102
return;

clang/lib/Driver/ToolChains/OHOS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ std::string OHOS::computeSysRoot() const {
274274
std::string SysRoot =
275275
!getDriver().SysRoot.empty()
276276
? getDriver().SysRoot
277-
: makePath({getDriver().getInstalledDir(), "..", "..", "sysroot"});
277+
: makePath({getDriver().Dir, "..", "..", "sysroot"});
278278
if (!llvm::sys::fs::exists(SysRoot))
279279
return std::string();
280280

clang/lib/Driver/ToolChains/WebAssembly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
198198

199199
assert(Triple.isArch32Bit() != Triple.isArch64Bit());
200200

201-
getProgramPaths().push_back(getDriver().getInstalledDir());
201+
getProgramPaths().push_back(getDriver().Dir);
202202

203203
auto SysRoot = getDriver().SysRoot;
204204
if (getTriple().getOS() == llvm::Triple::UnknownOS) {

clang/lib/Driver/ToolChains/ZOS.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ void ZOS::AddClangCXXStdlibIncludeArgs(
325325
switch (GetCXXStdlibType(DriverArgs)) {
326326
case ToolChain::CST_Libcxx: {
327327
// <install>/bin/../include/c++/v1
328-
llvm::SmallString<128> InstallBin =
329-
llvm::StringRef(getDriver().getInstalledDir());
328+
llvm::SmallString<128> InstallBin(getDriver().Dir);
330329
llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
331330
TryAddIncludeFromPath(InstallBin, DriverArgs, CC1Args);
332331
break;

0 commit comments

Comments
 (0)