in src/rust/engine/process_execution/src/remote.rs [736:823]
fn make_execute_request(
req: &ExecuteProcessRequest,
instance_name: &Option<String>,
cache_key_gen_version: &Option<String>,
mut platform_properties: BTreeMap<String, String>,
) -> Result<
(
bazel_protos::remote_execution::Action,
bazel_protos::remote_execution::Command,
bazel_protos::remote_execution::ExecuteRequest,
),
String,
> {
let mut command = bazel_protos::remote_execution::Command::new();
command.set_arguments(protobuf::RepeatedField::from_vec(req.argv.clone()));
for (ref name, ref value) in &req.env {
if name.as_str() == CACHE_KEY_GEN_VERSION_ENV_VAR_NAME {
return Err(format!(
"Cannot set env var with name {} as that is reserved for internal use by pants",
CACHE_KEY_GEN_VERSION_ENV_VAR_NAME
));
}
let mut env = bazel_protos::remote_execution::Command_EnvironmentVariable::new();
env.set_name(name.to_string());
env.set_value(value.to_string());
command.mut_environment_variables().push(env);
}
if let Some(cache_key_gen_version) = cache_key_gen_version {
let mut env = bazel_protos::remote_execution::Command_EnvironmentVariable::new();
env.set_name(CACHE_KEY_GEN_VERSION_ENV_VAR_NAME.to_string());
env.set_value(cache_key_gen_version.to_string());
command.mut_environment_variables().push(env);
}
let mut output_files = req
.output_files
.iter()
.map(|p| {
p.to_str()
.map(str::to_owned)
.ok_or_else(|| format!("Non-UTF8 output file path: {:?}", p))
})
.collect::<Result<Vec<String>, String>>()?;
output_files.sort();
command.set_output_files(protobuf::RepeatedField::from_vec(output_files));
let mut output_directories = req
.output_directories
.iter()
.map(|p| {
p.to_str()
.map(str::to_owned)
.ok_or_else(|| format!("Non-UTF8 output directory path: {:?}", p))
})
.collect::<Result<Vec<String>, String>>()?;
output_directories.sort();
command.set_output_directories(protobuf::RepeatedField::from_vec(output_directories));
if req.jdk_home.is_some() {
// Ideally, the JDK would be brought along as part of the input directory, but we don't
// currently have support for that. Scoot supports this property, and will symlink .jdk to a
// system-installed JDK https://github.com/twitter/scoot/pull/391 - we should probably come to
// some kind of consensus across tools as to how this should work; RBE appears to work by
// allowing you to specify a jdk-version platform property, and it will put a JDK at a
// well-known path in the docker container you specify in which to run.
platform_properties.insert("JDK_SYMLINK".to_owned(), ".jdk".to_owned());
}
for (name, value) in platform_properties {
command.mut_platform().mut_properties().push({
let mut property = bazel_protos::remote_execution::Platform_Property::new();
property.set_name(name.clone());
property.set_value(value.clone());
property
});
}
let mut action = bazel_protos::remote_execution::Action::new();
action.set_command_digest((&digest(&command)?).into());
action.set_input_root_digest((&req.input_files).into());
let mut execute_request = bazel_protos::remote_execution::ExecuteRequest::new();
if let Some(instance_name) = instance_name {
execute_request.set_instance_name(instance_name.clone());
}
execute_request.set_action_digest((&digest(&action)?).into());
Ok((action, command, execute_request))
}