summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2011-08-26 21:28:44 +0000
committerChad Rosier <mcrosier@apple.com>2011-08-26 21:28:44 +0000
commit39ab743e59634dfda9a936f7bc0fa99e1aba2326 (patch)
treef7cd6dfca9560a74f071b9943b3bc71c8aab5479 /clang/lib/Driver/Driver.cpp
parentf337ae9477c79788c76e896e65da316d6f987887 (diff)
downloadbcm5719-llvm-39ab743e59634dfda9a936f7bc0fa99e1aba2326.tar.gz
bcm5719-llvm-39ab743e59634dfda9a936f7bc0fa99e1aba2326.zip
[driver] When generating temporary files allow a prefix to be added. In many
cases we want the prefix to be the original file name less the suffix. For an input such as test.c to named temporary would be something like test-3O4Clq.o Part of <rdar://problem/8314451> llvm-svn: 138662
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r--clang/lib/Driver/Driver.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 2baed75e0c1..acdfdc21a25 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1335,6 +1335,15 @@ void Driver::BuildJobsForAction(Compilation &C,
}
}
+// Strip the directory and suffix from BaseInput.
+static const char *getBaseName (const char *BaseInput) {
+ std::pair<StringRef, StringRef> Split = StringRef(BaseInput).rsplit('/');
+ if (Split.second != "")
+ return Split.second.split('.').first.str().c_str();
+ else
+ return Split.first.split('.').first.str().c_str();
+}
+
const char *Driver::GetNamedOutputPath(Compilation &C,
const JobAction &JA,
const char *BaseInput,
@@ -1355,7 +1364,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
if ((!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) ||
CCGenDiagnostics) {
std::string TmpName =
- GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
+ GetTemporaryPath(getBaseName(BaseInput),
+ types::getTypeTempSuffix(JA.getType()));
return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
}
@@ -1388,9 +1398,10 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
// If we're saving temps and the temp filename conflicts with the input
// filename, then avoid overwriting input file.
if (!AtTopLevel && C.getArgs().hasArg(options::OPT_save_temps) &&
- NamedOutput == BaseName) {
+ NamedOutput == BaseName) {
std::string TmpName =
- GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
+ GetTemporaryPath(getBaseName(BaseInput),
+ types::getTypeTempSuffix(JA.getType()));
return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
}
@@ -1475,7 +1486,8 @@ std::string Driver::GetProgramPath(const char *Name, const ToolChain &TC,
return Name;
}
-std::string Driver::GetTemporaryPath(const char *Suffix) const {
+std::string Driver::GetTemporaryPath(const char *Prefix, const char *Suffix)
+ const {
// FIXME: This is lame; sys::Path should provide this function (in particular,
// it should know how to find the temporary files dir).
std::string Error;
@@ -1487,7 +1499,7 @@ std::string Driver::GetTemporaryPath(const char *Suffix) const {
if (!TmpDir)
TmpDir = "/tmp";
llvm::sys::Path P(TmpDir);
- P.appendComponent("cc");
+ P.appendComponent(Prefix);
if (P.makeUnique(false, &Error)) {
Diag(clang::diag::err_drv_unable_to_make_temp) << Error;
return "";
OpenPOWER on IntegriCloud