-
Notifications
You must be signed in to change notification settings - Fork 5
Track RPL_PATS environment variable and pattern files #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ use rustc_span::Symbol; | |
| // use crate::passes::create_rpl_ctxt; | ||
|
|
||
| pub static RPL_ARGS_ENV: &str = "RPL_ARGS"; | ||
| pub static RPL_PATS_ENV: &str = "RPL_PATS"; | ||
|
|
||
| fn track_rpl_args(psess: &mut ParseSess, args_env_var: &Option<String>) { | ||
| psess.env_depinfo.get_mut().insert(( | ||
|
|
@@ -40,6 +41,20 @@ fn track_files(psess: &mut ParseSess) { | |
| } | ||
| } | ||
|
|
||
| fn track_rpl_pats(psess: &mut ParseSess, pats_env_var: Option<String>, pats: &[String]) { | ||
| let rpl_pats = pats_env_var; | ||
| psess | ||
| .env_depinfo | ||
| .get_mut() | ||
| .insert((Symbol::intern(RPL_PATS_ENV), rpl_pats.as_deref().map(Symbol::intern))); | ||
|
|
||
| let pat_depinfo = psess.file_depinfo.get_mut(); | ||
|
|
||
| for path in pats { | ||
| pat_depinfo.insert(Symbol::intern(path)); | ||
| } | ||
|
Comment on lines
+51
to
+55
|
||
| } | ||
|
|
||
| /// This is different from `DefaultCallbacks` that it will inform Cargo to track the value of | ||
| /// `RPL_ARGS` environment variable. | ||
| pub struct RustcCallbacks { | ||
|
|
@@ -66,13 +81,15 @@ impl rustc_driver::Callbacks for DefaultCallbacks {} | |
|
|
||
| pub struct RplCallbacks { | ||
| rpl_args_var: Option<String>, | ||
| rpl_pats_var: Option<String>, | ||
| pattern_paths: Option<Vec<String>>, | ||
| } | ||
|
|
||
| impl RplCallbacks { | ||
| pub fn new(rpl_args_var: Option<String>, pattern_paths: Option<Vec<String>>) -> Self { | ||
| pub fn new(rpl_args_var: Option<String>, rpl_pats_var: Option<String>, pattern_paths: Option<Vec<String>>) -> Self { | ||
| Self { | ||
| rpl_args_var, | ||
| rpl_pats_var, | ||
| pattern_paths, | ||
| } | ||
| } | ||
|
|
@@ -102,9 +119,12 @@ impl rustc_driver::Callbacks for RplCallbacks { | |
| #[allow(rustc::bad_opt_access)] | ||
| fn config(&mut self, config: &mut interface::Config) { | ||
| let rpl_args_var = self.rpl_args_var.take(); | ||
| let rpl_pats_var = self.rpl_pats_var.take(); | ||
| let rpl_pats = self.pattern_paths.clone(); | ||
|
Comment on lines
121
to
+123
|
||
| config.psess_created = Some(Box::new(move |psess| { | ||
| track_rpl_args(psess, &rpl_args_var); | ||
| track_files(psess); | ||
| track_rpl_pats(psess, rpl_pats_var, rpl_pats.as_deref().unwrap_or(&[])); | ||
| })); | ||
| config.locale_resources = crate::default_locale_resources(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,7 +221,8 @@ pub fn main() { | |
| let mut args: Vec<String> = orig_args.clone(); | ||
| pass_sysroot_env_if_given(&mut args, sys_root_env); | ||
|
|
||
| let pattern_paths = match env::var("RPL_PATS") { | ||
| let rpl_pats_var = env::var("RPL_PATS"); | ||
| let pattern_paths = match &rpl_pats_var { | ||
|
Comment on lines
+224
to
+225
|
||
| Ok(val) => Some(val.split(':').map(ToString::to_string).collect()), | ||
| Err(env::VarError::NotPresent) => None, | ||
| Err(env::VarError::NotUnicode(var)) => { | ||
|
|
@@ -261,7 +262,10 @@ pub fn main() { | |
| /* rustc_driver::RunCompiler::new(&args, &mut RplCallbacks::new(rpl_args_var)) | ||
| .set_using_internal_features(using_internal_features) | ||
| .run() */ | ||
| rustc_driver::run_compiler(&args, &mut RplCallbacks::new(rpl_args_var, pattern_paths)) | ||
| rustc_driver::run_compiler( | ||
| &args, | ||
| &mut RplCallbacks::new(rpl_args_var, rpl_pats_var.ok(), pattern_paths), | ||
| ) | ||
| } else { | ||
| rustc_driver::run_compiler(&args, &mut RustcCallbacks::new(rpl_args_var)) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RPL_PATS_ENVis introduced here, but the driver still hard-codes "RPL_PATS". To avoid drift/typos, consider re-exportingRPL_PATS_ENVfromcrates/rpl_interface/src/lib.rs(likeRPL_ARGS_ENV) and using the constant everywhere.