Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

xdrgen: Generalize/harden pathname construction

Use Python's built-in Path constructor to find the Jinja templates.
This provides better error checking, proper use of path component
separators, and more reliable location of the template files.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>

+6 -5
+6 -5
tools/net/sunrpc/xdrgen/generators/__init__.py
··· 2 2 3 3 """Define a base code generator class""" 4 4 5 - import sys 5 + from pathlib import Path 6 6 from jinja2 import Environment, FileSystemLoader, Template 7 7 8 8 from xdr_ast import _XdrAst, Specification, _RpcProgram, _XdrTypeSpecifier ··· 14 14 """Open a set of templates based on output language""" 15 15 match language: 16 16 case "C": 17 + templates_dir = ( 18 + Path(__file__).parent.parent / "templates" / language / xdr_type 19 + ) 17 20 environment = Environment( 18 - loader=FileSystemLoader(sys.path[0] + "/templates/C/" + xdr_type + "/"), 21 + loader=FileSystemLoader(templates_dir), 19 22 trim_blocks=True, 20 23 lstrip_blocks=True, 21 24 ) ··· 51 48 52 49 def header_guard_infix(filename: str) -> str: 53 50 """Extract the header guard infix from the specification filename""" 54 - basename = filename.split("/")[-1] 55 - program = basename.replace(".x", "") 56 - return program.upper() 51 + return Path(filename).stem.upper() 57 52 58 53 59 54 def kernel_c_type(spec: _XdrTypeSpecifier) -> str: