@@ -127,34 +127,63 @@ def _ensure_setup(self) -> None:
127127
128128 subprocess .run (cmd , check = True , cwd = source_dir )
129129
130- def build (self ) -> None :
131- """Builds the project using meson compile."""
130+ def _effective_build_dir (self , configuration : str | None ) -> Path :
131+ """Returns the build directory, optionally overridden by a configuration name.
132+
133+ Args:
134+ configuration: If provided, used as the build directory name instead of the
135+ configured ``build_directory``.
136+
137+ Returns:
138+ The absolute path to the build directory
139+ """
140+ directory = configuration if configuration else self .data .build_directory
141+ return self .data .build_file .parent / directory
142+
143+ def build (self , configuration : str | None = None ) -> None :
144+ """Builds the project using meson compile.
145+
146+ Args:
147+ configuration: Optional build directory name override.
148+ """
132149 self ._ensure_setup ()
133- cmd = [self ._meson_command (), 'compile' , '-C' , str (self ._build_dir ())]
150+ build_dir = self ._effective_build_dir (configuration )
151+ cmd = [self ._meson_command (), 'compile' , '-C' , str (build_dir )]
134152 subprocess .run (cmd , check = True , cwd = self .data .build_file .parent )
135153
136- def test (self ) -> None :
137- """Runs tests using meson test."""
138- cmd = [self ._meson_command (), 'test' , '-C' , str (self ._build_dir ())]
154+ def test (self , configuration : str | None = None ) -> None :
155+ """Runs tests using meson test.
156+
157+ Args:
158+ configuration: Optional build directory name override.
159+ """
160+ build_dir = self ._effective_build_dir (configuration )
161+ cmd = [self ._meson_command (), 'test' , '-C' , str (build_dir )]
139162 subprocess .run (cmd , check = True , cwd = self .data .build_file .parent )
140163
141- def bench (self ) -> None :
142- """Runs benchmarks using meson test --benchmark."""
143- cmd = [self ._meson_command (), 'test' , '--benchmark' , '-C' , str (self ._build_dir ())]
164+ def bench (self , configuration : str | None = None ) -> None :
165+ """Runs benchmarks using meson test --benchmark.
166+
167+ Args:
168+ configuration: Optional build directory name override.
169+ """
170+ build_dir = self ._effective_build_dir (configuration )
171+ cmd = [self ._meson_command (), 'test' , '--benchmark' , '-C' , str (build_dir )]
144172 subprocess .run (cmd , check = True , cwd = self .data .build_file .parent )
145173
146- def run (self , target : str ) -> None :
174+ def run (self , target : str , configuration : str | None = None ) -> None :
147175 """Runs a built executable by target name.
148176
149177 Searches the build directory for the executable matching the target name.
150178
151179 Args:
152180 target: The name of the build target/executable to run
181+ configuration: Optional build directory name override.
153182
154183 Raises:
155184 FileNotFoundError: If the target executable cannot be found
156185 """
157- build_dir = self ._build_dir ( )
186+ build_dir = self ._effective_build_dir ( configuration )
158187
159188 # Search for the executable in the build directory
160189 candidates = list (build_dir .rglob (target )) + list (build_dir .rglob (f'{ target } .exe' ))
0 commit comments