Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: allow patching Git source dependencies with patch files #9001

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add patch_files to Dependency
  • Loading branch information
da-x committed Dec 19, 2020
commit ec4c3c883f0f4cd61fcb748d2d2f40935e1eba2d
15 changes: 15 additions & 0 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct Inner {
specified_req: bool,
kind: DepKind,
only_match_name: bool,
patch_files: Vec<String>,
explicit_name_in_toml: Option<InternedString>,

optional: bool,
Expand Down Expand Up @@ -217,6 +218,7 @@ impl Dependency {
specified_req: false,
platform: None,
explicit_name_in_toml: None,
patch_files: vec![],
}),
}
}
Expand Down Expand Up @@ -249,6 +251,10 @@ impl Dependency {
self.explicit_name_in_toml().unwrap_or(self.inner.name)
}

pub fn patch_files(&self) -> &Vec<String> {
&self.inner.patch_files
}

/// The name of the package that this `Dependency` depends on.
///
/// Usually this is what's written on the left hand side of a dependencies
Expand Down Expand Up @@ -329,6 +335,15 @@ impl Dependency {
self
}

/// Sets the list of patch files
pub fn set_patch_files(
&mut self,
patch_files: impl IntoIterator<Item = impl Into<String>>,
) -> &mut Dependency {
Rc::make_mut(&mut self.inner).patch_files = patch_files.into_iter().map(|s| s.into()).collect();
self
}

/// Sets the list of features requested for the package.
pub fn set_features(
&mut self,
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ pub struct DetailedTomlDependency {
default_features2: Option<bool>,
package: Option<String>,
public: Option<bool>,
patch_files: Option<Vec<String>>,
}

/// This type is used to deserialize `Cargo.toml` files.
Expand Down Expand Up @@ -1756,6 +1757,7 @@ impl DetailedTomlDependency {
Some(id) => Dependency::parse(pkg_name, version, new_source_id, id, cx.config)?,
None => Dependency::parse_no_deprecated(pkg_name, version, new_source_id)?,
};
dep.set_patch_files(self.patch_files.iter().flatten());
dep.set_features(self.features.iter().flatten())
.set_default_features(
self.default_features
Expand Down