@@ -73,9 +73,11 @@ extern crate tikv_jemalloc_sys as jemalloc_sys;
7373
7474use std:: env:: { self , VarError } ;
7575use std:: io:: { self , IsTerminal } ;
76+ use std:: path:: Path ;
7677use std:: process;
7778
7879use rustc_errors:: DiagCtxtHandle ;
80+ use rustc_hir:: def_id:: LOCAL_CRATE ;
7981use rustc_interface:: interface;
8082use rustc_middle:: ty:: TyCtxt ;
8183use rustc_session:: config:: { ErrorOutputType , RustcOptGroup , make_crate_type_option} ;
@@ -654,9 +656,9 @@ fn opts() -> Vec<RustcOptGroup> {
654656 Unstable ,
655657 Multi ,
656658 "" ,
657- "doctest-compilation-args " ,
658- "" ,
659- "add arguments to be used when compiling doctests " ,
659+ "doctest-build-arg " ,
660+ "One argument (of possibly many) to be used when compiling doctests " ,
661+ "ARG " ,
660662 ) ,
661663 opt(
662664 Unstable ,
@@ -904,6 +906,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
904906 rustc_interface:: passes:: write_dep_info ( tcx) ;
905907 }
906908
909+ if let Some ( metrics_dir) = & sess. opts . unstable_opts . metrics_dir {
910+ dump_feature_usage_metrics ( tcx, metrics_dir) ;
911+ }
912+
907913 if run_check {
908914 // Since we're in "check" mode, no need to generate anything beyond this point.
909915 return ;
@@ -923,3 +929,16 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
923929 } )
924930 } )
925931}
932+
933+ fn dump_feature_usage_metrics ( tcxt : TyCtxt < ' _ > , metrics_dir : & Path ) {
934+ let hash = tcxt. crate_hash ( LOCAL_CRATE ) ;
935+ let crate_name = tcxt. crate_name ( LOCAL_CRATE ) ;
936+ let metrics_file_name = format ! ( "unstable_feature_usage_metrics-{crate_name}-{hash}.json" ) ;
937+ let metrics_path = metrics_dir. join ( metrics_file_name) ;
938+ if let Err ( error) = tcxt. features ( ) . dump_feature_usage_metrics ( metrics_path) {
939+ // FIXME(yaahc): once metrics can be enabled by default we will want "failure to emit
940+ // default metrics" to only produce a warning when metrics are enabled by default and emit
941+ // an error only when the user manually enables metrics
942+ tcxt. dcx ( ) . err ( format ! ( "cannot emit feature usage metrics: {error}" ) ) ;
943+ }
944+ }
0 commit comments