[llvm-ar] Support verbose mode for operation 'x'

Reviewed By: jhenderson, kongyi

Differential Revision: https://reviews.llvm.org/D69911
This commit is contained in:
Fangrui Song 2019-11-06 10:19:30 -08:00
parent f8622543ad
commit 7d2b0ec345
2 changed files with 17 additions and 4 deletions

View File

@ -5,18 +5,27 @@ RUN: rm -rf %t && mkdir -p %t/extracted/
# Extracting from an empty archive should not warn or error:
RUN: llvm-ar cr %t/empty.a
RUN: llvm-ar x %t/empty.a 2>&1 | count 0
RUN: llvm-ar xv %t/empty.a 2>&1 | count 0
RUN: echo filea > %t/a.txt
RUN: echo fileb > %t/b.txt
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: cd %t/extracted && llvm-ar xv %t/archive.a a.txt | FileCheck %s --check-prefix=A
RUN: diff %t/a.txt %t/extracted/a.txt
A: x - a.txt
# All members:
RUN: rm %t/extracted/a.txt
RUN: cd %t/extracted && llvm-ar x %t/archive.a
RUN: cd %t/extracted && llvm-ar xv %t/archive.a | FileCheck %s --check-prefix=AB
RUN: diff %t/a.txt %t/extracted/a.txt
RUN: diff %t/b.txt %t/extracted/b.txt
AB: x - a.txt
AB: x - b.txt
# No output if 'v' is not specified.
RUN: rm a.txt b.txt
RUN: llvm-ar x %t/archive.a 2>&1 | count 0
RUN: diff %t/a.txt %t/extracted/a.txt
RUN: diff %t/b.txt %t/extracted/b.txt

View File

@ -530,8 +530,12 @@ static void doExtract(StringRef Name, const object::Archive::Child &C) {
failIfError(ModeOrErr.takeError());
sys::fs::perms Mode = ModeOrErr.get();
llvm::StringRef outputFilePath = sys::path::filename(Name);
if (Verbose)
outs() << "x - " << outputFilePath << '\n';
int FD;
failIfError(sys::fs::openFileForWrite(sys::path::filename(Name), FD,
failIfError(sys::fs::openFileForWrite(outputFilePath, FD,
sys::fs::CD_CreateAlways,
sys::fs::OF_None, Mode),
Name);