Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a single profile set per workspace #3249

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct Manifest {
pub struct VirtualManifest {
replace: Vec<(PackageIdSpec, Dependency)>,
workspace: WorkspaceConfig,
profiles: Profiles,
}

/// General metadata about a package which is just blindly uploaded to the
Expand Down Expand Up @@ -139,7 +140,7 @@ pub struct Profile {
pub panic: Option<String>,
}

#[derive(Default, Clone, Debug)]
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct Profiles {
pub release: Profile,
pub dev: Profile,
Expand Down Expand Up @@ -250,10 +251,12 @@ impl Manifest {

impl VirtualManifest {
pub fn new(replace: Vec<(PackageIdSpec, Dependency)>,
workspace: WorkspaceConfig) -> VirtualManifest {
workspace: WorkspaceConfig,
profiles: Profiles) -> VirtualManifest {
VirtualManifest {
replace: replace,
workspace: workspace,
profiles: profiles,
}
}

Expand All @@ -264,6 +267,10 @@ impl VirtualManifest {
pub fn workspace_config(&self) -> &WorkspaceConfig {
&self.workspace
}

pub fn profiles(&self) -> &Profiles {
&self.profiles
}
}

impl Target {
Expand Down
37 changes: 36 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
use std::slice;

use core::{Package, VirtualManifest, EitherManifest, SourceId};
use core::{PackageIdSpec, Dependency};
use core::{PackageIdSpec, Dependency, Profile, Profiles};
use ops;
use util::{Config, CargoResult, Filesystem, human};
use util::paths;
Expand Down Expand Up @@ -162,6 +162,14 @@ impl<'cfg> Workspace<'cfg> {
self.config
}

pub fn profiles(&self) -> &Profiles {
let root = self.root_manifest.as_ref().unwrap_or(&self.current_manifest);
match *self.packages.get(root) {
MaybePackage::Package(ref p) => p.manifest().profiles(),
MaybePackage::Virtual(ref m) => m.profiles(),
}
}

/// Returns the root path of this workspace.
///
/// That is, this returns the path of the directory containing the
Expand Down Expand Up @@ -432,6 +440,33 @@ impl<'cfg> Workspace<'cfg> {
extra);
}

if let Some(ref root_manifest) = self.root_manifest {
let default_profiles = Profiles {
release: Profile::default_release(),
dev: Profile::default_dev(),
test: Profile::default_test(),
test_deps: Profile::default_dev(),
bench: Profile::default_bench(),
bench_deps: Profile::default_release(),
doc: Profile::default_doc(),
custom_build: Profile::default_custom_build(),
};

for pkg in self.members().filter(|p| p.manifest_path() != root_manifest) {
if pkg.manifest().profiles() != &default_profiles {
let message = &format!("profiles for the non root package will be ignored, \
specify profiles at the workspace root:\n\
package: {}\n\
workspace: {}",
pkg.manifest_path().display(),
root_manifest.display());

//TODO: remove `Eq` bound from `Profiles` when the warning is removed.
try!(self.config.shell().warn(&message));
}
}
}

Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
let resolve = try!(ops::resolve_ws(&mut registry, ws));
let packages = ops::get_resolved_packages(&resolve, registry);

let profiles = try!(ws.current()).manifest().profiles();
let profiles = ws.profiles();
let host_triple = try!(opts.config.rustc()).host.clone();
let mut cx = try!(Context::new(ws, &resolve, &packages, opts.config,
BuildConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
bail!("jobs must be at least 1")
}

let profiles = root_package.manifest().profiles();
let profiles = ws.profiles();
if spec.len() == 0 {
try!(generate_targets(root_package, profiles, mode, filter, release));
}
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ impl TomlManifest {
platform: None,
layout: layout,
}));
let profiles = build_profiles(&self.profile);
let workspace_config = match self.workspace {
Some(ref config) => {
WorkspaceConfig::Root { members: config.members.clone() }
Expand All @@ -733,7 +734,7 @@ impl TomlManifest {
bail!("virtual manifests must be configured with [workspace]");
}
};
Ok((VirtualManifest::new(replace, workspace_config), nested_paths))
Ok((VirtualManifest::new(replace, workspace_config, profiles), nested_paths))
}

fn replace(&self, cx: &mut Context)
Expand Down
68 changes: 68 additions & 0 deletions tests/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,71 @@ fn top_level_overrides_deps() {
prefix = env::consts::DLL_PREFIX,
suffix = env::consts::DLL_SUFFIX)));
}

#[test]
fn profile_in_non_root_manifest_triggers_a_warning() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.1.0"
authors = []

[workspace]
members = ["bar"]

[profile.dev]
debug = false
"#)
.file("src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
version = "0.1.0"
authors = []
workspace = ".."

[profile.dev]
opt-level = 1
"#)
.file("bar/src/main.rs", "fn main() {}");
p.build();

assert_that(p.cargo_process("build").cwd(p.root().join("bar")).arg("-v"),
execs().with_status(0).with_stderr("\
[WARNING] profiles for the non root package will be ignored, specify profiles at the workspace root:
package: [..]
workspace: [..]
[COMPILING] bar v0.1.0 ([..])
[RUNNING] `rustc [..]`
[FINISHED] debug [unoptimized] target(s) in [..]"));
}

#[test]
fn profile_in_virtual_manifest_works() {
let p = project("foo")
.file("Cargo.toml", r#"
[workspace]
members = ["bar"]

[profile.dev]
opt-level = 1
debug = false
"#)
.file("src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
version = "0.1.0"
authors = []
workspace = ".."
"#)
.file("bar/src/main.rs", "fn main() {}");
p.build();

assert_that(p.cargo_process("build").cwd(p.root().join("bar")).arg("-v"),
execs().with_status(0).with_stderr("\
[COMPILING] bar v0.1.0 ([..])
[RUNNING] `rustc [..]`
[FINISHED] debug [optimized] target(s) in [..]"));
}