@@ -193,9 +193,6 @@ def run_test(self, opts):
193193 if opts .test_prebuilt and opts .build_dir is None and not opts .exec_interleaved_builds :
194194 self ._fatal ("--test-prebuilt requires --build-dir (or use --exec-interleaved-builds)" )
195195
196- if opts .build_dir and not opts .test_prebuilt and not opts .exec_interleaved_builds :
197- self ._fatal ("--build-dir can only be used with --test-prebuilt or --exec-interleaved-builds" )
198-
199196 if opts .exec_interleaved_builds :
200197 # --exec-interleaved-builds implies --test-prebuilt
201198 opts .test_prebuilt = True
@@ -216,13 +213,17 @@ def run_test(self, opts):
216213 build_dir )
217214
218215 if opts .build_dir :
219- # Validate build directory
216+ # Validate and normalize build directory path
220217 opts .build_dir = os .path .abspath (opts .build_dir )
221- if not os .path .exists (opts .build_dir ):
222- self ._fatal ("--build-dir does not exist: %r" % opts .build_dir )
223- cmakecache = os .path .join (opts .build_dir , 'CMakeCache.txt' )
224- if not os .path .exists (cmakecache ):
225- self ._fatal ("--build-dir is not a configured build: %r" % opts .build_dir )
218+ if opts .test_prebuilt :
219+ # In test-prebuilt mode, build directory must already exist
220+ if not os .path .exists (opts .build_dir ):
221+ self ._fatal ("--build-dir does not exist: %r" % opts .build_dir )
222+ cmakecache = os .path .join (opts .build_dir , 'CMakeCache.txt' )
223+ if not os .path .exists (cmakecache ):
224+ self ._fatal ("--build-dir is not a configured build: %r" % opts .build_dir )
225+ # In normal build mode, --build-dir specifies where to create the build
226+ # (directory will be created if it doesn't exist)
226227
227228 if opts .cc is not None :
228229 opts .cc = resolve_command_path (opts .cc )
@@ -319,15 +320,15 @@ def run_test(self, opts):
319320 self .start_time = timestamp ()
320321
321322 # Work out where to put our build stuff
322- if opts .test_prebuilt and opts . build_dir :
323- # In test-prebuilt mode with -- build-dir, use the specified build directory
323+ if opts .build_dir :
324+ # If -- build-dir is specified , use it (for any build type)
324325 basedir = opts .build_dir
325326 elif opts .exec_interleaved_builds :
326327 # For exec-interleaved-builds, each build uses its own directory
327328 # We'll return early from _run_interleaved_builds(), so basedir doesn't matter
328329 basedir = opts .sandbox_path
329330 else :
330- # Normal mode or build-only mode : use sandbox/build or sandbox/test-<timestamp>
331+ # Normal mode: use sandbox/build or sandbox/test-<timestamp>
331332 if opts .timestamp_build :
332333 ts = self .start_time .replace (' ' , '_' ).replace (':' , '-' )
333334 build_dir_name = "test-%s" % ts
@@ -1364,9 +1365,10 @@ def diagnose(self):
13641365 is_flag = True , default = False )
13651366@click .option ("--build-dir" , "build_dir" ,
13661367 metavar = "PATH" ,
1367- help = "Path to pre-built test directory (used with --test-prebuilt). "
1368- "This is the actual build directory (e.g., sandbox/build), "
1369- "not the sandbox parent directory." ,
1368+ help = "Specify build directory location. With --test-prebuilt, this must "
1369+ "be an existing configured build. With --build-only or normal mode, "
1370+ "specifies where to create the build (overrides default sandbox/build "
1371+ "or timestamped directory). Path can be absolute or relative to sandbox." ,
13701372 type = click .UNPROCESSED , default = None )
13711373@click .option ("--exec-interleaved-builds" , "exec_interleaved_builds" ,
13721374 metavar = "BUILD1,BUILD2,..." ,
0 commit comments