Skip to content

Commit 729b5c9

Browse files
longlhoclaude
andauthored
Fix crash on git dependencies: key "path" not found (#90)
## Problem `_generate_hub_and_spokes` crashes with `key "path" not found in dictionary` when a workspace member has git dependencies in Cargo.toml: ```toml [dependencies] ruff_python_parser = { git = "https://github.com/astral-sh/ruff.git", tag = "0.15.10" } ``` The crash is at `extensions.bzl:1028`: ```starlark bazel_target = "//" + paths.join(workspace_package, _normalize_path(dep["path"]).removeprefix(repo_root + "/")) ``` Git deps don't have a `path` field — only path deps (workspace members) do. ## Fix Check for `dep.get("path")` before accessing it. Git/registry deps without a `bazel_target` are resolved elsewhere as external crate repos, so we skip them in the path-dep resolution path. ## Testing Tested with a real-world workspace (ppl-ai/agi) that has a crate depending on `ruff_python_parser` via git. Before: `bazel mod tidy` crashes. After: builds successfully. --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 43adac4 commit 729b5c9

6 files changed

Lines changed: 35 additions & 1 deletion

File tree

rs/extensions.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,12 @@ RESOLVED_PLATFORMS = select({{
10251025
for dep in package["dependencies"]:
10261026
bazel_target = dep.get("bazel_target")
10271027
if not bazel_target:
1028-
bazel_target = "//" + paths.join(workspace_package, _normalize_path(dep["path"]).removeprefix(repo_root + "/"))
1028+
dep_path = dep.get("path")
1029+
if not dep_path:
1030+
# Git or registry deps without a bazel_target are resolved
1031+
# elsewhere (e.g., as external crate repos). Skip here.
1032+
continue
1033+
bazel_target = "//" + paths.join(workspace_package, _normalize_path(dep_path).removeprefix(repo_root + "/"))
10291034

10301035
if dep.get("rename"):
10311036
aliases[bazel_target] = dep["rename"].replace("-", "_")

test/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ TESTS = [
150150
"workspace_path_dependency",
151151
"workspace_hyphen_dep_aliases",
152152
"workspace_renamed_path_dep_aliases",
153+
"workspace_git_dep",
153154
"binaries",
154155
"uv",
155156
]

test/workspace_git_dep/Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/workspace_git_dep/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[workspace]
2+
members = ["app"]
3+
resolver = "3"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "app"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[lib]
7+
8+
[dependencies]
9+
itoa = { git = "https://github.com/dtolnay/itoa", tag = "1.0.14" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Smoke test: workspace member with a git dependency.

0 commit comments

Comments
 (0)