From 7db194909d4868dcf0ac7ee247770ae74617e091 Mon Sep 17 00:00:00 2001 From: hadashiA Date: Sat, 26 Aug 2023 13:55:27 +0900 Subject: [PATCH] Remove ILPostProcessor and mono-cecil --- .../Assets/VContainer/Editor/CodeGen.meta | 8 - .../Editor/CodeGen/InjectionILGenerator.cs | 438 ------------------ .../CodeGen/InjectionILGenerator.cs.meta | 3 - .../CodeGen/PostProcessorAssemblyResolver.cs | 132 ------ .../PostProcessorAssemblyResolver.cs.meta | 3 - .../PostProcessorReflectionImporter.cs | 36 -- .../PostProcessorReflectionImporter.cs.meta | 3 - .../CodeGen/Unity.VContainer.CodeGen.asmdef | 23 - .../Unity.VContainer.CodeGen.asmdef.meta | 7 - .../Assets/VContainer/Editor/CodeGen/Utils.cs | 73 --- .../VContainer/Editor/CodeGen/Utils.cs.meta | 3 - .../CodeGen/VContainerILPostProcessor.cs | 65 --- .../CodeGen/VContainerILPostProcessor.cs.meta | 3 - VContainer/Assets/VContainer/package.json | 5 +- VContainer/Packages/manifest.json | 8 +- VContainer/Packages/packages-lock.json | 39 +- VContainer/ProjectSettings/ProjectVersion.txt | 4 +- VContainer/ProjectSettings/boot.config | 0 18 files changed, 25 insertions(+), 828 deletions(-) delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen.meta delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/InjectionILGenerator.cs delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/InjectionILGenerator.cs.meta delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorAssemblyResolver.cs delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorAssemblyResolver.cs.meta delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorReflectionImporter.cs delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorReflectionImporter.cs.meta delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/Unity.VContainer.CodeGen.asmdef delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/Unity.VContainer.CodeGen.asmdef.meta delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/Utils.cs delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/Utils.cs.meta delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/VContainerILPostProcessor.cs delete mode 100644 VContainer/Assets/VContainer/Editor/CodeGen/VContainerILPostProcessor.cs.meta delete mode 100644 VContainer/ProjectSettings/boot.config diff --git a/VContainer/Assets/VContainer/Editor/CodeGen.meta b/VContainer/Assets/VContainer/Editor/CodeGen.meta deleted file mode 100644 index 399cd240..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 9982e0d73b2ff4d6393599c7f6e7284a -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/InjectionILGenerator.cs b/VContainer/Assets/VContainer/Editor/CodeGen/InjectionILGenerator.cs deleted file mode 100644 index e677e1fd..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/InjectionILGenerator.cs +++ /dev/null @@ -1,438 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using Mono.Cecil; -using Mono.Cecil.Cil; -using Mono.Cecil.Rocks; -using Unity.CompilationPipeline.Common.Diagnostics; -using Unity.CompilationPipeline.Common.ILPostProcessing; -using MethodAttributes = Mono.Cecil.MethodAttributes; -using TypeAttributes = Mono.Cecil.TypeAttributes; -using VContainer.Internal; - -namespace VContainer.Editor.CodeGen -{ - sealed class InjectionILGenerator - { - readonly ModuleDefinition module; - readonly ICompiledAssembly compiledAssembly; - readonly IList targetNamespaces; - - Assembly currentAssembly; - - TypeReference ObjectResolverTypeRef => - objectResolverTypeRef ?? (objectResolverTypeRef = module.ImportReference(typeof(IObjectResolver))); - - TypeReference InjectorTypeRef => - injectorTypeRef ?? - (injectorTypeRef = module.ImportReference(typeof(IInjector))); - - TypeReference InjectParameterListTypeRef => - injectParameterListTypeRef ?? - (injectParameterListTypeRef = module.ImportReference(typeof(IReadOnlyList))); - - MethodReference GetTypeFromHandleRef => - getTypeFromHandleRef ?? - (getTypeFromHandleRef = module.ImportReference(typeof(Type).GetMethod("GetTypeFromHandle"))); - - MethodReference BaseEmptyConstructorRef => - baseEmptyConstructorRef ?? - (baseEmptyConstructorRef = module.ImportReference(typeof(object).GetConstructor(Type.EmptyTypes))); - - MethodReference ResolveMethodRef => - resolveMethodRef ?? - (resolveMethodRef = - module.ImportReference(typeof(IObjectResolverExtensions).GetMethod("ResolveNonGeneric"))); - - MethodReference ResolveOrParameterMethodRef => - resolveOrParameterMethodRef ?? - (resolveOrParameterMethodRef = - module.ImportReference(typeof(IObjectResolverExtensions).GetMethod("ResolveOrParameter"))); - - TypeReference objectResolverTypeRef; - TypeReference injectorTypeRef; - TypeReference injectParameterListTypeRef; - MethodReference baseEmptyConstructorRef; - MethodReference getTypeFromHandleRef; - MethodReference resolveMethodRef; - MethodReference resolveOrParameterMethodRef; - - public InjectionILGenerator( - ModuleDefinition module, - ICompiledAssembly compiledAssembly, - IList targetNamespaces = null) - { - this.module = module; - this.compiledAssembly = compiledAssembly; - this.targetNamespaces = targetNamespaces; - } - - public bool TryGenerate(out List diagnosticMessages) - { - var count = 0; - var sw = new Stopwatch(); - sw.Start(); - - diagnosticMessages = new List(); - - foreach (var typeDef in module.Types) - { - if (typeDef.FullName == "") continue; - - try - { - if (TryGenerateType(typeDef, diagnosticMessages)) - { - count += 1; - } - } - catch (Exception ex) - { - diagnosticMessages.Add(new DiagnosticMessage - { - DiagnosticType = DiagnosticType.Error, - MessageData = $"VContainer failed pre code gen for {typeDef.FullName} : {ex} {ex.Message}\n{ex.StackTrace}" - }); - return false; - } - } - - sw.Stop(); - if (count > 0) - { - var assemblyName = module.Assembly.Name.Name; - var message = - $"VContainer code generation optimization for {assemblyName} {count} types ({sw.Elapsed.TotalMilliseconds}ms)"; -#if UNITY_2020_2_OR_NEWER - diagnosticMessages.Add(new DiagnosticMessage - { - DiagnosticType = DiagnosticType.Warning, - MessageData = message - }); -#else - UnityEngine.Debug.Log(message); -#endif - return true; - } - return false; - } - - bool NeedsInjectType(Type type) - => !type.IsEnum && - !type.IsValueType && - !type.IsInterface && - !(type.IsAbstract && type.IsSealed) && - !typeof(Delegate).IsAssignableFrom(type) && - !typeof(Attribute).IsAssignableFrom(type) && - !type.IsGenericType && - (targetNamespaces == null || - targetNamespaces.Count <= 0 || - targetNamespaces.Contains(type.Namespace)); - - Type GetTypeFromDef(TypeDefinition typeDef) - { - try - { - return Type.GetType($"{typeDef.FullName}, {module.Assembly.FullName}"); - } - catch (FileLoadException) - { - if (currentAssembly == null) - currentAssembly = Assembly.Load(compiledAssembly.InMemoryAssembly.PeData); - return currentAssembly.GetType(typeDef.FullName); - } - } - - bool TryGenerateType(TypeDefinition typeDef, List diagnosticMessages) - { - Type type; - try - { - type = GetTypeFromDef(typeDef); - } - catch (Exception ex) - { - diagnosticMessages.Add(new DiagnosticMessage - { - DiagnosticType = DiagnosticType.Warning, - MessageData = $"Skip IL waving because cannot detect type: {typeDef.FullName}. {ex} {ex.Message}" - }); - return false; - - } - if (type == null) - { - diagnosticMessages.Add(new DiagnosticMessage - { - DiagnosticType = DiagnosticType.Warning, - MessageData = $"Skip IL waving because cannot detect type: {typeDef.FullName}" - }); - return false; - } - - if (!NeedsInjectType(type)) - return false; - - InjectTypeInfo injectTypeInfo; - try - { - injectTypeInfo = TypeAnalyzer.Analyze(type); - } - catch (Exception ex) - { - diagnosticMessages.Add(new DiagnosticMessage - { - DiagnosticType = DiagnosticType.Warning, - MessageData = $"Failed to analyze {type.FullName} : {ex} {ex.Message}" - }); - return false; - } - - GenerateInnerInjectorType(typeDef, injectTypeInfo); - return true; - } - - void GenerateInnerInjectorType(TypeDefinition typeDef, InjectTypeInfo injectTypeInfo) - { - var injectorTypeDef = new TypeDefinition( - "", - "__GeneratedInjector", - TypeAttributes.NestedPrivate | TypeAttributes.Sealed, - module.TypeSystem.Object); - - var injectorImpl = new InterfaceImplementation(InjectorTypeRef); - injectorTypeDef.Interfaces.Add(injectorImpl); - - GenerateDefaultConstructor(injectorTypeDef); - GenerateInjectMethod(typeDef, injectorTypeDef, injectTypeInfo); - GenerateCreateInstanceMethod(typeDef, injectorTypeDef, injectTypeInfo); - GenerateInjectorGetterMethod(typeDef, injectorTypeDef); - - typeDef.NestedTypes.Add(injectorTypeDef); - } - - void GenerateDefaultConstructor(TypeDefinition typeDef) - { - var constructorDef = new MethodDefinition( - ".ctor", - MethodAttributes.Public | - MethodAttributes.HideBySig | - MethodAttributes.SpecialName | - MethodAttributes.RTSpecialName, - module.TypeSystem.Void); - - var processor = constructorDef.Body.GetILProcessor(); - // processor.Emit(OpCodes.Nop); - processor.Emit(OpCodes.Ldarg_0); - processor.Emit(OpCodes.Call, BaseEmptyConstructorRef); - processor.Emit(OpCodes.Ret); - - constructorDef.DeclaringType = typeDef; - - typeDef.Methods.Add(constructorDef); - } - - void GenerateCreateInstanceMethod( - TypeDefinition typeDef, - TypeDefinition injectorTypeDef, - InjectTypeInfo injectTypeInfo) - { - var methodDef = new MethodDefinition("CreateInstance", - MethodAttributes.Public | MethodAttributes.Virtual, - module.TypeSystem.Object); - - var injectMethodDef = injectorTypeDef.Methods.Single(x => x.Name == "Inject"); - - injectorTypeDef.Methods.Add(methodDef); - - methodDef.Parameters.Add(new ParameterDefinition(ObjectResolverTypeRef) - { - Name = "resolver" - }); - - methodDef.Parameters.Add(new ParameterDefinition(InjectParameterListTypeRef) - { - Name = "parameters" - }); - - var body = methodDef.Body; - var processor = body.GetILProcessor(); - - processor.Emit(OpCodes.Nop); - - if (injectTypeInfo.InjectConstructor == null || - injectTypeInfo.Type.IsSubclassOf(typeof(UnityEngine.Component))) - { - processor.Emit(OpCodes.Ldnull); - processor.Emit(OpCodes.Ret); - return; - } - - var resultVariableDef = new VariableDefinition(module.TypeSystem.Object); - body.Variables.Add(resultVariableDef); - - var constructorRef = module.ImportReference(injectTypeInfo.InjectConstructor.ConstructorInfo); - for (var i = 0; i < constructorRef.Parameters.Count; i++) - { - var paramDef = constructorRef.Parameters[i]; - var paramInfo = injectTypeInfo.InjectConstructor.ParameterInfos[i]; - var paramTypeRef = Utils.CreateParameterTypeReference(module, paramInfo.ParameterType, typeDef); - - var paramVariableDef = new VariableDefinition(paramTypeRef); - body.Variables.Add(paramVariableDef); - - // TODO: Add ExceptionHandler - // Call ResolveOrParameter(IObjectResolver, Type, string, IReadOnlyList) - processor.Emit(OpCodes.Ldarg_1); - processor.Emit(OpCodes.Ldtoken, paramTypeRef); - processor.Emit(OpCodes.Call, GetTypeFromHandleRef); - processor.Emit(OpCodes.Ldstr, paramInfo.Name); - processor.Emit(OpCodes.Ldarg_2); - processor.Emit(OpCodes.Call, ResolveOrParameterMethodRef); - processor.Emit(OpCodes.Unbox_Any, paramTypeRef); - processor.Emit(OpCodes.Stloc_S, paramVariableDef); - processor.Emit(OpCodes.Ldloc_S, paramVariableDef); - } - - processor.Emit(OpCodes.Newobj, constructorRef); - processor.Emit(OpCodes.Stloc_0); - - processor.Emit(OpCodes.Ldarg_0); - processor.Emit(OpCodes.Ldloc_0); - processor.Emit(OpCodes.Ldarg_1); - processor.Emit(OpCodes.Ldarg_2); - processor.Emit(OpCodes.Callvirt, injectMethodDef); - - processor.Emit(OpCodes.Ldloc_0); - processor.Emit(OpCodes.Ret); - } - - void GenerateInjectMethod(TypeDefinition typeDef, TypeDefinition injectorTypeDef, InjectTypeInfo injectTypeInfo) - { - var methodDef = new MethodDefinition("Inject", - MethodAttributes.Public | MethodAttributes.Virtual, - module.TypeSystem.Void); - injectorTypeDef.Methods.Add(methodDef); - - methodDef.Parameters.Add(new ParameterDefinition(module.TypeSystem.Object) - { - Name = "instance" - }); - - methodDef.Parameters.Add(new ParameterDefinition(ObjectResolverTypeRef) - { - Name = "resolver" - }); - - methodDef.Parameters.Add(new ParameterDefinition(InjectParameterListTypeRef) - { - Name = "parameters" - }); - - var body = methodDef.Body; - var processor = body.GetILProcessor(); - - processor.Emit(OpCodes.Nop); - - var instanceVariableDef = new VariableDefinition(typeDef); - body.Variables.Add(instanceVariableDef); - - if (injectTypeInfo.InjectMethods != null || - injectTypeInfo.InjectFields != null || - injectTypeInfo.InjectProperties != null) - { - processor.Emit(OpCodes.Ldarg_1); - processor.Emit(OpCodes.Unbox_Any, typeDef); - processor.Emit(OpCodes.Stloc_S, instanceVariableDef); - } - - if (injectTypeInfo.InjectFields != null) - { - foreach (var injectField in injectTypeInfo.InjectFields) - { - var fieldRef = module.ImportReference(injectField); - var fieldTypeRef = Utils.CreateParameterTypeReference(module, injectField.FieldType, typeDef); - - processor.Emit(OpCodes.Ldloc_S, instanceVariableDef); - - // TODO: Add ExceptionHandler - // instance.Field = resolver.Resolve(Type) - processor.Emit(OpCodes.Ldarg_2); - processor.Emit(OpCodes.Ldtoken, fieldTypeRef); - processor.Emit(OpCodes.Call, GetTypeFromHandleRef); - processor.Emit(OpCodes.Call, ResolveMethodRef); - processor.Emit(OpCodes.Stfld, fieldRef); - } - } - - if (injectTypeInfo.InjectProperties != null) - { - foreach (var injectProperty in injectTypeInfo.InjectProperties) - { - var propertySetterRef = module.ImportReference(injectProperty.SetMethod); - var propertyTypeRef = Utils.CreateParameterTypeReference(module, injectProperty.PropertyType, typeDef); - - processor.Emit(OpCodes.Ldloc_S, instanceVariableDef); - - // TODO: Add ExceptionHandler - // instance.Property = resolver.Resolve(Type) - processor.Emit(OpCodes.Ldarg_2); - processor.Emit(OpCodes.Ldtoken, propertyTypeRef); - processor.Emit(OpCodes.Call, GetTypeFromHandleRef); - processor.Emit(OpCodes.Call, ResolveMethodRef); - processor.Emit(OpCodes.Callvirt, propertySetterRef); - } - } - - if (injectTypeInfo.InjectMethods != null) - { - foreach (var injectMethod in injectTypeInfo.InjectMethods) - { - var injectMethodRef = module.ImportReference(injectMethod.MethodInfo); - processor.Emit(OpCodes.Ldloc_S, instanceVariableDef); - for (var i = 0; i < injectMethodRef.Parameters.Count; i++) - { - var paramDef = injectMethodRef.Parameters[i]; - var paramInfo = injectMethod.ParameterInfos[i]; - var paramTypeRef = Utils.CreateParameterTypeReference(module, paramInfo.ParameterType, typeDef); - - var paramVariableDef = new VariableDefinition(paramDef.ParameterType); - body.Variables.Add(paramVariableDef); - - // TODO: Add ExceptionHandler - processor.Emit(OpCodes.Ldarg_2); - processor.Emit(OpCodes.Ldtoken, paramTypeRef); - processor.Emit(OpCodes.Call, GetTypeFromHandleRef); - processor.Emit(OpCodes.Ldstr, paramInfo.Name); - processor.Emit(OpCodes.Ldarg_3); - processor.Emit(OpCodes.Call, ResolveOrParameterMethodRef); - processor.Emit(OpCodes.Unbox_Any, paramTypeRef); - processor.Emit(OpCodes.Stloc_S, paramVariableDef); - processor.Emit(OpCodes.Ldloc_S, paramVariableDef); - } - processor.Emit(OpCodes.Callvirt, injectMethodRef); - } - } - - processor.Emit(OpCodes.Ret); - } - - void GenerateInjectorGetterMethod(TypeDefinition typeDef, TypeDefinition injectorTypeDef) - { - var constructorDef = injectorTypeDef.GetConstructors().First(); - var injectorGetterDef = new MethodDefinition( - "__GetGeneratedInjector", - MethodAttributes.Static | MethodAttributes.Public | MethodAttributes.HideBySig, - InjectorTypeRef); - - var processor = injectorGetterDef.Body.GetILProcessor(); - processor.Emit(OpCodes.Nop); - processor.Emit(OpCodes.Newobj, constructorDef); - processor.Emit(OpCodes.Ret); - typeDef.Methods.Add(injectorGetterDef); - } - } -} \ No newline at end of file diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/InjectionILGenerator.cs.meta b/VContainer/Assets/VContainer/Editor/CodeGen/InjectionILGenerator.cs.meta deleted file mode 100644 index 22564efd..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/InjectionILGenerator.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d738be7d7f374681961bf8db47db12b8 -timeCreated: 1594289306 \ No newline at end of file diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorAssemblyResolver.cs b/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorAssemblyResolver.cs deleted file mode 100644 index af6aa64c..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorAssemblyResolver.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Threading; -using Mono.Cecil; -using Unity.CompilationPipeline.Common.ILPostProcessing; - -namespace VContainer.Editor.CodeGen -{ - sealed class PostProcessorAssemblyResolver : IAssemblyResolver - { - readonly string[] references; - readonly IDictionary cache = new Dictionary(); - - readonly ICompiledAssembly compiledAssembly; - AssemblyDefinition selfAssembly; - - public PostProcessorAssemblyResolver(ICompiledAssembly compiledAssembly) - { - this.compiledAssembly = compiledAssembly; - references = compiledAssembly.References; - } - - public void Dispose() - { - } - - public AssemblyDefinition Resolve(AssemblyNameReference name) - { - return Resolve(name, new ReaderParameters(ReadingMode.Deferred)); - } - - public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) - { - lock (cache) - { - if (name.Name == compiledAssembly.Name) - return selfAssembly; - - var fileName = FindFile(name); - if (fileName == null) - return null; - - var lastWriteTime = File.GetLastWriteTime(fileName); - - var cacheKey = fileName + lastWriteTime.ToString(CultureInfo.InvariantCulture); - - if (cache.TryGetValue(cacheKey, out var result)) - return result; - - parameters.AssemblyResolver = this; - - var ms = MemoryStreamFor(fileName); - - var pdb = fileName + ".pdb"; - if (File.Exists(pdb)) - parameters.SymbolStream = MemoryStreamFor(pdb); - - var assemblyDefinition = AssemblyDefinition.ReadAssembly(ms, parameters); - cache.Add(cacheKey, assemblyDefinition); - return assemblyDefinition; - } - } - - string FindFile(AssemblyNameReference name) - { - var fileName = references.FirstOrDefault(r => Path.GetFileName(r) == name.Name + ".dll"); - if (fileName != null) - return fileName; - - // perhaps the type comes from an exe instead - fileName = references.FirstOrDefault(r => Path.GetFileName(r) == name.Name + ".exe"); - if (fileName != null) - return fileName; - - //Unfortunately the current ICompiledAssembly API only provides direct references. - //It is very much possible that a postprocessor ends up investigating a type in a directly - //referenced assembly, that contains a field that is not in a directly referenced assembly. - //if we don't do anything special for that situation, it will fail to resolve. We should fix this - //in the ILPostProcessing api. As a workaround, we rely on the fact here that the indirect references - //are always located next to direct references, so we search in all directories of direct references we - //got passed, and if we find the file in there, we resolve to it. - foreach (var parentDir in references.Select(Path.GetDirectoryName).Distinct()) - { - var candidate = Path.Combine(parentDir, name.Name + ".dll"); - if (File.Exists(candidate)) - return candidate; - } - - return null; - } - - static MemoryStream MemoryStreamFor(string fileName) - { - return Retry(10, TimeSpan.FromSeconds(1), () => { - byte[] byteArray; - using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) - { - byteArray = new byte[fs.Length]; - var readLength = fs.Read(byteArray, 0, (int)fs.Length); - if (readLength != fs.Length) - throw new InvalidOperationException("File read length is not full length of file."); - } - - return new MemoryStream(byteArray); - }); - } - - static MemoryStream Retry(int retryCount, TimeSpan waitTime, Func func) - { - try - { - return func(); - } - catch (IOException) - { - if (retryCount == 0) - throw; - Console.WriteLine($"Caught IO Exception, trying {retryCount} more times"); - Thread.Sleep(waitTime); - return Retry(retryCount - 1, waitTime, func); - } - } - - public void AddAssemblyDefinitionBeingOperatedOn(AssemblyDefinition assemblyDefinition) - { - selfAssembly = assemblyDefinition; - } - } -} \ No newline at end of file diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorAssemblyResolver.cs.meta b/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorAssemblyResolver.cs.meta deleted file mode 100644 index 080c6fa5..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorAssemblyResolver.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 604706cf8c28420fbe06179a681ae5ed -timeCreated: 1595520710 \ No newline at end of file diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorReflectionImporter.cs b/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorReflectionImporter.cs deleted file mode 100644 index cb785820..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorReflectionImporter.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Linq; -using System.Reflection; -using Mono.Cecil; - -namespace VContainer.Editor.CodeGen -{ - class PostProcessorReflectionImporterProvider : IReflectionImporterProvider - { - public IReflectionImporter GetReflectionImporter(ModuleDefinition module) - { - return new PostProcessorReflectionImporter(module); - } - } - - class PostProcessorReflectionImporter : DefaultReflectionImporter - { - const string SystemPrivateCoreLib = "System.Private.CoreLib"; - readonly AssemblyNameReference correctCorlib; - - public PostProcessorReflectionImporter(ModuleDefinition module) : base(module) - { - correctCorlib = module.AssemblyReferences.FirstOrDefault(a => - { - return a.Name == "mscorlib" || a.Name == "netstandard" || a.Name == SystemPrivateCoreLib; - }); - } - - public override AssemblyNameReference ImportReference(AssemblyName reference) - { - if (correctCorlib != null && reference.Name == SystemPrivateCoreLib) - return correctCorlib; - - return base.ImportReference(reference); - } - } -} \ No newline at end of file diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorReflectionImporter.cs.meta b/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorReflectionImporter.cs.meta deleted file mode 100644 index 1624e9e1..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/PostProcessorReflectionImporter.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e15e3e9af9314c32baefd60fc15dc1c9 -timeCreated: 1595521100 \ No newline at end of file diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/Unity.VContainer.CodeGen.asmdef b/VContainer/Assets/VContainer/Editor/CodeGen/Unity.VContainer.CodeGen.asmdef deleted file mode 100644 index d1cc861e..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/Unity.VContainer.CodeGen.asmdef +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "Unity.VContainer.CodeGen", - "rootNamespace": "", - "references": [ - "VContainer" - ], - "includePlatforms": [ - "Editor" - ], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": true, - "precompiledReferences": [ - "Mono.Cecil.dll", - "Mono.Cecil.Mdb.dll", - "Mono.Cecil.Pdb.dll", - "Mono.Cecil.Rocks.dll" - ], - "autoReferenced": false, - "defineConstraints": [], - "versionDefines": [], - "noEngineReferences": false -} diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/Unity.VContainer.CodeGen.asmdef.meta b/VContainer/Assets/VContainer/Editor/CodeGen/Unity.VContainer.CodeGen.asmdef.meta deleted file mode 100644 index eae0f7b9..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/Unity.VContainer.CodeGen.asmdef.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 785872fffe145415dab38c4e07086c55 -AssemblyDefinitionImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/Utils.cs b/VContainer/Assets/VContainer/Editor/CodeGen/Utils.cs deleted file mode 100644 index a6fc7134..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/Utils.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using Mono.Cecil; -using Mono.Cecil.Cil; -using Unity.CompilationPipeline.Common.ILPostProcessing; - -namespace VContainer.Editor.CodeGen -{ - static class Utils - { - public static AssemblyDefinition LoadAssemblyDefinition(ICompiledAssembly compiledAssembly) - { - var resolver = new PostProcessorAssemblyResolver(compiledAssembly); - var readerParameters = new ReaderParameters - { - SymbolStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PdbData.ToArray()), - SymbolReaderProvider = new PortablePdbReaderProvider(), - AssemblyResolver = resolver, - ReflectionImporterProvider = new PostProcessorReflectionImporterProvider(), - ReadingMode = ReadingMode.Immediate - }; - - var peStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PeData.ToArray()); - var assemblyDefinition = AssemblyDefinition.ReadAssembly(peStream, readerParameters); - - //apparently, it will happen that when we ask to resolve a type that lives inside Unity.Entities, and we - //are also postprocessing Unity.Entities, type resolving will fail, because we do not actually try to resolve - //inside the assembly we are processing. Let's make sure we do that, so that we can use postprocessor features inside - //unity.entities itself as well. - resolver.AddAssemblyDefinitionBeingOperatedOn(assemblyDefinition); - - return assemblyDefinition; - } - - public static TypeReference CreateParameterTypeReference( - ModuleDefinition module, - Type parameterType, - TypeReference typeRef) - { - if (!parameterType.ContainsGenericParameters) - { - return module.ImportReference(parameterType); - } - - if (parameterType.IsGenericParameter) - { - return typeRef.GenericParameters[parameterType.GenericParameterPosition]; - } - - if (parameterType.IsArray) - { - return new ArrayType( - CreateParameterTypeReference( - module, - parameterType.GetElementType(), - typeRef), - parameterType.GetArrayRank()); - } - - var openGenericType = parameterType.GetGenericTypeDefinition(); - var genericInstance = new GenericInstanceType(module.ImportReference(openGenericType)); - - foreach (var arg in parameterType.GenericTypeArguments) - { - genericInstance.GenericArguments.Add( - CreateParameterTypeReference(module, arg, typeRef)); - } - - return genericInstance; - } - } -} diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/Utils.cs.meta b/VContainer/Assets/VContainer/Editor/CodeGen/Utils.cs.meta deleted file mode 100644 index e55bb8eb..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/Utils.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: f255c8d2a0334092ae4e69870ee92db7 -timeCreated: 1595519996 \ No newline at end of file diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/VContainerILPostProcessor.cs b/VContainer/Assets/VContainer/Editor/CodeGen/VContainerILPostProcessor.cs deleted file mode 100644 index 2477d59b..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/VContainerILPostProcessor.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.IO; -using System.Linq; -using System.Reflection; -using Unity.CompilationPipeline.Common.Diagnostics; -using Unity.CompilationPipeline.Common.ILPostProcessing; -using Mono.Cecil; -using Mono.Cecil.Cil; - -namespace VContainer.Editor.CodeGen -{ - public sealed class VContainerILPostProcessor : ILPostProcessor - { - public override ILPostProcessor GetInstance() => this; - - public override bool WillProcess(ICompiledAssembly compiledAssembly) - { - var referenceDlls = compiledAssembly.References - .Select(Path.GetFileNameWithoutExtension); - - return referenceDlls.Any(x => x == "VContainer") && - referenceDlls.Any(x => x == "VContainer.EnableCodeGen"); - } - - public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly) - { - if (!WillProcess(compiledAssembly)) - return null; - - var assemblyDefinition = Utils.LoadAssemblyDefinition(compiledAssembly); - var generator = new InjectionILGenerator(assemblyDefinition.MainModule, compiledAssembly, null); - - if (generator.TryGenerate(out var diagnosticMessages)) - { - if (diagnosticMessages.Any(d => d.DiagnosticType == DiagnosticType.Error)) - { - return new ILPostProcessResult(null, diagnosticMessages); - } - - // TODO: - var (selfReference, selfReferenceIndex) = assemblyDefinition.MainModule.AssemblyReferences - .Select((x, i) => (x, i)) - .FirstOrDefault(e => e.x.Name == assemblyDefinition.Name.Name); - - if (selfReference != null) - { - assemblyDefinition.MainModule.AssemblyReferences.RemoveAt(selfReferenceIndex); - } - - var pe = new MemoryStream(); - var pdb = new MemoryStream(); - var writerParameters = new WriterParameters - { - SymbolWriterProvider = new PortablePdbWriterProvider(), - SymbolStream = pdb, - WriteSymbols = true - }; - - assemblyDefinition.Write(pe, writerParameters); - - return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), diagnosticMessages); - } - return new ILPostProcessResult(null, diagnosticMessages); - } - } -} diff --git a/VContainer/Assets/VContainer/Editor/CodeGen/VContainerILPostProcessor.cs.meta b/VContainer/Assets/VContainer/Editor/CodeGen/VContainerILPostProcessor.cs.meta deleted file mode 100644 index 8866cf2d..00000000 --- a/VContainer/Assets/VContainer/Editor/CodeGen/VContainerILPostProcessor.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a0d34cf082a74718aa2f69f99d21162f -timeCreated: 1595486082 \ No newline at end of file diff --git a/VContainer/Assets/VContainer/package.json b/VContainer/Assets/VContainer/package.json index f51e0d54..4f473dff 100644 --- a/VContainer/Assets/VContainer/package.json +++ b/VContainer/Assets/VContainer/package.json @@ -8,9 +8,6 @@ "license": "MIT", "documentationUrl": "https://vcontainer.hadashikick.jp/", "changelogUrl": "https://github.com/hadashiA/VContainer/releases", - "licensesUrl": "https://github.com/hadashiA/VContainer/blob/master/LICENSE", - "dependencies": { - "com.unity.nuget.mono-cecil": "1.10.1" - } + "licensesUrl": "https://github.com/hadashiA/VContainer/blob/master/LICENSE" } diff --git a/VContainer/Packages/manifest.json b/VContainer/Packages/manifest.json index cbcd0766..2085d724 100644 --- a/VContainer/Packages/manifest.json +++ b/VContainer/Packages/manifest.json @@ -1,10 +1,10 @@ { "dependencies": { "com.cysharp.runtimeunittesttoolkit": "https://github.com/Cysharp/RuntimeUnitTestToolkit.git?path=RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit", - "com.unity.ide.rider": "3.0.16", - "com.unity.ide.visualstudio": "2.0.16", - "com.unity.nuget.mono-cecil": "1.10.1", - "com.unity.test-framework": "1.1.31", + "com.unity.ai.navigation": "1.1.4", + "com.unity.ide.rider": "3.0.24", + "com.unity.ide.visualstudio": "2.0.18", + "com.unity.test-framework": "1.1.33", "com.unity.ugui": "1.0.0", "com.unity.modules.animation": "1.0.0", "com.unity.modules.assetbundle": "1.0.0", diff --git a/VContainer/Packages/packages-lock.json b/VContainer/Packages/packages-lock.json index 608f5575..606aaa0a 100644 --- a/VContainer/Packages/packages-lock.json +++ b/VContainer/Packages/packages-lock.json @@ -7,6 +7,15 @@ "dependencies": {}, "hash": "1a9d2bee8d37f8e5317b7efe91e70c977c679fd6" }, + "com.unity.ai.navigation": { + "version": "1.1.4", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.modules.ai": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.ext.nunit": { "version": "1.0.6", "depth": 1, @@ -15,7 +24,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "3.0.16", + "version": "3.0.24", "depth": 0, "source": "registry", "dependencies": { @@ -24,7 +33,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.16", + "version": "2.0.18", "depth": 0, "source": "registry", "dependencies": { @@ -32,15 +41,8 @@ }, "url": "https://packages.unity.com" }, - "com.unity.nuget.mono-cecil": { - "version": "1.10.1", - "depth": 0, - "source": "registry", - "dependencies": {}, - "url": "https://packages.unity.com" - }, "com.unity.test-framework": { - "version": "1.1.31", + "version": "1.1.33", "depth": 0, "source": "registry", "dependencies": { @@ -59,6 +61,12 @@ "com.unity.modules.imgui": "1.0.0" } }, + "com.unity.modules.ai": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": {} + }, "com.unity.modules.animation": { "version": "1.0.0", "depth": 0, @@ -123,17 +131,6 @@ "version": "1.0.0", "depth": 0, "source": "builtin", - "dependencies": { - "com.unity.modules.ui": "1.0.0", - "com.unity.modules.imgui": "1.0.0", - "com.unity.modules.jsonserialize": "1.0.0", - "com.unity.modules.uielementsnative": "1.0.0" - } - }, - "com.unity.modules.uielementsnative": { - "version": "1.0.0", - "depth": 1, - "source": "builtin", "dependencies": { "com.unity.modules.ui": "1.0.0", "com.unity.modules.imgui": "1.0.0", diff --git a/VContainer/ProjectSettings/ProjectVersion.txt b/VContainer/ProjectSettings/ProjectVersion.txt index 6a95707e..0a60761e 100644 --- a/VContainer/ProjectSettings/ProjectVersion.txt +++ b/VContainer/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.3.14f1 -m_EditorVersionWithRevision: 2021.3.14f1 (eee1884e7226) +m_EditorVersion: 2022.3.5f1 +m_EditorVersionWithRevision: 2022.3.5f1 (9674261d40ee) diff --git a/VContainer/ProjectSettings/boot.config b/VContainer/ProjectSettings/boot.config deleted file mode 100644 index e69de29b..00000000