Skip to content

Commit

Permalink
Other clippy things and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Nov 26, 2018
1 parent dad9fe6 commit 92485f8
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 213 deletions.
30 changes: 16 additions & 14 deletions src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
}

pub fn extern_crate_name(&self, unit: &Unit<'a>, dep: &Unit<'a>) -> CargoResult<String> {
self.resolve.extern_crate_name(unit.pkg.package_id(), dep.pkg.package_id(), dep.target)
self.resolve
.extern_crate_name(unit.pkg.package_id(), dep.pkg.package_id(), dep.target)
}

/// Whether a dependency should be compiled for the host or target platform,
Expand Down Expand Up @@ -266,10 +267,12 @@ impl TargetConfig {
let list = value.list(k)?;
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
}
"rustc-env" => for (name, val) in value.table(k)?.0 {
let val = val.string(name)?.0;
output.env.push((name.clone(), val.to_string()));
},
"rustc-env" => {
for (name, val) in value.table(k)?.0 {
let val = val.string(name)?.0;
output.env.push((name.clone(), val.to_string()));
}
}
"warning" | "rerun-if-changed" | "rerun-if-env-changed" => {
bail!("`{}` is not supported in build script overrides", k);
}
Expand Down Expand Up @@ -342,7 +345,8 @@ fn env_args(

// First try RUSTFLAGS from the environment
if let Ok(a) = env::var(name) {
let args = a.split(' ')
let args = a
.split(' ')
.map(str::trim)
.filter(|s| !s.is_empty())
.map(str::to_string);
Expand All @@ -351,7 +355,8 @@ fn env_args(

let mut rustflags = Vec::new();

let name = name.chars()
let name = name
.chars()
.flat_map(|c| c.to_lowercase())
.collect::<String>();
// Then the target.*.rustflags value...
Expand All @@ -367,13 +372,10 @@ fn env_args(
// ...including target.'cfg(...)'.rustflags
if let Some(target_cfg) = target_cfg {
if let Some(table) = config.get_table("target")? {
let cfgs = table.val.keys().filter_map(|key| {
if CfgExpr::matches_key(key, target_cfg) {
Some(key)
} else {
None
}
});
let cfgs = table
.val
.keys()
.filter(|key| CfgExpr::matches_key(key, target_cfg));

// Note that we may have multiple matching `[target]` sections and
// because we're passing flags to the compiler this can affect
Expand Down
137 changes: 60 additions & 77 deletions src/cargo/core/compiler/context/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};

use CargoResult;
use super::{BuildContext, CompileMode, Kind, Unit};
use core::dependency::Kind as DepKind;
use core::profiles::UnitFor;
use core::{Package, Target, PackageId};
use core::package::Downloads;
use super::{BuildContext, CompileMode, Kind, Unit};
use core::profiles::UnitFor;
use core::{Package, PackageId, Target};
use CargoResult;

struct State<'a: 'tmp, 'cfg: 'a, 'tmp> {
bcx: &'tmp BuildContext<'a, 'cfg>,
Expand Down Expand Up @@ -74,11 +74,11 @@ pub fn build_unit_dependencies<'a, 'cfg>(
deps_of(unit, &mut state, unit_for)?;
}

if state.waiting_on_download.len() > 0 {
if !state.waiting_on_download.is_empty() {
state.finish_some_downloads()?;
state.deps.clear();
} else {
break
break;
}
}
trace!("ALL UNIT DEPENDENCIES {:#?}", state.deps);
Expand Down Expand Up @@ -128,46 +128,43 @@ fn compute_deps<'a, 'cfg, 'tmp>(

let bcx = state.bcx;
let id = unit.pkg.package_id();
let deps = bcx.resolve.deps(id)
.filter(|&(_id, deps)| {
assert!(!deps.is_empty());
deps.iter().any(|dep| {
// If this target is a build command, then we only want build
// dependencies, otherwise we want everything *other than* build
// dependencies.
if unit.target.is_custom_build() != dep.is_build() {
return false;
}
let deps = bcx.resolve.deps(id).filter(|&(_id, deps)| {
assert!(!deps.is_empty());
deps.iter().any(|dep| {
// If this target is a build command, then we only want build
// dependencies, otherwise we want everything *other than* build
// dependencies.
if unit.target.is_custom_build() != dep.is_build() {
return false;
}

// If this dependency is *not* a transitive dependency, then it
// only applies to test/example targets
if !dep.is_transitive() &&
!unit.target.is_test() &&
!unit.target.is_example() &&
!unit.mode.is_any_test()
{
return false;
}
// If this dependency is *not* a transitive dependency, then it
// only applies to test/example targets
if !dep.is_transitive()
&& !unit.target.is_test()
&& !unit.target.is_example()
&& !unit.mode.is_any_test()
{
return false;
}

// If this dependency is only available for certain platforms,
// make sure we're only enabling it for that platform.
if !bcx.dep_platform_activated(dep, unit.kind) {
return false;
}
// If this dependency is only available for certain platforms,
// make sure we're only enabling it for that platform.
if !bcx.dep_platform_activated(dep, unit.kind) {
return false;
}

// If the dependency is optional, then we're only activating it
// if the corresponding feature was activated
if dep.is_optional() &&
!bcx.resolve.features(id).contains(&*dep.name_in_toml())
{
return false;
}
// If the dependency is optional, then we're only activating it
// if the corresponding feature was activated
if dep.is_optional() && !bcx.resolve.features(id).contains(&*dep.name_in_toml()) {
return false;
}

// If we've gotten past all that, then this dependency is
// actually used!
true
})
});
// If we've gotten past all that, then this dependency is
// actually used!
true
})
});

let mut ret = Vec::new();
for (id, _) in deps {
Expand All @@ -181,14 +178,7 @@ fn compute_deps<'a, 'cfg, 'tmp>(
};
let mode = check_or_build_mode(unit.mode, lib);
let dep_unit_for = unit_for.with_for_host(lib.for_host());
let unit = new_unit(
bcx,
pkg,
lib,
dep_unit_for,
unit.kind.for_target(lib),
mode,
);
let unit = new_unit(bcx, pkg, lib, dep_unit_for, unit.kind.for_target(lib), mode);
ret.push((unit, dep_unit_for));
}

Expand All @@ -211,7 +201,8 @@ fn compute_deps<'a, 'cfg, 'tmp>(

// If any integration tests/benches are being run, make sure that
// binaries are built as well.
if !unit.mode.is_check() && unit.mode.is_any_test()
if !unit.mode.is_check()
&& unit.mode.is_any_test()
&& (unit.target.is_test() || unit.target.is_bench())
{
ret.extend(
Expand Down Expand Up @@ -282,7 +273,8 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
state: &mut State<'a, 'cfg, 'tmp>,
) -> CargoResult<Vec<(Unit<'a>, UnitFor)>> {
let bcx = state.bcx;
let deps = bcx.resolve
let deps = bcx
.resolve
.deps(unit.pkg.package_id())
.filter(|&(_id, deps)| {
deps.iter().any(|dep| match dep.kind() {
Expand All @@ -308,14 +300,7 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
// However, for plugins/proc-macros, deps should be built like normal.
let mode = check_or_build_mode(unit.mode, lib);
let dep_unit_for = UnitFor::new_normal().with_for_host(lib.for_host());
let lib_unit = new_unit(
bcx,
dep,
lib,
dep_unit_for,
unit.kind.for_target(lib),
mode,
);
let lib_unit = new_unit(bcx, dep, lib, dep_unit_for, unit.kind.for_target(lib), mode);
ret.push((lib_unit, dep_unit_for));
if let CompileMode::Doc { deps: true } = unit.mode {
// Document this lib as well.
Expand Down Expand Up @@ -348,14 +333,7 @@ fn maybe_lib<'a>(
) -> Option<(Unit<'a>, UnitFor)> {
unit.pkg.targets().iter().find(|t| t.linkable()).map(|t| {
let mode = check_or_build_mode(unit.mode, t);
let unit = new_unit(
bcx,
unit.pkg,
t,
unit_for,
unit.kind.for_target(t),
mode,
);
let unit = new_unit(bcx, unit.pkg, t, unit_for, unit.kind.for_target(t), mode);
(unit, unit_for)
})
}
Expand Down Expand Up @@ -453,7 +431,8 @@ fn connect_run_custom_build_deps(state: &mut State) {
for (unit, deps) in state.deps.iter() {
for dep in deps {
if dep.mode == CompileMode::RunCustomBuild {
reverse_deps.entry(dep)
reverse_deps
.entry(dep)
.or_insert_with(HashSet::new)
.insert(unit);
}
Expand All @@ -469,7 +448,11 @@ fn connect_run_custom_build_deps(state: &mut State) {
// `links`, then we depend on that package's build script! Here we use
// `dep_build_script` to manufacture an appropriate build script unit to
// depend on.
for unit in state.deps.keys().filter(|k| k.mode == CompileMode::RunCustomBuild) {
for unit in state
.deps
.keys()
.filter(|k| k.mode == CompileMode::RunCustomBuild)
{
let reverse_deps = match reverse_deps.get(unit) {
Some(set) => set,
None => continue,
Expand All @@ -479,9 +462,9 @@ fn connect_run_custom_build_deps(state: &mut State) {
.iter()
.flat_map(|reverse_dep| state.deps[reverse_dep].iter())
.filter(|other| {
other.pkg != unit.pkg &&
other.target.linkable() &&
other.pkg.manifest().links().is_some()
other.pkg != unit.pkg
&& other.target.linkable()
&& other.pkg.manifest().links().is_some()
})
.filter_map(|other| dep_build_script(other, state.bcx).map(|p| p.0))
.collect::<HashSet<_>>();
Expand All @@ -502,15 +485,15 @@ impl<'a, 'cfg, 'tmp> State<'a, 'cfg, 'tmp> {
fn get(&mut self, id: &'a PackageId) -> CargoResult<Option<&'a Package>> {
let mut pkgs = self.pkgs.borrow_mut();
if let Some(pkg) = pkgs.get(id) {
return Ok(Some(pkg))
return Ok(Some(pkg));
}
if !self.waiting_on_download.insert(id) {
return Ok(None)
return Ok(None);
}
if let Some(pkg) = self.downloads.start(id)? {
pkgs.insert(id, pkg);
self.waiting_on_download.remove(id);
return Ok(Some(pkg))
return Ok(Some(pkg));
}
Ok(None)
}
Expand All @@ -535,7 +518,7 @@ impl<'a, 'cfg, 'tmp> State<'a, 'cfg, 'tmp> {
// less than this let's recompute the whole unit dependency graph
// again and try to find some more packages to download.
if self.downloads.remaining() < 5 {
break
break;
}
}
Ok(())
Expand Down
Loading

0 comments on commit 92485f8

Please sign in to comment.