Files
linux/scripts/sbom/sbom/path_utils.py
Luis Augenstein 9c16c1ea46 scripts/sbom: add cmd graph generation
Implement command graph generation by parsing .cmd files to build a
dependency graph.
Add CmdGraph, CmdGraphNode, and .cmd file parsing.
Supports generating a flat list of used source files via the
--generate-used-files cli argument.

Assisted-by: Cursor:claude-sonnet-4-5
Assisted-by: OpenCode:GLM-4-7
Co-developed-by: Maximilian Huber <maximilian.huber@tngtech.com>
Signed-off-by: Maximilian Huber <maximilian.huber@tngtech.com>
Signed-off-by: Luis Augenstein <luis.augenstein@tngtech.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-05-22 13:14:41 +02:00

23 lines
716 B
Python

# SPDX-License-Identifier: GPL-2.0-only OR MIT
# Copyright (C) 2025 TNG Technology Consulting GmbH
import os
from functools import lru_cache
PathStr = str
"""Filesystem path represented as a plain string for better performance than pathlib.Path."""
def is_relative_to(path: PathStr, base: PathStr) -> bool:
return os.path.commonpath([path, base]) == base
@lru_cache(maxsize=None)
def has_link(path: PathStr) -> bool:
"""Returns True if path or any of its ancestor directories is a symlink. Results are cached to avoid duplicate lstat syscalls."""
if os.path.islink(path):
return True
parent = os.path.dirname(path)
if parent == path:
return False
return has_link(parent)