[go: up one dir, main page]

Skip to content

Commit

Permalink
Auto merge of rust-lang#4401 - alexcrichton:beta-next, r=alexcrichton
Browse files Browse the repository at this point in the history
[beta] Allow to skip test code during publishing

Backport of rust-lang#4389
  • Loading branch information
bors committed Aug 12, 2017
2 parents 7e00b82 + 324c5ea commit 5b4b8b2
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 34 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ crossbeam = "0.2"
curl = "0.4.6"
docopt = "0.8"
env_logger = "0.4"
error-chain = "0.10.0"
error-chain = "0.11.0-rc.2"
filetime = "0.1"
flate2 = "0.2"
fs2 = "0.4"
Expand Down
19 changes: 16 additions & 3 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Manifest {
summary: Summary,
targets: Vec<Target>,
links: Option<String>,
warnings: Vec<String>,
warnings: Vec<DelayedWarning>,
exclude: Vec<String>,
include: Vec<String>,
metadata: ManifestMetadata,
Expand All @@ -32,6 +32,15 @@ pub struct Manifest {
original: Rc<TomlManifest>,
}

/// When parsing `Cargo.toml`, some warnings should silenced
/// if the manifest comes from a dependency. `ManifestWarning`
/// allows this delayed emission of warnings.
#[derive(Clone, Debug)]
pub struct DelayedWarning {
pub message: String,
pub is_critical: bool
}

#[derive(Clone, Debug)]
pub struct VirtualManifest {
replace: Vec<(PackageIdSpec, Dependency)>,
Expand Down Expand Up @@ -252,7 +261,7 @@ impl Manifest {
pub fn summary(&self) -> &Summary { &self.summary }
pub fn targets(&self) -> &[Target] { &self.targets }
pub fn version(&self) -> &Version { self.package_id().version() }
pub fn warnings(&self) -> &[String] { &self.warnings }
pub fn warnings(&self) -> &[DelayedWarning] { &self.warnings }
pub fn profiles(&self) -> &Profiles { &self.profiles }
pub fn publish(&self) -> bool { self.publish }
pub fn replace(&self) -> &[(PackageIdSpec, Dependency)] { &self.replace }
Expand All @@ -266,7 +275,11 @@ impl Manifest {
}

pub fn add_warning(&mut self, s: String) {
self.warnings.push(s)
self.warnings.push(DelayedWarning { message: s, is_critical: false })
}

pub fn add_critical_warning(&mut self, s: String) {
self.warnings.push(DelayedWarning { message: s, is_critical: true })
}

pub fn set_summary(&mut self, summary: Summary) {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ impl<'a> Context<'a> {
if !used_features.is_empty() {
let pkgid = candidate.package_id();

let mut set = self.resolve_features.entry(pkgid.clone())
let set = self.resolve_features.entry(pkgid.clone())
.or_insert_with(HashSet::new);
for feature in used_features {
if !set.contains(feature) {
Expand Down
12 changes: 10 additions & 2 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use core::resolver::Resolve;
use ops::{self, BuildOutput, Executor, DefaultExecutor};
use util::config::Config;
use util::{CargoResult, profile};
use util::errors::{CargoResultExt, CargoError};

/// Contains information about how a package should be compiled.
pub struct CompileOptions<'a> {
Expand Down Expand Up @@ -177,8 +178,15 @@ pub fn compile_with_exec<'a>(ws: &Workspace<'a>,
exec: Arc<Executor>)
-> CargoResult<ops::Compilation<'a>> {
for member in ws.members() {
for key in member.manifest().warnings().iter() {
options.config.shell().warn(key)?
for warning in member.manifest().warnings().iter() {
if warning.is_critical {
let err: CargoResult<_> = Err(CargoError::from(warning.message.to_owned()));
return err.chain_err(|| {
format!("failed to parse manifest at `{}`", member.manifest_path().display())
})
} else {
options.config.shell().warn(&warning.message)?
}
}
}
compile_ws(ws, None, options, exec)
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl Config {
format!("failed to load TOML configuration from `{}`", credentials.display())
})?;

let mut cfg = match *cfg {
let cfg = match *cfg {
CV::Table(ref mut map, _) => map,
_ => unreachable!(),
};
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unknown_lints)]

use std::error::Error;
use std::fmt;
use std::io;
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/util/read2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod imp {

pub fn read2(mut out_pipe: ChildStdout,
mut err_pipe: ChildStderr,
mut data: &mut FnMut(bool, &mut Vec<u8>, bool)) -> io::Result<()> {
data: &mut FnMut(bool, &mut Vec<u8>, bool)) -> io::Result<()> {
unsafe {
libc::fcntl(out_pipe.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK);
libc::fcntl(err_pipe.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK);
Expand Down Expand Up @@ -102,7 +102,7 @@ mod imp {

pub fn read2(out_pipe: ChildStdout,
err_pipe: ChildStderr,
mut data: &mut FnMut(bool, &mut Vec<u8>, bool)) -> io::Result<()> {
data: &mut FnMut(bool, &mut Vec<u8>, bool)) -> io::Result<()> {
let mut out = Vec::new();
let mut err = Vec::new();

Expand Down
9 changes: 7 additions & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ impl TomlManifest {
-> CargoResult<(Manifest, Vec<PathBuf>)> {
let mut nested_paths = vec![];
let mut warnings = vec![];
let mut errors = vec![];

let project = me.project.as_ref().or_else(|| me.package.as_ref());
let project = project.ok_or_else(|| {
Expand All @@ -517,7 +518,8 @@ impl TomlManifest {
// If we have no lib at all, use the inferred lib if available
// If we have a lib with a path, we're done
// If we have a lib with no path, use the inferred lib or_else package name
let targets = targets(me, package_name, package_root, &project.build, &mut warnings)?;
let targets = targets(me, package_name, package_root, &project.build,
&mut warnings, &mut errors)?;

if targets.is_empty() {
debug!("manifest has no build targets");
Expand Down Expand Up @@ -653,7 +655,10 @@ impl TomlManifest {
`license-file` is necessary".to_string());
}
for warning in warnings {
manifest.add_warning(warning.clone());
manifest.add_warning(warning);
}
for error in errors {
manifest.add_critical_warning(error);
}

Ok((manifest, nested_paths))
Expand Down
50 changes: 34 additions & 16 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub fn targets(manifest: &TomlManifest,
package_name: &str,
package_root: &Path,
custom_build: &Option<StringOrBool>,
warnings: &mut Vec<String>)
warnings: &mut Vec<String>,
errors: &mut Vec<String>)
-> CargoResult<Vec<Target>> {
let mut targets = Vec::new();

Expand All @@ -43,15 +44,15 @@ pub fn targets(manifest: &TomlManifest,
);

targets.extend(
clean_examples(manifest.example.as_ref(), package_root)?
clean_examples(manifest.example.as_ref(), package_root, errors)?
);

targets.extend(
clean_tests(manifest.test.as_ref(), package_root)?
clean_tests(manifest.test.as_ref(), package_root, errors)?
);

targets.extend(
clean_benches(manifest.bench.as_ref(), package_root, warnings)?
clean_benches(manifest.bench.as_ref(), package_root, warnings, errors)?
);

// processing the custom build script
Expand Down Expand Up @@ -191,7 +192,11 @@ fn clean_bins(toml_bins: Option<&Vec<TomlBinTarget>>,
} else {
None
}
})?;
});
let path = match path {
Ok(path) => path,
Err(e) => bail!("{}", e),
};

let mut target = Target::bin_target(&bin.name(), path,
bin.required_features.clone());
Expand Down Expand Up @@ -221,11 +226,12 @@ fn clean_bins(toml_bins: Option<&Vec<TomlBinTarget>>,
}

fn clean_examples(toml_examples: Option<&Vec<TomlExampleTarget>>,
package_root: &Path)
package_root: &Path,
errors: &mut Vec<String>)
-> CargoResult<Vec<Target>> {
let targets = clean_targets("example", "example",
toml_examples, inferred_examples(package_root),
package_root)?;
package_root, errors)?;

let mut result = Vec::new();
for (path, toml) in targets {
Expand All @@ -244,10 +250,11 @@ fn clean_examples(toml_examples: Option<&Vec<TomlExampleTarget>>,
}

fn clean_tests(toml_tests: Option<&Vec<TomlTestTarget>>,
package_root: &Path) -> CargoResult<Vec<Target>> {
package_root: &Path,
errors: &mut Vec<String>) -> CargoResult<Vec<Target>> {
let targets = clean_targets("test", "test",
toml_tests, inferred_tests(package_root),
package_root)?;
package_root, errors)?;

let mut result = Vec::new();
for (path, toml) in targets {
Expand All @@ -261,7 +268,8 @@ fn clean_tests(toml_tests: Option<&Vec<TomlTestTarget>>,

fn clean_benches(toml_benches: Option<&Vec<TomlBenchTarget>>,
package_root: &Path,
warnings: &mut Vec<String>) -> CargoResult<Vec<Target>> {
warnings: &mut Vec<String>,
errors: &mut Vec<String>) -> CargoResult<Vec<Target>> {
let mut legacy_bench_path = |bench: &TomlTarget| {
let legacy_path = package_root.join("src").join("bench.rs");
if !(bench.name() == "bench" && legacy_path.exists()) {
Expand All @@ -283,6 +291,7 @@ fn clean_benches(toml_benches: Option<&Vec<TomlBenchTarget>>,
let targets = clean_targets_with_legacy_path("benchmark", "bench",
toml_benches, inferred_benches(package_root),
package_root,
errors,
&mut legacy_bench_path)?;

let mut result = Vec::new();
Expand All @@ -299,19 +308,22 @@ fn clean_benches(toml_benches: Option<&Vec<TomlBenchTarget>>,
fn clean_targets(target_kind_human: &str, target_kind: &str,
toml_targets: Option<&Vec<TomlTarget>>,
inferred: Vec<(String, PathBuf)>,
package_root: &Path)
package_root: &Path,
errors: &mut Vec<String>)
-> CargoResult<Vec<(PathBuf, TomlTarget)>> {
clean_targets_with_legacy_path(target_kind_human, target_kind,
toml_targets,
inferred,
package_root,
errors,
&mut |_| None)
}

fn clean_targets_with_legacy_path(target_kind_human: &str, target_kind: &str,
toml_targets: Option<&Vec<TomlTarget>>,
inferred: Vec<(String, PathBuf)>,
package_root: &Path,
errors: &mut Vec<String>,
legacy_path: &mut FnMut(&TomlTarget) -> Option<PathBuf>)
-> CargoResult<Vec<(PathBuf, TomlTarget)>> {
let toml_targets = match toml_targets {
Expand All @@ -332,7 +344,14 @@ fn clean_targets_with_legacy_path(target_kind_human: &str, target_kind: &str,
validate_unique_names(&toml_targets, target_kind)?;
let mut result = Vec::new();
for target in toml_targets {
let path = target_path(&target, &inferred, target_kind, package_root, legacy_path)?;
let path = target_path(&target, &inferred, target_kind, package_root, legacy_path);
let path = match path {
Ok(path) => path,
Err(e) => {
errors.push(e);
continue
},
};
result.push((path, target));
}
Ok(result)
Expand Down Expand Up @@ -459,7 +478,7 @@ fn target_path(target: &TomlTarget,
inferred: &[(String, PathBuf)],
target_kind: &str,
package_root: &Path,
legacy_path: &mut FnMut(&TomlTarget) -> Option<PathBuf>) -> CargoResult<PathBuf> {
legacy_path: &mut FnMut(&TomlTarget) -> Option<PathBuf>) -> Result<PathBuf, String> {
if let Some(ref path) = target.path {
// Should we verify that this path exists here?
return Ok(package_root.join(&path.0));
Expand All @@ -478,9 +497,8 @@ fn target_path(target: &TomlTarget,
if let Some(path) = legacy_path(target) {
return Ok(path);
}

bail!("can't find `{name}` {target_kind}, specify {target_kind}.path",
name = name, target_kind = target_kind)
Err(format!("can't find `{name}` {target_kind}, specify {target_kind}.path",
name = name, target_kind = target_kind))
}
(None, Some(_)) => unreachable!()
}
Expand Down
2 changes: 1 addition & 1 deletion src/crates-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ path = "lib.rs"

[dependencies]
curl = "0.4"
error-chain = "0.10.0"
error-chain = "0.11.0-rc.2"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
2 changes: 2 additions & 0 deletions src/crates-io/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unknown_lints)]

extern crate curl;
extern crate url;
#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,7 @@ fn dir_and_file_with_same_name_in_bin() {
.file("src/bin/foo.rs", "fn main() {}")
.file("src/bin/foo/main.rs", "fn main() {}");

assert_that(p.cargo_process("build"),
assert_that(p.cargo_process("build"),
execs().with_status(101)
.with_stderr_contains("\
[..]found duplicate binary name foo, but all binary targets must have a unique name[..]
Expand Down
Loading

0 comments on commit 5b4b8b2

Please sign in to comment.