Skip to content

Commit

Permalink
[upstream_utils] Add mrcal
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Oct 21, 2024
1 parent 40af8db commit c548884
Show file tree
Hide file tree
Showing 26 changed files with 16,686 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/comment-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
python-version: 3.9
- name: Install jinja
run: python -m pip install jinja2
- name: Install protobuf dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler && wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf-1.3.3-linux-x86_64.exe && chmod +x protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Install protobuf and perl dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler liblist-moreutils-perl && wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf-1.3.3-linux-x86_64.exe && chmod +x protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Regenerate all
run: ./.github/workflows/pregen_all.py --quickbuf_plugin=protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Commit
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pregen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def main(argv):
subprocess.run(["python", f"{REPO_ROOT}/hal/generate_usage_reporting.py"])
subprocess.run(["python", f"{REPO_ROOT}/ntcore/generate_topics.py"])
subprocess.run(["python", f"{REPO_ROOT}/wpimath/generate_numbers.py"])
subprocess.run(["python", f"{REPO_ROOT}/wpimath/generate_mrcal.py"])
subprocess.run(
[
"python",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pregenerate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python-version: 3.9
- name: Install jinja
run: python -m pip install jinja2
- name: Install protobuf dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler && wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf-1.3.3-linux-x86_64.exe && chmod +x protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Install protobuf and perl dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler liblist-moreutils-perl && wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf-1.3.3-linux-x86_64.exe && chmod +x protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Regenerate all
run: python ./.github/workflows/pregen_all.py --quickbuf_plugin protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
- name: Add untracked files to index so they count as changes
Expand Down
54 changes: 54 additions & 0 deletions upstream_utils/mrcal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

import os
import shutil
import subprocess

from upstream_utils import (
walk_cwd_and_copy_if,
Lib,
)


def copy_upstream_src(wpilib_root):
wpical = os.path.join(wpilib_root, "wpimath")

# Delete old install
for d in [
"src/main/native/thirdparty/mrcal/src",
"src/main/native/thirdparty/mrcal/include",
]:
shutil.rmtree(os.path.join(wpical, d), ignore_errors=True)

walk_cwd_and_copy_if(
lambda dp, f: (f.endswith(".h") or f.endswith(".hh"))
and not f.endswith("mrcal-image.h")
and not f.endswith("stereo.h")
and not f.endswith("stereo-matching-libelas.h")
and not dp.startswith(os.path.join(".", "test")),
os.path.join(wpical, "src/main/native/thirdparty/mrcal/include"),
)
walk_cwd_and_copy_if(
lambda dp, f: (f.endswith(".c") or f.endswith(".cc") or f.endswith(".pl"))
and not f.endswith("mrcal-pywrap.c")
and not f.endswith("image.c")
and not f.endswith("stereo.c")
and not f.endswith("stereo-matching-libelas.cc")
and not f.endswith("uncertainty.c")
and not dp.startswith(os.path.join(".", "doc"))
and not dp.startswith(os.path.join(".", "test")),
os.path.join(wpical, "src/main/native/thirdparty/mrcal/src"),
)


def main():
name = "mrcal"
url = "https://github.com/dkogan/mrcal"
tag = "71c89c4e9f268a0f4fb950325e7d551986a281ec"

mrcal = Lib(name, url, tag, copy_upstream_src)
mrcal.main()


if __name__ == "__main__":
main()
35 changes: 35 additions & 0 deletions wpimath/generate_mrcal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3


import os
import subprocess
import sys
import argparse
from pathlib import Path


def main(argv):
script_path = Path(__file__).resolve()
dirname = script_path.parent

parser = argparse.ArgumentParser()
parser.add_argument(
"--output_directory",
help="Optional. If set, will output the generated files to this directory, otherwise it will use a path relative to the script",
default=dirname / "src/main/native/thirdparty/mrcal/generated/",
type=Path,
)
args = parser.parse_args(argv)

args.output_directory.mkdir(parents=True, exist_ok=True)
result = subprocess.run(
f"{dirname}/src/main/native/thirdparty/mrcal/src/minimath/minimath_generate.pl",
capture_output=True,
)
(args.output_directory / "minimath_generated.h").write_text(
str(result.stdout, encoding="UTF8")
)


if __name__ == "__main__":
main(sys.argv[1:])
Loading

0 comments on commit c548884

Please sign in to comment.