Merge changes from topic "aconfig-package-ident-fixes" am: 9c3da21b6e
am: 081d19bb1f
am: e30c479502
am: 67f93bfbdf
Original change: https://android-review.googlesource.com/c/platform/build/+/2643656 Change-Id: I4c8b5e3160ca56bfdf218e58b6c10a69f13875ec Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -32,12 +32,15 @@ pub fn is_valid_name_ident(s: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid_package_ident(s: &str) -> bool {
|
pub fn is_valid_package_ident(s: &str) -> bool {
|
||||||
|
if !s.contains('.') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
s.split('.').all(is_valid_name_ident)
|
s.split('.').all(is_valid_name_ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_device_config_ident(package: &str, flag_name: &str) -> Result<String> {
|
pub fn create_device_config_ident(package: &str, flag_name: &str) -> Result<String> {
|
||||||
ensure!(is_valid_package_ident(package), "bad package");
|
ensure!(is_valid_package_ident(package), "bad package");
|
||||||
ensure!(is_valid_package_ident(flag_name), "bad flag name");
|
ensure!(is_valid_name_ident(flag_name), "bad flag name");
|
||||||
Ok(format!("{}.{}", package, flag_name))
|
Ok(format!("{}.{}", package, flag_name))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,12 +64,13 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_valid_package_ident() {
|
fn test_is_valid_package_ident() {
|
||||||
assert!(is_valid_package_ident("foo"));
|
|
||||||
assert!(is_valid_package_ident("foo_bar_123"));
|
|
||||||
assert!(is_valid_package_ident("foo.bar"));
|
assert!(is_valid_package_ident("foo.bar"));
|
||||||
|
assert!(is_valid_package_ident("foo.bar_baz"));
|
||||||
assert!(is_valid_package_ident("foo.bar.a123"));
|
assert!(is_valid_package_ident("foo.bar.a123"));
|
||||||
assert!(!is_valid_package_ident("foo._bar"));
|
|
||||||
|
|
||||||
|
assert!(!is_valid_package_ident("foo_bar_123"));
|
||||||
|
assert!(!is_valid_package_ident("foo"));
|
||||||
|
assert!(!is_valid_package_ident("foo._bar"));
|
||||||
assert!(!is_valid_package_ident(""));
|
assert!(!is_valid_package_ident(""));
|
||||||
assert!(!is_valid_package_ident("123_foo"));
|
assert!(!is_valid_package_ident("123_foo"));
|
||||||
assert!(!is_valid_package_ident("foo-bar"));
|
assert!(!is_valid_package_ident("foo-bar"));
|
||||||
@@ -75,6 +79,7 @@ mod tests {
|
|||||||
assert!(!is_valid_package_ident(".foo.bar"));
|
assert!(!is_valid_package_ident(".foo.bar"));
|
||||||
assert!(!is_valid_package_ident("foo.bar."));
|
assert!(!is_valid_package_ident("foo.bar."));
|
||||||
assert!(!is_valid_package_ident("."));
|
assert!(!is_valid_package_ident("."));
|
||||||
|
assert!(!is_valid_package_ident(".."));
|
||||||
assert!(!is_valid_package_ident("foo..bar"));
|
assert!(!is_valid_package_ident("foo..bar"));
|
||||||
assert!(!is_valid_package_ident("foo.__bar"));
|
assert!(!is_valid_package_ident("foo.__bar"));
|
||||||
}
|
}
|
||||||
|
@@ -549,7 +549,7 @@ parsed_flag {
|
|||||||
// bad input: parsed_flag not sorted by package
|
// bad input: parsed_flag not sorted by package
|
||||||
let text_proto = r#"
|
let text_proto = r#"
|
||||||
parsed_flag {
|
parsed_flag {
|
||||||
package: "bbb"
|
package: "bbb.bbb"
|
||||||
name: "first"
|
name: "first"
|
||||||
namespace: "first_ns"
|
namespace: "first_ns"
|
||||||
description: "This is the description of the first flag."
|
description: "This is the description of the first flag."
|
||||||
@@ -562,7 +562,7 @@ parsed_flag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
parsed_flag {
|
parsed_flag {
|
||||||
package: "aaa"
|
package: "aaa.aaa"
|
||||||
name: "second"
|
name: "second"
|
||||||
namespace: "second_ns"
|
namespace: "second_ns"
|
||||||
description: "This is the description of the second flag."
|
description: "This is the description of the second flag."
|
||||||
@@ -578,7 +578,7 @@ parsed_flag {
|
|||||||
let error = try_from_binary_proto_from_text_proto(text_proto).unwrap_err();
|
let error = try_from_binary_proto_from_text_proto(text_proto).unwrap_err();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", error),
|
format!("{:?}", error),
|
||||||
"bad parsed flags: not sorted: bbb.first comes before aaa.second"
|
"bad parsed flags: not sorted: bbb.bbb.first comes before aaa.aaa.second"
|
||||||
);
|
);
|
||||||
|
|
||||||
// bad input: parsed_flag not sorted by name
|
// bad input: parsed_flag not sorted by name
|
||||||
|
Reference in New Issue
Block a user