Skip to content

Commit

Permalink
[antlir][build_defs] Fix fb_deps and fb_test_deps logic
Browse files Browse the repository at this point in the history
Summary:
In our build defs, `fb_test_deps` can work when used with `rust_unittest`, but if used with `rust_{binary,library}`, the argument does not get forwarded to unittest rule, but to the main rule (since it starts with `fb_test_`, and we only check for `test_`).

There's also a problem that if we have both `fb_deps` and `fb_test_deps`, one will override the other, instead of merging.

In this diff, I'm changing `_split_rust_kwargs` to be able to turn `kwargs["fb_test_deps"]` into `test_kwargs["fb_deps"]`.

Test Plan: Signals here should catch regressions

Reviewed By: sergeyfd

Differential Revision: D68327867

fbshipit-source-id: aa43b473aec6fcddbf9dcb725e231ee9eeb64f35
  • Loading branch information
pzmarzly authored and facebook-github-bot committed Jan 20, 2025
1 parent 542eb5e commit 2eb076f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions antlir/bzl/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,23 @@ def _rust_implicit_test(kwargs, test_kwargs):
test_kwargs.pop("linker_flags", None)
test_kwargs["srcs"] = test_kwargs.get("srcs", []) + kwargs.get("srcs", [])
test_kwargs["deps"] = test_kwargs.get("deps", []) + kwargs.get("deps", [])
test_kwargs["fb_deps"] = test_kwargs.get("fb_deps", []) + kwargs.get("fb_deps", [])
_rust_common(shim.rust_unittest, **test_kwargs)

def _split_rust_kwargs(kwargs):
test_kwargs = dict(kwargs)
test_kwargs = {k: v for k, v in test_kwargs.items() if not k.startswith("test_")}
test_kwargs.update({k[len("test_"):]: v for k, v in kwargs.items() if k.startswith("test_")})
kwargs = {k: v for k, v in kwargs.items() if not k.startswith("test_")}
def _is_rust_test_key(key):
return key.startswith("test_") or key.startswith("fb_test_")

def _rust_test_key_to_regular_key(key):
if key.startswith("test_"):
return key[5:]
if key.startswith("fb_test_"):
return "fb_" + key[8:]
return key

def _split_rust_kwargs(kwargs):
test_kwargs = {k: v for k, v in kwargs.items() if not _is_rust_test_key(k)}
test_kwargs.update({_rust_test_key_to_regular_key(k): v for k, v in kwargs.items() if _is_rust_test_key(k)})
kwargs = {k: v for k, v in kwargs.items() if not _is_rust_test_key(k)}
return kwargs, test_kwargs

def _normalize_rust_dep(dep):
Expand Down

0 comments on commit 2eb076f

Please sign in to comment.