Skip to content

Commit a009fa7

Browse files
authored
[Driver] Some improvements for path handling on NetBSD (#66863)
- Make use of concat macro with various paths - Replace usage of = with SysRoot
1 parent cc3491f commit a009fa7

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

clang/lib/Driver/ToolChains/NetBSD.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
360360
// what all logic is needed to emulate the '=' prefix here.
361361
switch (Triple.getArch()) {
362362
case llvm::Triple::x86:
363-
getFilePaths().push_back("=/usr/lib/i386");
363+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/i386"));
364364
break;
365365
case llvm::Triple::arm:
366366
case llvm::Triple::armeb:
@@ -369,35 +369,35 @@ NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
369369
switch (Triple.getEnvironment()) {
370370
case llvm::Triple::EABI:
371371
case llvm::Triple::GNUEABI:
372-
getFilePaths().push_back("=/usr/lib/eabi");
372+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/eabi"));
373373
break;
374374
case llvm::Triple::EABIHF:
375375
case llvm::Triple::GNUEABIHF:
376-
getFilePaths().push_back("=/usr/lib/eabihf");
376+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/eabihf"));
377377
break;
378378
default:
379-
getFilePaths().push_back("=/usr/lib/oabi");
379+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/oabi"));
380380
break;
381381
}
382382
break;
383383
case llvm::Triple::mips64:
384384
case llvm::Triple::mips64el:
385385
if (tools::mips::hasMipsAbiArg(Args, "o32"))
386-
getFilePaths().push_back("=/usr/lib/o32");
386+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/o32"));
387387
else if (tools::mips::hasMipsAbiArg(Args, "64"))
388-
getFilePaths().push_back("=/usr/lib/64");
388+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/64"));
389389
break;
390390
case llvm::Triple::ppc:
391-
getFilePaths().push_back("=/usr/lib/powerpc");
391+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/powerpc"));
392392
break;
393393
case llvm::Triple::sparc:
394-
getFilePaths().push_back("=/usr/lib/sparc");
394+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/sparc"));
395395
break;
396396
default:
397397
break;
398398
}
399399

400-
getFilePaths().push_back("=/usr/lib");
400+
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
401401
}
402402
}
403403

@@ -467,11 +467,11 @@ void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
467467
llvm::opt::ArgStringList &CC1Args) const {
468468
const std::string Candidates[] = {
469469
// directory relative to build tree
470-
getDriver().Dir + "/../include/c++/v1",
470+
concat(getDriver().Dir, "/../include/c++/v1"),
471471
// system install with full upstream path
472-
getDriver().SysRoot + "/usr/include/c++/v1",
472+
concat(getDriver().SysRoot, "/usr/include/c++/v1"),
473473
// system install from src
474-
getDriver().SysRoot + "/usr/include/c++",
474+
concat(getDriver().SysRoot, "/usr/include/c++"),
475475
};
476476

477477
for (const auto &IncludePath : Candidates) {
@@ -486,7 +486,7 @@ void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
486486

487487
void NetBSD::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
488488
llvm::opt::ArgStringList &CC1Args) const {
489-
addLibStdCXXIncludePaths(getDriver().SysRoot + "/usr/include/g++", "", "",
489+
addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/g++"), "", "",
490490
DriverArgs, CC1Args);
491491
}
492492

clang/test/Driver/Inputs/basic_netbsd_tree/usr/include/g++/.keep

Whitespace-only changes.

clang/test/Driver/netbsd.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,14 @@
264264
// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
265265
// DRIVER-PASS-INCLUDES: "-internal-isystem" "[[RESOURCE]]{{/|\\\\}}include"
266266
// DRIVER-PASS-INCLUDES: "-internal-externc-isystem" "{{.*}}/usr/include"
267+
268+
// Test NetBSD with libstdc++ when the sysroot path ends with `/`.
269+
// RUN: %clangxx -### %s 2>&1 \
270+
// RUN: --target=x86_64-unknown-netbsd \
271+
// RUN: -stdlib=libstdc++ \
272+
// RUN: --sysroot=%S/Inputs/basic_netbsd_tree/ \
273+
// RUN: --gcc-toolchain="" \
274+
// RUN: | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH %s
275+
// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-cc1"
276+
// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
277+
// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/g++"

0 commit comments

Comments
 (0)