diff --git a/src/Cargo.lock b/src/Cargo.lock index 04a556705b5a..0c12d7304da3 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1128,6 +1128,15 @@ dependencies = [ "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rls-data" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rls-span" version = "0.4.0" @@ -1459,7 +1468,7 @@ name = "rustc_save_analysis" version = "0.0.0" dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rls-data 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rls-data 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2172,6 +2181,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" "checksum rls-analysis 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ea940411ed2ad6d1e705fc2a0b146a0a3f30f8098ba4e61b45b4e5f2bfa7ed63" "checksum rls-data 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e502ac679bc35e023e982506c32d0278ef89e29af1e4ad21cb70c44b525b87a9" +"checksum rls-data 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f274ec7f966337dc2601fe9bde060b551d1293c277af782dc65cd7200ca070c0" "checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a" "checksum rls-vfs 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd34691a510938bb67fe0444fb363103c73ffb31c121d1e16bc92d8945ea8ff" "checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 1f9f6aad9053..0fc17e645151 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -578,6 +578,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { state.expanded_crate.unwrap(), state.analysis.unwrap(), state.crate_name.unwrap(), + None, DumpHandler::new(save_analysis_format(state.session), state.out_dir, state.crate_name.unwrap())) diff --git a/src/librustc_save_analysis/Cargo.toml b/src/librustc_save_analysis/Cargo.toml index 1ae666fbc2f5..2a51bf9430e7 100644 --- a/src/librustc_save_analysis/Cargo.toml +++ b/src/librustc_save_analysis/Cargo.toml @@ -14,7 +14,7 @@ rustc = { path = "../librustc" } rustc_typeck = { path = "../librustc_typeck" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } -rls-data = "0.7" +rls-data = "0.9" rls-span = "0.4" # FIXME(#40527) should move rustc serialize out of tree rustc-serialize = "0.3" diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index ac2baa9e8b1d..530e29a8c82c 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -43,10 +43,10 @@ use rustc::hir::def::Def as HirDef; use rustc::hir::map::{Node, NodeItem}; use rustc::hir::def_id::DefId; use rustc::session::config::CrateType::CrateTypeExecutable; -use rustc::session::Session; use rustc::ty::{self, TyCtxt}; use rustc_typeck::hir_ty_to_ty; +use std::default::Default; use std::env; use std::fs::File; use std::path::{Path, PathBuf}; @@ -68,6 +68,7 @@ use span_utils::SpanUtils; use rls_data::{Ref, RefKind, SpanData, MacroRef, Def, DefKind, Relation, RelationKind, ExternalCrateData, Import, CratePreludeData}; +use rls_data::config::Config; pub struct SaveContext<'l, 'tcx: 'l> { @@ -75,6 +76,7 @@ pub struct SaveContext<'l, 'tcx: 'l> { tables: &'l ty::TypeckTables<'tcx>, analysis: &'l ty::CrateAnalysis, span_utils: SpanUtils<'tcx>, + config: Config, } #[derive(Debug)] @@ -900,39 +902,41 @@ impl<'a> DumpHandler<'a> { } } - fn output_file(&self, sess: &Session) -> File { - let mut root_path = match env::var_os("RUST_SAVE_ANALYSIS_FOLDER") { - Some(val) => PathBuf::from(val), - None => match self.odir { - Some(val) => val.join("save-analysis"), - None => PathBuf::from("save-analysis-temp"), - }, + fn output_file(&self, ctx: &SaveContext) -> File { + let sess = &ctx.tcx.sess; + let file_name = match ctx.config.output_file { + Some(ref s) => PathBuf::from(s), + None => { + let mut root_path = match self.odir { + Some(val) => val.join("save-analysis"), + None => PathBuf::from("save-analysis-temp"), + }; + + if let Err(e) = std::fs::create_dir_all(&root_path) { + error!("Could not create directory {}: {}", root_path.display(), e); + } + + let executable = sess.crate_types.borrow().iter().any(|ct| *ct == CrateTypeExecutable); + let mut out_name = if executable { + "".to_owned() + } else { + "lib".to_owned() + }; + out_name.push_str(&self.cratename); + out_name.push_str(&sess.opts.cg.extra_filename); + out_name.push_str(self.format.extension()); + root_path.push(&out_name); + + root_path + } }; - if let Err(e) = std::fs::create_dir_all(&root_path) { - error!("Could not create directory {}: {}", root_path.display(), e); - } + info!("Writing output to {}", file_name.display()); - { - let disp = root_path.display(); - info!("Writing output to {}", disp); - } - - let executable = sess.crate_types.borrow().iter().any(|ct| *ct == CrateTypeExecutable); - let mut out_name = if executable { - "".to_owned() - } else { - "lib".to_owned() - }; - out_name.push_str(&self.cratename); - out_name.push_str(&sess.opts.cg.extra_filename); - out_name.push_str(self.format.extension()); - root_path.push(&out_name); - let output_file = File::create(&root_path).unwrap_or_else(|e| { - let disp = root_path.display(); - sess.fatal(&format!("Could not open {}: {}", disp, e)); + let output_file = File::create(&file_name).unwrap_or_else(|e| { + sess.fatal(&format!("Could not open {}: {}", file_name.display(), e)) }); - root_path.pop(); + output_file } } @@ -952,7 +956,7 @@ impl<'a> SaveHandler for DumpHandler<'a> { }} } - let output = &mut self.output_file(&save_ctxt.tcx.sess); + let output = &mut self.output_file(&save_ctxt); match self.format { Format::Json => dump!(JsonDumper::new(output)), @@ -994,6 +998,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(tcx: TyCtxt<'l, 'tcx, 'tcx>, krate: &ast::Crate, analysis: &'l ty::CrateAnalysis, cratename: &str, + config: Option, mut handler: H) { let _ignore = tcx.dep_graph.in_ignore(); @@ -1006,11 +1011,25 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(tcx: TyCtxt<'l, 'tcx, 'tcx>, tables: &ty::TypeckTables::empty(), analysis: analysis, span_utils: SpanUtils::new(&tcx.sess), + config: find_config(config), }; handler.save(save_ctxt, krate, cratename) } +fn find_config(supplied: Option) -> Config { + if let Some(config) = supplied { + return config; + } + match env::var_os("RUST_SAVE_ANALYSIS_CONFIG") { + Some(config_string) => { + rustc_serialize::json::decode(config_string.to_str().unwrap()) + .expect("Could not deserialize save-analysis config") + }, + None => Config::default(), + } +} + // Utility functions for the module. // Helper function to escape quotes in a string