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

Add cargo doc --lib/--bin #2577

Merged
merged 1 commit into from
Apr 20, 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: 10 additions & 1 deletion src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct Options {
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_package: Vec<String>,
flag_lib: bool,
flag_bin: Vec<String>,
}

pub const USAGE: &'static str = "
Expand All @@ -30,6 +32,8 @@ Options:
-p SPEC, --package SPEC ... Package to document
--no-deps Don't build documentation for dependencies
-j N, --jobs N The number of jobs to run in parallel
--lib Document only this package's library
--bin NAME Document only the specified binary
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
Expand All @@ -55,6 +59,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {

let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));

let empty = Vec::new();
let doc_opts = ops::DocOptions {
open_result: options.flag_open,
compile_opts: ops::CompileOptions {
Expand All @@ -65,7 +70,11 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
no_default_features: options.flag_no_default_features,
spec: &options.flag_package,
exec_engine: None,
filter: ops::CompileFilter::Everything,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin,
&empty,
&empty,
&empty),
release: options.flag_release,
mode: ops::CompileMode::Doc {
deps: !options.flag_no_deps,
Expand Down
24 changes: 24 additions & 0 deletions tests/test_cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,27 @@ test!(rerun_when_dir_removed {
execs().with_status(0));
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
});

test!(document_only_lib {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", r#"
/// dox
pub fn foo() {}
"#)
.file("src/bin/bar.rs", r#"
/// ```
/// ☃
/// ```
pub fn foo() {}
fn main() { foo(); }
"#);
assert_that(p.cargo_process("doc").arg("--lib"),
execs().with_status(0));
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
});