Skip to content

Commit 8db82e4

Browse files
committed
Merge ignoring config files.
1 parent 4016af7 commit 8db82e4

File tree

12 files changed

+131
-30
lines changed

12 files changed

+131
-30
lines changed

.changes/931.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
{
2-
"description": "add support for cargo aliases.",
3-
"type": "added",
4-
"issues": [562],
5-
}
1+
[
2+
{
3+
"description": "add support for cargo aliases.",
4+
"type": "added",
5+
"issues": [562],
6+
},
7+
{
8+
"description": "allow users to ignore config files in the package.",
9+
"type": "added",
10+
"issues": [621]
11+
}
12+
]

docs/cross_toml.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ For example:
2121

2222
```toml
2323
[build.env]
24+
ignore-cargo-config = false
2425
volumes = ["VOL1_ARG", "VOL2_ARG"]
2526
passthrough = ["IMPORTANT_ENV_VARIABLES"]
2627
```

src/cargo_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22

33
use crate::cargo_toml::CargoToml;
4-
use crate::config::Environment;
4+
use crate::config::{split_to_cloned_by_ws, Environment};
55
use crate::errors::*;
66

77
pub const CARGO_NO_PREFIX_ENVVARS: &[&str] = &[
@@ -27,7 +27,7 @@ impl CargoEnvironment {
2727
let key = format!("ALIAS_{name}");
2828
self.0
2929
.get_var(&self.0.var_name(&key))
30-
.map(|x| x.split_whitespace().map(ToOwned::to_owned).collect())
30+
.map(|x| split_to_cloned_by_ws(&x))
3131
}
3232
}
3333

src/cargo_toml.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::BTreeSet;
22
use std::env;
33
use std::path::Path;
44

5+
use crate::config::split_to_cloned_by_ws;
56
use crate::errors::*;
67
use crate::file;
78

@@ -123,7 +124,7 @@ impl CargoToml {
123124
pub fn alias(&self, name: &str) -> Result<Option<Vec<String>>> {
124125
let parse_alias = |value: &Value| -> Result<Vec<String>> {
125126
if let Some(s) = value.as_str() {
126-
Ok(s.split_whitespace().map(ToOwned::to_owned).collect())
127+
Ok(split_to_cloned_by_ws(s))
127128
} else if let Some(a) = value.as_array() {
128129
a.iter()
129130
.map(|i| {

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn parse_subcommand(
182182
config: &CargoConfig,
183183
seen: &mut Vec<String>,
184184
) -> Result<()> {
185-
if seen.iter().position(|x| x == &arg).is_some() {
185+
if seen.iter().any(|x| x == &arg) {
186186
let chain = seen.join(" -> ");
187187
MessageInfo::default().fatal(
188188
format_args!("alias {arg} has unresolvable recursive definition: {chain} -> {arg}"),
@@ -203,7 +203,7 @@ fn parse_subcommand(
203203
}
204204

205205
// fallthrough
206-
result.all.push(arg.clone());
206+
result.all.push(arg);
207207
result.subcommand = Some(subcommand);
208208

209209
Ok(())

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub fn bool_from_envvar(envvar: &str) -> bool {
1515
}
1616
}
1717

18+
pub fn split_to_cloned_by_ws(string: &str) -> Vec<String> {
19+
string.split_whitespace().map(String::from).collect()
20+
}
21+
1822
#[derive(Debug)]
1923
pub struct Environment(&'static str, Option<HashMap<&'static str, &'static str>>);
2024

src/cross_config.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use crate::config::{bool_from_envvar, Environment};
3+
use crate::config::{bool_from_envvar, split_to_cloned_by_ws, Environment};
44
use crate::docker::custom::PreBuild;
55
use crate::shell::MessageInfo;
66
use crate::{CrossToml, Result, Target, TargetList};
@@ -84,6 +84,10 @@ impl CrossEnvironment {
8484
self.get_target_var(target, "RUNNER")
8585
}
8686

87+
fn ignore_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
88+
self.get_values_for("ENV_IGNORE_CARGO_CONFIG", target, bool_from_envvar)
89+
}
90+
8791
fn passthrough(&self, target: &Target) -> (Option<Vec<String>>, Option<Vec<String>>) {
8892
self.get_values_for("ENV_PASSTHROUGH", target, split_to_cloned_by_ws)
8993
}
@@ -108,10 +112,6 @@ impl CrossEnvironment {
108112
}
109113
}
110114

111-
fn split_to_cloned_by_ws(string: &str) -> Vec<String> {
112-
string.split_whitespace().map(String::from).collect()
113-
}
114-
115115
#[derive(Debug)]
116116
pub struct CrossConfig {
117117
toml: Option<CrossToml>,
@@ -272,6 +272,14 @@ impl CrossConfig {
272272
self.env.custom_toolchain()
273273
}
274274

275+
pub fn env_ignore_cargo_config(&self, target: &Target) -> Option<bool> {
276+
self.bool_from_config(
277+
target,
278+
CrossEnvironment::ignore_cargo_config,
279+
CrossToml::env_ignore_cargo_config,
280+
)
281+
}
282+
275283
pub fn env_passthrough(&self, target: &Target) -> Result<Option<Vec<String>>> {
276284
self.vec_from_config(
277285
target,

src/cross_toml.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use serde::{Deserialize, Deserializer, Serialize};
1515

1616
/// Environment configuration
1717
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
18+
#[serde(rename_all = "kebab-case")]
1819
pub struct CrossEnvConfig {
20+
ignore_cargo_config: Option<bool>,
1921
volumes: Option<Vec<String>>,
2022
passthrough: Option<Vec<String>>,
2123
}
@@ -74,6 +76,7 @@ impl FromStr for CrossTargetDockerfileConfig {
7476

7577
/// Cross configuration
7678
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
79+
#[serde(rename_all = "kebab-case")]
7780
pub struct CrossToml {
7881
#[serde(default, rename = "target")]
7982
pub targets: HashMap<Target, CrossTargetConfig>,
@@ -321,6 +324,15 @@ impl CrossToml {
321324
self.get_value(target, |b| b.build_std, |t| t.build_std)
322325
}
323326

327+
/// Returns the whether to ignore cargo config files.
328+
pub fn env_ignore_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
329+
self.get_value(
330+
target,
331+
|b| b.env.ignore_cargo_config,
332+
|t| t.env.ignore_cargo_config,
333+
)
334+
}
335+
324336
/// Returns the list of environment variables to pass through for `build` and `target`
325337
pub fn env_passthrough(&self, target: &Target) -> (Option<&[String]>, Option<&[String]>) {
326338
self.get_ref(
@@ -537,6 +549,7 @@ mod tests {
537549
targets: HashMap::new(),
538550
build: CrossBuildConfig {
539551
env: CrossEnvConfig {
552+
ignore_cargo_config: Some(false),
540553
volumes: Some(vec![s!("VOL1_ARG"), s!("VOL2_ARG")]),
541554
passthrough: Some(vec![s!("VAR1"), s!("VAR2")]),
542555
},
@@ -554,6 +567,7 @@ mod tests {
554567
pre-build = ["echo 'Hello World!'"]
555568
556569
[build.env]
570+
ignore-cargo-config = false
557571
volumes = ["VOL1_ARG", "VOL2_ARG"]
558572
passthrough = ["VAR1", "VAR2"]
559573
"#;
@@ -574,6 +588,7 @@ mod tests {
574588
},
575589
CrossTargetConfig {
576590
env: CrossEnvConfig {
591+
ignore_cargo_config: None,
577592
passthrough: Some(vec![s!("VAR1"), s!("VAR2")]),
578593
volumes: Some(vec![s!("VOL1_ARG"), s!("VOL2_ARG")]),
579594
},
@@ -628,6 +643,7 @@ mod tests {
628643
pre_build: Some(PreBuild::Lines(vec![s!("echo 'Hello'")])),
629644
runner: None,
630645
env: CrossEnvConfig {
646+
ignore_cargo_config: None,
631647
passthrough: None,
632648
volumes: Some(vec![s!("VOL")]),
633649
},
@@ -638,6 +654,7 @@ mod tests {
638654
targets: target_map,
639655
build: CrossBuildConfig {
640656
env: CrossEnvConfig {
657+
ignore_cargo_config: Some(true),
641658
volumes: None,
642659
passthrough: Some(vec![]),
643660
},
@@ -655,6 +672,7 @@ mod tests {
655672
pre-build = []
656673
657674
[build.env]
675+
ignore-cargo-config = true
658676
passthrough = []
659677
660678
[target.aarch64-unknown-linux-gnu]
@@ -696,6 +714,7 @@ mod tests {
696714
targets: HashMap::new(),
697715
build: CrossBuildConfig {
698716
env: CrossEnvConfig {
717+
ignore_cargo_config: None,
699718
passthrough: None,
700719
volumes: None,
701720
},

src/docker/local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn run(
5555
docker
5656
.args(&["-v", &format!("{}:/rust:Z,ro", dirs.sysroot.to_utf8()?)])
5757
.args(&["-v", &format!("{}:/target:Z", dirs.target.to_utf8()?)]);
58-
docker_cwd(&mut docker, &paths)?;
58+
docker_cwd(&mut docker, &paths, options.ignore_cargo_config)?;
5959

6060
// When running inside NixOS or using Nix packaging we need to add the Nix
6161
// Store to the running container so it can load the needed binaries.

src/docker/remote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ symlink_recurse \"${{prefix}}\"
11701170
let mut docker = subcommand(engine, "exec");
11711171
docker_user_id(&mut docker, engine.kind);
11721172
docker_envvars(&mut docker, &options.config.cross, target, msg_info)?;
1173-
docker_cwd(&mut docker, &paths)?;
1173+
docker_cwd(&mut docker, &paths, options.ignore_cargo_config)?;
11741174
docker.arg(&container);
11751175
docker.args(&["sh", "-c", &format!("PATH=$PATH:/rust/bin {:?}", cmd)]);
11761176
bail_container_exited!();

0 commit comments

Comments
 (0)