Skip to content

Commit c72b1d7

Browse files
Merge #750
750: Allow key-value pairs in config volumes. r=otavio a=Alexhuszagh Allow volumes to use the `["VOL=/path/to/volume"]' syntax as well, so additional mount points can be defined by value in the `env.volumes` section of the config file. Allows the following syntax: ```toml [build.env] volumes = ["VOL=/path/to/mount/"] ``` Not implementing it with the `env.passthrough` was a complete oversight on my part, related to #743 and #748. Co-authored-by: Alex Huszagh <[email protected]>
2 parents ee4df2b + 7359534 commit c72b1d7

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/docker.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> {
5252
.run(verbose)
5353
}
5454

55+
fn validate_env_var(var: &str) -> Result<(&str, Option<&str>)> {
56+
let (key, value) = match var.split_once('=') {
57+
Some((key, value)) => (key, Some(value)),
58+
_ => (var, None),
59+
};
60+
61+
if key == "CROSS_RUNNER" {
62+
bail!("CROSS_RUNNER environment variable name is reserved and cannot be pass through");
63+
}
64+
65+
Ok((key, value))
66+
}
67+
5568
#[allow(clippy::too_many_arguments)] // TODO: refactor
5669
pub fn run(
5770
target: &Target,
@@ -114,19 +127,6 @@ pub fn run(
114127

115128
let mut docker = docker_command("run")?;
116129

117-
let validate_env_var = |var: &str| -> Result<()> {
118-
let var = match var.split_once('=') {
119-
Some((key, _)) => key,
120-
_ => var,
121-
};
122-
123-
if var == "CROSS_RUNNER" {
124-
bail!("CROSS_RUNNER environment variable name is reserved and cannot be pass through");
125-
}
126-
127-
Ok(())
128-
};
129-
130130
for ref var in config.env_passthrough(target)? {
131131
validate_env_var(var)?;
132132

@@ -136,9 +136,13 @@ pub fn run(
136136
}
137137
let mut env_volumes = false;
138138
for ref var in config.env_volumes(target)? {
139-
validate_env_var(var)?;
139+
let (var, value) = validate_env_var(var)?;
140+
let value = match value {
141+
Some(v) => Ok(v.to_string()),
142+
None => env::var(var),
143+
};
140144

141-
if let Ok(val) = env::var(var) {
145+
if let Ok(val) = value {
142146
let host_path: PathBuf;
143147
let mount_path: PathBuf;
144148

0 commit comments

Comments
 (0)