1*7e06c0feSBruce Richardson#!/usr/bin/env python3 2*7e06c0feSBruce Richardson# SPDX-License-Identifier: BSD-3-Clause 3*7e06c0feSBruce Richardson# Copyright(c) 2021 Intel Corporation 4*7e06c0feSBruce Richardson 5*7e06c0feSBruce Richardsonimport os 6*7e06c0feSBruce Richardsonimport sys 7*7e06c0feSBruce Richardsonimport shutil 8*7e06c0feSBruce Richardsonfrom os.path import abspath, dirname, join 9*7e06c0feSBruce Richardson 10*7e06c0feSBruce Richardsondef fixup_library_renames(contents): 11*7e06c0feSBruce Richardson """since library directory names have dropped the 'librte_' prefix, 12*7e06c0feSBruce Richardson add those prefixes back in for patches than need it""" 13*7e06c0feSBruce Richardson modified = False 14*7e06c0feSBruce Richardson 15*7e06c0feSBruce Richardson # first get all the DPDK libs to build up replacement list 16*7e06c0feSBruce Richardson # stored in function attribute between calls 17*7e06c0feSBruce Richardson try: 18*7e06c0feSBruce Richardson libdirs = fixup_library_renames.libdirs 19*7e06c0feSBruce Richardson except AttributeError: 20*7e06c0feSBruce Richardson dpdk_libdir = abspath(join(dirname(sys.argv[0]), '..', 'lib')) 21*7e06c0feSBruce Richardson for root, dirs, files in os.walk(dpdk_libdir): 22*7e06c0feSBruce Richardson fixup_library_renames.libdirs = dirs 23*7e06c0feSBruce Richardson libdirs = dirs 24*7e06c0feSBruce Richardson break 25*7e06c0feSBruce Richardson 26*7e06c0feSBruce Richardson for i in range(len(contents)): 27*7e06c0feSBruce Richardson # skip over any lines which don't have lib in it 28*7e06c0feSBruce Richardson if not "lib/" in contents[i]: 29*7e06c0feSBruce Richardson continue 30*7e06c0feSBruce Richardson for d in libdirs: 31*7e06c0feSBruce Richardson if f'lib/{d}' in contents[i]: 32*7e06c0feSBruce Richardson modified = True 33*7e06c0feSBruce Richardson contents[i] = contents[i].replace(f'lib/{d}', f'lib/librte_{d}') 34*7e06c0feSBruce Richardson return modified 35*7e06c0feSBruce Richardson 36*7e06c0feSBruce Richardsondef main(): 37*7e06c0feSBruce Richardson "takes list of patches off argv and processes each" 38*7e06c0feSBruce Richardson for patch in sys.argv[1:]: 39*7e06c0feSBruce Richardson modified = False 40*7e06c0feSBruce Richardson with open(patch) as f: 41*7e06c0feSBruce Richardson contents = f.readlines() 42*7e06c0feSBruce Richardson 43*7e06c0feSBruce Richardson modified |= fixup_library_renames(contents) 44*7e06c0feSBruce Richardson # other functions to change the patch go here 45*7e06c0feSBruce Richardson 46*7e06c0feSBruce Richardson if not modified: 47*7e06c0feSBruce Richardson continue 48*7e06c0feSBruce Richardson shutil.copyfile(f'{patch}', f'{patch}.bak') 49*7e06c0feSBruce Richardson with open(patch, 'w') as f: 50*7e06c0feSBruce Richardson f.writelines(contents) 51*7e06c0feSBruce Richardson 52*7e06c0feSBruce Richardsonif __name__ == "__main__": 53*7e06c0feSBruce Richardson main() 54