@@ -16,6 +16,9 @@ use std::path::PathBuf;
1616use toml;
1717
1818pub struct AndroidConfig {
19+ /// Name of the cargo package
20+ pub cargo_package_name : String ,
21+
1922 /// Path to the manifest
2023 pub manifest_path : PathBuf ,
2124 /// Path to the root of the Android SDK.
@@ -51,17 +54,19 @@ impl AndroidConfig {
5154 /// Builds the android target config based on the default target config and the specific target configs defined in the manifest
5255 pub fn resolve ( & self , target : ( TargetKind , String ) ) -> CargoResult < AndroidTargetConfig > {
5356 let primary_config = self . target_configs . get ( & target) ;
54- let package_name = target. 1 ;
57+ let target_name = target. 1 ;
58+ let is_default_target = target_name == self . cargo_package_name ;
59+ let example = target. 0 == TargetKind :: ExampleBin ;
5560
5661 Ok ( AndroidTargetConfig {
5762 package_name : primary_config
5863 . and_then ( |a| a. package_name . clone ( ) )
59- . or_else ( || self . default_target_config . package_name . clone ( ) )
60- . unwrap_or_else ( || format ! ( "rust.{}" , package_name ) ) ,
64+ . or_else ( || if is_default_target { self . default_target_config . package_name . clone ( ) } else { None } )
65+ . unwrap_or_else ( || if example { format ! ( "rust.{}.example.{} " , self . cargo_package_name , target_name ) } else { format ! ( "rust.{}" , target_name ) } ) ,
6166 package_label : primary_config
6267 . and_then ( |a| a. label . clone ( ) )
63- . or_else ( || self . default_target_config . label . clone ( ) )
64- . unwrap_or_else ( || package_name . clone ( ) ) ,
68+ . or_else ( || if is_default_target { self . default_target_config . label . clone ( ) } else { None } )
69+ . unwrap_or_else ( || target_name . clone ( ) ) ,
6570 package_icon : primary_config
6671 . and_then ( |a| a. icon . clone ( ) )
6772 . or_else ( || self . default_target_config . icon . clone ( ) ) ,
@@ -333,6 +338,7 @@ pub fn load(
333338
334339 // For the moment some fields of the config are dummies.
335340 Ok ( AndroidConfig {
341+ cargo_package_name : package. name ( ) . to_string ( ) ,
336342 manifest_path : package. manifest_path ( ) . to_owned ( ) ,
337343 sdk_path : Path :: new ( & sdk_path) . to_owned ( ) ,
338344 ndk_path : Path :: new ( & ndk_path) . to_owned ( ) ,
@@ -380,6 +386,7 @@ struct TomlMetadata {
380386}
381387
382388#[ derive( Debug , Clone , Deserialize ) ]
389+ #[ serde( deny_unknown_fields) ]
383390struct TomlAndroid {
384391 android_version : Option < u32 > ,
385392 target_sdk_version : Option < u32 > ,
@@ -394,20 +401,23 @@ struct TomlAndroid {
394401}
395402
396403#[ derive( Debug , Clone , Deserialize ) ]
404+ #[ serde( deny_unknown_fields) ]
397405struct TomlFeature {
398406 name : String ,
399407 required : Option < bool > ,
400408 version : Option < String > ,
401409}
402410
403411#[ derive( Debug , Clone , Deserialize ) ]
412+ #[ serde( deny_unknown_fields) ]
404413struct TomlPermission {
405414 name : String ,
406415 max_sdk_version : Option < u32 > ,
407416}
408417
409418/// Configuration specific to a single cargo target
410419#[ derive( Debug , Clone , Deserialize ) ]
420+ #[ serde( deny_unknown_fields) ]
411421struct TomlAndroidSpecificTarget {
412422 name : String ,
413423
0 commit comments