[llvm] 7d2b0ec - [llvm-ar] Support verbose mode for operation 'x'
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 09:29:02 PST 2019
Author: Fangrui Song
Date: 2019-11-07T09:26:31-08:00
New Revision: 7d2b0ec345487537e37a24b323d612c7c06295cd
URL: https://github.com/llvm/llvm-project/commit/7d2b0ec345487537e37a24b323d612c7c06295cd
DIFF: https://github.com/llvm/llvm-project/commit/7d2b0ec345487537e37a24b323d612c7c06295cd.diff
LOG: [llvm-ar] Support verbose mode for operation 'x'
Reviewed By: jhenderson, kongyi
Differential Revision: https://reviews.llvm.org/D69911
Added:
Modified:
llvm/test/tools/llvm-ar/extract.test
llvm/tools/llvm-ar/llvm-ar.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-ar/extract.test b/llvm/test/tools/llvm-ar/extract.test
index a2059d1ba9e9..278a89db005a 100644
--- a/llvm/test/tools/llvm-ar/extract.test
+++ b/llvm/test/tools/llvm-ar/extract.test
@@ -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
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index c70b8814b285..18cad21f9644 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -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);
More information about the llvm-commits
mailing list