Skip to content

Commit f737865

Browse files
committed
Revert "[llvm-config] Quote and escape paths if necessary (llvm#97305)"
This reverts commit e8c9414.
1 parent 8419da8 commit f737865

File tree

3 files changed

+26
-56
lines changed

3 files changed

+26
-56
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,6 @@ Changes to the LLVM tools
369369
jumping in reverse direction with shift+L/R/B). (`#95662
370370
<https://github.com/llvm/llvm-project/pull/95662>`_).
371371

372-
* llvm-config now quotes and escapes paths emitted in stdout, to account for
373-
spaces or other special characters in path.
374-
(`#97305 <https://github.com/llvm/llvm-project/pull/97305>`_).
375-
376372
Changes to LLDB
377373
---------------------------------
378374

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Check directory options for obvious issues.
22

33
RUN: llvm-config --bindir 2>&1 | FileCheck --check-prefix=CHECK-BINDIR %s
4-
CHECK-BINDIR: {{.*}}{{/|\\\\}}bin
4+
CHECK-BINDIR: {{.*}}{{/|\\}}bin
55
CHECK-BINDIR-NOT: error:
66
CHECK-BINDIR-NOT: warning
77

88
RUN: llvm-config --includedir 2>&1 | FileCheck --check-prefix=CHECK-INCLUDEDIR %s
9-
CHECK-INCLUDEDIR: {{.*}}{{/|\\\\}}include
9+
CHECK-INCLUDEDIR: {{.*}}{{/|\\}}include
1010
CHECK-INCLUDEDIR-NOT: error:
1111
CHECK-INCLUDEDIR-NOT: warning
1212

1313
RUN: llvm-config --libdir 2>&1 | FileCheck --check-prefix=CHECK-LIBDIR %s
14-
CHECK-LIBDIR: {{.*}}{{/|\\\\}}lib{{.*}}
14+
CHECK-LIBDIR: {{.*}}{{/|\\}}lib{{.*}}
1515
CHECK-LIBDIR-NOT: error:
1616
CHECK-LIBDIR-NOT: warning
1717

1818
RUN: llvm-config --cmakedir 2>&1 | FileCheck --check-prefix=CHECK-CMAKEDIR %s
19-
CHECK-CMAKEDIR: {{.*}}{{/|\\\\}}cmake{{/|\\\\}}llvm
19+
CHECK-CMAKEDIR: {{.*}}{{/|\\}}cmake{{/|\\}}llvm
2020
CHECK-CMAKEDIR-NOT: error:
2121
CHECK-CMAKEDIR-NOT: warning

llvm/tools/llvm-config/llvm-config.cpp

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "llvm/Config/config.h"
2525
#include "llvm/Support/FileSystem.h"
2626
#include "llvm/Support/Path.h"
27-
#include "llvm/Support/Program.h"
2827
#include "llvm/Support/WithColor.h"
2928
#include "llvm/Support/raw_ostream.h"
3029
#include "llvm/TargetParser/Triple.h"
@@ -327,7 +326,7 @@ int main(int argc, char **argv) {
327326
// information.
328327
std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir,
329328
ActiveCMakeDir;
330-
std::vector<std::string> ActiveIncludeOptions;
329+
std::string ActiveIncludeOption;
331330
if (IsInDevelopmentTree) {
332331
ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
333332
ActivePrefix = CurrentExecPrefix;
@@ -353,8 +352,8 @@ int main(int argc, char **argv) {
353352
}
354353

355354
// We need to include files from both the source and object trees.
356-
ActiveIncludeOptions.push_back(ActiveIncludeDir);
357-
ActiveIncludeOptions.push_back(ActiveObjRoot + "/include");
355+
ActiveIncludeOption =
356+
("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");
358357
} else {
359358
ActivePrefix = CurrentExecPrefix;
360359
{
@@ -373,7 +372,7 @@ int main(int argc, char **argv) {
373372
sys::fs::make_absolute(ActivePrefix, Path);
374373
ActiveCMakeDir = std::string(Path);
375374
}
376-
ActiveIncludeOptions.push_back(ActiveIncludeDir);
375+
ActiveIncludeOption = "-I" + ActiveIncludeDir;
377376
}
378377

379378
/// We only use `shared library` mode in cases where the static library form
@@ -402,8 +401,8 @@ int main(int argc, char **argv) {
402401
std::replace(ActiveBinDir.begin(), ActiveBinDir.end(), '/', '\\');
403402
std::replace(ActiveLibDir.begin(), ActiveLibDir.end(), '/', '\\');
404403
std::replace(ActiveCMakeDir.begin(), ActiveCMakeDir.end(), '/', '\\');
405-
for (auto &Include : ActiveIncludeOptions)
406-
std::replace(Include.begin(), Include.end(), '/', '\\');
404+
std::replace(ActiveIncludeOption.begin(), ActiveIncludeOption.end(), '/',
405+
'\\');
407406
}
408407
SharedDir = ActiveBinDir;
409408
StaticDir = ActiveLibDir;
@@ -505,20 +504,6 @@ int main(int argc, char **argv) {
505504
};
506505

507506
raw_ostream &OS = outs();
508-
509-
// Render include paths and associated flags
510-
auto RenderFlags = [&](StringRef Flags) {
511-
bool First = true;
512-
for (auto &Include : ActiveIncludeOptions) {
513-
if (!First)
514-
OS << ' ';
515-
OS << "-I";
516-
sys::printArg(OS, Include, /*Quote=*/true);
517-
First = false;
518-
}
519-
OS << ' ' << Flags << '\n';
520-
};
521-
522507
for (int i = 1; i != argc; ++i) {
523508
StringRef Arg = argv[i];
524509

@@ -527,30 +512,24 @@ int main(int argc, char **argv) {
527512
if (Arg == "--version") {
528513
OS << PACKAGE_VERSION << '\n';
529514
} else if (Arg == "--prefix") {
530-
sys::printArg(OS, ActivePrefix, /*Quote=*/true);
531-
OS << '\n';
515+
OS << ActivePrefix << '\n';
532516
} else if (Arg == "--bindir") {
533-
sys::printArg(OS, ActiveBinDir, /*Quote=*/true);
534-
OS << '\n';
517+
OS << ActiveBinDir << '\n';
535518
} else if (Arg == "--includedir") {
536-
sys::printArg(OS, ActiveIncludeDir, /*Quote=*/true);
537-
OS << '\n';
519+
OS << ActiveIncludeDir << '\n';
538520
} else if (Arg == "--libdir") {
539-
sys::printArg(OS, ActiveLibDir, /*Quote=*/true);
540-
OS << '\n';
521+
OS << ActiveLibDir << '\n';
541522
} else if (Arg == "--cmakedir") {
542-
sys::printArg(OS, ActiveCMakeDir, /*Quote=*/true);
543-
OS << '\n';
523+
OS << ActiveCMakeDir << '\n';
544524
} else if (Arg == "--cppflags") {
545-
RenderFlags(LLVM_CPPFLAGS);
525+
OS << ActiveIncludeOption << ' ' << LLVM_CPPFLAGS << '\n';
546526
} else if (Arg == "--cflags") {
547-
RenderFlags(LLVM_CFLAGS);
527+
OS << ActiveIncludeOption << ' ' << LLVM_CFLAGS << '\n';
548528
} else if (Arg == "--cxxflags") {
549-
RenderFlags(LLVM_CXXFLAGS);
529+
OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n';
550530
} else if (Arg == "--ldflags") {
551-
OS << ((HostTriple.isWindowsMSVCEnvironment()) ? "-LIBPATH:" : "-L");
552-
sys::printArg(OS, ActiveLibDir, /*Quote=*/true);
553-
OS << ' ' << LLVM_LDFLAGS << '\n';
531+
OS << ((HostTriple.isWindowsMSVCEnvironment()) ? "-LIBPATH:" : "-L")
532+
<< ActiveLibDir << ' ' << LLVM_LDFLAGS << '\n';
554533
} else if (Arg == "--system-libs") {
555534
PrintSystemLibs = true;
556535
} else if (Arg == "--libs") {
@@ -611,8 +590,7 @@ int main(int argc, char **argv) {
611590
} else if (Arg == "--shared-mode") {
612591
PrintSharedMode = true;
613592
} else if (Arg == "--obj-root") {
614-
sys::printArg(OS, ActivePrefix, /*Quote=*/true);
615-
OS << '\n';
593+
OS << ActivePrefix << '\n';
616594
} else if (Arg == "--ignore-libllvm") {
617595
LinkDyLib = false;
618596
LinkMode = BuiltSharedLibs ? LinkModeShared : LinkModeAuto;
@@ -717,30 +695,26 @@ int main(int argc, char **argv) {
717695

718696
auto PrintForLib = [&](const StringRef &Lib) {
719697
const bool Shared = LinkMode == LinkModeShared;
720-
std::string LibFileName;
721698
if (PrintLibNames) {
722-
LibFileName = GetComponentLibraryFileName(Lib, Shared);
699+
OS << GetComponentLibraryFileName(Lib, Shared);
723700
} else if (PrintLibFiles) {
724-
LibFileName = GetComponentLibraryPath(Lib, Shared);
701+
OS << GetComponentLibraryPath(Lib, Shared);
725702
} else if (PrintLibs) {
726703
// On Windows, output full path to library without parameters.
727704
// Elsewhere, if this is a typical library name, include it using -l.
728705
if (HostTriple.isWindowsMSVCEnvironment()) {
729-
LibFileName = GetComponentLibraryPath(Lib, Shared);
706+
OS << GetComponentLibraryPath(Lib, Shared);
730707
} else {
731-
OS << "-l";
732708
StringRef LibName;
733709
if (GetComponentLibraryNameSlice(Lib, LibName)) {
734710
// Extract library name (remove prefix and suffix).
735-
LibFileName = LibName;
711+
OS << "-l" << LibName;
736712
} else {
737713
// Lib is already a library name without prefix and suffix.
738-
LibFileName = Lib;
714+
OS << "-l" << Lib;
739715
}
740716
}
741717
}
742-
if (!LibFileName.empty())
743-
sys::printArg(OS, LibFileName, /*Quote=*/true);
744718
};
745719

746720
if (LinkMode == LinkModeShared && LinkDyLib) {

0 commit comments

Comments
 (0)