Index: llvm/test/tools/llvm-ar/extract.test =================================================================== --- llvm/test/tools/llvm-ar/extract.test +++ llvm/test/tools/llvm-ar/extract.test @@ -12,11 +12,11 @@ RUN: llvm-ar rc %t/archive.a %t/a.txt %t/b.txt # Single member: -RUN: cd %t/extracted && llvm-ar x %t/archive.a a.txt +RUN: llvm-ar --output=%t/extracted x %t/archive.a a.txt RUN: diff %t/a.txt %t/extracted/a.txt # All members: RUN: rm %t/extracted/a.txt -RUN: cd %t/extracted && llvm-ar x %t/archive.a +RUN: llvm-ar --output=%t/extracted x %t/archive.a RUN: diff %t/a.txt %t/extracted/a.txt RUN: diff %t/b.txt %t/extracted/b.txt Index: llvm/tools/llvm-ar/llvm-ar.cpp =================================================================== --- llvm/tools/llvm-ar/llvm-ar.cpp +++ llvm/tools/llvm-ar/llvm-ar.cpp @@ -80,6 +80,7 @@ =gnu - gnu =darwin - darwin =bsd - bsd + --output= - directory extract to --plugin= - ignored for compatibility -h --help - display this help and exit --version - print the version and exit @@ -171,6 +172,7 @@ } static Format FormatType = Default; +static std::string outputPath; static std::string Options; @@ -425,6 +427,8 @@ "operations"); if (OriginalDates && Operation != Extract) fail("the 'o' modifier is only applicable to the 'x' operation"); + if (!outputPath.empty() && Operation != Extract) + fail("the 'output' option is only applicable to the 'x' operation"); if (OnlyUpdate && Operation != ReplaceOrInsert) fail("the 'u' modifier is only applicable to the 'r' operation"); if (AddLibrary && Operation != QuickAppend) @@ -531,7 +535,10 @@ sys::fs::perms Mode = ModeOrErr.get(); int FD; - failIfError(sys::fs::openFileForWrite(sys::path::filename(Name), FD, + std::string outputFilePath = sys::path::filename(Name); + if (!outputPath.empty()) + outputFilePath = outputPath + '/' + outputFilePath; + failIfError(sys::fs::openFileForWrite(outputFilePath, FD, sys::fs::CD_CreateAlways, sys::fs::OF_None, Mode), Name); @@ -1130,6 +1137,8 @@ .Default(Unknown); if (FormatType == Unknown) fail(std::string("Invalid format ") + match); + } else if (MatchFlagWithArg("output")) { + outputPath = match; } else if (MatchFlagWithArg("plugin")) { // Ignored. } else {