blob: dcc623e3ed51bb1dad47ded9b69c39d59f22fbdf [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001#!/usr/bin/env python3
2#
3# Wrapper around 'ar' that defaults to deterministic archives
4
5import os
6import shutil
7import sys
8
9# calculate path to the real 'ar'
10path = os.environ['PATH']
11path = path.replace(os.path.dirname(sys.argv[0]), '')
12real_ar = shutil.which('ar', path=path)
13
14if len(sys.argv) == 1:
15 os.execl(real_ar, 'ar')
16
17# modify args to mimic 'ar' configured with --default-deterministic-archives
18argv = sys.argv
19if argv[1].startswith('--'):
20 # No modifier given
21 None
22else:
23 # remove the optional '-'
24 if argv[1][0] == '-':
25 argv[1] = argv[1][1:]
26 if 'U' in argv[1]:
27 sys.stderr.write("ar: non-deterministic mode requested\n")
28 else:
29 argv[1] = argv[1].replace('u', '')
30 argv[1] = 'D' + argv[1]
31
32os.execv(real_ar, argv)