MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / wrap_with_env

Function wrap_with_env

src/executor/helpers/run_with_env.rs:35–51  ·  view source on GitHub ↗

Wraps a command to run with environment variables forwarded. # Returns Returns a tuple of (CommandBuilder, NamedTempFile) where: - CommandBuilder is wrapped with bash to source the environment and run the original command - NamedTempFile is the environment file that must be kept alive until command execution

(
    mut cmd_builder: CommandBuilder,
    extra_env: &HashMap<String, String>,
)

Source from the content-addressed store, hash-verified

33/// - CommandBuilder is wrapped with bash to source the environment and run the original command
34/// - NamedTempFile is the environment file that must be kept alive until command execution
35pub fn wrap_with_env(
36 mut cmd_builder: CommandBuilder,
37 extra_env: &HashMap<String, String>,
38) -> Result<(CommandBuilder, NamedTempFile)> {
39 let env_file = create_env_file(extra_env)?;
40
41 // Create bash command that sources the env file and runs the original command
42 let original_command = cmd_builder.as_command_line();
43 let bash_command = format!(
44 "source {} && {}",
45 env_file.path().display(),
46 original_command
47 );
48 cmd_builder.wrap("bash", ["-c", &bash_command]);
49
50 Ok((cmd_builder, env_file))
51}
52
53fn create_env_file(extra_env: &HashMap<String, String>) -> Result<NamedTempFile> {
54 let system_env = get_exported_system_env()?;

Callers 2

walltime_bench_cmdMethod · 0.85

Calls 3

create_env_fileFunction · 0.85
as_command_lineMethod · 0.80
wrapMethod · 0.80

Tested by

no test coverage detected