@@ -194,9 +194,6 @@ def run_test(self, opts):
194194        if  opts .test_prebuilt  and  opts .build_dir  is  None  and  not  opts .exec_interleaved_builds :
195195            self ._fatal ("--test-prebuilt requires --build-dir (or use --exec-interleaved-builds)" )
196196
197-         if  opts .build_dir  and  not  opts .test_prebuilt  and  not  opts .exec_interleaved_builds :
198-             self ._fatal ("--build-dir can only be used with --test-prebuilt or --exec-interleaved-builds" )
199- 
200197        if  opts .exec_interleaved_builds :
201198            # --exec-interleaved-builds implies --test-prebuilt 
202199            opts .test_prebuilt  =  True 
@@ -217,13 +214,17 @@ def run_test(self, opts):
217214                        build_dir )
218215
219216        if  opts .build_dir :
220-             # Validate build directory 
217+             # Validate and normalize  build directory path  
221218            opts .build_dir  =  os .path .abspath (opts .build_dir )
222-             if  not  os .path .exists (opts .build_dir ):
223-                 self ._fatal ("--build-dir does not exist: %r"  %  opts .build_dir )
224-             cmakecache  =  os .path .join (opts .build_dir , 'CMakeCache.txt' )
225-             if  not  os .path .exists (cmakecache ):
226-                 self ._fatal ("--build-dir is not a configured build: %r"  %  opts .build_dir )
219+             if  opts .test_prebuilt :
220+                 # In test-prebuilt mode, build directory must already exist 
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 )
226+             # In normal build mode, --build-dir specifies where to create the build 
227+             # (directory will be created if it doesn't exist) 
227228
228229        if  opts .cc  is  not   None :
229230            opts .cc  =  resolve_command_path (opts .cc )
@@ -320,15 +321,15 @@ def run_test(self, opts):
320321        self .start_time  =  timestamp ()
321322
322323        # Work out where to put our build stuff 
323-         if  opts .test_prebuilt   and   opts . build_dir :
324-             # In test-prebuilt mode with -- build-dir, use the specified  build directory  
324+         if  opts .build_dir :
325+             # If -- build-dir is specified , use it (for any  build type)  
325326            basedir  =  opts .build_dir 
326327        elif  opts .exec_interleaved_builds :
327328            # For exec-interleaved-builds, each build uses its own directory 
328329            # We'll return early from _run_interleaved_builds(), so basedir doesn't matter 
329330            basedir  =  opts .sandbox_path 
330331        else :
331-             # Normal mode or build-only mode : use sandbox/build or sandbox/test-<timestamp> 
332+             # Normal mode: use sandbox/build or sandbox/test-<timestamp> 
332333            if  opts .timestamp_build :
333334                ts  =  self .start_time .replace (' ' , '_' ).replace (':' , '-' )
334335                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