[libcxx-commits] [libcxx] r353671 - [libcxx] Preserve order, avoid duplicates when merging static archives

Petr Hosek via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 11 00:48:48 PST 2019


Author: phosek
Date: Mon Feb 11 00:48:47 2019
New Revision: 353671

URL: http://llvm.org/viewvc/llvm-project?rev=353671&view=rev
Log:
[libcxx] Preserve order, avoid duplicates when merging static archives

glob can return files in arbitrary order which breaks deterministic
builds. Rather, use `ar t` to list the files in each archive and
preserve the original order. Using `ar q` results in duplicate entries
in the archive, instead use `ar r` to avoid duplicates.

Differential Revision: https://reviews.llvm.org/D58024

Modified:
    libcxx/trunk/utils/merge_archives.py

Modified: libcxx/trunk/utils/merge_archives.py
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/merge_archives.py?rev=353671&r1=353670&r2=353671&view=diff
==============================================================================
--- libcxx/trunk/utils/merge_archives.py (original)
+++ libcxx/trunk/utils/merge_archives.py Mon Feb 11 00:48:47 2019
@@ -78,6 +78,7 @@ def execute_command_verbose(cmd, cwd=Non
         sys.stderr.write('%s\n' % report)
         if exitCode != 0:
             exit_with_cleanups(exitCode)
+    return out
 
 def main():
     parser = ArgumentParser(
@@ -119,15 +120,15 @@ def main():
     global temp_directory_root
     temp_directory_root = tempfile.mkdtemp('.libcxx.merge.archives')
 
+    files = []
     for arc in archives:
-        execute_command_verbose([ar_exe, 'x', arc], cwd=temp_directory_root,
-                                verbose=args.verbose)
+        execute_command_verbose([ar_exe, 'x', arc],
+                                cwd=temp_directory_root, verbose=args.verbose)
+        out = execute_command_verbose([ar_exe, 't', arc])
+        files.extend(out.splitlines())
 
-    files = glob.glob(os.path.join(temp_directory_root, '*.o*'))
-    if not files:
-        print_and_exit('Failed to glob for %s' % temp_directory_root)
-    cmd = [ar_exe, 'qcs', args.output] + files
-    execute_command_verbose(cmd, cwd=temp_directory_root, verbose=args.verbose)
+    execute_command_verbose([ar_exe, 'rcsD', args.output] + files,
+                            cwd=temp_directory_root, verbose=args.verbose)
 
 
 if __name__ == '__main__':




More information about the libcxx-commits mailing list