fn produce_context(&self, cargo_workspace_root: &Path) -> Result<CrateContext> {
    let package = self.crate_catalog_entry.package();

    let manifest_path = PathBuf::from(&package.manifest_path);
    assert!(manifest_path.is_absolute());
    let package_root = self.find_package_root_for_manifest(&manifest_path)?;

    let mut targets = self.produce_targets(&package_root)?;
    let build_script_target_opt = self.take_build_script_target(&mut targets);

    let lib_target_name = targets
      .iter()
      .find(|target| target.kind == "lib" || target.kind == "proc-macro")
      .map(|target| target.name.clone());

    let is_proc_macro = targets.iter().any(|target| target.kind == "proc-macro");

    let mut deps = self.produce_deps()?;

    // Take the default deps that are not bound to platform targets
    let default_deps = deps.remove(&None).unwrap_or_default();

    // Remove anything in default_deps
    for ctx in deps.values_mut() {
      ctx.subtract(&default_deps);
    }

    // Build a list of dependencies while addression a potential allowlist of target triples
    let mut targeted_deps = deps
      .into_iter()
      .map(|(target, deps)| {
        let target = target.unwrap();
        let platform_targets = util::get_matching_bazel_triples(&target, &self.settings.targets)?
          .map(|x| x.to_string())
          .collect();

        Ok(CrateTargetedDepContext {
          target,
          deps,
          platform_targets,
        })
      })
      .filter(|res| match res {
        Ok(ctx) => !ctx.platform_targets.is_empty(),
        Err(_) => true,
      })
      .collect::<Result<Vec<_>>>()?;

    targeted_deps.sort();

    let mut workspace_member_dependents: Vec<PathBuf> = Vec::new();
    let mut workspace_member_dev_dependents: Vec<PathBuf> = Vec::new();
    let mut workspace_member_build_dependents: Vec<PathBuf> = Vec::new();

    for pkg_id in self.crate_catalog_entry.workspace_member_dependents.iter() {
      let workspace_member = self
        .crate_catalog
        .metadata
        .packages
        .iter()
        .find(|pkg| pkg.id == *pkg_id);

      if let Some(member) = workspace_member {
        // UNWRAP: This should always return a dependency
        let current_dependency = member
          .dependencies
          .iter()
          .find(|dep| dep.name == package.name)
          .unwrap();

        let workspace_member_path = util::get_workspace_member_path(
          member.manifest_path.as_ref(),
          self.crate_catalog.metadata.workspace_root.as_ref(),
        )
        .ok_or_else(|| {
          anyhow!(
            "Failed to generate workspace_member_path for {} and {}",
            &package.manifest_path,
            &self.crate_catalog.metadata.workspace_root
          )
        })?;

        match current_dependency.kind {
          DependencyKind::Development => {
            workspace_member_dev_dependents.push(workspace_member_path)
          }
          DependencyKind::Normal => workspace_member_dependents.push(workspace_member_path),
          DependencyKind::Build => workspace_member_build_dependents.push(workspace_member_path),
          _ => {}
        }
      }
    }

    let is_workspace_member_dependency = !&workspace_member_dependents.is_empty()
      || !&workspace_member_dev_dependents.is_empty()
      || !&workspace_member_build_dependents.is_empty();
    let is_binary_dependency = self.settings.binary_deps.contains_key(&package.name);

    // Generate canonicalized paths to additional build files so they're guaranteed to exist
    // and always locatable.
    let raze_settings = self.crate_settings.cloned().unwrap_or_default();
    let canonical_additional_build_file = match &raze_settings.additional_build_file {
      Some(build_file) => Some(
        cargo_workspace_root
          .join(&build_file)
          .canonicalize()
          .with_context(|| {
            format!(
              "Failed to find additional_build_file: {}",
              &build_file.display()
            )
          })?,
      ),
      None => None,
    };

    let context = CrateContext {
      pkg_name: package.name.clone(),
      pkg_version: package.version.clone(),
      edition: package.edition.clone(),
      license: self.produce_license(),
      features: self.node.features.clone(),
      workspace_member_dependents,
      workspace_member_dev_dependents,
      workspace_member_build_dependents,
      is_workspace_member_dependency,
      is_binary_dependency,
      is_proc_macro,
      default_deps,
      targeted_deps,
      workspace_path_to_crate: self.crate_catalog_entry.workspace_path(self.settings)?,
      build_script_target: build_script_target_opt,
      links: package.links.clone(),
      raze_settings,
      canonical_additional_build_file,
      source_details: self.produce_source_details(
        &self.settings.registry,
        package,
        &package_root,
        self.settings.binary_deps.get(&package.name),
      )?,
      expected_build_path: self.crate_catalog_entry.local_build_path(self.settings)?,
      sha256: self.sha256.clone(),
      lib_target_name,
      targets,
    };

    Ok(context)
  }
/// Builds a crate context from internal state.
Builds a crate context from internal state.
Builds a crate context from internal state .
fn produce_context(&self, cargo_workspace_root: &Path) -> Result<CrateContext> {
    let package = self.crate_catalog_entry.package();
    let manifest_path = PathBuf::from(&package.manifest_path);
    assert!(manifest_path.is_absolute());
    let package_root = self.find_package_root_for_manifest(&manifest_path)?;
    let mut targets = self.produce_targets(&package_root)?;
    let build_script_target_opt = self.take_build_script_target(&mut targets);
    let lib_target_name = targets
      .iter()
      .find(|target| target.kind == "lib" || target.kind == "proc-macro")
      .map(|target| target.name.clone());
    let is_proc_macro = targets.iter().any(|target| target.kind == "proc-macro");
    let mut deps = self.produce_deps()?;
    // Take the default deps that are not bound to platform targets
    let default_deps = deps.remove(&None).unwrap_or_default();
    // Remove anything in default_deps
    for ctx in deps.values_mut() {
      ctx.subtract(&default_deps);
    }
    // Build a list of dependencies while addression a potential allowlist of target triples
    let mut targeted_deps = deps
      .into_iter()
      .map(|(target, deps)| {
        let target = target.unwrap();
        let platform_targets = util::get_matching_bazel_triples(&target, &self.settings.targets)?
          .map(|x| x.to_string())
          .collect();
        Ok(CrateTargetedDepContext {
          target,
          deps,
          platform_targets,
        })
      })
      .filter(|res| match res {
        Ok(ctx) => !ctx.platform_targets.is_empty(),
        Err(_) => true,
      })
      .collect::<Result<Vec<_>>>()?;
    targeted_deps.sort();
    let mut workspace_member_dependents: Vec<PathBuf> = Vec::new();
    let mut workspace_member_dev_dependents: Vec<PathBuf> = Vec::new();
    let mut workspace_member_build_dependents: Vec<PathBuf> = Vec::new();
    for pkg_id in self.crate_catalog_entry.workspace_member_dependents.iter() {
      let workspace_member = self
        .crate_catalog
        .metadata
        .packages
        .iter()
        .find(|pkg| pkg.id == *pkg_id);
      if let Some(member) = workspace_member {
        // UNWRAP: This should always return a dependency
        let current_dependency = member
          .dependencies
          .iter()
          .find(|dep| dep.name == package.name)
          .unwrap();
        let workspace_member_path = util::get_workspace_member_path(
          member.manifest_path.as_ref(),
          self.crate_catalog.metadata.workspace_root.as_ref(),
        )
        .ok_or_else(|| {
          anyhow!(
            "Failed to generate workspace_member_path for {} and {}",
            &package.manifest_path,
            &self.crate_catalog.metadata.workspace_root
          )
        })?;
        match current_dependency.kind {
          DependencyKind::Development => {
            workspace_member_dev_dependents.push(workspace_member_path)
          }
          DependencyKind::Normal => workspace_member_dependents.push(workspace_member_path),
          DependencyKind::Build => workspace_member_build_dependents.push(workspace_member_path),
          _ => {}
        }
      }
    }
    let is_workspace_member_dependency = !&workspace_member_dependents.is_empty()
      || !&workspace_member_dev_dependents.is_empty()
      || !&workspace_member_build_dependents.is_empty();
    let is_binary_dependency = self.settings.binary_deps.contains_key(&package.name);
    // Generate canonicalized paths to additional build files so they're guaranteed to exist
    // and always locatable.
    let raze_settings = self.crate_settings.cloned().unwrap_or_default();
    let canonical_additional_build_file = match &raze_settings.additional_build_file {
      Some(build_file) => Some(
        cargo_workspace_root
          .join(&build_file)
          .canonicalize()
          .with_context(|| {
            format!(
              "Failed to find additional_build_file: {}",
              &build_file.display()
            )
          })?,
      ),
      None => None,
    };
    let context = CrateContext {
      pkg_name: package.name.clone(),
      pkg_version: package.version.clone(),
      edition: package.edition.clone(),
      license: self.produce_license(),
      features: self.node.features.clone(),
      workspace_member_dependents,
      workspace_member_dev_dependents,
      workspace_member_build_dependents,
      is_workspace_member_dependency,
      is_binary_dependency,
      is_proc_macro,
      default_deps,
      targeted_deps,
      workspace_path_to_crate: self.crate_catalog_entry.workspace_path(self.settings)?,
      build_script_target: build_script_target_opt,
      links: package.links.clone(),
      raze_settings,
      canonical_additional_build_file,
      source_details: self.produce_source_details(
        &self.settings.registry,
        package,
        &package_root,
        self.settings.binary_deps.get(&package.name),
      )?,
      expected_build_path: self.crate_catalog_entry.local_build_path(self.settings)?,
      sha256: self.sha256.clone(),
      lib_target_name,
      targets,
    };
    Ok(context)
  }
fn produce_context ( & self , cargo_workspace_root : & Path ) -> Result < CrateContext > { let package = self . crate_catalog_entry . package ( ) ; let manifest_path = PathBuf :: from ( & package . manifest_path ) ; assert ! ( manifest_path is_absolute ( ) ) ; let package_root = self . find_package_root_for_manifest ( & manifest_path ) ? ; let mut targets = self . produce_targets ( & package_root ) ? ; let build_script_target_opt = self . take_build_script_target ( & mut targets ) ; let lib_target_name = targets . iter ( ) . find ( | target | target . kind == " " || target . kind == " " ) . map ( | target | target . name . clone ( ) ) ; let is_proc_macro = targets . iter ( ) . any ( | target | target . kind == " " ) ; let mut deps = self . produce_deps ( ) ? ; // Take the default deps that are not bound to platform targets let default_deps = deps . remove ( & None ) . unwrap_or_default ( ) ; // Remove anything in default_deps for ctx in deps . values_mut ( ) { ctx . subtract ( & default_deps ) ; } // Build a list of dependencies while addression a potential allowlist of target triples let mut targeted_deps = deps . into_iter ( ) . map ( | ( target , deps ) | { let target = target . unwrap ( ) ; let platform_targets = util :: get_matching_bazel_triples ( & target , & self . settings . targets ) ? . map ( | x | x . to_string ( ) ) . collect ( ) ; Ok ( CrateTargetedDepContext { target , deps , platform_targets , } ) } ) . filter ( | res | match res { Ok ( ctx ) => ! ctx . platform_targets . is_empty ( ) , Err ( _ ) => true , } ) . collect :: < Result < Vec < _ > > > ( ) ? ; targeted_deps . sort ( ) ; let mut workspace_member_dependents : Vec < PathBuf > = Vec :: new ( ) ; let mut workspace_member_dev_dependents : Vec < PathBuf > = Vec :: new ( ) ; let mut workspace_member_build_dependents : Vec < PathBuf > = Vec :: new ( ) ; for pkg_id in self . crate_catalog_entry . workspace_member_dependents . iter ( ) { let workspace_member = self . crate_catalog . metadata . packages . iter ( ) . find ( | pkg | pkg . id == * pkg_id ) ; if let Some ( member ) = workspace_member { // UNWRAP: This should always return a dependency let current_dependency = member . dependencies . iter ( ) . find ( | dep | dep . name == package . name ) . unwrap ( ) ; let workspace_member_path = util :: get_workspace_member_path ( member . manifest_path . as_ref ( ) , self . crate_catalog . metadata . workspace_root . as_ref ( ) , ) . ok_or_else ( | | { anyhow ! ( " " package manifest_path self crate_catalog metadata workspace_root ) } ) ? ; match current_dependency . kind { DependencyKind :: Development => { workspace_member_dev_dependents . push ( workspace_member_path ) } DependencyKind :: Normal => workspace_member_dependents . push ( workspace_member_path ) , DependencyKind :: Build => workspace_member_build_dependents . push ( workspace_member_path ) , _ => { } } } } let is_workspace_member_dependency = ! & workspace_member_dependents . is_empty ( ) || ! & workspace_member_dev_dependents . is_empty ( ) || ! & workspace_member_build_dependents . is_empty ( ) ; let is_binary_dependency = self . settings . binary_deps . contains_key ( & package . name ) ; // Generate canonicalized paths to additional build files so they're guaranteed to exist // and always locatable. let raze_settings = self . crate_settings . cloned ( ) . unwrap_or_default ( ) ; let canonical_additional_build_file = match & raze_settings . additional_build_file { Some ( build_file ) => Some ( cargo_workspace_root . join ( & build_file ) . canonicalize ( ) . with_context ( | | { format ! ( " " build_file display ( ) ) } ) ? , ) , None => None , } ; let context = CrateContext { pkg_name : package . name . clone ( ) , pkg_version : package . version . clone ( ) , edition : package . edition . clone ( ) , license : self . produce_license ( ) , features : self . node . features . clone ( ) , workspace_member_dependents , workspace_member_dev_dependents , workspace_member_build_dependents , is_workspace_member_dependency , is_binary_dependency , is_proc_macro , default_deps , targeted_deps , workspace_path_to_crate : self . crate_catalog_entry . workspace_path ( self . settings ) ? , build_script_target : build_script_target_opt , links : package . links . clone ( ) , raze_settings , canonical_additional_build_file , source_details : self . produce_source_details ( & self . settings . registry , package , & package_root , self . settings . binary_deps . get ( & package . name ) , ) ? , expected_build_path : self . crate_catalog_entry . local_build_path ( self . settings ) ? , sha256 : self . sha256 . clone ( ) , lib_target_name , targets , } ; Ok ( context ) }
Builds a crate context from internal state.
Builds a crate context from internal state .
&self
cargo_workspace_root
&Path
&self
cargo_workspace_root
&Path