buildtools: support object file extraction for Windows

clang archiver tool is llvm-ar on Windows and ar on other platforms.
MinGW always uses ar. Replace shell script (Unix-only) that calls ar
with a Python script (OS-independent) that calls an appropriate archiver
tool selected at configuration time. Move the logic not to generate
empty sources into pmdinfogen.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
This commit is contained in:
Dmitry Kozlyuk 2021-01-08 05:47:22 +03:00 committed by Thomas Monjalon
parent 0fe5c4e5ad
commit e6e9730c70
5 changed files with 35 additions and 17 deletions

View File

@ -99,7 +99,6 @@ F: meson.build
F: meson_options.txt F: meson_options.txt
F: config/ F: config/
F: buildtools/call-sphinx-build.py F: buildtools/call-sphinx-build.py
F: buildtools/gen-pmdinfo-cfile.sh
F: buildtools/list-dir-globs.py F: buildtools/list-dir-globs.py
F: buildtools/pkg-config/ F: buildtools/pkg-config/
F: buildtools/symlink-drivers-solibs.sh F: buildtools/symlink-drivers-solibs.sh
@ -135,6 +134,7 @@ Driver information
M: Neil Horman <nhorman@tuxdriver.com> M: Neil Horman <nhorman@tuxdriver.com>
M: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> M: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
F: buildtools/coff.py F: buildtools/coff.py
F: buildtools/gen-pmdinfo-cfile.py
F: buildtools/pmdinfogen.py F: buildtools/pmdinfogen.py
F: usertools/dpdk-pmdinfo.py F: usertools/dpdk-pmdinfo.py
F: doc/guides/tools/pmdinfo.rst F: doc/guides/tools/pmdinfo.rst

View File

@ -0,0 +1,19 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2020 Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
import os
import subprocess
import sys
import tempfile
_, ar, archive, output, *pmdinfogen = sys.argv
with tempfile.TemporaryDirectory() as temp:
proc = subprocess.run(
# Don't use "ar p", because its output is corrupted on Windows.
[ar, "xv", os.path.abspath(archive)], capture_output=True, check=True, cwd=temp
)
lines = proc.stdout.decode().splitlines()
names = [line[len("x - ") :] for line in lines]
paths = [os.path.join(temp, name) for name in names]
subprocess.run(pmdinfogen + paths + [output], check=True)

View File

@ -1,14 +0,0 @@
#! /bin/sh
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2017 Intel Corporation
arfile=$1
output=$2
shift 2
pmdinfogen=$*
# The generated file must not be empty if compiled in pedantic mode
echo 'static __attribute__((unused)) const char *generator = "'$0'";' > $output
for ofile in `ar t $arfile` ; do
ar p $arfile $ofile | $pmdinfogen - - >> $output
done

View File

@ -2,7 +2,6 @@
# Copyright(c) 2017-2019 Intel Corporation # Copyright(c) 2017-2019 Intel Corporation
pkgconf = find_program('pkg-config', 'pkgconf', required: false) pkgconf = find_program('pkg-config', 'pkgconf', required: false)
pmdinfo = find_program('gen-pmdinfo-cfile.sh')
list_dir_globs = find_program('list-dir-globs.py') list_dir_globs = find_program('list-dir-globs.py')
check_symbols = find_program('check-symbols.sh') check_symbols = find_program('check-symbols.sh')
ldflags_ibverbs_static = find_program('options-ibverbs-static.sh') ldflags_ibverbs_static = find_program('options-ibverbs-static.sh')
@ -18,11 +17,18 @@ endif
map_to_win_cmd = py3 + files('map_to_win.py') map_to_win_cmd = py3 + files('map_to_win.py')
sphinx_wrapper = py3 + files('call-sphinx-build.py') sphinx_wrapper = py3 + files('call-sphinx-build.py')
# select object file format # select library and object file format
pmdinfo = py3 + files('gen-pmdinfo-cfile.py')
pmdinfogen = py3 + files('pmdinfogen.py') pmdinfogen = py3 + files('pmdinfogen.py')
if host_machine.system() == 'windows' if host_machine.system() == 'windows'
if cc.get_id() == 'gcc'
pmdinfo += 'ar'
else
pmdinfo += 'llvm-ar'
endif
pmdinfogen += 'coff' pmdinfogen += 'coff'
else else
pmdinfo += 'ar'
pmdinfogen += 'elf' pmdinfogen += 'elf'
endif endif

View File

@ -233,6 +233,12 @@ def open_output(path):
return open(path, "w") return open(path, "w")
def write_header(output):
output.write(
"static __attribute__((unused)) const char *generator = \"%s\";\n" % sys.argv[0]
)
def main(): def main():
args = parse_args() args = parse_args()
if args.input.count('-') > 1: if args.input.count('-') > 1:
@ -241,6 +247,7 @@ def main():
raise Exception("elftools module not found") raise Exception("elftools module not found")
output = open_output(args.output) output = open_output(args.output)
write_header(output)
for path in args.input: for path in args.input:
image = load_image(args.format, path) image = load_image(args.format, path)
drivers = load_drivers(image) drivers = load_drivers(image)