From f6e8c4dd29d23305d284fded62bdb519c739fc0f Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 31 Mar 2017 21:10:53 +0000 Subject: [PATCH] [llvm-ar] Extract objects to their basename in the CWD This is helpful when extracting objects from archives produced by MSVC's lib.exe, which users absolute paths to describe the archive members. llvm-svn: 299264 --- llvm/test/tools/llvm-ar/Inputs/absolute-paths.lib | 0 llvm/test/tools/llvm-ar/absolute-paths.test | 20 ++++++++++++++++++++ llvm/tools/llvm-ar/llvm-ar.cpp | 4 +++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 llvm/test/tools/llvm-ar/Inputs/absolute-paths.lib create mode 100644 llvm/test/tools/llvm-ar/absolute-paths.test diff --git a/llvm/test/tools/llvm-ar/Inputs/absolute-paths.lib b/llvm/test/tools/llvm-ar/Inputs/absolute-paths.lib new file mode 100644 index 0000000..e69de29 diff --git a/llvm/test/tools/llvm-ar/absolute-paths.test b/llvm/test/tools/llvm-ar/absolute-paths.test new file mode 100644 index 0000000..0b42d7d --- /dev/null +++ b/llvm/test/tools/llvm-ar/absolute-paths.test @@ -0,0 +1,20 @@ +MSVC's lib.exe produces archives with absolute paths to the members. It's useful +for llvm-ar to extract them to their basename in the CWD, since usually the +directories in the path in the archive won't exist during archive extraction. + +Get a temp clean cwd to extract into. +RUN: rm -rf %t && mkdir %t && cd %t + +RUN: llvm-ar t %S/Inputs/absolute-paths.lib | FileCheck %s --check-prefix=CHECK-LIST +CHECK-LIST: C:/src/llvm-project/build/dne/b.o +CHECK-LIST: C:/src/llvm-project/build/dne/a.o + +Check that a.o comes out and defines foo. +RUN: llvm-ar x %S/Inputs/absolute-paths.lib 'C:/src/llvm-project/build/dne/a.o' +RUN: llvm-nm a.o | FileCheck %s --check-prefix=CHECK-A +CHECK-A: T foo + +Check that b.o comes out and defines bar. +RUN: llvm-ar x %S/Inputs/absolute-paths.lib C:/src/llvm-project/build/dne/b.o +RUN: llvm-nm b.o | FileCheck %s --check-prefix=CHECK-B +CHECK-B: T bar diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index 6d7c1c1..17e78a6b 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -377,7 +377,9 @@ static void doExtract(StringRef Name, const object::Archive::Child &C) { sys::fs::perms Mode = ModeOrErr.get(); int FD; - failIfError(sys::fs::openFileForWrite(Name, FD, sys::fs::F_None, Mode), Name); + failIfError(sys::fs::openFileForWrite(sys::path::filename(Name), FD, + sys::fs::F_None, Mode), + Name); { raw_fd_ostream file(FD, false); -- 2.7.4