mirror of
https://github.com/rust-lang/cargo
synced 2024-09-17 23:01:51 +00:00
refactor(toml): Pull fs out as explicit step
So diagnostics can use this for reporting.
This commit is contained in:
parent
89f1cce439
commit
69ee34a274
|
@ -54,20 +54,9 @@ pub fn read_manifest(
|
|||
path.display(),
|
||||
source_id
|
||||
);
|
||||
let mut contents = paths::read(path).map_err(|err| ManifestError::new(err, path.into()))?;
|
||||
let embedded = is_embedded(path);
|
||||
if embedded {
|
||||
if !gctx.cli_unstable().script {
|
||||
return Err(ManifestError::new(
|
||||
anyhow::anyhow!("parsing `{}` requires `-Zscript`", path.display()),
|
||||
path.into(),
|
||||
))?;
|
||||
}
|
||||
contents = embedded::expand_manifest(&contents, path, gctx)
|
||||
.map_err(|err| ManifestError::new(err, path.into()))?;
|
||||
}
|
||||
let contents = read_toml_string(path, gctx)?;
|
||||
|
||||
read_manifest_from_str(&contents, path, embedded, source_id, gctx).map_err(|err| {
|
||||
read_manifest_from_str(&contents, path, source_id, gctx).map_err(|err| {
|
||||
if err.is::<AlreadyPrintedError>() {
|
||||
err
|
||||
} else {
|
||||
|
@ -80,6 +69,22 @@ pub fn read_manifest(
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
fn read_toml_string(path: &Path, gctx: &GlobalContext) -> CargoResult<String> {
|
||||
let mut contents = paths::read(path).map_err(|err| ManifestError::new(err, path.into()))?;
|
||||
if is_embedded(path) {
|
||||
if !gctx.cli_unstable().script {
|
||||
return Err(ManifestError::new(
|
||||
anyhow::anyhow!("parsing `{}` requires `-Zscript`", path.display()),
|
||||
path.into(),
|
||||
))?;
|
||||
}
|
||||
contents = embedded::expand_manifest(&contents, path, gctx)
|
||||
.map_err(|err| ManifestError::new(err, path.into()))?;
|
||||
}
|
||||
Ok(contents)
|
||||
}
|
||||
|
||||
/// See also `bin/cargo/commands/run.rs`s `is_manifest_command`
|
||||
pub fn is_embedded(path: &Path) -> bool {
|
||||
let ext = path.extension();
|
||||
|
@ -99,7 +104,6 @@ pub fn is_embedded(path: &Path) -> bool {
|
|||
fn read_manifest_from_str(
|
||||
contents: &str,
|
||||
manifest_file: &Path,
|
||||
embedded: bool,
|
||||
source_id: SourceId,
|
||||
gctx: &GlobalContext,
|
||||
) -> CargoResult<(EitherManifest, Vec<PathBuf>)> {
|
||||
|
@ -186,6 +190,7 @@ fn read_manifest_from_str(
|
|||
}
|
||||
}
|
||||
return if manifest.project.is_some() || manifest.package.is_some() {
|
||||
let embedded = is_embedded(manifest_file);
|
||||
let (mut manifest, paths) =
|
||||
to_real_manifest(manifest, embedded, source_id, package_root, gctx)?;
|
||||
add_unused(manifest.warnings_mut());
|
||||
|
|
Loading…
Reference in a new issue