static bool ShouldProcess(ICompiledAssembly compiledAssembly)
        {
            if (!compiledAssembly.RequiresCodegen())
            {
                return(false);
            }

            var assemblyName = compiledAssembly.Name;

            if (assemblyName == CodeGenUtils.ExternalPropertyBagAssemblyName)
            {
                return(false);
            }

            // TODO: Debug type load exception and other assembly-specific issues
            if (k_IgnoredAssemblies.Contains(assemblyName))
            {
                return(false);
            }

            if (RuntimeSerializationSettingsUtils.GetAssemblyExceptions().Contains(assemblyName))
            {
                return(false);
            }

            if (CodeGenUtils.IsTestAssembly(compiledAssembly))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        static ILPostProcessResult GeneratePropertyBags(AssemblyDefinition compiledAssembly, string[] defines)
        {
            var context = new Context(compiledAssembly.MainModule, defines);

            // TODO: collection pools
            var fields     = new List <FieldInfo>();
            var properties = new List <PropertyInfo>();

#if UNITY_2020_2_OR_NEWER
            var editorAssemblyPath = Assembly.GetAssembly(typeof(EditorApplication)).Location;
            var editorPath         = editorAssemblyPath.Substring(0, editorAssemblyPath.Length - k_EditorAssemblyPathSuffix);
#else
            var editorPath = EditorApplication.applicationContentsPath;
#endif
            var serializableContainerTypes = new HashSet <Type>();
            var assemblyExceptions         = RuntimeSerializationSettingsUtils.GetAssemblyExceptions();
            var namespaceExceptions        = RuntimeSerializationSettingsUtils.GetNamespaceExceptions();
            var typeExceptions             = RuntimeSerializationSettingsUtils.GetTypeExceptions();
            ReflectionUtils.ForEachAssembly(assembly =>
            {
                Console.WriteLine($"Process assembly {assembly.FullName}");
                if (assembly.IsDynamic)
                {
                    return;
                }

                if (!CodeGenUtils.IsBuiltInAssembly(assembly, editorPath))
                {
                    return;
                }

                if (assemblyExceptions.Contains(assembly.FullName))
                {
                    return;
                }

                PostProcessAssembly(namespaceExceptions, typeExceptions, assembly, fields, properties, serializableContainerTypes);
            });

            serializableContainerTypes.ExceptWith(k_IgnoredTypes);

            if (serializableContainerTypes.Count == 0)
            {
                return(null);
            }

            GeneratePropertyBagsForSerializableTypes(context, serializableContainerTypes);

            return(CreatePostProcessResult(compiledAssembly));
        }
        public override void OnGUI(string searchContext)
        {
            base.OnGUI(searchContext);
            GUILayout.Label("AOT Code Generation Exceptions", EditorStyles.boldLabel);
            var assemblyExceptions  = RuntimeSerializationSettingsUtils.GetAssemblyExceptions();
            var namespaceExceptions = RuntimeSerializationSettingsUtils.GetNamespaceExceptions();
            var typeExceptions      = RuntimeSerializationSettingsUtils.GetTypeExceptions();

            DrawButtons(assemblyExceptions, "assemblies", m_ExcludeAllAssemblies, k_ClearExceptions);
            DrawButtons(namespaceExceptions, "namespaces", m_ExcludeAllNamespaces, k_ClearExceptions);
            DrawButtons(typeExceptions, "types", m_ExcludeAllTypes, k_ClearExceptions);

            foreach (var assemblyRow in m_AssemblyRows)
            {
                assemblyRow.Draw(assemblyExceptions, namespaceExceptions, typeExceptions);
            }
        }
        static ILPostProcessResult ProcessAssembly(AssemblyDefinition compiledAssembly)
        {
            var module         = compiledAssembly.MainModule;
            var componentTypes = new List <TypeContainer>();

#if UNITY_2020_2_OR_NEWER
            var editorAssemblyPath = Assembly.GetAssembly(typeof(EditorApplication)).Location;
            var editorPath         = editorAssemblyPath.Substring(0, editorAssemblyPath.Length - k_EditorAssemblyPathSuffix);
#else
            var editorPath = EditorApplication.applicationContentsPath;
#endif

            var assemblyExceptions  = RuntimeSerializationSettingsUtils.GetAssemblyExceptions();
            var namespaceExceptions = RuntimeSerializationSettingsUtils.GetNamespaceExceptions();
            var typeExceptions      = RuntimeSerializationSettingsUtils.GetTypeExceptions();
            ReflectionUtils.ForEachAssembly(assembly =>
            {
                if (assembly.IsDynamic)
                {
                    return;
                }

                if (!CodeGenUtils.IsBuiltInAssembly(assembly, editorPath) && !k_PlayerAssemblies.Contains(assembly.GetName().Name))
                {
                    return;
                }

                if (assemblyExceptions.Contains(assembly.FullName))
                {
                    return;
                }

                PostProcessAssembly(namespaceExceptions, typeExceptions, module, assembly, componentTypes);
            });

            PostProcessGenericMethodWrapper(componentTypes, module);

            return(CreatePostProcessResult(compiledAssembly));
        }