Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): honor Cargo target dir in local installs (#2486)

简律纯7cb6810b429e
diff --git a/libs/cua-driver/scripts/_install-local-rust.sh b/libs/cua-driver/scripts/_install-local-rust.sh
index 15929c43fc..5fb926bc45 100755
--- a/libs/cua-driver/scripts/_install-local-rust.sh
+++ b/libs/cua-driver/scripts/_install-local-rust.sh
@@ -187,6 +187,16 @@ fi
# --- Build --------------------------------------------------------------
+# Keep Cargo's output directory and the binary staged below on one path.
+# Cargo resolves a relative CARGO_TARGET_DIR from the workspace we build in,
+# so make that resolution explicit before invoking it.
+BUILD_TARGET_DIR="${CARGO_TARGET_DIR:-$REPO_ROOT/target}"
+case "$BUILD_TARGET_DIR" in
+ /*) ;;
+ *) BUILD_TARGET_DIR="$REPO_ROOT/$BUILD_TARGET_DIR" ;;
+esac
+export CARGO_TARGET_DIR="$BUILD_TARGET_DIR"
+
echo "${BOLD}Building cua-driver ($BUILD_CONFIG)...${NORMAL}"
cd "$REPO_ROOT"
if [ "$BUILD_CONFIG" = "release" ]; then
@@ -195,7 +205,7 @@ else
cargo build -p cua-driver
fi
-BUILT_BINARY="$REPO_ROOT/target/$BUILD_CONFIG/cua-driver"
+BUILT_BINARY="$BUILD_TARGET_DIR/$BUILD_CONFIG/cua-driver"
if [ ! -x "$BUILT_BINARY" ]; then
echo "${RED}Error: build produced no binary at $BUILT_BINARY${NORMAL}"
exit 1
diff --git a/libs/cua-driver/scripts/tests/test_install_local.py b/libs/cua-driver/scripts/tests/test_install_local.py
new file mode 100644
index 0000000000..8324df0baf
--- /dev/null
+++ b/libs/cua-driver/scripts/tests/test_install_local.py
@@ -0,0 +1,91 @@
+from __future__ import annotations
+
+import os
+import shutil
+import subprocess
+from pathlib import Path
+
+import pytest
+
+INSTALL_LOCAL = Path(__file__).resolve().parents[1] / "_install-local-rust.sh"
+LOCAL_SIGNING = INSTALL_LOCAL.with_name("_local-signing.sh")
+
+
+def _write_executable(path: Path, body: str) -> None:
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(f"#!/bin/sh\n{body}", encoding="utf-8")
+ path.chmod(0o755)
+
+
[email protected]("relative_target", [False, True], ids=["absolute", "relative"])
+def test_installer_stages_binary_from_custom_cargo_target(
+ tmp_path: Path, relative_target: bool
+) -> None:
+ fixture_root = tmp_path / "cua-driver"
+ scripts_dir = fixture_root / "scripts"
+ rust_dir = fixture_root / "rust"
+ scripts_dir.mkdir(parents=True)
+ rust_dir.mkdir()
+ shutil.copy2(INSTALL_LOCAL, scripts_dir / INSTALL_LOCAL.name)
+ shutil.copy2(LOCAL_SIGNING, scripts_dir / LOCAL_SIGNING.name)
+
+ stale_binary = rust_dir / "target/release/cua-driver"
+ _write_executable(stale_binary, "printf 'stale workspace target\\n'")
+
+ custom_target = (
+ rust_dir / "relative custom target" if relative_target else tmp_path / "custom target"
+ )
+ cargo_target_dir = (
+ str(custom_target.relative_to(rust_dir)) if relative_target else str(custom_target)
+ )
+ fake_bin = tmp_path / "fake-bin"
+ _write_executable(
+ fake_bin / "cargo",
+ """set -eu
+test "${1:-}" = build
+test "$CARGO_TARGET_DIR" = "$EXPECTED_CARGO_TARGET_DIR"
+mkdir -p "$CARGO_TARGET_DIR/release"
+printf 'fresh custom target\n' > "$CARGO_TARGET_DIR/release/cua-driver"
+chmod +x "$CARGO_TARGET_DIR/release/cua-driver"
+""",
+ )
+ _write_executable(
+ fake_bin / "uname",
+ """case "${1:-}" in
+ -s) printf 'Linux\n' ;;
+ -m) printf 'x86_64\n' ;;
+ *) exit 2 ;;
+esac
+""",
+ )
+ _write_executable(fake_bin / "systemctl", "exit 0")
+ _write_executable(fake_bin / "pkill", "exit 0")
+
+ local_home = tmp_path / "local-home"
+ install_bin = tmp_path / "install-bin"
+ env = os.environ.copy()
+ env.pop("SUDO_USER", None)
+ env.update(
+ {
+ "HOME": str(tmp_path / "home"),
+ "PATH": f"{fake_bin}:/usr/bin:/bin",
+ "CARGO_TARGET_DIR": cargo_target_dir,
+ "EXPECTED_CARGO_TARGET_DIR": str(custom_target),
+ "CUA_DRIVER_SOURCE_SHA": "a" * 40,
+ "CUA_DRIVER_LOCAL_HOME": str(local_home),
+ "CUA_DRIVER_LOCAL_INSTALL_DIR": str(install_bin),
+ }
+ )
+
+ result = subprocess.run(
+ ["/bin/bash", str(scripts_dir / INSTALL_LOCAL.name), "--release"],
+ cwd=fixture_root,
+ env=env,
+ text=True,
+ capture_output=True,
+ check=False,
+ )
+
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert (custom_target / "release/cua-driver").read_text() == "fresh custom target\n"
+ assert (install_bin / "cua-driver-local").read_text() == "fresh custom target\n"