22
33using System ;
44using System . Collections . Generic ;
5- using System . Diagnostics ;
65using System . IO ;
76using System . IO . MemoryMappedFiles ;
87using System . Linq ;
98using System . Reflection ;
109using System . Text ;
1110using Microsoft . Build . Framework ;
12- using Microsoft . Build . Utilities ;
1311using Mono . Cecil ;
1412
1513
@@ -179,7 +177,7 @@ void RunDebugNoLinking ()
179177
180178 LogRunMode ( "Debug, no linking" ) ;
181179 XAAssemblyResolver resolver = MakeResolver ( useMarshalMethods : false ) ;
182- var assemblies = CollectInterestingAssemblies < RidAgnosticInputAssemblySet > ( ( AndroidTargetArch arch ) => resolver ) ;
180+ var assemblies = CollectInterestingAssemblies < RidAgnosticInputAssemblySet > ( allowAbiSpecific : false , ( AndroidTargetArch arch ) => resolver ) ;
183181 throw new NotImplementedException ( ) ;
184182 }
185183
@@ -191,7 +189,7 @@ void RunDebugWithLinking ()
191189
192190 LogRunMode ( "Debug, with linking" ) ;
193191 XAAssemblyResolver resolver = MakeResolver ( useMarshalMethods : false ) ;
194- var assemblies = CollectInterestingAssemblies < RidSpecificInputAssemblySet > ( ( AndroidTargetArch arch ) => resolver ) ;
192+ var assemblies = CollectInterestingAssemblies < RidSpecificInputAssemblySet > ( allowAbiSpecific : true , ( AndroidTargetArch arch ) => resolver ) ;
195193 throw new NotImplementedException ( ) ;
196194 }
197195
@@ -203,7 +201,7 @@ void RunReleaseNoLinking (bool useMarshalMethods)
203201
204202 LogRunMode ( "Release, no linking" ) ;
205203 XAAssemblyResolver resolver = MakeResolver ( useMarshalMethods ) ;
206- var assemblies = CollectInterestingAssemblies < RidAgnosticInputAssemblySet > ( ( AndroidTargetArch arch ) => resolver ) ;
204+ var assemblies = CollectInterestingAssemblies < RidAgnosticInputAssemblySet > ( allowAbiSpecific : false , ( AndroidTargetArch arch ) => resolver ) ;
207205 var state = new RunState {
208206 UseMarshalMethods = useMarshalMethods ,
209207 AssemblySet = assemblies ,
@@ -233,7 +231,7 @@ void RunReleaseWithLinking (bool useMarshalMethods)
233231 // We don't check whether we have a resolver for `arch` on purpose, if it throws then it means we have a bug which
234232 // should be fixed since there shouldn't be any assemblies passed to this task that belong in ABIs other than those
235233 // specified in `SupportedAbis`
236- var assemblies = CollectInterestingAssemblies < RidSpecificInputAssemblySet > ( ( AndroidTargetArch arch ) => resolvers [ arch ] ) ;
234+ var assemblies = CollectInterestingAssemblies < RidSpecificInputAssemblySet > ( allowAbiSpecific : true , ( AndroidTargetArch arch ) => resolvers [ arch ] ) ;
237235 bool first = true ;
238236
239237 foreach ( var kvp in resolvers ) {
@@ -265,7 +263,7 @@ void LogRunMode (string mode)
265263 Log . LogDebugMessage ( $ "GenerateJavaStubs mode: { mode } ") ;
266264 }
267265
268- T CollectInterestingAssemblies < T > ( Func < AndroidTargetArch , XAAssemblyResolver > getResolver ) where T : InputAssemblySet , new ( )
266+ T CollectInterestingAssemblies < T > ( bool allowAbiSpecific , Func < AndroidTargetArch , XAAssemblyResolver > getResolver ) where T : InputAssemblySet , new ( )
269267 {
270268 var assemblies = new T ( ) ;
271269 AndroidTargetArch targetArch ;
@@ -294,7 +292,7 @@ void LogRunMode (string mode)
294292 assemblies . AddJavaTypeAssembly ( assembly ) ;
295293 }
296294
297- targetArch = MonoAndroidHelper . GetTargetArch ( assembly ) ;
295+ targetArch = GetTargetArch ( assembly ) ;
298296 getResolver ( targetArch ) . Load ( targetArch , assembly . ItemSpec ) ;
299297 }
300298
@@ -305,13 +303,24 @@ void LogRunMode (string mode)
305303 continue ;
306304 }
307305
308- targetArch = MonoAndroidHelper . GetTargetArch ( assembly ) ;
306+ targetArch = GetTargetArch ( assembly ) ;
309307 getResolver ( targetArch ) . Load ( targetArch , assembly . ItemSpec ) ;
310308
311309 assemblies . AddJavaTypeAssembly ( assembly ) ;
312310 assemblies . AddUserAssembly ( assembly ) ;
313311 }
312+
314313 return assemblies ;
314+
315+ AndroidTargetArch GetTargetArch ( ITaskItem assembly )
316+ {
317+ AndroidTargetArch targetArch = MonoAndroidHelper . GetTargetArch ( assembly ) ;
318+ if ( ! allowAbiSpecific && targetArch != AndroidTargetArch . None ) {
319+ throw new InvalidOperationException ( $ "Internal error: ABI-specific assemblies are not allowed in this build configuration") ;
320+ }
321+
322+ return targetArch ;
323+ }
315324 }
316325
317326 void DoRun ( RunState state , out ApplicationConfigTaskState ? appConfState )
@@ -335,17 +344,17 @@ void DoRun (RunState state, out ApplicationConfigTaskState? appConfState)
335344 var scanner = new XAJavaTypeScanner ( Log , cache ) {
336345 ErrorOnCustomJavaObject = ErrorOnCustomJavaObject ,
337346 } ;
338- List < JavaType > allJavaTypes = scanner . GetJavaTypes ( state . JavaTypeAssemblies , state . Resolver ) ;
339- var javaTypes = new List < JavaType > ( ) ;
347+ ICollection < TypeDefinition > allJavaTypes = scanner . GetJavaTypes ( state . JavaTypeAssemblies , state . Resolver ) ;
348+ var javaTypes = new List < TypeDefinition > ( ) ;
340349
341- foreach ( JavaType jt in allJavaTypes ) {
350+ foreach ( TypeDefinition javaType in allJavaTypes ) {
342351 // Whem marshal methods are in use we do not want to skip non-user assemblies (such as Mono.Android) - we need to generate JCWs for them during
343352 // application build, unlike in Debug configuration or when marshal methods are disabled, in which case we use JCWs generated during Xamarin.Android
344353 // build and stored in a jar file.
345- if ( ( ! state . UseMarshalMethods && ! state . AssemblySet . IsUserAssembly ( jt . Type . Module . Assembly . Name . Name ) ) || JavaTypeScanner . ShouldSkipJavaCallableWrapperGeneration ( jt . Type , cache ) ) {
354+ if ( ( ! state . UseMarshalMethods && ! state . AssemblySet . IsUserAssembly ( javaType . Module . Assembly . Name . Name ) ) || JavaTypeScanner . ShouldSkipJavaCallableWrapperGeneration ( javaType , cache ) ) {
346355 continue ;
347356 }
348- javaTypes . Add ( jt ) ;
357+ javaTypes . Add ( javaType ) ;
349358 }
350359
351360 MarshalMethodsClassifier ? classifier = null ;
@@ -402,12 +411,11 @@ void DoRun (RunState state, out ApplicationConfigTaskState? appConfState)
402411 }
403412 }
404413
405- void CreateAdditionalJavaSources ( List < JavaType > javaTypes , TypeDefinitionCache cache , MarshalMethodsClassifier ? classifier )
414+ void CreateAdditionalJavaSources ( ICollection < TypeDefinition > javaTypes , TypeDefinitionCache cache , MarshalMethodsClassifier ? classifier )
406415 {
407416 StringWriter regCallsWriter = new StringWriter ( ) ;
408417 regCallsWriter . WriteLine ( "\t \t // Application and Instrumentation ACWs must be registered first." ) ;
409- foreach ( JavaType jt in javaTypes ) {
410- TypeDefinition type = jt . Type ;
418+ foreach ( TypeDefinition type in javaTypes ) {
411419 if ( JavaNativeTypeManager . IsApplication ( type , cache ) || JavaNativeTypeManager . IsInstrumentation ( type , cache ) ) {
412420 if ( classifier != null && ! classifier . FoundDynamicallyRegisteredMethods ( type ) ) {
413421 continue ;
@@ -426,7 +434,7 @@ void CreateAdditionalJavaSources (List<JavaType> javaTypes, TypeDefinitionCache
426434 template => template . Replace ( "// REGISTER_APPLICATION_AND_INSTRUMENTATION_CLASSES_HERE" , regCallsWriter . ToString ( ) ) ) ;
427435 }
428436
429- void UpdateAndroidManifest ( RunState state , TypeDefinitionCache cache , List < JavaType > allJavaTypes )
437+ void UpdateAndroidManifest ( RunState state , TypeDefinitionCache cache , ICollection < TypeDefinition > allJavaTypes )
430438 {
431439 var manifest = new ManifestDocument ( ManifestTemplate ) {
432440 PackageName = PackageName ,
@@ -468,7 +476,7 @@ void UpdateAndroidManifest (RunState state, TypeDefinitionCache cache, List<Java
468476 }
469477 }
470478
471- void WriteAcwMaps ( List < JavaType > javaTypes , TypeDefinitionCache cache )
479+ void WriteAcwMaps ( List < TypeDefinition > javaTypes , TypeDefinitionCache cache )
472480 {
473481 var writer = new AcwMapWriter ( Log , AcwMapFile ) ;
474482 writer . Write ( javaTypes , cache ) ;
@@ -504,7 +512,7 @@ AssemblyDefinition LoadAssembly (string path, XAAssemblyResolver? resolver = nul
504512 }
505513 }
506514
507- bool CreateJavaSources ( IEnumerable < JavaType > newJavaTypes , TypeDefinitionCache cache , MarshalMethodsClassifier classifier , bool useMarshalMethods )
515+ bool CreateJavaSources ( IEnumerable < TypeDefinition > newJavaTypes , TypeDefinitionCache cache , MarshalMethodsClassifier classifier , bool useMarshalMethods )
508516 {
509517 if ( useMarshalMethods && classifier == null ) {
510518 throw new ArgumentNullException ( nameof ( classifier ) ) ;
@@ -516,8 +524,7 @@ bool CreateJavaSources (IEnumerable<JavaType> newJavaTypes, TypeDefinitionCache
516524 bool generateOnCreateOverrides = int . Parse ( AndroidSdkPlatform ) <= 10 ;
517525
518526 bool ok = true ;
519- foreach ( JavaType jt in newJavaTypes ) {
520- TypeDefinition t = jt . Type ; // JCW generator doesn't care about ABI-specific types or token ids
527+ foreach ( TypeDefinition t in newJavaTypes ) {
521528 if ( t . IsInterface ) {
522529 // Interfaces are in typemap but they shouldn't have JCW generated for them
523530 continue ;
@@ -620,7 +627,7 @@ void SaveResource (string resource, string filename, string destDir, Func<string
620627 Files . CopyIfStringChanged ( template , Path . Combine ( destDir , filename ) ) ;
621628 }
622629
623- void WriteTypeMappings ( AndroidTargetArch targetArch , List < JavaType > types , TypeDefinitionCache cache , out ApplicationConfigTaskState appConfState )
630+ void WriteTypeMappings ( AndroidTargetArch targetArch , ICollection < TypeDefinition > types , TypeDefinitionCache cache , out ApplicationConfigTaskState appConfState )
624631 {
625632 Log . LogDebugMessage ( $ "Generating typemaps for arch { targetArch } , { types . Count } types") ;
626633 var tmg = new TypeMapGenerator ( targetArch , Log , SupportedAbis ) ;
0 commit comments