Files
allwpilib/shared/bazel/rules/robotpy/wrapper.py
PJ Reiniger bd1dcc4358 [bazel][robotpy] Add mirror for robotpy's wpiuil and wpinet libraries (#8062)
Project import generated by Copybara.

GitOrigin-RevId: 92ea93d1b47a82667044bd0af05f7fdb34d2c2c2
2025-08-30 11:55:11 -07:00

56 lines
1.5 KiB
Python

import importlib
import os
import pathlib
import sys
from shared.bazel.rules.robotpy.hack_pkgcfgs import hack_pkgconfig
"""
This file will wrap various semiwrap.tools executables. In the event that it fails
it will provide more helpful debug information for bazel users.
It can also "hack" the PKG_CONFIG_PATH environment variable. This allows us to use
generated package config files without having to install the libraries which decreases
build dependencies and increases the amount of parallelization that can happen during
the build.
"""
def main():
tool = sys.argv[1]
if "--pkgcfgs" in sys.argv[2:]:
pkgcfg_index = sys.argv.index("--pkgcfgs")
args = sys.argv[2:pkgcfg_index]
pkgcfgs = [pathlib.Path(x) for x in sys.argv[pkgcfg_index + 1 :]]
else:
args = sys.argv[2:]
pkgcfgs = []
hack_pkgconfig(pkgcfgs)
module = importlib.import_module(tool)
tool_main = getattr(module, "main")
sys.argv = [""] + args
try:
tool_main()
except SystemExit as e:
if e.code != 0:
raise Exception(
"sys.exit() explicitly called with a non-zero error code", e
)
except:
print("-------------------------------------")
print("Failed to run wrapped tool.")
print(f"CWD: {os.getcwd()}")
print(f"Tool: {tool}, Args:")
for a in args:
print(" ", a)
print("-------------------------------------")
raise
if __name__ == "__main__":
main()