Skip to content

Commit 12a6e13

Browse files
committed
Merge ignore and complete.
1 parent a7a516f commit 12a6e13

File tree

7 files changed

+60
-87
lines changed

7 files changed

+60
-87
lines changed

docs/cross_toml.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ For example:
2121

2222
```toml
2323
[build.env]
24-
complete-cargo-config = true
25-
ignore-cargo-config = false
24+
cargo-config = "complete"
2625
volumes = ["VOL1_ARG", "VOL2_ARG"]
2726
passthrough = ["IMPORTANT_ENV_VARIABLES"]
2827
```
@@ -65,6 +64,7 @@ This is similar to `build.env`, but allows you to be more specific per target.
6564

6665
```toml
6766
[target.x86_64-unknown-linux-gnu.env]
67+
cargo-config = "ignore"
6868
volumes = ["VOL1_ARG", "VOL2_ARG"]
6969
passthrough = ["IMPORTANT_ENV_VARIABLES"]
7070
```

src/cross_config.rs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::str::FromStr;
23

34
use crate::config::{bool_from_envvar, split_to_cloned_by_ws, Environment};
45
use crate::cross_toml::CargoConfigBehavior;
@@ -85,15 +86,18 @@ impl CrossEnvironment {
8586
self.get_target_var(target, "RUNNER")
8687
}
8788

88-
// TODO(ahuszagh) Need to change this.
89-
// Need to have an enum here.
90-
91-
fn complete_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
92-
self.get_values_for("ENV_COMPLETE_CARGO_CONFIG", target, bool_from_envvar)
93-
}
94-
95-
fn ignore_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
96-
self.get_values_for("ENV_IGNORE_CARGO_CONFIG", target, bool_from_envvar)
89+
fn cargo_config(
90+
&self,
91+
target: &Target,
92+
) -> Result<(Option<CargoConfigBehavior>, Option<CargoConfigBehavior>)> {
93+
let (build, target) =
94+
self.get_values_for("ENV_CARGO_CONFIG", target, CargoConfigBehavior::from_str);
95+
Ok(match (build, target) {
96+
(Some(b), Some(t)) => (Some(b?), Some(t?)),
97+
(Some(b), None) => (Some(b?), None),
98+
(None, Some(t)) => (None, Some(t?)),
99+
(None, None) => (None, None),
100+
})
97101
}
98102

99103
fn passthrough(&self, target: &Target) -> (Option<Vec<String>>, Option<Vec<String>>) {
@@ -280,23 +284,27 @@ impl CrossConfig {
280284
self.env.custom_toolchain()
281285
}
282286

283-
// TODO(ahuszagh) This should actually be an enough
284-
// Ignore, default, complete.
287+
pub fn env_cargo_config(&self, target: &Target) -> Result<Option<CargoConfigBehavior>> {
288+
let (env_build, env_target) = self.env.cargo_config(target)?;
285289

286-
pub fn env_complete_cargo_config(&self, target: &Target) -> Option<bool> {
287-
self.bool_from_config(
288-
target,
289-
CrossEnvironment::complete_cargo_config,
290-
CrossToml::env_complete_cargo_config,
291-
)
292-
}
290+
if let Some(env_target) = env_target {
291+
return Ok(Some(env_target));
292+
}
293293

294-
pub fn env_ignore_cargo_config(&self, target: &Target) -> Option<bool> {
295-
self.bool_from_config(
296-
target,
297-
CrossEnvironment::ignore_cargo_config,
298-
CrossToml::env_ignore_cargo_config,
299-
)
294+
let (build, target) = self
295+
.toml
296+
.as_ref()
297+
.map(|t| t.env_cargo_config(target))
298+
.unwrap_or_default();
299+
300+
// FIXME: let expression
301+
if target.is_none() && env_build.is_some() {
302+
Ok(env_build)
303+
} else if target.is_none() {
304+
Ok(build)
305+
} else {
306+
Ok(target)
307+
}
300308
}
301309

302310
pub fn env_passthrough(&self, target: &Target) -> Result<Option<Vec<String>>> {

src/cross_toml.rs

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ use serde::{Deserialize, Deserializer, Serialize};
1717
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
1818
#[serde(rename_all = "kebab-case")]
1919
pub struct CrossEnvConfig {
20-
// TODO(ahuszagh) Change to an enum
2120
cargo_config: Option<CargoConfigBehavior>,
22-
complete_cargo_config: Option<bool>,
23-
ignore_cargo_config: Option<bool>,
2421
volumes: Option<Vec<String>>,
2522
passthrough: Option<Vec<String>>,
2623
}
@@ -356,30 +353,11 @@ impl CrossToml {
356353
}
357354

358355
/// Returns the cargo config behavior.
359-
pub fn env_cargo_config(&self, target: &Target) -> (Option<CargoConfigBehavior>, Option<CargoConfigBehavior>) {
360-
self.get_value(
361-
target,
362-
|b| b.env.cargo_config,
363-
|t| t.env.cargo_config,
364-
)
365-
}
366-
367-
/// Returns the whether to use the complete cargo config settings.
368-
pub fn env_complete_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
369-
self.get_value(
370-
target,
371-
|b| b.env.complete_cargo_config,
372-
|t| t.env.complete_cargo_config,
373-
)
374-
}
375-
376-
/// Returns the whether to ignore cargo config files.
377-
pub fn env_ignore_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
378-
self.get_value(
379-
target,
380-
|b| b.env.ignore_cargo_config,
381-
|t| t.env.ignore_cargo_config,
382-
)
356+
pub fn env_cargo_config(
357+
&self,
358+
target: &Target,
359+
) -> (Option<CargoConfigBehavior>, Option<CargoConfigBehavior>) {
360+
self.get_value(target, |b| b.env.cargo_config, |t| t.env.cargo_config)
383361
}
384362

385363
/// Returns the list of environment variables to pass through for `build` and `target`
@@ -582,7 +560,10 @@ mod tests {
582560
pub fn test_toml_cargo_config_behavior() -> Result<()> {
583561
assert_eq!(CargoConfigBehavior::Normal, toml::from_str("\"default\"")?);
584562
assert_eq!(CargoConfigBehavior::Ignore, toml::from_str("\"ignore\"")?);
585-
assert_eq!(CargoConfigBehavior::Complete, toml::from_str("\"complete\"")?);
563+
assert_eq!(
564+
CargoConfigBehavior::Complete,
565+
toml::from_str("\"complete\"")?
566+
);
586567
assert!(toml::from_str::<CargoConfigBehavior>("\"other\"").is_err());
587568
assert!(toml::from_str::<CargoConfigBehavior>("true").is_err());
588569
assert!(toml::from_str::<CargoConfigBehavior>("0").is_err());
@@ -610,10 +591,7 @@ mod tests {
610591
targets: HashMap::new(),
611592
build: CrossBuildConfig {
612593
env: CrossEnvConfig {
613-
// TODO(ahuszagh) Remove
614-
cargo_config: None,
615-
complete_cargo_config: None,
616-
ignore_cargo_config: Some(false),
594+
cargo_config: Some(CargoConfigBehavior::Ignore),
617595
volumes: Some(vec![s!("VOL1_ARG"), s!("VOL2_ARG")]),
618596
passthrough: Some(vec![s!("VAR1"), s!("VAR2")]),
619597
},
@@ -631,7 +609,7 @@ mod tests {
631609
pre-build = ["echo 'Hello World!'"]
632610
633611
[build.env]
634-
ignore-cargo-config = false
612+
cargo-config = "ignore"
635613
volumes = ["VOL1_ARG", "VOL2_ARG"]
636614
passthrough = ["VAR1", "VAR2"]
637615
"#;
@@ -652,10 +630,7 @@ mod tests {
652630
},
653631
CrossTargetConfig {
654632
env: CrossEnvConfig {
655-
// TODO(ahuszagh) Remove
656633
cargo_config: None,
657-
complete_cargo_config: None,
658-
ignore_cargo_config: None,
659634
passthrough: Some(vec![s!("VAR1"), s!("VAR2")]),
660635
volumes: Some(vec![s!("VOL1_ARG"), s!("VOL2_ARG")]),
661636
},
@@ -710,10 +685,7 @@ mod tests {
710685
pre_build: Some(PreBuild::Lines(vec![s!("echo 'Hello'")])),
711686
runner: None,
712687
env: CrossEnvConfig {
713-
// TODO(ahuszagh) Remove
714688
cargo_config: None,
715-
complete_cargo_config: None,
716-
ignore_cargo_config: None,
717689
passthrough: None,
718690
volumes: Some(vec![s!("VOL")]),
719691
},
@@ -724,10 +696,7 @@ mod tests {
724696
targets: target_map,
725697
build: CrossBuildConfig {
726698
env: CrossEnvConfig {
727-
// TODO(ahuszagh) Remove
728-
cargo_config: None,
729-
complete_cargo_config: None,
730-
ignore_cargo_config: Some(true),
699+
cargo_config: Some(CargoConfigBehavior::Complete),
731700
volumes: None,
732701
passthrough: Some(vec![]),
733702
},
@@ -745,7 +714,7 @@ mod tests {
745714
pre-build = []
746715
747716
[build.env]
748-
ignore-cargo-config = true
717+
cargo-config = "complete"
749718
passthrough = []
750719
751720
[target.aarch64-unknown-linux-gnu]
@@ -787,10 +756,7 @@ mod tests {
787756
targets: HashMap::new(),
788757
build: CrossBuildConfig {
789758
env: CrossEnvConfig {
790-
// TODO(ahuszagh) Remove
791759
cargo_config: None,
792-
complete_cargo_config: None,
793-
ignore_cargo_config: None,
794760
passthrough: None,
795761
volumes: None,
796762
},

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, options.ignore_cargo_config)?;
58+
docker_cwd(&mut docker, &paths, options.cargo_config_behavior)?;
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, options.ignore_cargo_config)?;
1173+
docker_cwd(&mut docker, &paths, options.cargo_config_behavior)?;
11741174
docker.arg(&container);
11751175
docker.args(&["sh", "-c", &format!("PATH=$PATH:/rust/bin {:?}", cmd)]);
11761176
bail_container_exited!();

src/docker/shared.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::cargo::{cargo_metadata_with_args, CargoMetadata};
99
use crate::cargo_config::CARGO_NO_PREFIX_ENVVARS;
1010
use crate::config::{bool_from_envvar, Config};
1111
use crate::cross_config::CrossConfig;
12+
use crate::cross_toml::CargoConfigBehavior;
1213
use crate::errors::*;
1314
use crate::extensions::{CommandExt, SafeCommand};
1415
use crate::file::{self, write_file, PathExt, ToUtf8};
@@ -39,7 +40,7 @@ pub struct DockerOptions {
3940
pub target: Target,
4041
pub config: Config,
4142
pub uses_xargo: bool,
42-
pub ignore_cargo_config: bool,
43+
pub cargo_config_behavior: CargoConfigBehavior,
4344
}
4445

4546
impl DockerOptions {
@@ -48,14 +49,14 @@ impl DockerOptions {
4849
target: Target,
4950
config: Config,
5051
uses_xargo: bool,
51-
ignore_cargo_config: bool,
52+
cargo_config_behavior: CargoConfigBehavior,
5253
) -> DockerOptions {
5354
DockerOptions {
5455
engine,
5556
target,
5657
config,
5758
uses_xargo,
58-
ignore_cargo_config,
59+
cargo_config_behavior,
5960
}
6061
}
6162

@@ -513,7 +514,7 @@ pub(crate) fn docker_envvars(
513514
fn mount_to_ignore_cargo_config(
514515
docker: &mut Command,
515516
paths: &DockerPaths,
516-
ignore_cargo_config: bool,
517+
cargo_config_behavior: CargoConfigBehavior,
517518
) -> Result<()> {
518519
let check_mount =
519520
|cmd: &mut Command, host: &Path, mount: &Path, relpath: &Path| -> Result<()> {
@@ -525,7 +526,7 @@ fn mount_to_ignore_cargo_config(
525526

526527
Ok(())
527528
};
528-
if ignore_cargo_config {
529+
if let CargoConfigBehavior::Ignore = cargo_config_behavior {
529530
let mount_root = Path::new(paths.mount_root());
530531
let mount_cwd = Path::new(paths.mount_cwd());
531532
check_mount(docker, &paths.cwd, mount_cwd, Path::new(""))?;
@@ -544,10 +545,10 @@ fn mount_to_ignore_cargo_config(
544545
pub(crate) fn docker_cwd(
545546
docker: &mut Command,
546547
paths: &DockerPaths,
547-
ignore_cargo_config: bool,
548+
cargo_config_behavior: CargoConfigBehavior,
548549
) -> Result<()> {
549550
docker.args(&["-w", paths.mount_cwd()]);
550-
mount_to_ignore_cargo_config(docker, paths, ignore_cargo_config)?;
551+
mount_to_ignore_cargo_config(docker, paths, cargo_config_behavior)?;
551552

552553
Ok(())
553554
}

src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,14 @@ pub fn run() -> Result<ExitStatus> {
540540
}
541541

542542
let paths = docker::DockerPaths::create(&engine, metadata, cwd, sysroot)?;
543-
let ignore_cargo_config = config
544-
.cross
545-
.env_ignore_cargo_config(&target)
546-
.unwrap_or_default();
543+
let cargo_config_behavior =
544+
config.cross.env_cargo_config(&target)?.unwrap_or_default();
547545
let options = docker::DockerOptions::new(
548546
engine,
549547
target.clone(),
550548
config,
551549
uses_xargo,
552-
ignore_cargo_config,
550+
cargo_config_behavior,
553551
);
554552
let status = docker::run(options, paths, &filtered_args, &mut msg_info)
555553
.wrap_err("could not run container")?;

0 commit comments

Comments
 (0)