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

Added '--deps-only' to {build, doc} subcommands #3567

Closed
Closed
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
1 change: 1 addition & 0 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
spec: ops::Packages::Packages(&options.flag_package),
release: true,
mode: ops::CompileMode::Bench,
deps_only: false,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin,
&options.flag_test,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Options {
flag_locked: bool,
flag_frozen: bool,
flag_all: bool,
flag_deps_only: bool,
}

pub const USAGE: &'static str = "
Expand All @@ -39,6 +40,7 @@ Options:
-h, --help Print this message
-p SPEC, --package SPEC ... Package to build
--all Build all packages in the workspace
--deps-only Build only dependencies
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--lib Build only this package's library
--bin NAME Build only the specified binary
Expand Down Expand Up @@ -97,6 +99,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
no_default_features: options.flag_no_default_features,
spec: spec,
mode: ops::CompileMode::Build,
deps_only: options.flag_deps_only,
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin,
Expand Down
1 change: 1 addition & 0 deletions src/bin/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
no_default_features: options.flag_no_default_features,
spec: ops::Packages::Packages(&options.flag_package),
mode: ops::CompileMode::Check,
deps_only: false,
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Options {
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
flag_no_deps: bool,
flag_deps_only: bool,
flag_open: bool,
flag_release: bool,
flag_verbose: u32,
Expand All @@ -38,6 +39,7 @@ Options:
-p SPEC, --package SPEC ... Package to document
--all Document all packages in the workspace
--no-deps Don't build documentation for dependencies
--deps-only Build documentation only for dependencies
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--lib Document only this package's library
--bin NAME Document only the specified binary
Expand Down Expand Up @@ -102,6 +104,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
mode: ops::CompileMode::Doc {
deps: !options.flag_no_deps,
},
deps_only: options.flag_deps_only,
target_rustc_args: None,
target_rustdoc_args: None,
},
Expand Down
1 change: 1 addition & 0 deletions src/bin/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
no_default_features: options.flag_no_default_features,
spec: ops::Packages::Packages(&[]),
mode: ops::CompileMode::Build,
deps_only: false,
release: !options.flag_debug,
filter: ops::CompileFilter::new(false, &options.flag_bin, &[],
&options.flag_example, &[]),
Expand Down
1 change: 1 addition & 0 deletions src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
bins: &bins, examples: &examples,
}
},
deps_only: false,
message_format: options.flag_message_format,
target_rustdoc_args: None,
target_rustc_args: None,
Expand Down
1 change: 1 addition & 0 deletions src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
no_default_features: options.flag_no_default_features,
spec: Packages::Packages(&spec),
mode: mode,
deps_only: false,
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin,
Expand Down
1 change: 1 addition & 0 deletions src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
&options.flag_bench),
message_format: options.flag_message_format,
mode: ops::CompileMode::Doc { deps: false },
deps_only: false,
target_rustdoc_args: Some(&options.arg_opts),
target_rustc_args: None,
},
Expand Down
1 change: 1 addition & 0 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
spec: spec,
release: options.flag_release,
mode: mode,
deps_only: false,
filter: filter,
message_format: options.flag_message_format,
target_rustdoc_args: None,
Expand Down
8 changes: 6 additions & 2 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct CompileOptions<'a> {
pub release: bool,
/// Mode for this compile.
pub mode: CompileMode,
/// Whether only dependencies of the package should be compiled
pub deps_only: bool,
/// `--error_format` flag for the compiler.
pub message_format: MessageFormat,
/// Extra arguments to be passed to rustdoc (for main crate and dependencies)
Expand All @@ -75,6 +77,7 @@ impl<'a> CompileOptions<'a> {
no_default_features: false,
spec: ops::Packages::Packages(&[]),
mode: mode,
deps_only: false,
release: false,
filter: ops::CompileFilter::new(false, &[], &[], &[], &[]),
message_format: MessageFormat::Human,
Expand Down Expand Up @@ -158,7 +161,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
-> CargoResult<ops::Compilation<'a>> {
let CompileOptions { config, jobs, target, spec, features,
all_features, no_default_features,
release, mode, message_format,
release, mode, deps_only, message_format,
ref filter,
ref target_rustdoc_args,
ref target_rustc_args } = *options;
Expand Down Expand Up @@ -253,8 +256,9 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
build_config.test = mode == CompileMode::Test || mode == CompileMode::Bench;
build_config.json_messages = message_format == MessageFormat::Json;
if let CompileMode::Doc { deps } = mode {
build_config.doc_all = deps;
build_config.doc_deps = deps;
}
build_config.deps_only = deps_only;

ops::compile_targets(ws,
&package_targets,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ fn run_verify(ws: &Workspace, tar: &File, opts: &PackageOpts) -> CargoResult<()>
spec: ops::Packages::Packages(&[]),
filter: ops::CompileFilter::Everything,
release: false,
deps_only: false,
message_format: ops::MessageFormat::Human,
mode: ops::CompileMode::Build,
target_rustdoc_args: None,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
profile: self.lib_profile(),
kind: unit.kind.for_target(lib),
});
if self.build_config.doc_all {
if self.build_config.doc_deps {
ret.push(Unit {
pkg: dep,
target: lib,
Expand Down
29 changes: 21 additions & 8 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pub struct BuildConfig {
pub jobs: u32,
pub release: bool,
pub test: bool,
pub doc_all: bool,
/// If set no action is taken for the main units only for their dependencies
pub deps_only: bool,
/// If set and units are documented, their dependencies are documented also
pub doc_deps: bool,
pub json_messages: bool,
}

Expand Down Expand Up @@ -113,6 +116,8 @@ pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
})
}).collect::<Vec<_>>();

let deps_only = build_config.deps_only;

let mut cx = Context::new(ws, resolve, packages, config,
build_config, profiles)?;

Expand All @@ -123,13 +128,21 @@ pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
cx.build_used_in_plugin_map(&units)?;
custom_build::build_map(&mut cx, &units)?;

for unit in units.iter() {
// Build up a list of pending jobs, each of which represent
// compiling a particular package. No actual work is executed as
// part of this, that's all done next as part of the `execute`
// function which will run everything in order with proper
// parallelism.
compile(&mut cx, &mut queue, unit, exec.clone())?;
if deps_only {
for unit in &units {
for dep in &cx.dep_targets(unit)? {
compile(&mut cx, &mut queue, dep, exec.clone())?;
}
}
} else {
for unit in units.iter() {
// Build up a list of pending jobs, each of which represent
// compiling a particular package. No actual work is executed as
// part of this, that's all done next as part of the `execute`
// function which will run everything in order with proper
// parallelism.
compile(&mut cx, &mut queue, unit, exec.clone())?;
}
}

// Now that we've figured out everything that we're going to do, do it!
Expand Down