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