-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-source-subcommand'
Add a new subcommand to grep for and print the Android.bp definition of a module. * add-source-subcommand: Add `source` subcommand Add method to grep for module definition in Android.bp file deps: regex (1.10) Import Android.bp for unit tests Signed-off-by: Mårten Kongstad <[email protected]>
- Loading branch information
Showing
6 changed files
with
498 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use anyhow::Result; | ||
use regex::Regex; | ||
|
||
#[allow(dead_code)] | ||
pub fn find_module_source<'h>(haystack: &'h str, name: &str) -> Result<Option<&'h str>> { | ||
let regex_module = Regex::new(r"(?ms)[ \t]*[_a-zA-Z0-9]+\s*\{.*?^\}")?; | ||
let regex_name = Regex::new(&format!(r#"(?m)^\s*name:\s*"{}""#, name))?; | ||
for cap in regex_module.captures_iter(haystack) { | ||
let match_ = cap.get(0).unwrap(); | ||
if regex_name.is_match(match_.as_str()) { | ||
return Ok(Some(&haystack[match_.range()])); | ||
} | ||
} | ||
|
||
Ok(None) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
const BLUEPRINT: &str = include_str!("../tests/data/Android.bp"); | ||
|
||
#[test] | ||
fn test_find_module_source() { | ||
assert!(find_module_source("", "").unwrap().is_none()); | ||
assert!(find_module_source(BLUEPRINT, "none").unwrap().is_none()); | ||
let source = find_module_source(BLUEPRINT, "idmap2").unwrap().unwrap(); | ||
assert!(source.starts_with("cc_binary {\n name: \"idmap2\",\n")); | ||
assert!(source.ends_with("},\n\n}")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.