11mod aquery;
2+ mod command;
23mod rust_project;
34
45use std:: { collections:: HashMap , process:: Command } ;
56
67use anyhow:: bail;
78use camino:: Utf8Path ;
9+ use command:: BazelCommand ;
810use runfiles:: Runfiles ;
911use rust_project:: RustProject ;
1012pub use rust_project:: { DiscoverProject , NormalizedProjectString , RustAnalyzerArg } ;
@@ -24,12 +26,7 @@ pub fn generate_crate_info(
2426 log:: info!( "running bazel build..." ) ;
2527 log:: debug!( "Building rust_analyzer_crate_spec files for {:?}" , targets) ;
2628
27- let output = Command :: new ( bazel)
28- . current_dir ( workspace)
29- . env_remove ( "BAZELISK_SKIP_WRAPPER" )
30- . env_remove ( "BUILD_WORKING_DIRECTORY" )
31- . env_remove ( "BUILD_WORKSPACE_DIRECTORY" )
32- . arg ( format ! ( "--output_base={output_base}" ) )
29+ let output = Command :: new_bazel_command ( bazel, Some ( workspace) , Some ( output_base) )
3330 . arg ( "build" )
3431 . arg ( "--norun_validations" )
3532 . arg ( format ! (
@@ -40,11 +37,9 @@ pub fn generate_crate_info(
4037 . output ( ) ?;
4138
4239 if !output. status . success ( ) {
43- bail ! (
44- "bazel build failed:({})\n {}" ,
45- output. status,
46- String :: from_utf8_lossy( & output. stderr)
47- ) ;
40+ let status = output. status ;
41+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
42+ bail ! ( "bazel build failed: ({status})\n {stderr}" ) ;
4843 }
4944
5045 log:: info!( "bazel build finished" ) ;
@@ -89,21 +84,14 @@ pub fn get_bazel_info(
8984 workspace : Option < & Utf8Path > ,
9085 output_base : Option < & Utf8Path > ,
9186) -> anyhow:: Result < HashMap < String , String > > {
92- let output = Command :: new ( & bazel)
93- // Switch to the workspace directory if one was provided.
94- . current_dir ( workspace. unwrap_or ( Utf8Path :: new ( "." ) ) )
95- . env_remove ( "BAZELISK_SKIP_WRAPPER" )
96- . env_remove ( "BUILD_WORKING_DIRECTORY" )
97- . env_remove ( "BUILD_WORKSPACE_DIRECTORY" )
98- // Set the output_base if one was provided.
99- . args ( output_base. map ( |s| format ! ( "--output_base={s}" ) ) )
87+ let output = Command :: new_bazel_command ( bazel, workspace, output_base)
10088 . arg ( "info" )
10189 . output ( ) ?;
10290
10391 if !output. status . success ( ) {
10492 let status = output. status ;
10593 let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
106- bail ! ( "Failed to run ` bazel info` ({status:?}): {stderr}" ) ;
94+ bail ! ( "bazel info failed: ({status:?})\n {stderr}" ) ;
10795 }
10896
10997 // Extract and parse the output.
0 commit comments