mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[bazel][robotpy] Add mirror for robotpy's wpiuil and wpinet libraries (#8062)
Project import generated by Copybara. GitOrigin-RevId: 92ea93d1b47a82667044bd0af05f7fdb34d2c2c2
This commit is contained in:
55
shared/bazel/rules/robotpy/wrapper.py
Normal file
55
shared/bazel/rules/robotpy/wrapper.py
Normal file
@@ -0,0 +1,55 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user