@@ -897,42 +897,56 @@ pub fn build_session_options(binary: ~str,
897
897
return sopts;
898
898
}
899
899
900
- pub fn build_session ( sopts : @session:: Options , demitter : @diagnostic:: Emitter )
900
+ pub fn build_session ( sopts : @session:: Options ,
901
+ local_crate_source_file : Option < Path > ,
902
+ demitter : @diagnostic:: Emitter )
901
903
-> Session {
902
904
let codemap = @codemap:: CodeMap :: new ( ) ;
903
905
let diagnostic_handler =
904
906
diagnostic:: mk_handler ( Some ( demitter) ) ;
905
907
let span_diagnostic_handler =
906
908
diagnostic:: mk_span_handler ( diagnostic_handler, codemap) ;
907
- build_session_ ( sopts, codemap, demitter, span_diagnostic_handler)
909
+
910
+ build_session_ ( sopts, local_crate_source_file, codemap, demitter, span_diagnostic_handler)
908
911
}
909
912
910
913
pub fn build_session_ ( sopts : @session:: Options ,
911
- cm : @codemap:: CodeMap ,
914
+ local_crate_source_file : Option < Path > ,
915
+ codemap : @codemap:: CodeMap ,
912
916
demitter : @diagnostic:: Emitter ,
913
917
span_diagnostic_handler : @diagnostic:: SpanHandler )
914
918
-> Session {
915
919
let target_cfg = build_target_config ( sopts, demitter) ;
916
- let p_s = parse:: new_parse_sess_special_handler ( span_diagnostic_handler,
917
- cm) ;
920
+ let p_s = parse:: new_parse_sess_special_handler ( span_diagnostic_handler, codemap) ;
918
921
let cstore = @CStore :: new ( token:: get_ident_interner ( ) ) ;
919
922
let filesearch = @filesearch:: FileSearch :: new (
920
923
& sopts. maybe_sysroot ,
921
924
sopts. target_triple ,
922
925
sopts. addl_lib_search_paths ) ;
926
+
927
+ // Make the path absolute, if necessary
928
+ let local_crate_source_file = local_crate_source_file. map ( |path|
929
+ if path. is_absolute ( ) {
930
+ path. clone ( )
931
+ } else {
932
+ os:: getcwd ( ) . join ( path. clone ( ) )
933
+ }
934
+ ) ;
935
+
923
936
@Session_ {
924
937
targ_cfg : target_cfg,
925
938
opts : sopts,
926
939
cstore : cstore,
927
940
parse_sess : p_s,
928
- codemap : cm ,
941
+ codemap : codemap ,
929
942
// For a library crate, this is always none
930
943
entry_fn : RefCell :: new ( None ) ,
931
944
entry_type : Cell :: new ( None ) ,
932
945
macro_registrar_fn : RefCell :: new ( None ) ,
933
946
span_diagnostic : span_diagnostic_handler,
934
947
filesearch : filesearch,
935
948
building_library : Cell :: new ( false ) ,
949
+ local_crate_source_file : local_crate_source_file,
936
950
working_dir : os:: getcwd ( ) ,
937
951
lints : RefCell :: new ( HashMap :: new ( ) ) ,
938
952
node_id : Cell :: new ( 1 ) ,
@@ -1164,13 +1178,8 @@ mod test {
1164
1178
Ok ( m) => m,
1165
1179
Err ( f) => fail ! ( "test_switch_implies_cfg_test: {}" , f. to_err_msg( ) )
1166
1180
} ;
1167
- let sessopts = build_session_options (
1168
- ~"rustc",
1169
- matches,
1170
- @diagnostic:: DefaultEmitter as @diagnostic:: Emitter ) ;
1171
- let sess = build_session ( sessopts,
1172
- @diagnostic:: DefaultEmitter as
1173
- @diagnostic:: Emitter ) ;
1181
+ let sessopts = build_session_options ( ~"rustc", matches, @diagnostic:: DefaultEmitter ) ;
1182
+ let sess = build_session ( sessopts, None , @diagnostic:: DefaultEmitter ) ;
1174
1183
let cfg = build_configuration ( sess) ;
1175
1184
assert ! ( ( attr:: contains_name( cfg, "test" ) ) ) ;
1176
1185
}
@@ -1187,13 +1196,8 @@ mod test {
1187
1196
f. to_err_msg( ) ) ;
1188
1197
}
1189
1198
} ;
1190
- let sessopts = build_session_options (
1191
- ~"rustc",
1192
- matches,
1193
- @diagnostic:: DefaultEmitter as @diagnostic:: Emitter ) ;
1194
- let sess = build_session ( sessopts,
1195
- @diagnostic:: DefaultEmitter as
1196
- @diagnostic:: Emitter ) ;
1199
+ let sessopts = build_session_options ( ~"rustc", matches, @diagnostic:: DefaultEmitter ) ;
1200
+ let sess = build_session ( sessopts, None , @diagnostic:: DefaultEmitter ) ;
1197
1201
let cfg = build_configuration ( sess) ;
1198
1202
let mut test_items = cfg. iter ( ) . filter ( |m| "test" == m. name ( ) ) ;
1199
1203
assert ! ( test_items. next( ) . is_some( ) ) ;
0 commit comments