Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
[guppy] upgrade to cargo_metadata 0.13.1
Browse files Browse the repository at this point in the history
Ah unfortunately there's a couple of small breaking changes, will
release guppy 0.9.0 for it.
  • Loading branch information
sunshowers committed Mar 11, 2021
1 parent d8a3990 commit b171edb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 70 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions fixtures/src/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ use guppy::{
DependencyKind, PackageId, Platform, Version,
};
use pretty_assertions::assert_eq;
use std::{
collections::{BTreeMap, HashMap},
path::PathBuf,
};
use std::collections::{BTreeMap, HashMap};

/// This captures metadata fields that are relevant for tests. They are meant to be written out
/// lazily as tests are filled out -- feel free to add more details as necessary!
Expand Down Expand Up @@ -306,7 +303,13 @@ pub struct PackageDetails {
license: Option<&'static str>,

source: Option<PackageSource<'static>>,
build_targets: Option<Vec<(BuildTargetId<'static>, BuildTargetKind<'static>, PathBuf)>>,
build_targets: Option<
Vec<(
BuildTargetId<'static>,
BuildTargetKind<'static>,
Utf8PathBuf,
)>,
>,
// The vector items are (name, package id).
// XXX add more details about dependency edges here?
deps: Option<Vec<(&'static str, PackageId)>>,
Expand Down
5 changes: 5 additions & 0 deletions guppy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- `DependencyKind::VALUES` lists out all the values of `DependencyKind`.
- `DependencyReq::no_default_features()` returns the enabled status for a dependency when `default-features = false`.

### Changed

- `PackageMetadata::readme` now returns `&Utf8Path` rather than `&Path`.
- `BuildTarget::path` now returns `&Utf8Path` rather than `&Path`.

## [0.8.0] - 2021-02-23

### Changed
Expand Down
2 changes: 1 addition & 1 deletion guppy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ maintenance = { status = "actively-developed" }

[dependencies]
camino = "1.0.2"
cargo_metadata = "0.12.3"
cargo_metadata = "0.13.1"
guppy-summaries = { version = "0.4.0", path = "../guppy-summaries", optional = true }
fixedbitset = { version = "0.2.0", default-features = false }
nested = "0.1.1"
Expand Down
66 changes: 12 additions & 54 deletions guppy/src/graph/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ use cargo_metadata::{Dependency, DependencyKind, Metadata, NodeDep, Package, Res
use once_cell::sync::OnceCell;
use petgraph::prelude::*;
use semver::Version;
use std::{
collections::{BTreeMap, HashMap, HashSet},
path::Path,
};
use std::collections::{BTreeMap, HashMap, HashSet};
use target_spec::TargetSpec;

impl PackageGraph {
Expand All @@ -36,13 +33,7 @@ impl PackageGraph {
.map(PackageId::from_metadata)
.collect();

let workspace_root =
Utf8PathBuf::from_path_buf(metadata.workspace_root).map_err(|path_buf| {
Error::PackageGraphConstructError(format!(
"workspace root is invalid UTF-8: {}",
path_buf.display()
))
})?;
let workspace_root = metadata.workspace_root;

let mut build_state = GraphBuildState::new(
&metadata.packages,
Expand Down Expand Up @@ -204,20 +195,14 @@ impl<'a> GraphBuildState<'a> {
None => {
return Err(Error::PackageGraphConstructError(format!(
"package '{}': manifest path '{}' does not have parent",
package_id,
package.manifest_path.display(),
package_id, package.manifest_path,
)));
}
};
let rel_path = pathdiff::diff_paths(dirname, self.workspace_root)
.expect("workspace root is absolute");
let rel_path = Utf8PathBuf::from_path_buf(rel_path).map_err(|path_buf| {
Error::PackageGraphConstructError(format!(
"package '{}': location '{}' is invalid UTF-8",
package_id,
path_buf.display()
))
})?;
let rel_path = Utf8PathBuf::from_path_buf(rel_path)
.expect("diff between two UTF-8 paths should produce a UTF-8 path");
PackageSourceImpl::Path(rel_path.into_boxed_path())
};

Expand Down Expand Up @@ -290,31 +275,6 @@ impl<'a> GraphBuildState<'a> {
.chain(optional_deps)
.collect();

let license_file = match package.license_file {
Some(license_file) => Some(
Utf8PathBuf::from_path_buf(license_file)
.map_err(|path_buf| {
Error::PackageGraphConstructError(format!(
"for package '{}', license file is invalid UTF-8: {}",
package_id,
path_buf.display()
))
})?
.into(),
),
None => None,
};

let manifest_path = Utf8PathBuf::from_path_buf(package.manifest_path)
.map_err(|path_buf| {
Error::PackageGraphConstructError(format!(
"for package '{}', manifest path is invalid UTF-8: {}",
package_id,
path_buf.display()
))
})?
.into();

Ok((
package_id,
PackageMetadataImpl {
Expand All @@ -323,8 +283,8 @@ impl<'a> GraphBuildState<'a> {
authors: package.authors,
description: package.description.map(|s| s.into()),
license: package.license.map(|s| s.into()),
license_file,
manifest_path,
license_file: package.license_file.map(|f| f.into()),
manifest_path: package.manifest_path.into(),
categories: package.categories,
keywords: package.keywords,
readme: package.readme.map(|s| s.into()),
Expand Down Expand Up @@ -357,7 +317,11 @@ impl<'a> GraphBuildState<'a> {

/// Computes the workspace path for this package. Errors if this package is not in the
/// workspace.
fn workspace_path(&self, id: &PackageId, manifest_path: &Path) -> Result<Box<Utf8Path>, Error> {
fn workspace_path(
&self,
id: &PackageId,
manifest_path: &Utf8Path,
) -> Result<Box<Utf8Path>, Error> {
// Strip off the workspace path from the manifest path.
let workspace_path = manifest_path
.strip_prefix(self.workspace_root)
Expand All @@ -373,12 +337,6 @@ impl<'a> GraphBuildState<'a> {
id, manifest_path
))
})?;
let workspace_path = Utf8Path::from_path(workspace_path).ok_or_else(|| {
Error::PackageGraphConstructError(format!(
"workspace member '{}' has invalid UTF-8 manifest path {:?}",
id, manifest_path
))
})?;
Ok(workspace_path.to_path_buf().into_boxed_path())
}

Expand Down
10 changes: 5 additions & 5 deletions guppy/src/graph/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

use crate::sorted_set::SortedSet;
use std::{borrow::Borrow, cmp::Ordering, path::Path};
use camino::Utf8Path;
use std::{borrow::Borrow, cmp::Ordering};

/// A build target in a package.
///
Expand Down Expand Up @@ -59,7 +60,7 @@ impl<'g> BuildTarget<'g> {
}

/// Returns the absolute path of the location where the source for this build target is located.
pub fn path(&self) -> &'g Path {
pub fn path(&self) -> &'g Utf8Path {
&self.inner.path
}

Expand Down Expand Up @@ -191,7 +192,7 @@ pub(super) struct BuildTargetImpl {
// This is only set if the id is BuildTargetId::Library.
pub(super) lib_name: Option<Box<str>>,
pub(super) required_features: Vec<String>,
pub(super) path: Box<Path>,
pub(super) path: Box<Utf8Path>,
pub(super) edition: Box<str>,
pub(super) doc_tests: bool,
}
Expand Down Expand Up @@ -229,8 +230,7 @@ pub(super) enum BuildTargetKindImpl {
Binary,
}

// Allow Borrow usage for complex keys. Adapted from
// http://idubrov.name/rust/2018/06/01/tricking-the-hashmap.html.
// Borrow for complex keys. See https://github.com/sunshowers/borrow-complex-key-example.
pub(super) trait BuildTargetKey {
fn key(&self) -> BuildTargetId;
}
Expand Down
5 changes: 2 additions & 3 deletions guppy/src/graph/graph_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use std::{
collections::{BTreeMap, HashMap, HashSet},
fmt, iter,
iter::FromIterator,
path::Path,
};
use target_spec::TargetSpec;

Expand Down Expand Up @@ -813,7 +812,7 @@ impl<'g> PackageMetadata<'g> {
///
/// This is the same as the `readme` field of `Cargo.toml`. The path returned is relative to the
/// directory the `Cargo.toml` is in (i.e. relative to the parent of `self.manifest_path()`).
pub fn readme(&self) -> Option<&'g Path> {
pub fn readme(&self) -> Option<&'g Utf8Path> {
self.inner.readme.as_ref().map(|path| path.as_ref())
}

Expand Down Expand Up @@ -1016,7 +1015,7 @@ pub(crate) struct PackageMetadataImpl {
pub(super) manifest_path: Box<Utf8Path>,
pub(super) categories: Vec<String>,
pub(super) keywords: Vec<String>,
pub(super) readme: Option<Box<Path>>,
pub(super) readme: Option<Box<Utf8Path>>,
pub(super) repository: Option<Box<str>>,
pub(super) edition: Box<str>,
pub(super) metadata_table: JsonValue,
Expand Down

0 comments on commit b171edb

Please sign in to comment.