mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Add an Edition on TomlTarget & Target, & wire
This commit is contained in:
parent
db48c63b36
commit
76001afbfe
@ -200,6 +200,7 @@ pub struct Target {
|
|||||||
doctest: bool,
|
doctest: bool,
|
||||||
harness: bool, // whether to use the test harness (--test)
|
harness: bool, // whether to use the test harness (--test)
|
||||||
for_host: bool,
|
for_host: bool,
|
||||||
|
edition: Edition,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
@ -280,6 +281,7 @@ compact_debug! {
|
|||||||
doctest
|
doctest
|
||||||
harness
|
harness
|
||||||
for_host
|
for_host
|
||||||
|
edition
|
||||||
)]
|
)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -507,6 +509,7 @@ impl Target {
|
|||||||
doctest: false,
|
doctest: false,
|
||||||
harness: true,
|
harness: true,
|
||||||
for_host: false,
|
for_host: false,
|
||||||
|
edition: Edition::Edition2015,
|
||||||
tested: true,
|
tested: true,
|
||||||
benched: true,
|
benched: true,
|
||||||
}
|
}
|
||||||
@ -625,6 +628,7 @@ impl Target {
|
|||||||
pub fn for_host(&self) -> bool {
|
pub fn for_host(&self) -> bool {
|
||||||
self.for_host
|
self.for_host
|
||||||
}
|
}
|
||||||
|
pub fn edition(&self) -> Edition { self.edition }
|
||||||
pub fn benched(&self) -> bool {
|
pub fn benched(&self) -> bool {
|
||||||
self.benched
|
self.benched
|
||||||
}
|
}
|
||||||
@ -746,6 +750,10 @@ impl Target {
|
|||||||
self.for_host = for_host;
|
self.for_host = for_host;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
pub fn set_edition(&mut self, edition: Edition) -> &mut Target {
|
||||||
|
self.edition = edition;
|
||||||
|
self
|
||||||
|
}
|
||||||
pub fn set_harness(&mut self, harness: bool) -> &mut Target {
|
pub fn set_harness(&mut self, harness: bool) -> &mut Target {
|
||||||
self.harness = harness;
|
self.harness = harness;
|
||||||
self
|
self
|
||||||
|
@ -1357,6 +1357,7 @@ struct TomlTarget {
|
|||||||
harness: Option<bool>,
|
harness: Option<bool>,
|
||||||
#[serde(rename = "required-features")]
|
#[serde(rename = "required-features")]
|
||||||
required_features: Option<Vec<String>>,
|
required_features: Option<Vec<String>>,
|
||||||
|
edition: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -15,7 +15,7 @@ use std::fs::{self, DirEntry};
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use core::{compiler, Edition, Target};
|
use core::{compiler, Edition, Target};
|
||||||
use util::errors::CargoResult;
|
use util::errors::{CargoResult, CargoResultExt};
|
||||||
use super::{LibKind, PathValue, StringOrBool, TomlBenchTarget, TomlBinTarget, TomlExampleTarget,
|
use super::{LibKind, PathValue, StringOrBool, TomlBenchTarget, TomlBinTarget, TomlExampleTarget,
|
||||||
TomlLibTarget, TomlManifest, TomlTarget, TomlTestTarget};
|
TomlLibTarget, TomlManifest, TomlTarget, TomlTestTarget};
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ fn clean_lib(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut target = Target::lib_target(&lib.name(), crate_types, path);
|
let mut target = Target::lib_target(&lib.name(), crate_types, path);
|
||||||
configure(lib, &mut target);
|
configure(lib, &mut target)?;
|
||||||
Ok(Some(target))
|
Ok(Some(target))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ fn clean_bins(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut target = Target::bin_target(&bin.name(), path, bin.required_features.clone());
|
let mut target = Target::bin_target(&bin.name(), path, bin.required_features.clone());
|
||||||
configure(bin, &mut target);
|
configure(bin, &mut target)?;
|
||||||
result.push(target);
|
result.push(target);
|
||||||
}
|
}
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
@ -324,7 +324,7 @@ fn clean_examples(
|
|||||||
path,
|
path,
|
||||||
toml.required_features.clone(),
|
toml.required_features.clone(),
|
||||||
);
|
);
|
||||||
configure(&toml, &mut target);
|
configure(&toml, &mut target)?;
|
||||||
result.push(target);
|
result.push(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +357,7 @@ fn clean_tests(
|
|||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
for (path, toml) in targets {
|
for (path, toml) in targets {
|
||||||
let mut target = Target::test_target(&toml.name(), path, toml.required_features.clone());
|
let mut target = Target::test_target(&toml.name(), path, toml.required_features.clone());
|
||||||
configure(&toml, &mut target);
|
configure(&toml, &mut target)?;
|
||||||
result.push(target);
|
result.push(target);
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
@ -410,7 +410,7 @@ fn clean_benches(
|
|||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
for (path, toml) in targets {
|
for (path, toml) in targets {
|
||||||
let mut target = Target::bench_target(&toml.name(), path, toml.required_features.clone());
|
let mut target = Target::bench_target(&toml.name(), path, toml.required_features.clone());
|
||||||
configure(&toml, &mut target);
|
configure(&toml, &mut target)?;
|
||||||
result.push(target);
|
result.push(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,7 +682,7 @@ fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResu
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure(toml: &TomlTarget, target: &mut Target) {
|
fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
|
||||||
let t2 = target.clone();
|
let t2 = target.clone();
|
||||||
target
|
target
|
||||||
.set_tested(toml.test.unwrap_or_else(|| t2.tested()))
|
.set_tested(toml.test.unwrap_or_else(|| t2.tested()))
|
||||||
@ -694,7 +694,13 @@ fn configure(toml: &TomlTarget, target: &mut Target) {
|
|||||||
(None, None) => t2.for_host(),
|
(None, None) => t2.for_host(),
|
||||||
(Some(true), _) | (_, Some(true)) => true,
|
(Some(true), _) | (_, Some(true)) => true,
|
||||||
(Some(false), _) | (_, Some(false)) => false,
|
(Some(false), _) | (_, Some(false)) => false,
|
||||||
|
})
|
||||||
|
.set_edition(match toml.edition.clone() {
|
||||||
|
None => t2.edition(),
|
||||||
|
// TODO: Check the edition feature gate
|
||||||
|
Some(s) => s.parse().chain_err(|| "failed to parse the `edition` key")?,
|
||||||
});
|
});
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_path(
|
fn target_path(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user