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

Implement workspaces in Cargo #2759

Merged
merged 1 commit into from
Jul 5, 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
4 changes: 3 additions & 1 deletion src/bin/bench.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, CliError, Human, Config, human};
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -91,7 +92,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

let err = try!(ops::run_benches(&root, &ops, &options.arg_args));
let ws = try!(Workspace::new(&root, config));
let err = try!(ops::run_benches(&ws, &ops, &options.arg_args));
match err {
None => Ok(None),
Some(err) => {
Expand Down
4 changes: 3 additions & 1 deletion src/bin/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops::CompileOptions;
use cargo::ops;
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -86,6 +87,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
target_rustc_args: None,
};

try!(ops::compile(&root, &opts));
let ws = try!(Workspace::new(&root, config));
try!(ops::compile(&ws, &opts));
Ok(None)
}
4 changes: 3 additions & 1 deletion src/bin/clean.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -50,6 +51,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
target: options.flag_target.as_ref().map(|s| &s[..]),
release: options.flag_release,
};
try!(ops::clean(&root, &opts));
let ws = try!(Workspace::new(&root, config));
try!(ops::clean(&ws, &opts));
Ok(None)
}
4 changes: 3 additions & 1 deletion src/bin/doc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -84,6 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

try!(ops::doc(&root, &doc_opts));
let ws = try!(Workspace::new(&root, config));
try!(ops::doc(&ws, &doc_opts));
Ok(None)
}
4 changes: 3 additions & 1 deletion src/bin/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
Expand Down Expand Up @@ -38,7 +39,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
try!(ops::fetch(&root, config));
let ws = try!(Workspace::new(&root, config));
try!(ops::fetch(&ws));
Ok(None)
}

4 changes: 3 additions & 1 deletion src/bin/generate_lockfile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
Expand Down Expand Up @@ -33,6 +34,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));

try!(ops::generate_lockfile(&root, config));
let ws = try!(Workspace::new(&root, config));
try!(ops::generate_lockfile(&ws));
Ok(None)
}
10 changes: 3 additions & 7 deletions src/bin/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
extern crate cargo;
extern crate docopt;
extern crate rustc_serialize;
extern crate toml;

use cargo::core::Workspace;
use cargo::ops::{output_metadata, OutputMetadataOptions, ExportInfo};
use cargo::util::important_paths::find_root_manifest_for_wd;
use cargo::util::{CliResult, Config};
Expand Down Expand Up @@ -48,12 +44,12 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo

let options = OutputMetadataOptions {
features: options.flag_features,
manifest_path: &manifest,
no_default_features: options.flag_no_default_features,
no_deps: options.flag_no_deps,
version: options.flag_format_version,
};

let result = try!(output_metadata(options, config));
let ws = try!(Workspace::new(&manifest, config));
let result = try!(output_metadata(&ws, &options));
Ok(Some(result))
}
4 changes: 3 additions & 1 deletion src/bin/package.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
Expand Down Expand Up @@ -38,7 +39,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
try!(ops::package(&root, &ops::PackageOpts {
let ws = try!(Workspace::new(&root, config));
try!(ops::package(&ws, &ops::PackageOpts {
config: config,
verify: !options.flag_no_verify,
list: options.flag_list,
Expand Down
4 changes: 3 additions & 1 deletion src/bin/pkgid.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -51,9 +52,10 @@ pub fn execute(options: Options,
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd()));
let ws = try!(Workspace::new(&root, config));

let spec = options.arg_spec.as_ref().map(|s| &s[..]);
let spec = try!(ops::pkgid(&root, spec, config));
let spec = try!(ops::pkgid(&ws, spec));
println!("{}", spec);
Ok(None)
}
Expand Down
4 changes: 3 additions & 1 deletion src/bin/publish.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
Expand Down Expand Up @@ -47,7 +48,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
} = options;

let root = try!(find_root_manifest_for_wd(flag_manifest_path.clone(), config.cwd()));
try!(ops::publish(&root, &ops::PublishOpts {
let ws = try!(Workspace::new(&root, config));
try!(ops::publish(&ws, &ops::PublishOpts {
config: config,
token: token,
index: host,
Expand Down
4 changes: 3 additions & 1 deletion src/bin/run.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, CliError, Config, Human};
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -85,7 +86,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
target_rustc_args: None,
};

match try!(ops::run(&root, &compile_opts, &options.arg_args)) {
let ws = try!(Workspace::new(&root, config));
match try!(ops::run(&ws, &compile_opts, &options.arg_args)) {
None => Ok(None),
Some(err) => {
// If we never actually spawned the process then that sounds pretty
Expand Down
4 changes: 3 additions & 1 deletion src/bin/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops::{CompileOptions, CompileMode};
use cargo::ops;
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -104,7 +105,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]),
};

try!(ops::compile(&root, &opts));
let ws = try!(Workspace::new(&root, config));
try!(ops::compile(&ws, &opts));
Ok(None)
}

4 changes: 3 additions & 1 deletion src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -91,7 +92,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

try!(ops::doc(&root, &doc_opts));
let ws = try!(Workspace::new(&root, config));
try!(ops::doc(&ws, &doc_opts));

Ok(None)
}
4 changes: 3 additions & 1 deletion src/bin/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, CliError, Human, human, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
Expand Down Expand Up @@ -119,7 +120,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

let err = try!(ops::run_tests(&root, &ops, &options.arg_args));
let ws = try!(Workspace::new(&root, config));
let err = try!(ops::run_tests(&ws, &ops, &options.arg_args));
match err {
None => Ok(None),
Some(err) => {
Expand Down
4 changes: 3 additions & 1 deletion src/bin/update.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
Expand Down Expand Up @@ -66,6 +67,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
config: config,
};

try!(ops::update_lockfile(&root, &update_opts));
let ws = try!(Workspace::new(&root, config));
try!(ops::update_lockfile(&ws, &update_opts));
Ok(None)
}
40 changes: 38 additions & 2 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ use std::path::{PathBuf, Path};
use semver::Version;
use rustc_serialize::{Encoder, Encodable};

use core::{Dependency, PackageId, PackageIdSpec, Summary};
use core::{Dependency, PackageId, PackageIdSpec, Summary, WorkspaceConfig};
use core::package_id::Metadata;

pub enum EitherManifest {
Real(Manifest),
Virtual(VirtualManifest),
}

/// Contains all the information about a package, as loaded from a Cargo.toml.
#[derive(Clone, Debug)]
pub struct Manifest {
Expand All @@ -20,6 +25,13 @@ pub struct Manifest {
profiles: Profiles,
publish: bool,
replace: Vec<(PackageIdSpec, Dependency)>,
workspace: WorkspaceConfig,
}

#[derive(Clone, Debug)]
pub struct VirtualManifest {
replace: Vec<(PackageIdSpec, Dependency)>,
workspace: WorkspaceConfig,
}

/// General metadata about a package which is just blindly uploaded to the
Expand Down Expand Up @@ -175,7 +187,8 @@ impl Manifest {
metadata: ManifestMetadata,
profiles: Profiles,
publish: bool,
replace: Vec<(PackageIdSpec, Dependency)>) -> Manifest {
replace: Vec<(PackageIdSpec, Dependency)>,
workspace: WorkspaceConfig) -> Manifest {
Manifest {
summary: summary,
targets: targets,
Expand All @@ -187,6 +200,7 @@ impl Manifest {
profiles: profiles,
publish: publish,
replace: replace,
workspace: workspace,
}
}

Expand All @@ -207,6 +221,10 @@ impl Manifest {
self.links.as_ref().map(|s| &s[..])
}

pub fn workspace_config(&self) -> &WorkspaceConfig {
&self.workspace
}

pub fn add_warning(&mut self, s: String) {
self.warnings.push(s)
}
Expand All @@ -216,6 +234,24 @@ impl Manifest {
}
}

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

pub fn replace(&self) -> &[(PackageIdSpec, Dependency)] {
&self.replace
}

pub fn workspace_config(&self) -> &WorkspaceConfig {
&self.workspace
}
}

impl Target {
fn blank() -> Target {
Target {
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub use self::dependency::{Dependency, DependencyInner};
pub use self::manifest::{Manifest, Target, TargetKind, Profile, LibKind, Profiles};
pub use self::manifest::{EitherManifest, VirtualManifest};
pub use self::package::{Package, PackageSet};
pub use self::package_id::{PackageId, Metadata};
pub use self::package_id_spec::PackageIdSpec;
Expand All @@ -8,6 +9,7 @@ pub use self::resolver::Resolve;
pub use self::shell::{Shell, MultiShell, ShellConfig, Verbosity, ColorConfig};
pub use self::source::{Source, SourceId, SourceMap, GitReference};
pub use self::summary::Summary;
pub use self::workspace::{Workspace, WorkspaceConfig};

pub mod source;
pub mod package;
Expand All @@ -19,3 +21,4 @@ pub mod summary;
pub mod shell;
pub mod registry;
mod package_id_spec;
mod workspace;
Loading