diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index f45867febde..ad1a536fa38 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -203,7 +203,10 @@ impl Package { } pub fn to_registry_toml(&self, config: &Config) -> CargoResult { - let manifest = self.manifest().original().prepare_for_publish(config)?; + let manifest = self + .manifest() + .original() + .prepare_for_publish(config, self.root())?; let toml = toml::to_string(&manifest)?; Ok(format!( "# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO\n\ diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 21522c57307..9678dd4d368 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -1,26 +1,20 @@ use std::collections::{BTreeSet, HashMap}; -use std::fmt::Display; use std::fs::{self, File}; use std::io::prelude::*; use std::io::SeekFrom; -use std::path::{self, Path, PathBuf}; +use std::path::{Path, PathBuf}; use std::rc::Rc; use std::sync::Arc; use std::time::SystemTime; use flate2::read::GzDecoder; -use flate2::write::GzEncoder; use flate2::{Compression, GzBuilder}; use log::debug; -use serde_json::{self, json}; use tar::{Archive, Builder, EntryType, Header}; use crate::core::compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor}; - -use crate::core::Feature; -use crate::core::{ - Package, PackageId, PackageSet, Resolve, Source, SourceId, Verbosity, Workspace, -}; +use crate::core::{Feature, Verbosity, Workspace}; +use crate::core::{Package, PackageId, PackageSet, Resolve, Source, SourceId}; use crate::ops; use crate::sources::PathSource; use crate::util::errors::{CargoResult, CargoResultExt}; @@ -41,7 +35,24 @@ pub struct PackageOpts<'cfg> { pub no_default_features: bool, } -static VCS_INFO_FILE: &str = ".cargo_vcs_info.json"; +const VCS_INFO_FILE: &str = ".cargo_vcs_info.json"; + +struct ArchiveFile { + /// The relative path in the archive (not including the top-level package + /// name directory). + rel_path: PathBuf, + /// String variant of `rel_path`, for convenience. + rel_str: String, + /// The contents to add to the archive. + contents: FileContents, +} + +enum FileContents { + /// Absolute path to the file on disk to add to the archive. + OnDisk(PathBuf), + /// Contents of a file generated in memory. + Generated(String), +} pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult> { if ws.root().join("Cargo.lock").exists() { @@ -68,40 +79,23 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult