Auto merge of #35340 - michaelwoerister:incr-comp-cli-args, r=nikomatsakis
Take commandline arguments into account for incr. comp. Implements the conservative strategy described in https://github.com/rust-lang/rust/issues/33727. From now one, every time a new commandline option is added, one has to specify if it influences the incremental compilation cache. I've tried to implement this as automatic as possible: One just has to added either the `[TRACKED]` or the `[UNTRACKED]` marker next to the field. The `Options`, `CodegenOptions`, and `DebuggingOptions` definitions in `session::config` show plenty of examples. The PR removes some cruft from `session::config::Options`, mostly unnecessary copies of flags also present in `DebuggingOptions` or `CodeGenOptions` in the same struct. One notable removal is the `cfg` field that contained the values passed via `--cfg` commandline arguments. I chose to remove it because (1) its content is only a subset of what later is stored in `hir::Crate::config` and it's pretty likely that reading the cfgs from `Options` would not be what you wanted, and (2) we could not incorporate it into the dep-tracking hash of the `Options` struct because of how the test framework works, leaving us with a piece of untracked but vital data. It is now recommended (just as before) to access the crate config via the `krate()` method in the HIR map. Because the `cfg` field is not present in the `Options` struct any more, some methods in the `CompilerCalls` trait now take the crate config as an explicit parameter -- which might constitute a breaking change for plugin authors.
This commit is contained in:
commit
f65d96fe3f
26 changed files with 1183 additions and 245 deletions
|
|
@ -45,7 +45,6 @@ pub enum MaybeTyped<'a, 'tcx: 'a> {
|
|||
NotTyped(&'a session::Session)
|
||||
}
|
||||
|
||||
pub type Externs = HashMap<String, Vec<String>>;
|
||||
pub type ExternalPaths = HashMap<DefId, (Vec<String>, clean::TypeKind)>;
|
||||
|
||||
pub struct DocContext<'a, 'tcx: 'a> {
|
||||
|
|
@ -99,7 +98,7 @@ impl DocAccessLevels for AccessLevels<DefId> {
|
|||
|
||||
pub fn run_core(search_paths: SearchPaths,
|
||||
cfgs: Vec<String>,
|
||||
externs: Externs,
|
||||
externs: config::Externs,
|
||||
input: Input,
|
||||
triple: Option<String>) -> (clean::Crate, RenderInfo)
|
||||
{
|
||||
|
|
@ -120,7 +119,6 @@ pub fn run_core(search_paths: SearchPaths,
|
|||
lint_cap: Some(lint::Allow),
|
||||
externs: externs,
|
||||
target_triple: triple.unwrap_or(config::host_triple().to_string()),
|
||||
cfg: config::parse_cfgspecs(cfgs),
|
||||
// Ensure that rustdoc works even if rustc is feature-staged
|
||||
unstable_features: UnstableFeatures::Allow,
|
||||
..config::basic_options().clone()
|
||||
|
|
@ -139,7 +137,7 @@ pub fn run_core(search_paths: SearchPaths,
|
|||
codemap, cstore.clone());
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
|
||||
let mut cfg = config::build_configuration(&sess);
|
||||
let mut cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs));
|
||||
target_features::add_configuration(&mut cfg, &sess);
|
||||
|
||||
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ extern crate rustc_errors as errors;
|
|||
|
||||
extern crate serialize as rustc_serialize; // used by deriving
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::default::Default;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -60,7 +60,8 @@ use std::sync::mpsc::channel;
|
|||
|
||||
use externalfiles::ExternalHtml;
|
||||
use rustc::session::search_paths::SearchPaths;
|
||||
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options};
|
||||
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options,
|
||||
Externs};
|
||||
|
||||
#[macro_use]
|
||||
pub mod externalfiles;
|
||||
|
|
@ -323,7 +324,7 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
/// Looks inside the command line arguments to extract the relevant input format
|
||||
/// and files and then generates the necessary rustdoc output for formatting.
|
||||
fn acquire_input(input: &str,
|
||||
externs: core::Externs,
|
||||
externs: Externs,
|
||||
matches: &getopts::Matches) -> Result<Output, String> {
|
||||
match matches.opt_str("r").as_ref().map(|s| &**s) {
|
||||
Some("rust") => Ok(rust_input(input, externs, matches)),
|
||||
|
|
@ -335,10 +336,10 @@ fn acquire_input(input: &str,
|
|||
}
|
||||
|
||||
/// Extracts `--extern CRATE=PATH` arguments from `matches` and
|
||||
/// returns a `HashMap` mapping crate names to their paths or else an
|
||||
/// returns a map mapping crate names to their paths or else an
|
||||
/// error message.
|
||||
fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
|
||||
let mut externs = HashMap::new();
|
||||
fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
|
||||
let mut externs = BTreeMap::new();
|
||||
for arg in &matches.opt_strs("extern") {
|
||||
let mut parts = arg.splitn(2, '=');
|
||||
let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
|
||||
|
|
@ -346,9 +347,9 @@ fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
|
|||
.ok_or("--extern value must be of the format `foo=bar`"
|
||||
.to_string())?;
|
||||
let name = name.to_string();
|
||||
externs.entry(name).or_insert(vec![]).push(location.to_string());
|
||||
externs.entry(name).or_insert_with(BTreeSet::new).insert(location.to_string());
|
||||
}
|
||||
Ok(externs)
|
||||
Ok(Externs::new(externs))
|
||||
}
|
||||
|
||||
/// Interprets the input file as a rust source file, passing it through the
|
||||
|
|
@ -356,7 +357,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
|
|||
/// generated from the cleaned AST of the crate.
|
||||
///
|
||||
/// This form of input will run all of the plug/cleaning passes
|
||||
fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matches) -> Output {
|
||||
fn rust_input(cratefile: &str, externs: Externs, matches: &getopts::Matches) -> Output {
|
||||
let mut default_passes = !matches.opt_present("no-defaults");
|
||||
let mut passes = matches.opt_strs("passes");
|
||||
let mut plugins = matches.opt_strs("plugins");
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ use std::io::prelude::*;
|
|||
use std::io;
|
||||
use std::path::{PathBuf, Path};
|
||||
|
||||
use core;
|
||||
use getopts;
|
||||
use testing;
|
||||
use rustc::session::search_paths::SearchPaths;
|
||||
use rustc::session::config::Externs;
|
||||
|
||||
use externalfiles::ExternalHtml;
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
|||
}
|
||||
|
||||
/// Run any tests/code examples in the markdown file `input`.
|
||||
pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: core::Externs,
|
||||
pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
||||
mut test_args: Vec<String>) -> isize {
|
||||
let input_str = load_or_return!(input, 1, 2);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ use rustc_lint;
|
|||
use rustc::dep_graph::DepGraph;
|
||||
use rustc::hir::map as hir_map;
|
||||
use rustc::session::{self, config};
|
||||
use rustc::session::config::{get_unstable_features_setting, OutputType};
|
||||
use rustc::session::config::{get_unstable_features_setting, OutputType,
|
||||
OutputTypes, Externs};
|
||||
use rustc::session::search_paths::{SearchPaths, PathKind};
|
||||
use rustc_back::dynamic_lib::DynamicLibrary;
|
||||
use rustc_back::tempdir::TempDir;
|
||||
|
|
@ -55,7 +56,7 @@ pub struct TestOptions {
|
|||
pub fn run(input: &str,
|
||||
cfgs: Vec<String>,
|
||||
libs: SearchPaths,
|
||||
externs: core::Externs,
|
||||
externs: Externs,
|
||||
mut test_args: Vec<String>,
|
||||
crate_name: Option<String>)
|
||||
-> isize {
|
||||
|
|
@ -89,8 +90,7 @@ pub fn run(input: &str,
|
|||
cstore.clone());
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
|
||||
let mut cfg = config::build_configuration(&sess);
|
||||
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
|
||||
let cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
|
||||
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
|
||||
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
|
||||
phase_2_configure_and_expand(
|
||||
|
|
@ -172,7 +172,7 @@ fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
|
|||
}
|
||||
|
||||
fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
||||
externs: core::Externs,
|
||||
externs: Externs,
|
||||
should_panic: bool, no_run: bool, as_test_harness: bool,
|
||||
compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions) {
|
||||
// the test harness wants its own `main` & top level functions, so
|
||||
|
|
@ -182,8 +182,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
|||
name: driver::anon_src(),
|
||||
input: test.to_owned(),
|
||||
};
|
||||
let mut outputs = HashMap::new();
|
||||
outputs.insert(OutputType::Exe, None);
|
||||
let outputs = OutputTypes::new(&[(OutputType::Exe, None)]);
|
||||
|
||||
let sessopts = config::Options {
|
||||
maybe_sysroot: Some(env::current_exe().unwrap().parent().unwrap()
|
||||
|
|
@ -247,8 +246,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
|||
let outdir = Mutex::new(TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir"));
|
||||
let libdir = sess.target_filesearch(PathKind::All).get_lib_path();
|
||||
let mut control = driver::CompileController::basic();
|
||||
let mut cfg = config::build_configuration(&sess);
|
||||
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
|
||||
let cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
|
||||
let out = Some(outdir.lock().unwrap().path().to_path_buf());
|
||||
|
||||
if no_run {
|
||||
|
|
@ -396,7 +394,7 @@ pub struct Collector {
|
|||
names: Vec<String>,
|
||||
cfgs: Vec<String>,
|
||||
libs: SearchPaths,
|
||||
externs: core::Externs,
|
||||
externs: Externs,
|
||||
cnt: usize,
|
||||
use_headers: bool,
|
||||
current_header: Option<String>,
|
||||
|
|
@ -405,7 +403,7 @@ pub struct Collector {
|
|||
}
|
||||
|
||||
impl Collector {
|
||||
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: core::Externs,
|
||||
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
||||
use_headers: bool, opts: TestOptions) -> Collector {
|
||||
Collector {
|
||||
tests: Vec::new(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue