-
Notifications
You must be signed in to change notification settings - Fork 31
make: Fix intermittent dash_r_with_file test failure and inference ru… #559
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
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -66,6 +66,37 @@ impl Rule { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.recipes.iter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Runs an inference rule for a specific target (not a CWD scan). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// This is used when POSIX requires applying an inference rule to a specific | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// target that has no commands of its own. The internal macros ($<, $*, etc.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// are substituted based on the target name and the inference rule's suffixes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn run_for_target( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| &self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global_config: &GlobalConfig, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| macros: &[VariableDefinition], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target: &Target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| up_to_date: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Result<(), ErrorCode> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // For an inference rule applied to a specific target, compute the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // input/output pair from the target name and the rule's suffixes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let files = if let Some(Target::Inference { from, to, .. }) = self.targets().next() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let target_name = target.as_ref(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let expected_suffix = format!(".{}", to); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let Some(stem) = target_name.strip_suffix(&expected_suffix) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let input = PathBuf::from(format!("{}.{}", stem, from)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let output = PathBuf::from(target_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vec![(input, output)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vec![(PathBuf::from(""), PathBuf::from(""))] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vec![(PathBuf::from(""), PathBuf::from(""))] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.run_with_files(global_config, macros, target, up_to_date, files) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+81
to
+97
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // For an inference rule applied to a specific target, compute the | |
| // input/output pair from the target name and the rule's suffixes. | |
| let files = if let Some(Target::Inference { from, to, .. }) = self.targets().next() { | |
| let target_name = target.as_ref(); | |
| let expected_suffix = format!(".{}", to); | |
| if let Some(stem) = target_name.strip_suffix(&expected_suffix) { | |
| let input = PathBuf::from(format!("{}.{}", stem, from)); | |
| let output = PathBuf::from(target_name); | |
| vec![(input, output)] | |
| } else { | |
| vec![(PathBuf::from(""), PathBuf::from(""))] | |
| } | |
| } else { | |
| vec![(PathBuf::from(""), PathBuf::from(""))] | |
| }; | |
| self.run_with_files(global_config, macros, target, up_to_date, files) | |
| let target_name = target.as_ref(); | |
| // For an inference rule applied to a specific target, compute the | |
| // input/output pair from the target name and the rule's suffixes. | |
| if let Some(Target::Inference { from, to, .. }) = self.targets().next() { | |
| let expected_suffix = format!(".{}", to); | |
| if let Some(stem) = target_name.strip_suffix(&expected_suffix) { | |
| let input = PathBuf::from(format!("{}.{}", stem, from)); | |
| let output = PathBuf::from(target_name); | |
| let files = vec![(input, output)]; | |
| return self.run_with_files(global_config, macros, target, up_to_date, files); | |
| } | |
| // Suffix does not match this inference rule; do not run any recipes. | |
| return Ok(()); | |
| } | |
| // `run_for_target` should only be used with inference rules; treat other | |
| // usages as a programmer error and report a missing target. | |
| debug_assert!( | |
| false, | |
| "run_for_target called on non-inference rule for target {target_name}" | |
| ); | |
| Err(NoTarget { | |
| target: Some(target_name.to_string()), | |
| }) |
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.
The struct-level invariant comment says
first_target()"always returns a valid default target per POSIX", butfirst_target()explicitly falls back toself.inference_rules.first()when there are no regular targets, which returns an inference rule target (and will scan the CWD). The comment should be updated to match the actual behavior (or the fallback behavior adjusted) so future changes don’t rely on an incorrect invariant.