Skip to content

Commit

Permalink
Auto merge of #2129 - alexcrichton:cargo-rustdoc, r=brson
Browse files Browse the repository at this point in the history
Along the same lines as `cargo rustc` basically
  • Loading branch information
bors committed Nov 9, 2015
2 parents b01770c + 54127ce commit 178ede2
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
&options.flag_test,
&options.flag_example,
&options.flag_bench),
target_rustdoc_args: None,
target_rustc_args: None,
},
};
Expand Down
1 change: 1 addition & 0 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
&options.flag_test,
&options.flag_example,
&options.flag_bench),
target_rustdoc_args: None,
target_rustc_args: None,
};

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ macro_rules! each_subcommand{ ($mac:ident) => ({
$mac!(read_manifest);
$mac!(run);
$mac!(rustc);
$mac!(rustdoc);
$mac!(search);
$mac!(test);
$mac!(uninstall);
Expand Down
1 change: 1 addition & 0 deletions src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
deps: !options.flag_no_deps,
},
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 @@ -95,6 +95,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
filter: ops::CompileFilter::new(false, &options.flag_bin, &[],
&options.flag_example, &[]),
target_rustc_args: None,
target_rustdoc_args: None,
};

let source = if let Some(url) = options.flag_git {
Expand Down
1 change: 1 addition & 0 deletions src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
bins: &bins, examples: &examples,
}
},
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 @@ -84,6 +84,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
&options.flag_test,
&options.flag_example,
&options.flag_bench),
target_rustdoc_args: None,
target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]),
};

Expand Down
96 changes: 96 additions & 0 deletions src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_cwd};

#[derive(RustcDecodable)]
struct Options {
arg_opts: Vec<String>,
flag_target: Option<String>,
flag_features: Vec<String>,
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
flag_open: bool,
flag_verbose: bool,
flag_release: bool,
flag_quiet: bool,
flag_color: Option<String>,
flag_package: Option<String>,
flag_lib: bool,
flag_bin: Vec<String>,
flag_example: Vec<String>,
flag_test: Vec<String>,
flag_bench: Vec<String>,
}

pub const USAGE: &'static str = "
Build a package's documentation, using specified custom flags.
Usage:
cargo rustdoc [options] [--] [<opts>...]
Options:
-h, --help Print this message
--open Opens the docs in a browser after the operation
-p SPEC, --package SPEC Package to document
-j N, --jobs N The number of jobs to run in parallel
--lib Build only this package's library
--bin NAME Build only the specified binary
--example NAME Build only the specified example
--test NAME Build only the specified test target
--bench NAME Build only the specified benchmark target
--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
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to document
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
The specified target for the current package (or package specified by SPEC if
provided) will be documented with the specified <opts>... being passed to the
final rustdoc invocation. Dependencies will not be documented as part of this
command. Note that rustdoc will still unconditionally receive arguments such
as -L, --extern, and --crate-type, and the specified <opts>... will simply be
added to the rustdoc invocation.
If the --package argument is given, then SPEC is a package id specification
which indicates which package should be documented. If it is not given, then the
current package is documented. For more information on SPEC and its format, see
the `cargo help pkgid` command.
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));

let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));

let mut doc_opts = ops::DocOptions {
open_result: options.flag_open,
compile_opts: ops::CompileOptions {
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]),
exec_engine: None,
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin,
&options.flag_test,
&options.flag_example,
&options.flag_bench),
mode: ops::CompileMode::Doc { deps: false },
target_rustdoc_args: Some(&options.arg_opts),
target_rustc_args: None,
},
};

try!(ops::doc(&root, &mut doc_opts));

Ok(None)
}

1 change: 1 addition & 0 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
&options.flag_test,
&options.flag_example,
&options.flag_bench),
target_rustdoc_args: None,
target_rustc_args: None,
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub struct Profile {
pub lto: bool,
pub codegen_units: Option<u32>, // None = use rustc default
pub rustc_args: Option<Vec<String>>,
pub rustdoc_args: Option<Vec<String>>,
pub debuginfo: bool,
pub debug_assertions: bool,
pub rpath: bool,
Expand Down Expand Up @@ -474,6 +475,7 @@ impl Default for Profile {
lto: false,
codegen_units: None,
rustc_args: None,
rustdoc_args: None,
debuginfo: false,
debug_assertions: false,
rpath: false,
Expand Down
58 changes: 38 additions & 20 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub struct CompileOptions<'a> {
pub release: bool,
/// Mode for this compile.
pub mode: CompileMode,
/// Extra arguments to be passed to rustdoc (for main crate and dependencies)
pub target_rustdoc_args: Option<&'a [String]>,
/// The specified target will be compiled with all the available arguments,
/// note that this only accounts for the *final* invocation of rustc
pub target_rustc_args: Option<&'a [String]>,
Expand Down Expand Up @@ -145,6 +147,7 @@ pub fn compile_pkg<'a>(root_package: &Package,
let CompileOptions { config, jobs, target, spec, features,
no_default_features, release, mode,
ref filter, ref exec_engine,
ref target_rustdoc_args,
ref target_rustc_args } = *options;

let target = target.map(|s| s.to_string());
Expand Down Expand Up @@ -185,29 +188,44 @@ pub fn compile_pkg<'a>(root_package: &Package,
let mut package_targets = Vec::new();

let profiles = root_package.manifest().profiles();
match *target_rustc_args {
Some(args) => {
if to_builds.len() == 1 {
let targets = try!(generate_targets(to_builds[0], profiles,
mode, filter, release));
if targets.len() == 1 {
let (target, profile) = targets[0];
let mut profile = profile.clone();
profile.rustc_args = Some(args.to_vec());
general_targets.push((target, profile));
} else {
return Err(human("extra arguments to `rustc` can only be \
passed to one target, consider \
filtering\nthe package by passing e.g. \
`--lib` or `--bin NAME` to specify \
a single target"))

}
match (*target_rustc_args, *target_rustdoc_args) {
(Some(..), _) |
(_, Some(..)) if to_builds.len() != 1 => {
panic!("`rustc` and `rustdoc` should not accept multiple `-p` flags")
}
(Some(args), _) => {
let targets = try!(generate_targets(to_builds[0], profiles,
mode, filter, release));
if targets.len() == 1 {
let (target, profile) = targets[0];
let mut profile = profile.clone();
profile.rustc_args = Some(args.to_vec());
general_targets.push((target, profile));
} else {
return Err(human("extra arguments to `rustc` can only be \
passed to one target, consider \
filtering\nthe package by passing e.g. \
`--lib` or `--bin NAME` to specify \
a single target"))
}
}
(None, Some(args)) => {
let targets = try!(generate_targets(to_builds[0], profiles,
mode, filter, release));
if targets.len() == 1 {
let (target, profile) = targets[0];
let mut profile = profile.clone();
profile.rustdoc_args = Some(args.to_vec());
general_targets.push((target, profile));
} else {
panic!("`rustc` should not accept multiple `-p` flags")
return Err(human("extra arguments to `rustdoc` can only be \
passed to one target, consider \
filtering\nthe package by passing e.g. \
`--lib` or `--bin NAME` to specify \
a single target"))
}
}
None => {
(None, None) => {
for &to_build in to_builds.iter() {
let targets = try!(generate_targets(to_build, profiles, mode,
filter, release));
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 @@ -220,6 +220,7 @@ fn run_verify(config: &Config, pkg: &Package, tar: &Path)
exec_engine: None,
release: false,
mode: ops::CompileMode::Build,
target_rustdoc_args: None,
target_rustc_args: None,
}));

Expand Down
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
}
}

if let Some(ref args) = unit.profile.rustdoc_args {
rustdoc.args(args);
}

try!(build_deps_args(&mut rustdoc, cx, unit));

if unit.pkg.has_custom_build() {
Expand Down Expand Up @@ -448,6 +452,7 @@ fn build_base_args(cx: &Context,
let Profile {
opt_level, lto, codegen_units, ref rustc_args, debuginfo,
debug_assertions, rpath, test, doc: _doc, run_custom_build,
rustdoc_args: _,
} = *unit.profile;
assert!(!run_custom_build);

Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ fn build_profiles(profiles: &Option<TomlProfiles>) -> Profiles {
lto: lto.unwrap_or(profile.lto),
codegen_units: codegen_units,
rustc_args: None,
rustdoc_args: None,
debuginfo: debug.unwrap_or(profile.debuginfo),
debug_assertions: debug_assertions.unwrap_or(profile.debug_assertions),
rpath: rpath.unwrap_or(profile.rpath),
Expand Down
Loading

0 comments on commit 178ede2

Please sign in to comment.