Skip to content

Commit 4798322

Browse files
committed
build(panda): fr3 copy over
1 parent d618fed commit 4798322

2 files changed

Lines changed: 97 additions & 1 deletion

File tree

extensions/rcs_panda/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
4444
find_package(pinocchio REQUIRED)
4545
find_package(rcs REQUIRED)
4646

47+
set(RCS_PANDA_MATERIALIZED_SRC_DIR "${CMAKE_CURRENT_BINARY_DIR}/materialized_src_fr3")
48+
execute_process(
49+
COMMAND
50+
${Python3_EXECUTABLE}
51+
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/materialize_fr3_sources.py"
52+
--project-root "${CMAKE_CURRENT_SOURCE_DIR}"
53+
--output-dir "${RCS_PANDA_MATERIALIZED_SRC_DIR}"
54+
COMMAND_ERROR_IS_FATAL ANY
55+
)
56+
4757
FetchContent_Declare(
4858
libfranka
4959
GIT_REPOSITORY https://github.com/frankaemika/libfranka.git
@@ -101,4 +111,4 @@ endif()
101111
FetchContent_MakeAvailable(libfranka)
102112
set_target_properties(franka PROPERTIES CXX_STANDARD 17)
103113

104-
add_subdirectory(src_fr3)
114+
add_subdirectory("${RCS_PANDA_MATERIALIZED_SRC_DIR}" src_fr3)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from __future__ import annotations
2+
3+
import argparse
4+
import os
5+
import shutil
6+
import subprocess
7+
import tempfile
8+
from pathlib import Path
9+
10+
try:
11+
import tomllib
12+
except ModuleNotFoundError: # pragma: no cover
13+
import tomli as tomllib # type: ignore
14+
15+
16+
REPO_URL = "https://github.com/RobotControlStack/robot-control-stack.git"
17+
18+
19+
def load_version(project_root: Path) -> str:
20+
data = tomllib.loads((project_root / "pyproject.toml").read_text())
21+
return data["project"]["version"]
22+
23+
24+
def find_shared_source(project_root: Path) -> Path:
25+
env_override = os.environ.get("RCS_FR3_SOURCE_DIR")
26+
if env_override:
27+
candidate = Path(env_override).resolve()
28+
if (candidate / "CMakeLists.txt").is_file():
29+
return candidate
30+
msg = f"RCS_FR3_SOURCE_DIR does not point to a valid FR3 source tree: {candidate}"
31+
raise FileNotFoundError(msg)
32+
33+
sibling = (project_root.parent / "rcs_fr3" / "src").resolve()
34+
if (sibling / "CMakeLists.txt").is_file():
35+
return sibling
36+
37+
version = load_version(project_root)
38+
tmpdir = Path(tempfile.mkdtemp(prefix="rcs_panda_fr3_"))
39+
try:
40+
subprocess.run(
41+
["git", "clone", "--depth", "1", "--branch", f"v{version}", REPO_URL, str(tmpdir)],
42+
check=True,
43+
)
44+
except subprocess.CalledProcessError:
45+
shutil.rmtree(tmpdir, ignore_errors=True)
46+
tmpdir = Path(tempfile.mkdtemp(prefix="rcs_panda_fr3_"))
47+
subprocess.run(
48+
["git", "clone", "--depth", "1", REPO_URL, str(tmpdir)],
49+
check=True,
50+
)
51+
cloned = tmpdir / "extensions" / "rcs_fr3" / "src"
52+
if not (cloned / "CMakeLists.txt").is_file():
53+
msg = f"Could not locate FR3 shared sources in cloned repo at {cloned}"
54+
raise FileNotFoundError(msg)
55+
return cloned
56+
57+
58+
def copy_file(src: Path, dest: Path) -> None:
59+
dest.parent.mkdir(parents=True, exist_ok=True)
60+
shutil.copy2(src, dest)
61+
62+
63+
def materialize(project_root: Path, output_dir: Path) -> None:
64+
shared_src = find_shared_source(project_root)
65+
panda_src = project_root / "src_fr3"
66+
67+
if output_dir.exists():
68+
shutil.rmtree(output_dir)
69+
output_dir.mkdir(parents=True, exist_ok=True)
70+
71+
copy_file(shared_src / "CMakeLists.txt", output_dir / "CMakeLists.txt")
72+
shutil.copytree(shared_src / "hw", output_dir / "hw")
73+
copy_file(panda_src / "pybind" / "CMakeLists.txt", output_dir / "pybind" / "CMakeLists.txt")
74+
copy_file(shared_src / "pybind" / "rcs.cpp", output_dir / "pybind" / "rcs.cpp")
75+
76+
77+
def main() -> None:
78+
parser = argparse.ArgumentParser()
79+
parser.add_argument("--project-root", type=Path, required=True)
80+
parser.add_argument("--output-dir", type=Path, required=True)
81+
args = parser.parse_args()
82+
materialize(args.project_root.resolve(), args.output_dir.resolve())
83+
84+
85+
if __name__ == "__main__":
86+
main()

0 commit comments

Comments
 (0)