Skip to content

Commit

Permalink
Rework planning to be based off the resolve tree and not directly pac…
Browse files Browse the repository at this point in the history
…kages

There are a range of subtle and irritating bugs that stem from
attempting to work with renames from the package set provided by cargo
metadata.

Fortunatly, recent versions of cargo metadata provide a limited version
of the resolve nodes, both as the original node ids and as a newer set
providing both rename and targetting information.

As such we can (hopefully) simplify crate -> dep node resolution, remove
a bunch of sublte aliasing bugs.

Fixes google#241, fixes google#269, fixes google#270, resolves google#144, resolves google#187
  • Loading branch information
GregBowyer committed Nov 7, 2020
1 parent 5e46892 commit 4a89d7c
Show file tree
Hide file tree
Showing 12 changed files with 744 additions and 546 deletions.
51 changes: 51 additions & 0 deletions impl/Cargo.lock

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

3 changes: 3 additions & 0 deletions impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ tempfile = "3.1.0"
tera = "1.5.0"
toml = "0.5.7"
url = "2.1.1"
derivative = "2.1"

[dev-dependencies]
flate2 = "1.0.18"
Expand All @@ -53,3 +54,5 @@ indoc = "1.0.3"
lazy_static = "1.4.0"
serde_json = "1.0.59"
tar = "0.4.30"
pretty_assertions = "0.6"
literal = "0.2.0"
12 changes: 8 additions & 4 deletions impl/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use crate::settings::CrateSettings;
use serde::Serialize;
use semver::Version;
use std::collections::BTreeSet;
use derivative::Derivative;

/** A struct containing information about a crate's dependency that's buildable in Bazel
*
Expand All @@ -29,9 +31,11 @@ pub struct BuildableDependency {
pub is_proc_macro: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize)]
#[derive(Debug, Clone, Eq, PartialOrd, Ord, Serialize, Derivative)]
#[derivative(Hash, PartialEq)]
pub struct DependencyAlias {
pub target: String,
#[derivative(Hash="ignore", PartialEq="ignore")]
pub alias: String,
}

Expand Down Expand Up @@ -81,21 +85,21 @@ pub struct SourceDetails {
pub git_data: Option<GitRepo>,
}

#[derive(Debug, Clone, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Default, Debug, Clone, Serialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct CrateDependencyContext {
pub dependencies: Vec<BuildableDependency>,
pub proc_macro_dependencies: Vec<BuildableDependency>,
pub build_dependencies: Vec<BuildableDependency>,
pub build_proc_macro_dependencies: Vec<BuildableDependency>,
pub dev_dependencies: Vec<BuildableDependency>,
pub aliased_dependencies: Vec<DependencyAlias>,
pub aliased_dependencies: BTreeSet<DependencyAlias>,
}

#[derive(Debug, Clone, Serialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct CrateTargetedDepContext {
pub target: String,
pub deps: CrateDependencyContext,
pub conditions: Vec<String>,
pub platform_targets: Vec<String>,
}

#[derive(Debug, Clone, Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion impl/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
use anyhow::{anyhow, Result};

use cargo_metadata::MetadataCommand;
pub use cargo_metadata::{DependencyKind, Metadata, Node, Package, PackageId};
pub use cargo_metadata::{Dependency, DepKindInfo, DependencyKind, Metadata, Node, Package, PackageId};

use tempfile::TempDir;

Expand Down
Loading

0 comments on commit 4a89d7c

Please sign in to comment.