diff --git a/crates/cargo-util-schemas/src/manifest/mod.rs b/crates/cargo-util-schemas/src/manifest/mod.rs index 4fbdd39212b..80f474a6c65 100644 --- a/crates/cargo-util-schemas/src/manifest/mod.rs +++ b/crates/cargo-util-schemas/src/manifest/mod.rs @@ -215,6 +215,15 @@ impl TomlPackage { self.authors.as_ref().map(|v| v.resolved()).transpose() } + pub fn resolved_build(&self) -> Result, UnresolvedError> { + let readme = self.build.as_ref().ok_or(UnresolvedError)?; + match readme { + StringOrBool::Bool(false) => Ok(None), + StringOrBool::Bool(true) => Err(UnresolvedError), + StringOrBool::String(value) => Ok(Some(value)), + } + } + pub fn resolved_exclude(&self) -> Result>, UnresolvedError> { self.exclude.as_ref().map(|v| v.resolved()).transpose() } @@ -243,15 +252,12 @@ impl TomlPackage { } pub fn resolved_readme(&self) -> Result, UnresolvedError> { - self.readme - .as_ref() - .map(|v| { - v.resolved().and_then(|sb| match sb { - StringOrBool::Bool(_) => Err(UnresolvedError), - StringOrBool::String(value) => Ok(value), - }) - }) - .transpose() + let readme = self.readme.as_ref().ok_or(UnresolvedError)?; + readme.resolved().and_then(|sb| match sb { + StringOrBool::Bool(false) => Ok(None), + StringOrBool::Bool(true) => Err(UnresolvedError), + StringOrBool::String(value) => Ok(Some(value)), + }) } pub fn resolved_keywords(&self) -> Result>, UnresolvedError> { diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index b2133b204e2..14245c410e8 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -483,6 +483,7 @@ impl Manifest { pub fn contents(&self) -> &str { self.contents.as_str() } + /// See [`Manifest::resolved_toml`] for what "resolved" means pub fn to_resolved_contents(&self) -> CargoResult { let toml = toml::to_string_pretty(self.resolved_toml())?; Ok(format!("{}\n{}", MANIFEST_PREAMBLE, toml)) @@ -496,6 +497,11 @@ impl Manifest { &self.original_toml } /// The [`TomlManifest`] with all fields expanded + /// + /// This is the intersection of what fields need resolving for cargo-publish that also are + /// useful for the operation of cargo, including + /// - workspace inheritance + /// - target discovery pub fn resolved_toml(&self) -> &TomlManifest { &self.resolved_toml } diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 7a7474825d1..533852551c2 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -689,7 +689,11 @@ fn tar( let base_name = format!("{}-{}", pkg.name(), pkg.version()); let base_path = Path::new(&base_name); - let publish_pkg = prepare_for_publish(pkg, ws)?; + let included = ar_files + .iter() + .map(|ar_file| ar_file.rel_path.clone()) + .collect::>(); + let publish_pkg = prepare_for_publish(pkg, ws, &included)?; let mut uncompressed_size = 0; for ar_file in ar_files { diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index d89829e0482..66bab28157c 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -256,6 +256,7 @@ fn to_workspace_root_config( ws_root_config } +/// See [`Manifest::resolved_toml`] for more details #[tracing::instrument(skip_all)] fn resolve_toml( original_toml: &manifest::TomlManifest, @@ -264,7 +265,7 @@ fn resolve_toml( manifest_file: &Path, gctx: &GlobalContext, warnings: &mut Vec, - _errors: &mut Vec, + errors: &mut Vec, ) -> CargoResult { if let Some(workspace) = &original_toml.workspace { if workspace.resolver.as_deref() == Some("3") { @@ -277,11 +278,11 @@ fn resolve_toml( package: None, project: None, profile: original_toml.profile.clone(), - lib: original_toml.lib.clone(), - bin: original_toml.bin.clone(), - example: original_toml.example.clone(), - test: original_toml.test.clone(), - bench: original_toml.bench.clone(), + lib: None, + bin: None, + example: None, + test: None, + bench: None, dependencies: None, dev_dependencies: None, dev_dependencies2: None, @@ -318,6 +319,47 @@ fn resolve_toml( }); resolved_toml.package = Some(resolved_package); + resolved_toml.lib = targets::resolve_lib( + original_toml.lib.as_ref(), + package_root, + &original_package.name, + edition, + warnings, + )?; + resolved_toml.bin = Some(targets::resolve_bins( + original_toml.bin.as_ref(), + package_root, + &original_package.name, + edition, + original_package.autobins, + warnings, + resolved_toml.lib.is_some(), + )?); + resolved_toml.example = Some(targets::resolve_examples( + original_toml.example.as_ref(), + package_root, + edition, + original_package.autoexamples, + warnings, + errors, + )?); + resolved_toml.test = Some(targets::resolve_tests( + original_toml.test.as_ref(), + package_root, + edition, + original_package.autotests, + warnings, + errors, + )?); + resolved_toml.bench = Some(targets::resolve_benches( + original_toml.bench.as_ref(), + package_root, + edition, + original_package.autobenches, + warnings, + errors, + )?); + let activated_opt_deps = resolved_toml .features .as_ref() @@ -494,7 +536,7 @@ fn resolve_package_toml<'a>( .map(|value| field_inherit_with(value, "authors", || inherit()?.authors())) .transpose()? .map(manifest::InheritableField::Value), - build: original_package.build.clone(), + build: targets::resolve_build(original_package.build.as_ref(), package_root), metabuild: original_package.metabuild.clone(), default_target: original_package.default_target.clone(), forced_target: original_package.forced_target.clone(), @@ -519,10 +561,10 @@ fn resolve_package_toml<'a>( .map(manifest::InheritableField::Value), workspace: original_package.workspace.clone(), im_a_teapot: original_package.im_a_teapot.clone(), - autobins: original_package.autobins.clone(), - autoexamples: original_package.autoexamples.clone(), - autotests: original_package.autotests.clone(), - autobenches: original_package.autobenches.clone(), + autobins: Some(false), + autoexamples: Some(false), + autotests: Some(false), + autobenches: Some(false), default_run: original_package.default_run.clone(), description: original_package .description @@ -553,7 +595,10 @@ fn resolve_package_toml<'a>( .transpose()? .as_ref(), ) - .map(|s| manifest::InheritableField::Value(StringOrBool::String(s))), + .map(|s| manifest::InheritableField::Value(StringOrBool::String(s))) + .or(Some(manifest::InheritableField::Value(StringOrBool::Bool( + false, + )))), keywords: original_package .keywords .clone() @@ -1146,11 +1191,10 @@ fn to_real_manifest( // If we have a lib with no path, use the inferred lib or else the package name. let targets = to_targets( &features, + &original_toml, &resolved_toml, - package_name, package_root, edition, - &resolved_package.build, &resolved_package.metabuild, warnings, errors, @@ -2357,10 +2401,15 @@ fn unused_dep_keys( } } -pub fn prepare_for_publish(me: &Package, ws: &Workspace<'_>) -> CargoResult { +pub fn prepare_for_publish( + me: &Package, + ws: &Workspace<'_>, + included: &[PathBuf], +) -> CargoResult { let contents = me.manifest().contents(); let document = me.manifest().document(); - let original_toml = prepare_toml_for_publish(me.manifest().resolved_toml(), ws, me.root())?; + let original_toml = + prepare_toml_for_publish(me.manifest().resolved_toml(), ws, me.root(), included)?; let resolved_toml = original_toml.clone(); let features = me.manifest().unstable_features().clone(); let workspace_config = me.manifest().workspace_config().clone(); @@ -2392,6 +2441,7 @@ fn prepare_toml_for_publish( me: &manifest::TomlManifest, ws: &Workspace<'_>, package_root: &Path, + included: &[PathBuf], ) -> CargoResult { let gctx = ws.gctx(); @@ -2408,11 +2458,21 @@ fn prepare_toml_for_publish( package.workspace = None; if let Some(StringOrBool::String(path)) = &package.build { let path = paths::normalize_path(Path::new(path)); - let path = path - .into_os_string() - .into_string() - .map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?; - package.build = Some(StringOrBool::String(normalize_path_string_sep(path))); + let build = if included.contains(&path) { + let path = path + .into_os_string() + .into_string() + .map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?; + let path = normalize_path_string_sep(path); + StringOrBool::String(path) + } else { + ws.gctx().shell().warn(format!( + "ignoring `package.build` as `{}` is not included in the published package", + path.display() + ))?; + StringOrBool::Bool(false) + }; + package.build = Some(build); } let current_resolver = package .resolver @@ -2502,14 +2562,14 @@ fn prepare_toml_for_publish( } let lib = if let Some(target) = &me.lib { - Some(prepare_target_for_publish(target, "library")?) + prepare_target_for_publish(target, included, "library", ws.gctx())? } else { None }; - let bin = prepare_targets_for_publish(me.bin.as_ref(), "binary")?; - let example = prepare_targets_for_publish(me.example.as_ref(), "example")?; - let test = prepare_targets_for_publish(me.test.as_ref(), "test")?; - let bench = prepare_targets_for_publish(me.bench.as_ref(), "benchmark")?; + let bin = prepare_targets_for_publish(me.bin.as_ref(), included, "binary", ws.gctx())?; + let example = prepare_targets_for_publish(me.example.as_ref(), included, "example", ws.gctx())?; + let test = prepare_targets_for_publish(me.test.as_ref(), included, "test", ws.gctx())?; + let bench = prepare_targets_for_publish(me.bench.as_ref(), included, "benchmark", ws.gctx())?; let all = |_d: &manifest::TomlDependency| true; let mut manifest = manifest::TomlManifest { @@ -2667,7 +2727,9 @@ fn prepare_toml_for_publish( fn prepare_targets_for_publish( targets: Option<&Vec>, + included: &[PathBuf], context: &str, + gctx: &GlobalContext, ) -> CargoResult>> { let Some(targets) = targets else { return Ok(None); @@ -2675,23 +2737,41 @@ fn prepare_targets_for_publish( let mut prepared = Vec::with_capacity(targets.len()); for target in targets { - let target = prepare_target_for_publish(target, context)?; + let Some(target) = prepare_target_for_publish(target, included, context, gctx)? else { + continue; + }; prepared.push(target); } - Ok(Some(prepared)) + if prepared.is_empty() { + Ok(None) + } else { + Ok(Some(prepared)) + } } fn prepare_target_for_publish( target: &manifest::TomlTarget, + included: &[PathBuf], context: &str, -) -> CargoResult { - let mut target = target.clone(); - if let Some(path) = target.path { - let path = normalize_path(&path.0); - target.path = Some(manifest::PathValue(normalize_path_sep(path, context)?)); + gctx: &GlobalContext, +) -> CargoResult> { + let path = target.path.as_ref().expect("previously resolved"); + let path = normalize_path(&path.0); + if !included.contains(&path) { + let name = target.name.as_ref().expect("previously resolved"); + gctx.shell().warn(format!( + "ignoring {context} `{name}` as `{}` is not included in the published package", + path.display() + ))?; + return Ok(None); } - Ok(target) + + let mut target = target.clone(); + let path = normalize_path_sep(path, context)?; + target.path = Some(manifest::PathValue(path.into())); + + Ok(Some(target)) } fn normalize_path_sep(path: PathBuf, context: &str) -> CargoResult { diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index 1795cf24752..5b7c313d748 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -34,37 +34,24 @@ const DEFAULT_EXAMPLE_DIR_NAME: &'static str = "examples"; #[tracing::instrument(skip_all)] pub(super) fn to_targets( features: &Features, + original_toml: &TomlManifest, resolved_toml: &TomlManifest, - package_name: &str, package_root: &Path, edition: Edition, - custom_build: &Option, metabuild: &Option, warnings: &mut Vec, errors: &mut Vec, ) -> CargoResult> { let mut targets = Vec::new(); - let has_lib; - - let lib = resolve_lib( - resolved_toml.lib.as_ref(), - package_root, - package_name, - edition, - warnings, - )?; if let Some(target) = to_lib_target( + original_toml.lib.as_ref(), resolved_toml.lib.as_ref(), - lib.as_ref(), package_root, edition, warnings, )? { targets.push(target); - has_lib = true; - } else { - has_lib = false; } let package = resolved_toml @@ -72,58 +59,38 @@ pub(super) fn to_targets( .as_ref() .ok_or_else(|| anyhow::format_err!("manifest has no `package` (or `project`)"))?; - let bins = resolve_bins( - resolved_toml.bin.as_ref(), - package_root, - package_name, - edition, - package.autobins, - warnings, - has_lib, - )?; targets.extend(to_bin_targets( features, - &bins, + resolved_toml.bin.as_deref().unwrap_or_default(), package_root, edition, errors, )?); - let toml_examples = resolve_examples( - resolved_toml.example.as_ref(), + targets.extend(to_example_targets( + resolved_toml.example.as_deref().unwrap_or_default(), package_root, edition, - package.autoexamples, - warnings, - errors, - )?; - targets.extend(to_example_targets(&toml_examples, package_root, edition)?); + )?); - let toml_tests = resolve_tests( - resolved_toml.test.as_ref(), + targets.extend(to_test_targets( + resolved_toml.test.as_deref().unwrap_or_default(), package_root, edition, - package.autotests, - warnings, - errors, - )?; - targets.extend(to_test_targets(&toml_tests, package_root, edition)?); + )?); - let toml_benches = resolve_benches( - resolved_toml.bench.as_ref(), + targets.extend(to_bench_targets( + resolved_toml.bench.as_deref().unwrap_or_default(), package_root, edition, - package.autobenches, - warnings, - errors, - )?; - targets.extend(to_bench_targets(&toml_benches, package_root, edition)?); + )?); // processing the custom build script - if let Some(custom_build) = maybe_custom_build(custom_build, package_root) { + if let Some(custom_build) = package.resolved_build().expect("should be resolved") { if metabuild.is_some() { anyhow::bail!("cannot specify both `metabuild` and `build`"); } + let custom_build = Path::new(custom_build); let name = format!( "build-script-{}", custom_build @@ -158,7 +125,7 @@ pub(super) fn to_targets( Ok(targets) } -fn resolve_lib( +pub fn resolve_lib( original_lib: Option<&TomlLibTarget>, package_root: &Path, package_name: &str, @@ -283,7 +250,7 @@ fn to_lib_target( Ok(Some(target)) } -fn resolve_bins( +pub fn resolve_bins( toml_bins: Option<&Vec>, package_root: &Path, package_name: &str, @@ -409,7 +376,7 @@ fn legacy_bin_path(package_root: &Path, name: &str, has_lib: bool) -> Option>, package_root: &Path, edition: Edition, @@ -464,7 +431,7 @@ fn to_example_targets( Ok(result) } -fn resolve_tests( +pub fn resolve_tests( toml_tests: Option<&Vec>, package_root: &Path, edition: Edition, @@ -512,7 +479,7 @@ fn to_test_targets( Ok(result) } -fn resolve_benches( +pub fn resolve_benches( toml_benches: Option<&Vec>, package_root: &Path, edition: Edition, @@ -1072,22 +1039,22 @@ Cargo doesn't know which to use because multiple target files found at `{}` and } /// Returns the path to the build script if one exists for this crate. -fn maybe_custom_build(build: &Option, package_root: &Path) -> Option { - let build_rs = package_root.join("build.rs"); - match *build { - // Explicitly no build script. - Some(StringOrBool::Bool(false)) => None, - Some(StringOrBool::Bool(true)) => Some(build_rs), - Some(StringOrBool::String(ref s)) => Some(PathBuf::from(s)), +pub fn resolve_build(build: Option<&StringOrBool>, package_root: &Path) -> Option { + const BUILD_RS: &str = "build.rs"; + match build { None => { // If there is a `build.rs` file next to the `Cargo.toml`, assume it is // a build script. + let build_rs = package_root.join(BUILD_RS); if build_rs.is_file() { - Some(build_rs) + Some(StringOrBool::String(BUILD_RS.to_owned())) } else { - None + Some(StringOrBool::Bool(false)) } } + // Explicitly no build script. + Some(StringOrBool::Bool(false)) | Some(StringOrBool::String(_)) => build.cloned(), + Some(StringOrBool::Bool(true)) => Some(StringOrBool::String(BUILD_RS.to_owned())), } } diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index fd36a8386e2..e4b6374f40f 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -2214,13 +2214,23 @@ edition = "2015" name = "foo" version = "0.1.0" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "foo" documentation = "foo" +readme = false license = "MIT" repository = "foo" resolver = "2" +[lib] +name = "foo" +path = "src/lib.rs" + [dependencies.bar] version = "1.0" artifact = ["bin"] diff --git a/tests/testsuite/features2.rs b/tests/testsuite/features2.rs index 18a365624c8..9d696978f91 100644 --- a/tests/testsuite/features2.rs +++ b/tests/testsuite/features2.rs @@ -1703,10 +1703,20 @@ edition = "2015" name = "a" version = "0.1.0" authors = ["Zzz"] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "https://example.com/" +readme = false license = "MIT" resolver = "2" + +[lib] +name = "a" +path = "src/lib.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ); diff --git a/tests/testsuite/features_namespaced.rs b/tests/testsuite/features_namespaced.rs index b53637547dd..1c9b90ae2c5 100644 --- a/tests/testsuite/features_namespaced.rs +++ b/tests/testsuite/features_namespaced.rs @@ -985,10 +985,20 @@ You may press ctrl-c [..] edition = "2015" name = "foo" version = "0.1.0" +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "https://example.com/" +readme = false license = "MIT" +[lib] +name = "foo" +path = "src/lib.rs" + [dependencies.opt-dep1] version = "1.0" optional = true @@ -1103,10 +1113,20 @@ You may press ctrl-c [..] edition = "2015" name = "foo" version = "0.1.0" +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "https://example.com/" +readme = false license = "MIT" +[lib] +name = "foo" +path = "src/lib.rs" + [dependencies.bar] version = "1.0" optional = true diff --git a/tests/testsuite/inheritable_workspace_fields.rs b/tests/testsuite/inheritable_workspace_fields.rs index a84d4cdf4df..a91b7abb6f9 100644 --- a/tests/testsuite/inheritable_workspace_fields.rs +++ b/tests/testsuite/inheritable_workspace_fields.rs @@ -217,6 +217,7 @@ rust-version = "1.60" name = "foo" version = "1.2.3" authors = ["Rustaceans"] +build = false exclude = ["foo.txt"] include = [ "bar.txt", @@ -224,13 +225,22 @@ include = [ "Cargo.toml", ] publish = true +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "This is a crate" homepage = "https://www.rust-lang.org" documentation = "https://www.rust-lang.org/learn" +readme = false keywords = ["cli"] categories = ["development-tools"] license = "MIT" repository = "https://github.com/example/example" + +[[bin]] +name = "foo" +path = "src/main.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ), @@ -383,6 +393,16 @@ edition = "2015" name = "bar" version = "0.2.0" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = false + +[[bin]] +name = "bar" +path = "src/main.rs" [dependencies.dep] version = "0.1" @@ -514,6 +534,16 @@ edition = "2015" name = "bar" version = "0.2.0" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = false + +[[bin]] +name = "bar" +path = "src/main.rs" [dependencies.dep] version = "0.1.2" @@ -755,6 +785,7 @@ rust-version = "1.60" name = "bar" version = "1.2.3" authors = ["Rustaceans"] +build = false exclude = ["foo.txt"] include = [ "bar.txt", @@ -764,6 +795,10 @@ include = [ "README.md", ] publish = true +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "This is a crate" homepage = "https://www.rust-lang.org" documentation = "https://www.rust-lang.org/learn" @@ -773,6 +808,10 @@ categories = ["development-tools"] license = "MIT" license-file = "LICENSE" repository = "https://github.com/example/example" + +[[bin]] +name = "bar" +path = "src/main.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ), @@ -927,6 +966,16 @@ edition = "2015" name = "bar" version = "0.2.0" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = false + +[[bin]] +name = "bar" +path = "src/main.rs" [dependencies.dep] version = "0.1" diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 5c48f56a534..850fe9c50b9 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1217,13 +1217,23 @@ edition = "2015" name = "foo" version = "0.0.1" authors = [] +build = false exclude = ["*.txt"] +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" +readme = false license = "MIT" [package.metadata] foo = "bar" +[[bin]] +name = "foo" +path = "src/main.rs" + [dependencies.abc] version = "1.0" @@ -1293,6 +1303,16 @@ edition = "2015" name = "bar" version = "0.1.0" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = false + +[lib] +name = "bar" +path = "src/lib.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ); @@ -1360,6 +1380,16 @@ fn package_public_dep() { edition = "2015" name = "foo" version = "0.0.1" +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = false + +[[bin]] +name = "foo" +path = "src/main.rs" [dependencies.bar] version = "1.0.0" @@ -1378,6 +1408,16 @@ version = "1.0.0" edition = "2015" name = "foo" version = "0.0.1" +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = false + +[[bin]] +name = "foo" +path = "src/main.rs" [dependencies.bar] version = "1.0.0" @@ -2855,7 +2895,17 @@ fn workspace_overrides_resolver() { edition = "2021" name = "bar" version = "0.1.0" +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = false resolver = "1" + +[lib] +name = "bar" +path = "src/lib.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ); @@ -2874,6 +2924,16 @@ resolver = "1" edition = "2015" name = "baz" version = "0.1.0" +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = false + +[lib] +name = "baz" +path = "src/lib.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ); @@ -2935,10 +2995,20 @@ edition = "2015" name = "foo" version = "0.0.1" authors = [] +build = false exclude = ["*.txt"] +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "https://example.com/" +readme = false license = "MIT" + +[[bin]] +name = "foo" +path = "src/main.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ); @@ -3030,9 +3100,19 @@ edition = "2015" name = "foo" version = "0.0.1" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" documentation = "https://example.com/" +readme = false license = "MIT" + +[[bin]] +name = "foo" +path = "src/main.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ); @@ -3137,9 +3217,19 @@ edition = "2015" name = "foo" version = "0.0.1" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "https://example.com/" +readme = false license = "MIT" + +[[bin]] +name = "foo" +path = "src/main.rs" "#, cargo::core::manifest::MANIFEST_PREAMBLE ); @@ -3224,8 +3314,12 @@ src/main.rs.bak #[cfg(windows)] // windows is the platform that is most consistently configured for case insensitive filesystems fn normalize_case() { let p = project() - .file("src/main.rs", r#"fn main() { println!("hello"); }"#) + .file("Build.rs", r#"fn main() { println!("hello"); }"#) + .file("src/Main.rs", r#"fn main() { println!("hello"); }"#) + .file("src/lib.rs", "") .file("src/bar.txt", "") // should be ignored when packaging + .file("Examples/ExampleFoo.rs", "") + .file("Tests/ExplicitPath.rs", "") .build(); // Workaround `project()` making a `Cargo.toml` on our behalf std::fs::remove_file(p.root().join("Cargo.toml")).unwrap(); @@ -3235,11 +3329,15 @@ fn normalize_case() { [package] name = "foo" version = "0.0.1" - edition = "2015" + edition = "2018" authors = [] exclude = ["*.txt"] license = "MIT" description = "foo" + + [[test]] + name = "explicitpath" + path = "tests/explicitpath.rs" "#, ) .unwrap(); @@ -3250,10 +3348,15 @@ fn normalize_case() { [WARNING] manifest has no documentation[..] See [..] [PACKAGING] foo v0.0.1 ([CWD]) +[WARNING] ignoring `package.build` as `build.rs` is not included in the published package +[WARNING] ignoring binary `foo` as `src/main.rs` is not included in the published package +[WARNING] ignoring example `ExampleFoo` as `examples/ExampleFoo.rs` is not included in the published package +[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package +[WARNING] ignoring test `ExplicitPath` as `tests/ExplicitPath.rs` is not included in the published package [VERIFYING] foo v0.0.1 ([CWD]) [COMPILING] foo v0.0.1 ([CWD][..]) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[PACKAGED] 4 files, [..] ([..] compressed) +[PACKAGED] 8 files, [..] ([..] compressed) ", ) .run(); @@ -3261,10 +3364,14 @@ See [..] p.cargo("package -l") .with_stdout( "\ +Build.rs Cargo.lock Cargo.toml Cargo.toml.orig -src/main.rs +Examples/ExampleFoo.rs +Tests/ExplicitPath.rs +src/Main.rs +src/lib.rs ", ) .run(); @@ -3274,10 +3381,15 @@ src/main.rs [WARNING] manifest has no documentation[..] See [..] [PACKAGING] foo v0.0.1 ([CWD]) +[WARNING] ignoring `package.build` as `build.rs` is not included in the published package +[WARNING] ignoring binary `foo` as `src/main.rs` is not included in the published package +[WARNING] ignoring example `ExampleFoo` as `examples/ExampleFoo.rs` is not included in the published package +[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package +[WARNING] ignoring test `ExplicitPath` as `tests/ExplicitPath.rs` is not included in the published package [VERIFYING] foo v0.0.1 ([CWD]) [COMPILING] foo v0.0.1 ([CWD][..]) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[PACKAGED] 4 files, [..] ([..] compressed) +[PACKAGED] 8 files, [..] ([..] compressed) ", ) .run(); @@ -3286,8 +3398,42 @@ See [..] validate_crate_contents( f, "foo-0.0.1.crate", - &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[], + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "Build.rs", + "src/Main.rs", + "src/lib.rs", + "Examples/ExampleFoo.rs", + "Tests/ExplicitPath.rs", + ], + &[( + "Cargo.toml", + &format!( + r#"{} +[package] +edition = "2018" +name = "foo" +version = "0.0.1" +authors = [] +build = false +exclude = ["*.txt"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + cargo::core::manifest::MANIFEST_PREAMBLE + ), + )], ); } @@ -3688,12 +3834,17 @@ name = "foo" version = "0.0.1" authors = [] build = "src/build.rs" +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" documentation = "docs.rs/foo" readme = "docs/README.md" license-file = "docs/LICENSE" [lib] +name = "foo" path = "src/lib.rs" [[bin]] @@ -3715,3 +3866,1065 @@ path = "benches/bench_foo.rs" )], ); } + +#[cargo_test] +fn discovery_inferred_build_rs_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs", "build.rs"] + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 4 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "build.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = "build.rs" +include = [ + "src/lib.rs", + "build.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_build_rs_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs"] + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[WARNING] ignoring `package.build` as `build.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 3 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/lib.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_build_rs_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs", "build.rs"] + build = "build.rs" + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 4 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "build.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = "build.rs" +include = [ + "src/lib.rs", + "build.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_build_rs_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs"] + build = "build.rs" + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[WARNING] ignoring `package.build` as `build.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 3 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/lib.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_lib_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/main.rs", "src/lib.rs"] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 5 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "src/main.rs", + "src/lib.rs", + ], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = [ + "src/main.rs", + "src/lib.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" + +[[bin]] +name = "foo" +path = "src/main.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_lib_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/main.rs"] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[WARNING] ignoring library `foo` as `src/lib.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 4 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/main.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[[bin]] +name = "foo" +path = "src/main.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_lib_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/main.rs", "src/lib.rs"] + + [lib] + path = "src/lib.rs" + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 5 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "src/main.rs", + "src/lib.rs", + ], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = [ + "src/main.rs", + "src/lib.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" + +[[bin]] +name = "foo" +path = "src/main.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_lib_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/main.rs"] + + [lib] + path = "src/lib.rs" + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[WARNING] ignoring library `foo` as `src/lib.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 4 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/main.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[[bin]] +name = "foo" +path = "src/main.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_other_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs", "src/bin/foo/main.rs", "examples/example_foo.rs", "tests/test_foo.rs", "benches/bench_foo.rs"] + "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 8 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "src/lib.rs", + "src/bin/foo/main.rs", + "examples/example_foo.rs", + "tests/test_foo.rs", + "benches/bench_foo.rs", + ], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = [ + "src/lib.rs", + "src/bin/foo/main.rs", + "examples/example_foo.rs", + "tests/test_foo.rs", + "benches/bench_foo.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" + +[[bin]] +name = "foo" +path = "src/bin/foo/main.rs" + +[[example]] +name = "example_foo" +path = "examples/example_foo.rs" + +[[test]] +name = "test_foo" +path = "tests/test_foo.rs" + +[[bench]] +name = "bench_foo" +path = "benches/bench_foo.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_other_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs"] + "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[WARNING] ignoring binary `foo` as `src/bin/foo/main.rs` is not included in the published package +[WARNING] ignoring example `example_foo` as `examples/example_foo.rs` is not included in the published package +[WARNING] ignoring test `test_foo` as `tests/test_foo.rs` is not included in the published package +[WARNING] ignoring benchmark `bench_foo` as `benches/bench_foo.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 4 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/lib.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_other_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs", "src/bin/foo/main.rs", "examples/example_foo.rs", "tests/test_foo.rs", "benches/bench_foo.rs"] + + [[bin]] + name = "foo" + + [[example]] + name = "example_foo" + + [[test]] + name = "test_foo" + + [[bench]] + name = "bench_foo" + "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 8 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "src/lib.rs", + "src/bin/foo/main.rs", + "examples/example_foo.rs", + "tests/test_foo.rs", + "benches/bench_foo.rs", + ], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = [ + "src/lib.rs", + "src/bin/foo/main.rs", + "examples/example_foo.rs", + "tests/test_foo.rs", + "benches/bench_foo.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" + +[[bin]] +name = "foo" +path = "src/bin/foo/main.rs" + +[[example]] +name = "example_foo" +path = "examples/example_foo.rs" + +[[test]] +name = "test_foo" +path = "tests/test_foo.rs" + +[[bench]] +name = "bench_foo" +path = "benches/bench_foo.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_other_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs"] + + [[main]] + name = "foo" + + [[example]] + name = "example_foo" + + [[test]] + name = "test_foo" + + [[bench]] + name = "bench_foo" + "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + "\ +[PACKAGING] foo v0.0.1 ([CWD]) +[WARNING] ignoring binary `foo` as `src/bin/foo/main.rs` is not included in the published package +[WARNING] ignoring example `example_foo` as `examples/example_foo.rs` is not included in the published package +[WARNING] ignoring test `test_foo` as `tests/test_foo.rs` is not included in the published package +[WARNING] ignoring benchmark `bench_foo` as `benches/bench_foo.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([CWD]) +[COMPILING] foo v0.0.1 ([CWD][..]) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[PACKAGED] 4 files, [..] ([..] compressed) +", + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/lib.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index f6181832675..38577bbcfdd 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -1560,9 +1560,19 @@ You may press ctrl-c [..] name = \"foo\"\n\ version = \"0.1.0\"\n\ authors = []\n\ + build = false\n\ + autobins = false\n\ + autoexamples = false\n\ + autotests = false\n\ + autobenches = false\n\ description = \"foo\"\n\ + readme = false\n\ license = \"MIT\"\n\ \n\ + [[bin]]\n\ + name = \"foo\"\n\ + path = \"src/main.rs\"\n\ + \n\ [dependencies.dep1]\n\ version = \"1.0\"\n\ ", @@ -1672,12 +1682,22 @@ edition = "2015" name = "foo" version = "0.1.0" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "foo" documentation = "foo" +readme = false license = "MIT" repository = "foo" +[lib] +name = "foo" +path = "src/lib.rs" + [dev-dependencies] "#, cargo::core::manifest::MANIFEST_PREAMBLE @@ -1931,12 +1951,22 @@ edition = "2015" name = "foo" version = "0.1.0" authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "foo" documentation = "foo" +readme = false license = "MIT" repository = "foo" +[[bin]] +name = "foo" +path = "src/main.rs" + [dependencies.normal-and-dev] version = "1.0" features = ["cat"] diff --git a/tests/testsuite/weak_dep_features.rs b/tests/testsuite/weak_dep_features.rs index 0695501935e..bf7b6207585 100644 --- a/tests/testsuite/weak_dep_features.rs +++ b/tests/testsuite/weak_dep_features.rs @@ -630,10 +630,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. edition = "2015" name = "foo" version = "0.1.0" +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "foo" homepage = "https://example.com/" +readme = false license = "MIT" +[lib] +name = "foo" +path = "src/lib.rs" + [dependencies.bar] version = "1.0" optional = true