|
15 | 15 | "split_lockfile_packages", |
16 | 16 | "workspace_dep_data", |
17 | 17 | _fq_crate = "fq_crate", |
| 18 | + _manifest_package_dir = "manifest_package_dir", |
18 | 19 | _normalize_path = "normalize_path", |
19 | 20 | _select = "select_items", |
20 | 21 | ) |
@@ -416,6 +417,12 @@ crate.annotation( |
416 | 417 | _fq_crate(package["name"], package["version"]): package |
417 | 418 | for package in packages |
418 | 419 | } |
| 420 | + workspace_member_by_fq = { |
| 421 | + _fq_crate(package["name"], package["version"]): package |
| 422 | + for package in cargo_metadata["packages"] |
| 423 | + } |
| 424 | + repo_root = _normalize_path(cargo_metadata["workspace_root"]) |
| 425 | + workspace_package = _label_directory(cargo_lock_path) |
419 | 426 |
|
420 | 427 | hub_contents = [] |
421 | 428 | for name, versions in versions_by_name.items(): |
@@ -478,6 +485,35 @@ alias( |
478 | 485 | default_version = default_version, |
479 | 486 | )) |
480 | 487 |
|
| 488 | + workspace_member_hub_aliases = {} |
| 489 | + hub_label_prefix = "@%s//:" % hub_name |
| 490 | + for package in packages: |
| 491 | + feature_resolutions = package["feature_resolutions"] |
| 492 | + for deps_by_triple in [feature_resolutions.deps, feature_resolutions.build_deps]: |
| 493 | + for deps in deps_by_triple.values(): |
| 494 | + for bazel_target in deps: |
| 495 | + if not bazel_target.startswith(hub_label_prefix): |
| 496 | + continue |
| 497 | + |
| 498 | + fq = bazel_target.removeprefix(hub_label_prefix) |
| 499 | + workspace_member = workspace_member_by_fq.get(fq) |
| 500 | + if workspace_member: |
| 501 | + workspace_member_hub_aliases[fq] = workspace_member |
| 502 | + |
| 503 | + for fq in sorted(workspace_member_hub_aliases.keys()): |
| 504 | + package = workspace_member_hub_aliases[fq] |
| 505 | + package_dir = _manifest_package_dir(package["manifest_path"], repo_root) |
| 506 | + bazel_package = paths.join(workspace_package, package_dir).removesuffix("/") |
| 507 | + hub_contents.append(""" |
| 508 | +alias( |
| 509 | + name = "{name}-{version}", |
| 510 | + actual = "@@//{bazel_package}", |
| 511 | +)""".format( |
| 512 | + name = package["name"], |
| 513 | + version = package["version"], |
| 514 | + bazel_package = bazel_package, |
| 515 | + )) |
| 516 | + |
481 | 517 | workspace_deps, conditional_workspace_deps = render_select( |
482 | 518 | [], |
483 | 519 | workspace_dep_labels_by_triple, |
@@ -577,8 +613,6 @@ RESOLVED_PLATFORMS = select({{ |
577 | 613 |
|
578 | 614 | _date(mctx, "done") |
579 | 615 |
|
580 | | - repo_root = _normalize_path(cargo_metadata["workspace_root"]) |
581 | | - workspace_package = _label_directory(cargo_lock_path) |
582 | 616 | data_bzl_contents = render_dep_data(workspace_dep_data( |
583 | 617 | cargo_metadata = cargo_metadata, |
584 | 618 | feature_resolutions_by_fq_crate = feature_resolutions_by_fq_crate, |
|
0 commit comments