[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-25 Thread Benjamin Kramer via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

ship it.


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-25 Thread Michał Górny via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285074: [Driver] Support obtaining active toolchain from 
gcc-config on Gentoo (authored by mgorny).

Changed prior to commit:
  https://reviews.llvm.org/D25661?vs=75707=75710#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25661

Files:
  cfe/trunk/lib/Driver/ToolChains.cpp
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/include/.keep
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbegin.o
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/.keep
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  cfe/trunk/test/Driver/linux-header-search.cpp


Index: cfe/trunk/test/Driver/linux-header-search.cpp
===
--- cfe/trunk/test/Driver/linux-header-search.cpp
+++ cfe/trunk/test/Driver/linux-header-search.cpp
@@ -301,6 +301,15 @@
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
+// Test support for Gentoo's gcc-config -- clang should prefer the older
+// (4.9.3) version over the newer (5.4.0) due to preference specified
+// in /etc/env.d/gcc/x86_64-pc-linux-gnu.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3 %s
+//
 // Check header search on Debian 6 / MIPS64
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target mips64-unknown-linux-gnuabi64 -stdlib=libstdc++ \
Index: 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
===
--- 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
+++ 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
@@ -0,0 +1,10 @@
+PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+ROOTPATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+GCC_PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/32"
+MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/man"
+INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/info"
+STDCXX_INCDIR="g++-v4"
+CTARGET="x86_64-pc-linux-gnu"
+GCC_SPECS=""
+MULTIOSDIRS="../lib64:../lib32"
Index: 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
===
--- 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
+++ 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
@@ -0,0 +1 @@
+CURRENT=x86_64-pc-linux-gnu-4.9.3
Index: 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
===
--- 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
+++ 
cfe/trunk/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
@@ -0,0 +1 @@
+Gentoo Base System release 2.3
Index: cfe/trunk/lib/Driver/ToolChains.cpp
===
--- cfe/trunk/lib/Driver/ToolChains.cpp
+++ cfe/trunk/lib/Driver/ToolChains.cpp
@@ -1438,6 +1438,43 @@
 }
   }
 
+  // Try to respect gcc-config on Gentoo. However, do that only
+  // if --gcc-toolchain is not provided or equal to the Gentoo install
+  // in /usr. This avoids accidentally enforcing the system GCC version
+  // when using a custom toolchain.
+  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
+for (StringRef CandidateTriple : CandidateTripleAliases) {
+  llvm::ErrorOr File =
+  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
+  

[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-25 Thread Michał Górny via cfe-commits
mgorny updated this revision to Diff 75707.
mgorny marked 3 inline comments as done.
mgorny added a comment.

Thanks for the review. Implemented all three suggestions.


https://reviews.llvm.org/D25661

Files:
  lib/Driver/ToolChains.cpp
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
  test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/include/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  test/Driver/linux-header-search.cpp


Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -301,6 +301,15 @@
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
+// Test support for Gentoo's gcc-config -- clang should prefer the older
+// (4.9.3) version over the newer (5.4.0) due to preference specified
+// in /etc/env.d/gcc/x86_64-pc-linux-gnu.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3 %s
+//
 // Check header search on Debian 6 / MIPS64
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target mips64-unknown-linux-gnuabi64 -stdlib=libstdc++ \
Index: test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
===
--- /dev/null
+++ test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
@@ -0,0 +1 @@
+Gentoo Base System release 2.3
Index: 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
===
--- /dev/null
+++ 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
@@ -0,0 +1,10 @@
+PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+ROOTPATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+GCC_PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/32"
+MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/man"
+INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/info"
+STDCXX_INCDIR="g++-v4"
+CTARGET="x86_64-pc-linux-gnu"
+GCC_SPECS=""
+MULTIOSDIRS="../lib64:../lib32"
Index: 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
===
--- /dev/null
+++ 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
@@ -0,0 +1 @@
+CURRENT=x86_64-pc-linux-gnu-4.9.3
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1430,6 +1430,43 @@
 }
   }
 
+  // Try to respect gcc-config on Gentoo. However, do that only
+  // if --gcc-toolchain is not provided or equal to the Gentoo install
+  // in /usr. This avoids accidentally enforcing the system GCC version
+  // when using a custom toolchain.
+  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
+for (StringRef CandidateTriple : CandidateTripleAliases) {
+  llvm::ErrorOr File =
+  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
+  CandidateTriple.str());
+  if (File) {
+SmallVector Lines;
+File.get()->getBuffer().split(Lines, "\n");
+for (StringRef Line : Lines) {
+  // CURRENT=triple-version
+  if (Line.consume_front("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.
+const std::string GentooPath = D.SysRoot + "/usr/lib/gcc/" +
+

[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-25 Thread Benjamin Kramer via cfe-commits
bkramer added inline comments.



Comment at: lib/Driver/ToolChains.cpp:1438
+  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
+for (const StringRef& CandidateTriple : CandidateTripleAliases) {
+  llvm::ErrorOr File =

drop the const&. Using StringRef by value is fine.



Comment at: lib/Driver/ToolChains.cpp:1445
+File.get()->getBuffer().split(Lines, "\n");
+for (const StringRef& Line : Lines) {
+  // CURRENT=triple-version

drop ref



Comment at: lib/Driver/ToolChains.cpp:1447
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =

We have StringRef::consume_front now to make this more convenient.


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-17 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.



Comment at: lib/Driver/ToolChains.cpp:1446-1463
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.

mgorny wrote:
> ABataev wrote:
> > mgorny wrote:
> > > ABataev wrote:
> > > > mgorny wrote:
> > > > > ABataev wrote:
> > > > > > I think it is better to use `llvm::Triple` class here for parsing 
> > > > > > `ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT` string rather 
> > > > > > than `StringRef::split()`
> > > > > This is not parsing the triple but detaching the version appended to 
> > > > > it.
> > > > But still it is better to use some standard infrastructure rather than 
> > > > inventing a new one (with possible bugs, incompatibilities etc.) 
> > > I still don't understand what you want me to do. `llvm::Triple` does not 
> > > support triple + version thingy that is the case here. I don't need to 
> > > parse the triple, just split the version out of it.
> > Can you use Triple::getEnvironmentVersion()?
> No. This is not embedded in environment field but used as a separate 
> component following it. Triple class doesn't cover it at all.
Ok


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-17 Thread Michał Górny via cfe-commits
mgorny added inline comments.



Comment at: lib/Driver/ToolChains.cpp:1446-1463
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.

ABataev wrote:
> mgorny wrote:
> > ABataev wrote:
> > > mgorny wrote:
> > > > ABataev wrote:
> > > > > I think it is better to use `llvm::Triple` class here for parsing 
> > > > > `ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT` string rather than 
> > > > > `StringRef::split()`
> > > > This is not parsing the triple but detaching the version appended to it.
> > > But still it is better to use some standard infrastructure rather than 
> > > inventing a new one (with possible bugs, incompatibilities etc.) 
> > I still don't understand what you want me to do. `llvm::Triple` does not 
> > support triple + version thingy that is the case here. I don't need to 
> > parse the triple, just split the version out of it.
> Can you use Triple::getEnvironmentVersion()?
No. This is not embedded in environment field but used as a separate component 
following it. Triple class doesn't cover it at all.


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-17 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.



Comment at: lib/Driver/ToolChains.cpp:1446-1463
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.

mgorny wrote:
> ABataev wrote:
> > mgorny wrote:
> > > ABataev wrote:
> > > > I think it is better to use `llvm::Triple` class here for parsing 
> > > > `ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT` string rather than 
> > > > `StringRef::split()`
> > > This is not parsing the triple but detaching the version appended to it.
> > But still it is better to use some standard infrastructure rather than 
> > inventing a new one (with possible bugs, incompatibilities etc.) 
> I still don't understand what you want me to do. `llvm::Triple` does not 
> support triple + version thingy that is the case here. I don't need to parse 
> the triple, just split the version out of it.
Can you use Triple::getEnvironmentVersion()?


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-17 Thread Michał Górny via cfe-commits
mgorny added inline comments.



Comment at: lib/Driver/ToolChains.cpp:1446-1463
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.

ABataev wrote:
> mgorny wrote:
> > ABataev wrote:
> > > I think it is better to use `llvm::Triple` class here for parsing 
> > > `ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT` string rather than 
> > > `StringRef::split()`
> > This is not parsing the triple but detaching the version appended to it.
> But still it is better to use some standard infrastructure rather than 
> inventing a new one (with possible bugs, incompatibilities etc.) 
I still don't understand what you want me to do. `llvm::Triple` does not 
support triple + version thingy that is the case here. I don't need to parse 
the triple, just split the version out of it.


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-17 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.



Comment at: lib/Driver/ToolChains.cpp:1446-1463
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.

mgorny wrote:
> ABataev wrote:
> > I think it is better to use `llvm::Triple` class here for parsing 
> > `ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT` string rather than 
> > `StringRef::split()`
> This is not parsing the triple but detaching the version appended to it.
But still it is better to use some standard infrastructure rather than 
inventing a new one (with possible bugs, incompatibilities etc.) 


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-17 Thread Michał Górny via cfe-commits
mgorny updated this revision to Diff 74855.
mgorny added a comment.

Updated to use range-based for loop as suggested by @ABataev.


https://reviews.llvm.org/D25661

Files:
  lib/Driver/ToolChains.cpp
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
  test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/include/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  test/Driver/linux-header-search.cpp


Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -301,6 +301,15 @@
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
+// Test support for Gentoo's gcc-config -- clang should prefer the older
+// (4.9.3) version over the newer (5.4.0) due to preference specified
+// in /etc/env.d/gcc/x86_64-pc-linux-gnu.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3 %s
+//
 // Check header search on Debian 6 / MIPS64
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target mips64-unknown-linux-gnuabi64 -stdlib=libstdc++ \
Index: test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
===
--- /dev/null
+++ test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
@@ -0,0 +1 @@
+Gentoo Base System release 2.3
Index: 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
===
--- /dev/null
+++ 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
@@ -0,0 +1,10 @@
+PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+ROOTPATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+GCC_PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/32"
+MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/man"
+INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/info"
+STDCXX_INCDIR="g++-v4"
+CTARGET="x86_64-pc-linux-gnu"
+GCC_SPECS=""
+MULTIOSDIRS="../lib64:../lib32"
Index: 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
===
--- /dev/null
+++ 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
@@ -0,0 +1 @@
+CURRENT=x86_64-pc-linux-gnu-4.9.3
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1430,6 +1430,43 @@
 }
   }
 
+  // Try to respect gcc-config on Gentoo. However, do that only
+  // if --gcc-toolchain is not provided or equal to the Gentoo install
+  // in /usr. This avoids accidentally enforcing the system GCC version
+  // when using a custom toolchain.
+  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
+for (const StringRef& CandidateTriple : CandidateTripleAliases) {
+  llvm::ErrorOr File =
+  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
+  CandidateTriple.str());
+  if (File) {
+SmallVector Lines;
+File.get()->getBuffer().split(Lines, "\n");
+for (const StringRef& Line : Lines) {
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.
+const std::string GentooPath = D.SysRoot + "/usr/lib/gcc/" +
+

[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-17 Thread Michał Górny via cfe-commits
mgorny added inline comments.



Comment at: lib/Driver/ToolChains.cpp:1446-1463
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.

ABataev wrote:
> I think it is better to use `llvm::Triple` class here for parsing 
> `ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT` string rather than 
> `StringRef::split()`
This is not parsing the triple but detaching the version appended to it.


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-17 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.



Comment at: lib/Driver/ToolChains.cpp:1438
+  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
+for (unsigned k = 0, ke = CandidateTripleAliases.size(); k < ke; ++k) {
+  llvm::ErrorOr File =

Use range-based `for` here



Comment at: lib/Driver/ToolChains.cpp:1446-1463
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, the file doesn't
+// contain anything new or especially useful to us.

I think it is better to use `llvm::Triple` class here for parsing 
`ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT` string rather than 
`StringRef::split()`


https://reviews.llvm.org/D25661



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-16 Thread Michał Górny via cfe-commits
mgorny created this revision.
mgorny added reviewers: rafael, chandlerc, bruno, bkramer.
mgorny added a subscriber: cfe-commits.

Support using gcc-config to determine the correct GCC toolchain location
on Gentoo. In order to do that, attempt to read gcc-config configuration
form [[sysroot]]/etc/env.d/gcc, if no custom toolchain location is
provided.


https://reviews.llvm.org/D25661

Files:
  lib/Driver/ToolChains.cpp
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
  test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/include/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  test/Driver/linux-header-search.cpp


Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -301,6 +301,15 @@
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
+// Test support for Gentoo's gcc-config -- clang should prefer the older
+// (4.9.3) version over the newer (5.4.0) due to preference specified
+// in /etc/env.d/gcc/x86_64-pc-linux-gnu.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3 %s
+//
 // Check header search on Debian 6 / MIPS64
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target mips64-unknown-linux-gnuabi64 -stdlib=libstdc++ \
Index: test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
===
--- /dev/null
+++ test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
@@ -0,0 +1 @@
+Gentoo Base System release 2.3
Index: 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
===
--- /dev/null
+++ 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
@@ -0,0 +1,10 @@
+PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+ROOTPATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+GCC_PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/32"
+MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/man"
+INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/info"
+STDCXX_INCDIR="g++-v4"
+CTARGET="x86_64-pc-linux-gnu"
+GCC_SPECS=""
+MULTIOSDIRS="../lib64:../lib32"
Index: 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
===
--- /dev/null
+++ 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
@@ -0,0 +1 @@
+CURRENT=x86_64-pc-linux-gnu-4.9.3
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1430,6 +1430,43 @@
 }
   }
 
+  // Try to respect gcc-config on Gentoo. However, do that only
+  // if --gcc-toolchain is not provided or equal to the Gentoo install
+  // in /usr. This avoids accidentally enforcing the system GCC version
+  // when using a custom toolchain.
+  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
+for (unsigned k = 0, ke = CandidateTripleAliases.size(); k < ke; ++k) {
+  llvm::ErrorOr File =
+  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
+  CandidateTripleAliases[k].str());
+  if (File) {
+SmallVector Lines;
+File.get()->getBuffer().split(Lines, "\n");
+for (StringRef& Line : Lines) {
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+