DepperDan/common/directory_helpers.py

33 lines
897 B
Python

# (c) 2025 by Stephan Menzel
# Licensed under the Apache License, Version 2.0.
# See attached file LICENSE for full details
import contextlib
import os
from pathlib import Path
from build_functions.build_utils import file_and_console_log
@contextlib.contextmanager
def pushd(new_dir):
"""temporarily go into subdir - https://stackoverflow.com/questions/6194499/pushd-through-os-system
"""
previous_dir = os.getcwd()
os.chdir(new_dir)
try:
yield
finally:
os.chdir(previous_dir)
def get_local_prefix(prefix: Path | str) -> Path:
p = Path(prefix) / Path.cwd().name
if os.name == 'posix':
if not "PKG_CONFIG_PATH" in os.environ:
os.environ["PKG_CONFIG_PATH"] = ''
os.environ["PKG_CONFIG_PATH"] += p / 'lib' / 'pkg_config'
file_and_console_log("PKG_CONFIG_PATH = " + os.environ["PKG_CONFIG_PATH"])
return p