mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
refactor: move getters method together
This commit is contained in:
parent
d99fed2de2
commit
e313b61621
@ -1632,18 +1632,6 @@ impl InheritableFields {
|
|||||||
("package.version", version -> semver::Version),
|
("package.version", version -> semver::Version),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_deps(&mut self, deps: Option<BTreeMap<String, TomlDependency>>) {
|
|
||||||
self.dependencies = deps;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_lints(&mut self, lints: Option<TomlLints>) {
|
|
||||||
self.lints = lints;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_ws_path(&mut self, ws_root: PathBuf) {
|
|
||||||
self.ws_root = ws_root;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets a workspace dependency with the `name`.
|
/// Gets a workspace dependency with the `name`.
|
||||||
pub fn get_dependency(&self, name: &str, package_root: &Path) -> CargoResult<TomlDependency> {
|
pub fn get_dependency(&self, name: &str, package_root: &Path) -> CargoResult<TomlDependency> {
|
||||||
let Some(deps) = &self.dependencies else {
|
let Some(deps) = &self.dependencies else {
|
||||||
@ -1659,6 +1647,14 @@ impl InheritableFields {
|
|||||||
Ok(dep)
|
Ok(dep)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the field `workspace.package.license-file`.
|
||||||
|
pub fn license_file(&self, package_root: &Path) -> CargoResult<String> {
|
||||||
|
let Some(license_file) = &self.license_file else {
|
||||||
|
bail!("`workspace.package.license-file` was not defined");
|
||||||
|
};
|
||||||
|
resolve_relative_path("license-file", &self.ws_root, package_root, license_file)
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the field `workspace.package.readme`.
|
/// Gets the field `workspace.package.readme`.
|
||||||
pub fn readme(&self, package_root: &Path) -> CargoResult<StringOrBool> {
|
pub fn readme(&self, package_root: &Path) -> CargoResult<StringOrBool> {
|
||||||
let Some(readme) = readme_for_package(self.ws_root.as_path(), self.readme.as_ref()) else {
|
let Some(readme) = readme_for_package(self.ws_root.as_path(), self.readme.as_ref()) else {
|
||||||
@ -1668,17 +1664,21 @@ impl InheritableFields {
|
|||||||
.map(StringOrBool::String)
|
.map(StringOrBool::String)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the field `workspace.package.license-file`.
|
|
||||||
pub fn license_file(&self, package_root: &Path) -> CargoResult<String> {
|
|
||||||
let Some(license_file) = &self.license_file else {
|
|
||||||
bail!("`workspace.package.license-file` was not defined");
|
|
||||||
};
|
|
||||||
resolve_relative_path("license-file", &self.ws_root, package_root, license_file)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ws_root(&self) -> &PathBuf {
|
pub fn ws_root(&self) -> &PathBuf {
|
||||||
&self.ws_root
|
&self.ws_root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_deps(&mut self, deps: Option<BTreeMap<String, TomlDependency>>) {
|
||||||
|
self.dependencies = deps;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_lints(&mut self, lints: Option<TomlLints>) {
|
||||||
|
self.lints = lints;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_ws_path(&mut self, ws_root: PathBuf) {
|
||||||
|
self.ws_root = ws_root;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TomlPackage {
|
impl TomlPackage {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user