in focus/internals/src/lib/target_resolver/oneshot_bazel_resolver.rs [97:155]
fn run_bazel_package_query(
app: Arc<App>,
request: &ResolutionRequest,
query: &str,
) -> Result<Vec<String>> {
let query_file_path = {
let (mut file, path, _serial) = app
.sandbox()
.create_file(Some("bazel_query"), None, None)
.context("creating bazel query file")?;
file.write_all(query.as_bytes())
.context("writing bazel query to disk")?;
path
};
let mut initial_bazel_args = Vec::<String>::new();
if request.repo.join(OUTLINING_BAZELRC_PATH).is_file() {
initial_bazel_args.push(String::from("--noworkspace_rc"));
initial_bazel_args.push(format!("--bazelrc={}", OUTLINING_BAZELRC_PATH));
}
let (mut cmd, scmd) = SandboxCommand::new(Self::locate_bazel_binary(request), app)?;
scmd.ensure_exit_with_status_or_log(
cmd.args(initial_bazel_args)
.arg("query")
.arg("--output=package")
.arg("--order_output=no")
.arg("--noimplicit_deps")
.arg("--query_file")
.arg(query_file_path)
.current_dir(&request.repo),
SandboxCommandOutput::Stderr,
&[0, 3],
// TODO: Attempt to disable fetching to speed Bazel further.
// --nofetch --experimental_repository_disable_download=true --keep_going
//
// We will have to allow Bazel PARTIAL_ANALYSIS_FAILURE because of --nofetch.
//
// See https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/util/ExitCode.java.
)?;
// Read to string so that we can print it if we need to debug.
let raw_result = {
let mut result = String::new();
scmd.read_to_string(SandboxCommandOutput::Stdout, &mut result)?;
result
};
debug!(?query, ?raw_result, "Query returned with result");
Ok(raw_result
.lines()
.filter_map(|s| {
if !s.starts_with('@') {
Some(s.to_owned())
} else {
None
}
})
.collect())
}