summaryrefslogtreecommitdiff
path: root/upstream-layers/openembedded-core/scripts/native-intercept/ar
blob: fd266c19d47e0a7e8cc31076f186078c739aa506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
#
# Wrapper around 'ar' that defaults to deterministic archives

import os
import shutil
import sys

# calculate path to the real 'ar'
path = os.environ['PATH']
path = path.replace(os.path.dirname(sys.argv[0]), '')
real_ar = shutil.which('ar', path=path)

if len(sys.argv) == 1:
    os.execl(real_ar, 'ar')

# modify args to mimic 'ar' configured with --default-deterministic-archives
argv = sys.argv
if argv[1].startswith('--'):
    # No modifier given
    None
elif argv[1][0] == '@':
    # Reading parameters from @file, we can try to inject D on the first line as well
    # but modifying input files seems a bit too far for this intercept, bazel-native
    # uses it but with rcsD by default
    None
else:
    # remove the optional '-'
    if argv[1][0] == '-':
        argv[1] = argv[1][1:]
    if 'U' in argv[1]:
        sys.stderr.write("ar: non-deterministic mode requested\n")
    else:
        argv[1] = argv[1].replace('u', '')
        argv[1] = 'D' + argv[1]

os.execv(real_ar, argv)