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

Commit

Permalink
[guppy] add Workspace::target_directory and Workspace::metadata_table
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshowers committed Mar 18, 2022
1 parent c0549a9 commit 36bc3e1
Show file tree
Hide file tree
Showing 7 changed files with 4,538 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

4,496 changes: 4,495 additions & 1 deletion fixtures/small/metadata1.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions guppy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.14.1] - 2022-03-18

### Added

- `Workspace::target_directory` returns the target directory provided in the Cargo metadata.
- `Workspace::metadata_table` returns the freeform `workspace.metadata` table.

## [0.14.0] - 2022-03-14

### Added
Expand Down Expand Up @@ -493,6 +500,7 @@ lazy_static = "0.2"
### Added
- Initial release.

[0.14.1]: https://github.com/facebookincubator/cargo-guppy/releases/tag/guppy-0.14.1
[0.14.0]: https://github.com/facebookincubator/cargo-guppy/releases/tag/guppy-0.14.0
[0.13.0]: https://github.com/facebookincubator/cargo-guppy/releases/tag/guppy-0.13.0
[0.12.6]: https://github.com/facebookincubator/cargo-guppy/releases/tag/guppy-0.12.6
Expand Down
2 changes: 1 addition & 1 deletion guppy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "guppy"
version = "0.14.0"
version = "0.14.1"
description = "Track and query Cargo dependency graphs."
documentation = "https://docs.rs/guppy"
repository = "https://github.com/facebookincubator/cargo-guppy"
Expand Down
12 changes: 11 additions & 1 deletion guppy/src/graph/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ impl PackageGraph {

let dep_graph = build_state.finish();

let workspace = WorkspaceImpl::new(workspace_root, &packages, workspace_members)?;
let workspace = WorkspaceImpl::new(
workspace_root,
metadata.target_directory,
metadata.workspace_metadata,
&packages,
workspace_members,
)?;

Ok(Self {
dep_graph,
Expand All @@ -72,6 +78,8 @@ impl WorkspaceImpl {
/// Indexes and creates a new workspace.
fn new(
workspace_root: impl Into<Utf8PathBuf>,
target_directory: impl Into<Utf8PathBuf>,
metadata_table: serde_json::Value,
packages: &HashMap<PackageId, PackageMetadataImpl>,
members: impl IntoIterator<Item = PackageId>,
) -> Result<Self, Error> {
Expand Down Expand Up @@ -116,6 +124,8 @@ impl WorkspaceImpl {

Ok(Self {
root: workspace_root,
target_directory: target_directory.into(),
metadata_table,
members_by_path,
members_by_name,
#[cfg(feature = "proptest1")]
Expand Down
15 changes: 15 additions & 0 deletions guppy/src/graph/graph_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ impl<'g> Workspace<'g> {
&self.inner.root
}

/// Returns the target directory in which output artifacts are stored.
pub fn target_directory(&self) -> &'g Utf8Path {
&self.inner.target_directory
}

/// Returns the number of packages in this workspace.
pub fn member_count(&self) -> usize {
self.inner.members_by_path.len()
Expand Down Expand Up @@ -604,6 +609,14 @@ impl<'g> Workspace<'g> {
.map(|name| self.member_by_name(name.as_ref()))
.collect()
}

/// Returns the freeform metadata table for this workspace.
///
/// This is the same as the `workspace.metadata` section of `Cargo.toml`. This section is
/// typically used by tools which would like to store workspace configuration in `Cargo.toml`.
pub fn metadata_table(&self) -> &'g JsonValue {
&self.inner.metadata_table
}
}

#[cfg(feature = "rayon1")]
Expand Down Expand Up @@ -660,6 +673,8 @@ mod workspace_rayon {
#[derive(Clone, Debug)]
pub(super) struct WorkspaceImpl {
pub(super) root: Utf8PathBuf,
pub(super) target_directory: Utf8PathBuf,
pub(super) metadata_table: JsonValue,
// This is a BTreeMap to allow presenting data in sorted order.
pub(super) members_by_path: BTreeMap<Utf8PathBuf, PackageId>,
pub(super) members_by_name: BTreeMap<Box<str>, PackageId>,
Expand Down
7 changes: 7 additions & 0 deletions guppy/tests/graph-tests/graph_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ mod small {
metadata1.verify();

let graph = metadata1.graph();

assert_eq!(
graph.workspace().target_directory(),
"/fakepath/testcrate/target",
"target directory matches"
);

let testcrate = graph
.metadata(&package_id(json::METADATA1_TESTCRATE))
.expect("root crate should exist");
Expand Down

0 comments on commit 36bc3e1

Please sign in to comment.