[llvm] a45409d - [Clang] Move clang::Job::printArg to llvm::sys::printArg. NFCI.
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 18 06:17:38 PDT 2020
Author: Alexandre Ganea
Date: 2020-06-18T09:17:13-04:00
New Revision: a45409d8855a1e4538990507ef25e9b51c090193
URL: https://github.com/llvm/llvm-project/commit/a45409d8855a1e4538990507ef25e9b51c090193
DIFF: https://github.com/llvm/llvm-project/commit/a45409d8855a1e4538990507ef25e9b51c090193.diff
LOG: [Clang] Move clang::Job::printArg to llvm::sys::printArg. NFCI.
This patch is to support/simplify https://reviews.llvm.org/D80833
Added:
Modified:
clang/include/clang/Driver/Job.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/Job.cpp
llvm/include/llvm/Support/Program.h
llvm/lib/Support/Program.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Job.h b/clang/include/clang/Driver/Job.h
index 9a3cad23363b..1c6ea6971919 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -128,9 +128,6 @@ class Command {
const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
- /// Print a command argument, and optionally quote it.
- static void printArg(llvm::raw_ostream &OS, StringRef Arg, bool Quote);
-
protected:
/// Optionally print the filenames to be compiled
void PrintFileNames() const;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a8442d2cd0af..a48761af400f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1167,7 +1167,7 @@ static void printArgList(raw_ostream &OS, const llvm::opt::ArgList &Args) {
for (auto I = ASL.begin(), E = ASL.end(); I != E; ++I) {
if (I != ASL.begin())
OS << ' ';
- Command::printArg(OS, *I, true);
+ llvm::sys::printArg(OS, *I, true);
}
OS << '\n';
}
diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index 6d1e7e61ba1d..274bda9dc9f1 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -100,24 +100,6 @@ static bool skipArgs(const char *Flag, bool HaveCrashVFS, int &SkipNum,
return false;
}
-void Command::printArg(raw_ostream &OS, StringRef Arg, bool Quote) {
- const bool Escape = Arg.find_first_of(" \"\\$") != StringRef::npos;
-
- if (!Quote && !Escape) {
- OS << Arg;
- return;
- }
-
- // Quote and escape. This isn't really complete, but good enough.
- OS << '"';
- for (const auto c : Arg) {
- if (c == '"' || c == '\\' || c == '$')
- OS << '\\';
- OS << c;
- }
- OS << '"';
-}
-
void Command::writeResponseFile(raw_ostream &OS) const {
// In a file list, we only write the set of inputs to the response file
if (Creator.getResponseFilesSupport() == Tool::RF_FileList) {
@@ -217,7 +199,7 @@ void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
CrashReportInfo *CrashInfo) const {
// Always quote the exe.
OS << ' ';
- printArg(OS, Executable, /*Quote=*/true);
+ llvm::sys::printArg(OS, Executable, /*Quote=*/true);
ArrayRef<const char *> Args = Arguments;
SmallVector<const char *, 128> ArgsRespFile;
@@ -245,7 +227,7 @@ void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
if (!NewIncFlags.empty()) {
for (auto &F : NewIncFlags) {
OS << ' ';
- printArg(OS, F.c_str(), Quote);
+ llvm::sys::printArg(OS, F.c_str(), Quote);
}
i += NumArgs - 1;
continue;
@@ -259,20 +241,20 @@ void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
// Replace the input file name with the crashinfo's file name.
OS << ' ';
StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
- printArg(OS, ShortName.str(), Quote);
+ llvm::sys::printArg(OS, ShortName.str(), Quote);
continue;
}
}
OS << ' ';
- printArg(OS, Arg, Quote);
+ llvm::sys::printArg(OS, Arg, Quote);
}
if (CrashInfo && HaveCrashVFS) {
OS << ' ';
- printArg(OS, "-ivfsoverlay", Quote);
+ llvm::sys::printArg(OS, "-ivfsoverlay", Quote);
OS << ' ';
- printArg(OS, CrashInfo->VFSPath.str(), Quote);
+ llvm::sys::printArg(OS, CrashInfo->VFSPath.str(), Quote);
// The leftover modules from the crash are stored in
// <name>.cache/vfs/modules
@@ -287,7 +269,7 @@ void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
ModCachePath.append(RelModCacheDir.c_str());
OS << ' ';
- printArg(OS, ModCachePath, Quote);
+ llvm::sys::printArg(OS, ModCachePath, Quote);
}
if (ResponseFile != nullptr) {
diff --git a/llvm/include/llvm/Support/Program.h b/llvm/include/llvm/Support/Program.h
index ff4777ebecee..ce0b6db5705f 100644
--- a/llvm/include/llvm/Support/Program.h
+++ b/llvm/include/llvm/Support/Program.h
@@ -210,6 +210,9 @@ namespace sys {
/// stored.
);
+ /// Print a command argument, and optionally quote it.
+ void printArg(llvm::raw_ostream &OS, StringRef Arg, bool Quote);
+
#if defined(_WIN32)
/// Given a list of command line arguments, quote and escape them as necessary
/// to build a single flat command line appropriate for calling CreateProcess
diff --git a/llvm/lib/Support/Program.cpp b/llvm/lib/Support/Program.cpp
index d90cb450d9f5..5294f65bd5a5 100644
--- a/llvm/lib/Support/Program.cpp
+++ b/llvm/lib/Support/Program.cpp
@@ -13,6 +13,7 @@
#include "llvm/Support/Program.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/raw_ostream.h"
#include <system_error>
using namespace llvm;
using namespace sys;
@@ -75,6 +76,24 @@ bool sys::commandLineFitsWithinSystemLimits(StringRef Program,
return commandLineFitsWithinSystemLimits(Program, StringRefArgs);
}
+void sys::printArg(raw_ostream &OS, StringRef Arg, bool Quote) {
+ const bool Escape = Arg.find_first_of(" \"\\$") != StringRef::npos;
+
+ if (!Quote && !Escape) {
+ OS << Arg;
+ return;
+ }
+
+ // Quote and escape. This isn't really complete, but good enough.
+ OS << '"';
+ for (const auto c : Arg) {
+ if (c == '"' || c == '\\' || c == '$')
+ OS << '\\';
+ OS << c;
+ }
+ OS << '"';
+}
+
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#include "Unix/Program.inc"
More information about the llvm-commits
mailing list