public override bool RunTask()
        {
            if (SourceFiles.Length != DestinationFiles.Length)
            {
                throw new ArgumentException("source and destination count mismatch");
            }

            var readerParameters = new ReaderParameters {
                ReadSymbols = true,
            };
            var writerParameters = new WriterParameters {
                DeterministicMvid = Deterministic,
            };

            using (var resolver = new DirectoryAssemblyResolver(this.CreateTaskLogger(), loadDebugSymbols: true, loadReaderParameters: readerParameters)) {
                // Add SearchDirectories with ResolvedAssemblies
                foreach (var assembly in ResolvedAssemblies)
                {
                    var path = Path.GetFullPath(Path.GetDirectoryName(assembly.ItemSpec));
                    if (!resolver.SearchDirectories.Contains(path))
                    {
                        resolver.SearchDirectories.Add(path);
                    }
                }

                // Run the FixAbstractMethodsStep
                var step = new FixAbstractMethodsStep(resolver, new TypeDefinitionCache(), Log);
                for (int i = 0; i < SourceFiles.Length; i++)
                {
                    var source      = SourceFiles [i];
                    var destination = DestinationFiles [i];
                    AssemblyDefinition assemblyDefinition = null;

                    if (!MTProfile.IsSdkAssembly(source.ItemSpec) && !MTProfile.IsProductAssembly(source.ItemSpec))
                    {
                        assemblyDefinition = resolver.GetAssembly(source.ItemSpec);
                        step.CheckAppDomainUsage(assemblyDefinition, (string msg) => Log.LogMessageFromText(msg, MessageImportance.High));
                    }

                    // Only run the step on "MonoAndroid" assemblies
                    if (MonoAndroidHelper.IsMonoAndroidAssembly(source) && !MonoAndroidHelper.IsSharedRuntimeAssembly(source.ItemSpec))
                    {
                        if (assemblyDefinition == null)
                        {
                            assemblyDefinition = resolver.GetAssembly(source.ItemSpec);
                        }

                        if (step.FixAbstractMethods(assemblyDefinition))
                        {
                            Log.LogDebugMessage($"Saving modified assembly: {destination.ItemSpec}");
                            writerParameters.WriteSymbols = assemblyDefinition.MainModule.HasSymbols;
                            assemblyDefinition.Write(destination.ItemSpec, writerParameters);
                            continue;
                        }
                    }

                    if (MonoAndroidHelper.CopyAssemblyAndSymbols(source.ItemSpec, destination.ItemSpec))
                    {
                        Log.LogDebugMessage($"Copied: {destination.ItemSpec}");
                    }
                    else
                    {
                        Log.LogDebugMessage($"Skipped unchanged file: {destination.ItemSpec}");

                        // NOTE: We still need to update the timestamp on this file, or this target would run again
                        File.SetLastWriteTimeUtc(destination.ItemSpec, DateTime.UtcNow);
                    }
                }
            }

            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 2
0
        List <string> GetFilesToAOT(IFileEnumerator files)
        {
            // Make a dictionary of included/excluded files to track if we've missed some at the end
            Dictionary <string, bool> includedAssemblies = new Dictionary <string, bool> ();

            foreach (var item in options.IncludedAssemblies)
            {
                includedAssemblies [item] = false;
            }

            Dictionary <string, bool> excludedAssemblies = new Dictionary <string, bool> ();

            foreach (var item in options.ExcludedAssemblies)
            {
                excludedAssemblies [item] = false;
            }

            var aotFiles = new List <string> ();

            foreach (var file in files.Files)
            {
                string fileName  = Path.GetFileName(file);
                string extension = Path.GetExtension(file);
                if (extension != ".exe" && extension != ".dll")
                {
                    continue;
                }

                if (excludedAssemblies.ContainsKey(fileName))
                {
                    excludedAssemblies [fileName] = true;
                    continue;
                }

                if (includedAssemblies.ContainsKey(fileName))
                {
                    includedAssemblies [fileName] = true;
                    aotFiles.Add(file);
                    continue;
                }

                switch (options.CompilationType)
                {
                case AOTCompilationType.All:
                    aotFiles.Add(file);
                    break;

                case AOTCompilationType.SDK:
                    string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName);
                    if (Profile.IsSdkAssembly(fileNameNoExtension) || fileName == "Xamarin.Mac.dll")
                    {
                        aotFiles.Add(file);
                    }
                    break;

                case AOTCompilationType.Core:
                    if (fileName == "Xamarin.Mac.dll" || fileName == "System.dll" || fileName == "mscorlib.dll")
                    {
                        aotFiles.Add(file);
                    }
                    break;

                case AOTCompilationType.Explicit:
                    break;                     // In explicit, only included includedAssemblies included

                default:
                    throw ErrorHelper.CreateError(0099, "Internal error \"GetFilesToAOT with aot: {0}\" Please file a bug report with a test case (https://github.com/xamarin/xamarin-macios/issues/new).", options.CompilationType);
                }
            }

            var unusedIncludes = includedAssemblies.Where(pair => !pair.Value).Select(pair => pair.Key).ToList();

            if (unusedIncludes.Count > 0)
            {
                throw ErrorHelper.CreateError(3009, "AOT of '{0}' was requested but was not found", String.Join(" ", unusedIncludes));
            }

            var unusedExcludes = excludedAssemblies.Where(pair => !pair.Value).Select(pair => pair.Key).ToList();

            if (unusedExcludes.Count > 0)
            {
                throw ErrorHelper.CreateError(3010, "Exclusion of AOT of '{0}' was requested but was not found", String.Join(" ", unusedExcludes));
            }

            return(aotFiles);
        }
Exemplo n.º 3
0
        List <string> GetFilesToAOT(IFileEnumerator files)
        {
            var aotFiles = new List <string> ();

            foreach (var file in files.Files)
            {
                string fileName  = Path.GetFileName(file);
                string extension = Path.GetExtension(file);
                if (extension != ".exe" && extension != ".dll")
                {
                    continue;
                }

                if (excludedAssemblies.ContainsKey(fileName))
                {
                    excludedAssemblies[fileName] = true;
                    continue;
                }

                if (includedAssemblies.ContainsKey(fileName))
                {
                    includedAssemblies[fileName] = true;
                    aotFiles.Add(file);
                    continue;
                }

                switch (aotType)
                {
                case AotType.All:
                    aotFiles.Add(file);
                    break;

                case AotType.SDK:
                    string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName);
                    if (Profile.IsSdkAssembly(fileNameNoExtension) || fileName == "Xamarin.Mac.dll")
                    {
                        aotFiles.Add(file);
                    }
                    break;

                case AotType.Core:
                    if (fileName == "Xamarin.Mac.dll" || fileName == "System.dll" || fileName == "mscorlib.dll")
                    {
                        aotFiles.Add(file);
                    }
                    break;

                case AotType.Explicit:
                    break;                     // In explicit, only included includedAssemblies included

                default:
                    throw ErrorHelper.CreateError(0099, "Internal error \"GetFilesToAOT with aot: {0}\" Please file a bug report with a test case (http://bugzilla.xamarin.com).", aotType);
                }
            }

            var unusedIncludes = includedAssemblies.Where(pair => !pair.Value).Select(pair => pair.Key).ToList();

            if (unusedIncludes.Count > 0)
            {
                throw ErrorHelper.CreateError(3009, "AOT of '{0}' was requested but was not found", String.Join(" ", unusedIncludes));
            }

            var unusedExcludes = excludedAssemblies.Where(pair => !pair.Value).Select(pair => pair.Key).ToList();

            if (unusedExcludes.Count > 0)
            {
                throw ErrorHelper.CreateError(3010, "Exclusion of AOT of '{0}' was requested but was not found", String.Join(" ", unusedExcludes));
            }

            return(aotFiles);
        }