fn produce_source_details(
    &self,
    crates_io_template: &str,
    package: &Package,
    package_root: &Path,
    binary_dep_spec: Option<&cargo_toml::Dependency>,
  ) -> Result<SourceDetails> {
    let mut git_data = None;
    let mut download_url = None;

    if let Some(source_id) = self.source_id {
      if source_id.is_git() {
        let manifest_parent = package.manifest_path.parent().ok_or_else(|| {
          anyhow!(
            "Expected manifest_path to have a parent but was {}",
            package.manifest_path
          )
        })?;
        let path_to_crate_root = manifest_parent
          .strip_prefix(package_root)
          .with_context(|| {
            anyhow!(
              "Expected package root `{}` to be a prefix of manifest path dir `{}` but it wasn't",
              package_root.display(),
              manifest_parent
            )
          })?;
        let path_to_crate_root = if path_to_crate_root.components().next().is_some() {
          Some(path_to_crate_root.to_string())
        } else {
          None
        };
        git_data = Some(GitRepo {
          remote: source_id.url().to_string(),
          commit: source_id
            .precise()
            .ok_or_else(|| {
              anyhow!(
                "Expected source_id to have a `precise` field with a git commit, but it didn't"
              )
            })?
            .to_owned(),
          path_to_crate_root,
        });
      }
      if source_id.is_remote_registry() {
        if let Some(source) = package.source.as_ref() {
          download_url = Some(
            Self::produce_download_url(crates_io_template, source, &package.name, &package.version)
              .with_context(|| {
                format!(
                  "Producing download URL for crate {} version {}",
                  &package.name, &package.version
                )
              })?,
          );
        } else {
          bail!(
            "Expected source to be present for package {} version {}",
            package.name,
            package.version.to_string()
          );
        }
      }
    } else if let Some(binary_dep_spec) = binary_dep_spec {
      if let Dependency::Detailed(detailed) = binary_dep_spec {
        if detailed.registry.is_some() || detailed.registry_index.is_some() {
          bail!("Binary deps do not support registries other than crates.io, but {} attempted to use a custom registry", package.name);
        }
      }
      let source = Source {
        repr: "registry+https://github.com/rust-lang/crates.io-index".to_owned(),
      };
      download_url = Some(
        Self::produce_download_url(crates_io_template, &source, &package.name, &package.version)
          .with_context(|| format!("Producing download URL for binary dep {}", package.name))?,
      );
    }
    Ok(SourceDetails {
      git_data,
      download_url,
    })
  }
/// Generates source details for internal crate.
Generates source details for internal crate.
Generates source details for internal crate .
fn produce_source_details(
    &self,
    crates_io_template: &str,
    package: &Package,
    package_root: &Path,
    binary_dep_spec: Option<&cargo_toml::Dependency>,
  ) -> Result<SourceDetails> {
    let mut git_data = None;
    let mut download_url = None;
    if let Some(source_id) = self.source_id {
      if source_id.is_git() {
        let manifest_parent = package.manifest_path.parent().ok_or_else(|| {
          anyhow!(
            "Expected manifest_path to have a parent but was {}",
            package.manifest_path
          )
        })?;
        let path_to_crate_root = manifest_parent
          .strip_prefix(package_root)
          .with_context(|| {
            anyhow!(
              "Expected package root `{}` to be a prefix of manifest path dir `{}` but it wasn't",
              package_root.display(),
              manifest_parent
            )
          })?;
        let path_to_crate_root = if path_to_crate_root.components().next().is_some() {
          Some(path_to_crate_root.to_string())
        } else {
          None
        };
        git_data = Some(GitRepo {
          remote: source_id.url().to_string(),
          commit: source_id
            .precise()
            .ok_or_else(|| {
              anyhow!(
                "Expected source_id to have a `precise` field with a git commit, but it didn't"
              )
            })?
            .to_owned(),
          path_to_crate_root,
        });
      }
      if source_id.is_remote_registry() {
        if let Some(source) = package.source.as_ref() {
          download_url = Some(
            Self::produce_download_url(crates_io_template, source, &package.name, &package.version)
              .with_context(|| {
                format!(
                  "Producing download URL for crate {} version {}",
                  &package.name, &package.version
                )
              })?,
          );
        } else {
          bail!(
            "Expected source to be present for package {} version {}",
            package.name,
            package.version.to_string()
          );
        }
      }
    } else if let Some(binary_dep_spec) = binary_dep_spec {
      if let Dependency::Detailed(detailed) = binary_dep_spec {
        if detailed.registry.is_some() || detailed.registry_index.is_some() {
          bail!("Binary deps do not support registries other than crates.io, but {} attempted to use a custom registry", package.name);
        }
      }
      let source = Source {
        repr: "registry+https://github.com/rust-lang/crates.io-index".to_owned(),
      };
      download_url = Some(
        Self::produce_download_url(crates_io_template, &source, &package.name, &package.version)
          .with_context(|| format!("Producing download URL for binary dep {}", package.name))?,
      );
    }
    Ok(SourceDetails {
      git_data,
      download_url,
    })
  }
fn produce_source_details ( & self , crates_io_template : & str , package : & Package , package_root : & Path , binary_dep_spec : Option < & cargo_toml :: Dependency > , ) -> Result < SourceDetails > { let mut git_data = None ; let mut download_url = None ; if let Some ( source_id ) = self . source_id { if source_id . is_git ( ) { let manifest_parent = package . manifest_path . parent ( ) . ok_or_else ( | | { anyhow ! ( " " package manifest_path ) } ) ? ; let path_to_crate_root = manifest_parent . strip_prefix ( package_root ) . with_context ( | | { anyhow ! ( " " package_root display ( ) manifest_parent ) } ) ? ; let path_to_crate_root = if path_to_crate_root . components ( ) . next ( ) . is_some ( ) { Some ( path_to_crate_root . to_string ( ) ) } else { None } ; git_data = Some ( GitRepo { remote : source_id . url ( ) . to_string ( ) , commit : source_id . precise ( ) . ok_or_else ( | | { anyhow ! ( " " ) } ) ? . to_owned ( ) , path_to_crate_root , } ) ; } if source_id . is_remote_registry ( ) { if let Some ( source ) = package . source . as_ref ( ) { download_url = Some ( Self :: produce_download_url ( crates_io_template , source , & package . name , & package . version ) . with_context ( | | { format ! ( " " package name package version ) } ) ? , ) ; } else { bail ! ( " " package name package version to_string ( ) ) ; } } } else if let Some ( binary_dep_spec ) = binary_dep_spec { if let Dependency :: Detailed ( detailed ) = binary_dep_spec { if detailed . registry . is_some ( ) || detailed . registry_index . is_some ( ) { bail ! ( " " package name ) ; } } let source = Source { repr : " " . to_owned ( ) , } ; download_url = Some ( Self :: produce_download_url ( crates_io_template , & source , & package . name , & package . version ) . with_context ( | | format ! ( " " package name ) ) ? , ) ; } Ok ( SourceDetails { git_data , download_url , } ) }
Generates source details for internal crate.
Generates source details for internal crate .
&self
crates_io_template
&str
package
&Package
package_root
&Path
binary_dep_spec
Option<&cargo_toml::Dependency>
&self
crates_io_template
&str
package
&Package
package_root
&Path
binary_dep_spec
Option<&cargo_toml::Dependency>