@@ -43,10 +43,10 @@ use rustc::hir::def::Def as HirDef;
43
43
use rustc:: hir:: map:: { Node , NodeItem } ;
44
44
use rustc:: hir:: def_id:: DefId ;
45
45
use rustc:: session:: config:: CrateType :: CrateTypeExecutable ;
46
- use rustc:: session:: Session ;
47
46
use rustc:: ty:: { self , TyCtxt } ;
48
47
use rustc_typeck:: hir_ty_to_ty;
49
48
49
+ use std:: default:: Default ;
50
50
use std:: env;
51
51
use std:: fs:: File ;
52
52
use std:: path:: { Path , PathBuf } ;
@@ -68,13 +68,15 @@ use span_utils::SpanUtils;
68
68
69
69
use rls_data:: { Ref , RefKind , SpanData , MacroRef , Def , DefKind , Relation , RelationKind ,
70
70
ExternalCrateData , Import , CratePreludeData } ;
71
+ use rls_data:: config:: Config ;
71
72
72
73
73
74
pub struct SaveContext < ' l , ' tcx : ' l > {
74
75
tcx : TyCtxt < ' l , ' tcx , ' tcx > ,
75
76
tables : & ' l ty:: TypeckTables < ' tcx > ,
76
77
analysis : & ' l ty:: CrateAnalysis ,
77
78
span_utils : SpanUtils < ' tcx > ,
79
+ config : Config ,
78
80
}
79
81
80
82
#[ derive( Debug ) ]
@@ -900,39 +902,41 @@ impl<'a> DumpHandler<'a> {
900
902
}
901
903
}
902
904
903
- fn output_file ( & self , sess : & Session ) -> File {
904
- let mut root_path = match env:: var_os ( "RUST_SAVE_ANALYSIS_FOLDER" ) {
905
- Some ( val) => PathBuf :: from ( val) ,
906
- None => match self . odir {
907
- Some ( val) => val. join ( "save-analysis" ) ,
908
- None => PathBuf :: from ( "save-analysis-temp" ) ,
909
- } ,
910
- } ;
905
+ fn output_file ( & self , ctx : & SaveContext ) -> File {
906
+ let sess = & ctx. tcx . sess ;
907
+ let file_name = match ctx. config . output_file {
908
+ Some ( ref s) => PathBuf :: from ( s) ,
909
+ None => {
910
+ let mut root_path = match self . odir {
911
+ Some ( val) => val. join ( "save-analysis" ) ,
912
+ None => PathBuf :: from ( "save-analysis-temp" ) ,
913
+ } ;
911
914
912
- if let Err ( e) = std:: fs:: create_dir_all ( & root_path) {
913
- error ! ( "Could not create directory {}: {}" , root_path. display( ) , e) ;
914
- }
915
+ if let Err ( e) = std:: fs:: create_dir_all ( & root_path) {
916
+ error ! ( "Could not create directory {}: {}" , root_path. display( ) , e) ;
917
+ }
915
918
916
- {
917
- let disp = root_path. display ( ) ;
918
- info ! ( "Writing output to {}" , disp) ;
919
- }
919
+ let executable = sess. crate_types . borrow ( ) . iter ( ) . any ( |ct| * ct == CrateTypeExecutable ) ;
920
+ let mut out_name = if executable {
921
+ "" . to_owned ( )
922
+ } else {
923
+ "lib" . to_owned ( )
924
+ } ;
925
+ out_name. push_str ( & self . cratename ) ;
926
+ out_name. push_str ( & sess. opts . cg . extra_filename ) ;
927
+ out_name. push_str ( self . format . extension ( ) ) ;
928
+ root_path. push ( & out_name) ;
920
929
921
- let executable = sess. crate_types . borrow ( ) . iter ( ) . any ( |ct| * ct == CrateTypeExecutable ) ;
922
- let mut out_name = if executable {
923
- "" . to_owned ( )
924
- } else {
925
- "lib" . to_owned ( )
930
+ root_path
931
+ }
926
932
} ;
927
- out_name. push_str ( & self . cratename ) ;
928
- out_name. push_str ( & sess. opts . cg . extra_filename ) ;
929
- out_name. push_str ( self . format . extension ( ) ) ;
930
- root_path. push ( & out_name) ;
931
- let output_file = File :: create ( & root_path) . unwrap_or_else ( |e| {
932
- let disp = root_path. display ( ) ;
933
- sess. fatal ( & format ! ( "Could not open {}: {}" , disp, e) ) ;
933
+
934
+ info ! ( "Writing output to {}" , file_name. display( ) ) ;
935
+
936
+ let output_file = File :: create ( & file_name) . unwrap_or_else ( |e| {
937
+ sess. fatal ( & format ! ( "Could not open {}: {}" , file_name. display( ) , e) )
934
938
} ) ;
935
- root_path . pop ( ) ;
939
+
936
940
output_file
937
941
}
938
942
}
@@ -952,7 +956,7 @@ impl<'a> SaveHandler for DumpHandler<'a> {
952
956
} }
953
957
}
954
958
955
- let output = & mut self . output_file ( & save_ctxt. tcx . sess ) ;
959
+ let output = & mut self . output_file ( & save_ctxt) ;
956
960
957
961
match self . format {
958
962
Format :: Json => dump ! ( JsonDumper :: new( output) ) ,
@@ -994,6 +998,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(tcx: TyCtxt<'l, 'tcx, 'tcx>,
994
998
krate : & ast:: Crate ,
995
999
analysis : & ' l ty:: CrateAnalysis ,
996
1000
cratename : & str ,
1001
+ config : Option < Config > ,
997
1002
mut handler : H ) {
998
1003
let _ignore = tcx. dep_graph . in_ignore ( ) ;
999
1004
@@ -1006,11 +1011,25 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(tcx: TyCtxt<'l, 'tcx, 'tcx>,
1006
1011
tables : & ty:: TypeckTables :: empty ( ) ,
1007
1012
analysis : analysis,
1008
1013
span_utils : SpanUtils :: new ( & tcx. sess ) ,
1014
+ config : find_config ( config) ,
1009
1015
} ;
1010
1016
1011
1017
handler. save ( save_ctxt, krate, cratename)
1012
1018
}
1013
1019
1020
+ fn find_config ( supplied : Option < Config > ) -> Config {
1021
+ if let Some ( config) = supplied {
1022
+ return config;
1023
+ }
1024
+ match env:: var_os ( "RUST_SAVE_ANALYSIS_CONFIG" ) {
1025
+ Some ( config_string) => {
1026
+ rustc_serialize:: json:: decode ( config_string. to_str ( ) . unwrap ( ) )
1027
+ . expect ( "Could not deserialize save-analysis config" )
1028
+ } ,
1029
+ None => Config :: default ( ) ,
1030
+ }
1031
+ }
1032
+
1014
1033
// Utility functions for the module.
1015
1034
1016
1035
// Helper function to escape quotes in a string
0 commit comments