[llvm] f737865 - Revert "[llvm-config] Quote and escape paths if necessary (#97305)"

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 4 18:56:42 PDT 2024


Author: Alexandre Ganea
Date: 2024-07-04T21:55:37-04:00
New Revision: f737865be2a115955880bb398b4bf61145db26a5

URL: https://github.com/llvm/llvm-project/commit/f737865be2a115955880bb398b4bf61145db26a5
DIFF: https://github.com/llvm/llvm-project/commit/f737865be2a115955880bb398b4bf61145db26a5.diff

LOG: Revert "[llvm-config] Quote and escape paths if necessary (#97305)"

This reverts commit e8c94149d3ca12d4d02fb8de89981c68ffa278f3.

Added: 
    

Modified: 
    llvm/docs/ReleaseNotes.rst
    llvm/test/tools/llvm-config/paths.test
    llvm/tools/llvm-config/llvm-config.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 07c531934eed6..a6bfd55119398 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -369,10 +369,6 @@ Changes to the LLVM tools
   jumping in reverse direction with shift+L/R/B). (`#95662
   <https://github.com/llvm/llvm-project/pull/95662>`_).
 
-* llvm-config now quotes and escapes paths emitted in stdout, to account for
-  spaces or other special characters in path.
-  (`#97305 <https://github.com/llvm/llvm-project/pull/97305>`_).
-
 Changes to LLDB
 ---------------------------------
 

diff  --git a/llvm/test/tools/llvm-config/paths.test b/llvm/test/tools/llvm-config/paths.test
index 6fa43a1561521..419f155ae1f83 100644
--- a/llvm/test/tools/llvm-config/paths.test
+++ b/llvm/test/tools/llvm-config/paths.test
@@ -1,21 +1,21 @@
 # Check directory options for obvious issues.
 
 RUN: llvm-config --bindir 2>&1 | FileCheck --check-prefix=CHECK-BINDIR %s
-CHECK-BINDIR: {{.*}}{{/|\\\\}}bin
+CHECK-BINDIR: {{.*}}{{/|\\}}bin
 CHECK-BINDIR-NOT: error:
 CHECK-BINDIR-NOT: warning
 
 RUN: llvm-config --includedir 2>&1 | FileCheck --check-prefix=CHECK-INCLUDEDIR %s
-CHECK-INCLUDEDIR: {{.*}}{{/|\\\\}}include
+CHECK-INCLUDEDIR: {{.*}}{{/|\\}}include
 CHECK-INCLUDEDIR-NOT: error:
 CHECK-INCLUDEDIR-NOT: warning
 
 RUN: llvm-config --libdir 2>&1 | FileCheck --check-prefix=CHECK-LIBDIR %s
-CHECK-LIBDIR: {{.*}}{{/|\\\\}}lib{{.*}}
+CHECK-LIBDIR: {{.*}}{{/|\\}}lib{{.*}}
 CHECK-LIBDIR-NOT: error:
 CHECK-LIBDIR-NOT: warning
 
 RUN: llvm-config --cmakedir 2>&1 | FileCheck --check-prefix=CHECK-CMAKEDIR %s
-CHECK-CMAKEDIR: {{.*}}{{/|\\\\}}cmake{{/|\\\\}}llvm
+CHECK-CMAKEDIR: {{.*}}{{/|\\}}cmake{{/|\\}}llvm
 CHECK-CMAKEDIR-NOT: error:
 CHECK-CMAKEDIR-NOT: warning

diff  --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp
index db92d462807d0..d5b76b1bb6c16 100644
--- a/llvm/tools/llvm-config/llvm-config.cpp
+++ b/llvm/tools/llvm-config/llvm-config.cpp
@@ -24,7 +24,6 @@
 #include "llvm/Config/config.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/Program.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
@@ -327,7 +326,7 @@ int main(int argc, char **argv) {
   // information.
   std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir,
               ActiveCMakeDir;
-  std::vector<std::string> ActiveIncludeOptions;
+  std::string ActiveIncludeOption;
   if (IsInDevelopmentTree) {
     ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
     ActivePrefix = CurrentExecPrefix;
@@ -353,8 +352,8 @@ int main(int argc, char **argv) {
     }
 
     // We need to include files from both the source and object trees.
-    ActiveIncludeOptions.push_back(ActiveIncludeDir);
-    ActiveIncludeOptions.push_back(ActiveObjRoot + "/include");
+    ActiveIncludeOption =
+        ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");
   } else {
     ActivePrefix = CurrentExecPrefix;
     {
@@ -373,7 +372,7 @@ int main(int argc, char **argv) {
       sys::fs::make_absolute(ActivePrefix, Path);
       ActiveCMakeDir = std::string(Path);
     }
-    ActiveIncludeOptions.push_back(ActiveIncludeDir);
+    ActiveIncludeOption = "-I" + ActiveIncludeDir;
   }
 
   /// We only use `shared library` mode in cases where the static library form
@@ -402,8 +401,8 @@ int main(int argc, char **argv) {
       std::replace(ActiveBinDir.begin(), ActiveBinDir.end(), '/', '\\');
       std::replace(ActiveLibDir.begin(), ActiveLibDir.end(), '/', '\\');
       std::replace(ActiveCMakeDir.begin(), ActiveCMakeDir.end(), '/', '\\');
-      for (auto &Include : ActiveIncludeOptions)
-        std::replace(Include.begin(), Include.end(), '/', '\\');
+      std::replace(ActiveIncludeOption.begin(), ActiveIncludeOption.end(), '/',
+                   '\\');
     }
     SharedDir = ActiveBinDir;
     StaticDir = ActiveLibDir;
@@ -505,20 +504,6 @@ int main(int argc, char **argv) {
   };
 
   raw_ostream &OS = outs();
-
-  // Render include paths and associated flags
-  auto RenderFlags = [&](StringRef Flags) {
-    bool First = true;
-    for (auto &Include : ActiveIncludeOptions) {
-      if (!First)
-        OS << ' ';
-      OS << "-I";
-      sys::printArg(OS, Include, /*Quote=*/true);
-      First = false;
-    }
-    OS << ' ' << Flags << '\n';
-  };
-
   for (int i = 1; i != argc; ++i) {
     StringRef Arg = argv[i];
 
@@ -527,30 +512,24 @@ int main(int argc, char **argv) {
       if (Arg == "--version") {
         OS << PACKAGE_VERSION << '\n';
       } else if (Arg == "--prefix") {
-        sys::printArg(OS, ActivePrefix, /*Quote=*/true);
-        OS << '\n';
+        OS << ActivePrefix << '\n';
       } else if (Arg == "--bindir") {
-        sys::printArg(OS, ActiveBinDir, /*Quote=*/true);
-        OS << '\n';
+        OS << ActiveBinDir << '\n';
       } else if (Arg == "--includedir") {
-        sys::printArg(OS, ActiveIncludeDir, /*Quote=*/true);
-        OS << '\n';
+        OS << ActiveIncludeDir << '\n';
       } else if (Arg == "--libdir") {
-        sys::printArg(OS, ActiveLibDir, /*Quote=*/true);
-        OS << '\n';
+        OS << ActiveLibDir << '\n';
       } else if (Arg == "--cmakedir") {
-        sys::printArg(OS, ActiveCMakeDir, /*Quote=*/true);
-        OS << '\n';
+        OS << ActiveCMakeDir << '\n';
       } else if (Arg == "--cppflags") {
-        RenderFlags(LLVM_CPPFLAGS);
+        OS << ActiveIncludeOption << ' ' << LLVM_CPPFLAGS << '\n';
       } else if (Arg == "--cflags") {
-        RenderFlags(LLVM_CFLAGS);
+        OS << ActiveIncludeOption << ' ' << LLVM_CFLAGS << '\n';
       } else if (Arg == "--cxxflags") {
-        RenderFlags(LLVM_CXXFLAGS);
+        OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n';
       } else if (Arg == "--ldflags") {
-        OS << ((HostTriple.isWindowsMSVCEnvironment()) ? "-LIBPATH:" : "-L");
-        sys::printArg(OS, ActiveLibDir, /*Quote=*/true);
-        OS << ' ' << LLVM_LDFLAGS << '\n';
+        OS << ((HostTriple.isWindowsMSVCEnvironment()) ? "-LIBPATH:" : "-L")
+           << ActiveLibDir << ' ' << LLVM_LDFLAGS << '\n';
       } else if (Arg == "--system-libs") {
         PrintSystemLibs = true;
       } else if (Arg == "--libs") {
@@ -611,8 +590,7 @@ int main(int argc, char **argv) {
       } else if (Arg == "--shared-mode") {
         PrintSharedMode = true;
       } else if (Arg == "--obj-root") {
-        sys::printArg(OS, ActivePrefix, /*Quote=*/true);
-        OS << '\n';
+        OS << ActivePrefix << '\n';
       } else if (Arg == "--ignore-libllvm") {
         LinkDyLib = false;
         LinkMode = BuiltSharedLibs ? LinkModeShared : LinkModeAuto;
@@ -717,30 +695,26 @@ int main(int argc, char **argv) {
 
       auto PrintForLib = [&](const StringRef &Lib) {
         const bool Shared = LinkMode == LinkModeShared;
-        std::string LibFileName;
         if (PrintLibNames) {
-          LibFileName = GetComponentLibraryFileName(Lib, Shared);
+          OS << GetComponentLibraryFileName(Lib, Shared);
         } else if (PrintLibFiles) {
-          LibFileName = GetComponentLibraryPath(Lib, Shared);
+          OS << GetComponentLibraryPath(Lib, Shared);
         } else if (PrintLibs) {
           // On Windows, output full path to library without parameters.
           // Elsewhere, if this is a typical library name, include it using -l.
           if (HostTriple.isWindowsMSVCEnvironment()) {
-            LibFileName = GetComponentLibraryPath(Lib, Shared);
+            OS << GetComponentLibraryPath(Lib, Shared);
           } else {
-            OS << "-l";
             StringRef LibName;
             if (GetComponentLibraryNameSlice(Lib, LibName)) {
               // Extract library name (remove prefix and suffix).
-              LibFileName = LibName;
+              OS << "-l" << LibName;
             } else {
               // Lib is already a library name without prefix and suffix.
-              LibFileName = Lib;
+              OS << "-l" << Lib;
             }
           }
         }
-        if (!LibFileName.empty())
-          sys::printArg(OS, LibFileName, /*Quote=*/true);
       };
 
       if (LinkMode == LinkModeShared && LinkDyLib) {


        


More information about the llvm-commits mailing list