Skip to content

Commit

Permalink
rust: extract common parts of rust.test and rust.doctest
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Nov 20, 2024
1 parent d385c5c commit 925031b
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions mesonbuild/modules/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,7 @@ def __init__(self, interpreter: Interpreter) -> None:
'proc_macro': self.proc_macro,
})

@typed_pos_args('rust.test', str, BuildTarget)
@typed_kwargs(
'rust.test',
*TEST_KWS,
DEPENDENCIES_KW,
LINK_WITH_KW.evolve(since='1.2.0'),
KwargInfo(
'rust_args',
ContainerTypeInfo(list, str),
listify=True,
default=[],
since='1.2.0',
),
KwargInfo('is_parallel', bool, default=False),
)
def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: FuncTest) -> ModuleReturnValue:
def test_common(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: FuncTest) -> T.Tuple[Executable, FuncTest]:
"""Generate a rust test target from a given rust target.
Rust puts its unitests inside its main source files, unlike most
Expand Down Expand Up @@ -179,7 +164,26 @@ def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: Func
base_target.objects, base_target.environment, base_target.compilers,
new_target_kwargs
)
return new_target, tkwargs

@typed_pos_args('rust.test', str, BuildTarget)
@typed_kwargs(
'rust.test',
*TEST_KWS,
DEPENDENCIES_KW,
LINK_WITH_KW.evolve(since='1.2.0'),
KwargInfo(
'rust_args',
ContainerTypeInfo(list, str),
listify=True,
default=[],
since='1.2.0',
),
KwargInfo('is_parallel', bool, default=False),
)
def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: FuncTest) -> ModuleReturnValue:
name, _ = args
new_target, tkwargs = self.test_common(state, args, kwargs)
test = self.interpreter.make_test(
self.interpreter.current_node, (name, new_target), tkwargs)

Expand Down

0 comments on commit 925031b

Please sign in to comment.