xref: /spdk/scripts/ar-xnvme-fixer (revision 9e843fdbd1f39af220e39a0a31ce33c91c89b902)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2022 Intel Corporation
4#  All rights reserved.
5
6# The xnvme build executes library_bundler.py which wraps itself around ar
7# to create libxnvme.a. It builds a set of MRI commands which then is
8# passed to ar via stdin. The set of members is declared via ADDLIB
9# followed by an absolute path to the file. On the physical nodes this
10# path may look as the following:
11#
12#   /workspace/foo-job@tmp/...
13#
14# The '@' has a special meaning for ar when spotted on the cmdline.
15# It ends up splitting the path into /workspace/foo-job treating it
16# as a member path which doesn't exist. This causes the entire build
17# to fail. To workaround this, we inject ourselves via AR_TOOL and
18# modify the MRI commands such that the absolute paths to members are
19# replaced with relative ones (relative to xnvme/builddir from where
20# the library_bundler.py is executed).
21
22curdir=$(readlink -f "$(dirname "$0")")
23rootdir=$(readlink -f "$curdir/../")
24
25[[ ! -t 0 ]] || exit 1
26
27while read -r cmd arg; do
28	if [[ $cmd == ADDLIB && $arg == /* ]]; then
29		arg=${arg/"$rootdir/xnvme/"/"../"}
30	fi
31	mri+=("$cmd${arg:+ $arg}")
32done
33
34ar "$@" < <(printf '%s\n' "${mri[@]}")
35