From: Reid Kleckner Date: Fri, 31 Mar 2017 21:10:53 +0000 (+0000) Subject: [llvm-ar] Extract objects to their basename in the CWD X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=761a817d0608cc9af9c1f73df0c69b514266c8f1;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299264 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/llvm-ar/Inputs/absolute-paths.lib b/test/tools/llvm-ar/Inputs/absolute-paths.lib new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/tools/llvm-ar/absolute-paths.test b/test/tools/llvm-ar/absolute-paths.test new file mode 100644 index 00000000000..0b42d7d2dcb --- /dev/null +++ b/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/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 6d7c1c1c546..17e78a6bf96 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/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);