mirror of https://github.com/rust-lang/cargo
refactor(toml): Move target build.rs logic next to use
This commit is contained in:
parent
807d7ed2f0
commit
778dc4d4b3
|
@ -1310,30 +1310,6 @@ impl schema::TomlManifest {
|
|||
}
|
||||
Ok(patch)
|
||||
}
|
||||
|
||||
/// Returns the path to the build script if one exists for this crate.
|
||||
fn maybe_custom_build(
|
||||
&self,
|
||||
build: &Option<schema::StringOrBool>,
|
||||
package_root: &Path,
|
||||
) -> Option<PathBuf> {
|
||||
let build_rs = package_root.join("build.rs");
|
||||
match *build {
|
||||
// Explicitly no build script.
|
||||
Some(schema::StringOrBool::Bool(false)) => None,
|
||||
Some(schema::StringOrBool::Bool(true)) => Some(build_rs),
|
||||
Some(schema::StringOrBool::String(ref s)) => Some(PathBuf::from(s)),
|
||||
None => {
|
||||
// If there is a `build.rs` file next to the `Cargo.toml`, assume it is
|
||||
// a build script.
|
||||
if build_rs.is_file() {
|
||||
Some(build_rs)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Context<'a, 'b> {
|
||||
|
|
|
@ -105,7 +105,7 @@ pub(super) fn targets(
|
|||
)?);
|
||||
|
||||
// processing the custom build script
|
||||
if let Some(custom_build) = manifest.maybe_custom_build(custom_build, package_root) {
|
||||
if let Some(custom_build) = maybe_custom_build(custom_build, package_root) {
|
||||
if metabuild.is_some() {
|
||||
anyhow::bail!("cannot specify both `metabuild` and `build`");
|
||||
}
|
||||
|
@ -964,3 +964,23 @@ Cargo doesn't know which to use because multiple target files found at `{}` and
|
|||
(None, Some(_)) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path to the build script if one exists for this crate.
|
||||
fn maybe_custom_build(build: &Option<StringOrBool>, package_root: &Path) -> Option<PathBuf> {
|
||||
let build_rs = package_root.join("build.rs");
|
||||
match *build {
|
||||
// Explicitly no build script.
|
||||
Some(StringOrBool::Bool(false)) => None,
|
||||
Some(StringOrBool::Bool(true)) => Some(build_rs),
|
||||
Some(StringOrBool::String(ref s)) => Some(PathBuf::from(s)),
|
||||
None => {
|
||||
// If there is a `build.rs` file next to the `Cargo.toml`, assume it is
|
||||
// a build script.
|
||||
if build_rs.is_file() {
|
||||
Some(build_rs)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue