Author: Paul Robinson Date: 2023-02-01T07:40:30-08:00 New Revision: ecb3cd0946a47c419efda7b92cd6f6fcc30b6be9
URL: https://github.com/llvm/llvm-project/commit/ecb3cd0946a47c419efda7b92cd6f6fcc30b6be9 DIFF: https://github.com/llvm/llvm-project/commit/ecb3cd0946a47c419efda7b92cd6f6fcc30b6be9.diff LOG: [Driver] Move PS4/PS5 header search path management to the driver This follows how OpenBSD, FreeBSD, and NetBSD now work. (See D138183 and D140817 for those cases.) It also tidies up some code duplication that wasn't exactly right. Added: Modified: clang/lib/Driver/ToolChains/PS4CPU.cpp clang/lib/Driver/ToolChains/PS4CPU.h clang/lib/Lex/InitHeaderSearch.cpp clang/test/Driver/ps4-ps5-header-search.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp index 643f815c5835a..fc5d46bc25605 100644 --- a/clang/lib/Driver/ToolChains/PS4CPU.cpp +++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp @@ -8,6 +8,7 @@ #include "PS4CPU.h" #include "CommonArgs.h" +#include "clang/Config/config.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" @@ -253,15 +254,14 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple, // SDK include or lib directories. This behavior could be changed if // -Weverything or -Winvalid-or-nonexistent-directory options are passed. // If -isysroot was passed, use that as the SDK base path. - std::string PrefixDir; if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { - PrefixDir = A->getValue(); - if (!llvm::sys::fs::exists(PrefixDir)) - D.Diag(clang::diag::warn_missing_sysroot) << PrefixDir; + SDKRootDir = A->getValue(); + if (!llvm::sys::fs::exists(SDKRootDir)) + D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir; } else - PrefixDir = std::string(SDKDir.str()); + SDKRootDir = std::string(SDKDir.str()); - SmallString<512> SDKIncludeDir(PrefixDir); + SmallString<512> SDKIncludeDir(SDKRootDir); llvm::sys::path::append(SDKIncludeDir, "target/include"); if (!Args.hasArg(options::OPT_nostdinc) && !Args.hasArg(options::OPT_nostdlibinc) && @@ -272,7 +272,7 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple, << Twine(Platform, " system headers").str() << SDKIncludeDir; } - SmallString<512> SDKLibDir(SDKDir); + SmallString<512> SDKLibDir(SDKRootDir); llvm::sys::path::append(SDKLibDir, "target/lib"); if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs) && @@ -287,6 +287,42 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple, getFilePaths().push_back(std::string(SDKLibDir.str())); } +void toolchains::PS4PS5Base::AddClangSystemIncludeArgs( + const ArgList &DriverArgs, + ArgStringList &CC1Args) const { + const Driver &D = getDriver(); + + if (DriverArgs.hasArg(options::OPT_nostdinc)) + return; + + if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { + SmallString<128> Dir(D.ResourceDir); + llvm::sys::path::append(Dir, "include"); + addSystemInclude(DriverArgs, CC1Args, Dir.str()); + } + + if (DriverArgs.hasArg(options::OPT_nostdlibinc)) + return; + + // Add dirs specified via 'configure --with-c-include-dirs'. + StringRef CIncludeDirs(C_INCLUDE_DIRS); + if (!CIncludeDirs.empty()) { + SmallVector<StringRef, 5> dirs; + CIncludeDirs.split(dirs, ":"); + for (StringRef dir : dirs) { + StringRef Prefix = + llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : ""; + addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + } + return; + } + + addExternCSystemInclude(DriverArgs, CC1Args, + SDKRootDir + "/target/include"); + addExternCSystemInclude(DriverArgs, CC1Args, + SDKRootDir + "/target/include_common"); +} + Tool *toolchains::PS4CPU::buildAssembler() const { return new tools::PScpu::Assembler(*this); } diff --git a/clang/lib/Driver/ToolChains/PS4CPU.h b/clang/lib/Driver/ToolChains/PS4CPU.h index 954e7d8d8d684..0866a5daa4cc6 100644 --- a/clang/lib/Driver/ToolChains/PS4CPU.h +++ b/clang/lib/Driver/ToolChains/PS4CPU.h @@ -63,6 +63,9 @@ class LLVM_LIBRARY_VISIBILITY PS4PS5Base : public Generic_ELF { const llvm::opt::ArgList &Args, StringRef Platform, const char *EnvVar); + void + AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; // No support for finding a C++ standard library yet. void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override { @@ -111,6 +114,10 @@ class LLVM_LIBRARY_VISIBILITY PS4PS5Base : public Generic_ELF { protected: Tool *buildLinker() const override; + +private: + // We compute the SDK root dir in the ctor, and use it later. + std::string SDKRootDir; }; // PS4-specific Toolchain class. diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp index d4465565718ef..48345592fed83 100644 --- a/clang/lib/Lex/InitHeaderSearch.cpp +++ b/clang/lib/Lex/InitHeaderSearch.cpp @@ -233,8 +233,6 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, switch (os) { case llvm::Triple::CloudABI: case llvm::Triple::NaCl: - case llvm::Triple::PS4: - case llvm::Triple::PS5: case llvm::Triple::ELFIAMCU: break; case llvm::Triple::Win32: @@ -339,31 +337,6 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, case llvm::Triple::NaCl: case llvm::Triple::ELFIAMCU: break; - case llvm::Triple::PS4: - case llvm::Triple::PS5: { - // <isysroot> gets prepended later in AddPath(). - std::string BaseSDKPath; - if (!HasSysroot) { - const char *EnvVar = (os == llvm::Triple::PS4) ? "SCE_ORBIS_SDK_DIR" - : "SCE_PROSPERO_SDK_DIR"; - const char *envValue = getenv(EnvVar); - if (envValue) - BaseSDKPath = envValue; - else { - // HSOpts.ResourceDir variable contains the location of Clang's - // resource files. - // Assuming that Clang is configured for PS4 without - // --with-clang-resource-dir option, the location of Clang's resource - // files is <SDK_DIR>/host_tools/lib/clang - SmallString<128> P = StringRef(HSOpts.ResourceDir); - llvm::sys::path::append(P, "../../.."); - BaseSDKPath = std::string(P.str()); - } - } - AddPath(BaseSDKPath + "/target/include", System, false); - AddPath(BaseSDKPath + "/target/include_common", System, false); - break; - } default: AddPath("/usr/include", ExternCSystem, false); break; @@ -412,6 +385,8 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths( case llvm::Triple::FreeBSD: case llvm::Triple::NetBSD: case llvm::Triple::OpenBSD: + case llvm::Triple::PS4: + case llvm::Triple::PS5: case llvm::Triple::Fuchsia: case llvm::Triple::Hurd: case llvm::Triple::Linux: diff --git a/clang/test/Driver/ps4-ps5-header-search.c b/clang/test/Driver/ps4-ps5-header-search.c index 59d3f2ab2d1df..066d284d08065 100644 --- a/clang/test/Driver/ps4-ps5-header-search.c +++ b/clang/test/Driver/ps4-ps5-header-search.c @@ -1,13 +1,13 @@ /// PS4 and PS5 use the same SDK layout, so use the same tree for both. // RUN: env SCE_ORBIS_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target x86_64-scei-ps4 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4 // RUN: env SCE_PROSPERO_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target x86_64-sie-ps5 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4 -// ENVPS4: Inputs/scei-ps4_tree/target/include{{$}} -// ENVPS4: Inputs/scei-ps4_tree/target/include_common{{$}} +// ENVPS4: Inputs/scei-ps4_tree/target/include +// ENVPS4: Inputs/scei-ps4_tree/target/include_common // ENVPS4-NOT: /usr/include // RUN: %clang -isysroot %S/Inputs/scei-ps4_tree -target x86_64-scei-ps4 -E -v %s 2>&1 | FileCheck %s --check-prefix=SYSROOTPS4 // RUN: %clang -isysroot %S/Inputs/scei-ps4_tree -target x86_64-sie-ps5 -E -v %s 2>&1 | FileCheck %s --check-prefix=SYSROOTPS4 // SYSROOTPS4: "{{[^"]*}}clang{{[^"]*}}" -// SYSROOTPS4: Inputs/scei-ps4_tree/target/include{{$}} -// SYSROOTPS4: Inputs/scei-ps4_tree/target/include_common{{$}} +// SYSROOTPS4: Inputs/scei-ps4_tree/target/include +// SYSROOTPS4: Inputs/scei-ps4_tree/target/include_common // SYSROOTPS4-NOT: /usr/include _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits