public static CSharpCompiler GetCSharpCompiler(BuildTarget targetPlatform, bool buildingForEditor, ScriptAssembly scriptAssembly) { var target = ModuleManager.GetTargetStringFromBuildTarget(targetPlatform); var extension = ModuleManager.GetCompilationExtension(target); return(extension.GetCsCompiler(buildingForEditor, scriptAssembly)); }
public virtual CSharpCompiler GetCsCompiler(bool buildingForEditor, ScriptAssembly scriptAssemly) { if (EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest) { return(CSharpCompiler.Microsoft); } return(CSharpCompiler.Mono); }
/// <summary> /// Lisää uuden assemblyn containeriin. /// </summary> /// <param name="scriptAssembly"></param> public void AddAssembly(ScriptAssembly scriptAssembly) { if (!ContainsAssembly(a => a.FullName == scriptAssembly.FullName)) { scriptAssembly.AssemblyLifeTime = PreferedLifeTime; assemblies.Add(scriptAssembly); } }
public ILPostProcessCompiledAssembly(ScriptAssembly scriptAssembly, string outputPath) { m_AssemblyFilename = scriptAssembly.Filename; Name = Path.GetFileNameWithoutExtension(m_AssemblyFilename); References = scriptAssembly.GetAllReferences(); m_OutputPath = outputPath; }
public ILPostProcessCompiledAssembly(ScriptAssembly scriptAssembly, string outputPath, FindReferences findReferences) { m_ScriptAssembly = scriptAssembly; Name = Path.GetFileNameWithoutExtension(scriptAssembly.Filename); References = scriptAssembly.GetAllReferences().Select(Path.GetFileName).ToArray(); m_OutputPath = outputPath; m_FindReferences = findReferences; }
internal static ScriptCompilerBase CreateCompilerInstance(ScriptAssembly scriptAssembly, EditorScriptCompilationOptions options, string tempOutputDirectory) { if (scriptAssembly.Files.Length == 0) { throw new ArgumentException("Cannot compile ScriptAssembly with no files"); } return(CSharpSupportedLanguage.CreateCompiler(scriptAssembly, options, tempOutputDirectory)); }
/// <summary> /// Luo uuden ScriptAssembly olion Assemblyn ja ResolverAtributes /// oliojen perusteella. /// </summary> private ScriptAssembly MakeScriptAssembly(Assembly assembly, ResolverWorkItem resolverWorkItem) { ScriptAssembly scriptAssembly = new ScriptAssembly(assembly, resolverWorkItem.ScriptBuilder.ScriptName, resolverWorkItem.FullName); scriptAssemblyContainer.AddAssembly(scriptAssembly); return(scriptAssembly); }
public HandleScriptDomain(ScriptEngines scriptDomain, string baseDirectory) : base(scriptDomain, baseDirectory) { if (ScriptEngines.IsDebug) { var scriptAssemblyName = ScriptEngines.Conf.GetString(DebugScriptAssemblyProperty, DefaultScriptAssembly); var scriptAssemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, scriptAssemblyName); debugScriptAssembly = new DllScriptAssembly(this, scriptAssemblyPath); } }
internal ScriptType(TypeDefinition typeDef, ScriptAssembly scriptAssembly, params ScriptType[] genericTypes) : this(typeDef, scriptAssembly) { _baseType = _typeDef.Interfaces.Any(_ => _.Name == "IAsyncStateMachine") ? ScriptContext.GetType(typeof(ScriptAsyncStateMachine)) : ScriptContext.GetType(_typeDef.BaseType); HostType = GetHostType(); IsDelegate = HostType.BaseType?.Name == "MulticastDelegate"; _genericTypes.AddRange(genericTypes); Initialize(); }
public override ScriptCompilerBase CreateCompiler(ScriptAssembly scriptAssembly, MonoIsland island, bool buildingForEditor, BuildTarget targetPlatform, bool runUpdater) { switch (GetCSharpCompiler(targetPlatform, buildingForEditor, scriptAssembly)) { case CSharpCompiler.Microsoft: return(new MicrosoftCSharpCompiler(island, runUpdater)); case CSharpCompiler.Mono: default: return(new MonoCSharpCompiler(island, runUpdater)); } }
private static AssemblyInfo ScriptAssemblyToAssemblyInfo(ScriptAssembly scriptAssembly, string outputDir) { return(new AssemblyInfo { Name = scriptAssembly.Filename, Files = scriptAssembly.Files.Select(Path.GetFullPath).ToArray(), Defines = scriptAssembly.Defines, References = scriptAssembly.GetAllReferences(), OutputDirectory = Path.GetFullPath(outputDir), AllowUnsafeCode = scriptAssembly.CompilerOptions.AllowUnsafeCode, }); }
public ScriptAssemblyViewModel(ScriptAssembly scriptAssembly, RootViewModel parent) { if (scriptAssembly == null) throw new ArgumentNullException("scriptAssembly"); if (parent == null) throw new ArgumentNullException("parent"); Parent = parent; this.scriptAssembly = scriptAssembly; UpdateScripts(); }
private static MonoIsland CreateMonoIsland(SupportedLanguage language) { const string kInputFilePath = "Packages/com.unity.inputsystem/InputSystem"; var outputAssemblyPath = Path.GetTempFileName(); var options = EditorScriptCompilationOptions.BuildingForEditor; var buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget; var buildTargetGroup = UnityEditor.EditorUserBuildSettings.activeBuildTargetGroup; var defines = ieu.GetCompilationDefines(options, buildTargetGroup, buildTarget); var references = new List <string>(); references.Add(ieu.GetEngineAssemblyPath()); references.Add(ieu.GetEngineCoreModuleAssemblyPath()); references.Add(ieu.GetEditorAssemblyPath()); references.AddRange(ModuleUtils.GetAdditionalReferencesForUserScripts()); #if UNITY_EDITOR_OSX references.Add(Path.Combine(EditorApplication.applicationContentsPath, "UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll")); #elif UNITY_EDITOR_WIN references.Add(Path.Combine(Path.GetDirectoryName(EditorApplication.applicationPath), "Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll")); #endif var unityAssemblies = InternalEditorUtility.GetUnityAssemblies(true, buildTargetGroup, buildTarget); foreach (var asm in unityAssemblies) { references.Add(asm.Path); } var apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.activeBuildTargetGroup); // Hopefully the churn on these mono library helpers is over, this is going to be a bit a pain to // always chase. #if UNITY_2018_3_OR_NEWER && !(UNITY_2019_1_OR_NEWER) var scriptAssembly = new ScriptAssembly { Filename = AssetPath.GetFileName(outputAssemblyPath), Flags = AssemblyFlags.None }; references.AddRange(MonoLibraryHelpers.GetSystemLibraryReferences(apiCompatibilityLevel, buildTarget, language, true, scriptAssembly)); #elif UNITY_2019_1_OR_NEWER references.AddRange(MonoLibraryHelpers.GetSystemLibraryReferences(apiCompatibilityLevel, buildTarget, language)); #endif var sources = new List <string>(); sources.AddRange(Directory.GetFiles(kInputFilePath, "*.cs", SearchOption.AllDirectories)); var island = new MonoIsland(buildTarget, apiCompatibilityLevel, true, sources.ToArray(), references.ToArray(), defines, outputAssemblyPath); return(island); }
private void OnCompilationStarted(ScriptAssembly assembly, int phase) { if (this.buildStarted != null) { try { this.buildStarted(this.assemblyPath); } catch (Exception exception) { Debug.LogException(exception); } } }
/// <summary> /// Reflect given scriptAssembly and add its modules into <c>entries</c>. /// </summary> /// <param name="scriptAssembly"><c>ScriptAssembly</c> to be reflected.</param> internal void ReflectLibraryNoLock(ScriptAssembly scriptAssembly) { foreach (ScriptModule module in scriptAssembly.GetModules()) { FullPath fullPath = new FullPath(module.RelativeSourcePath, Configuration.Application.Compiler.SourceRoot); Entry entry = new Entry(fullPath, module, scriptAssembly); if (!entries.ContainsKey(fullPath)) { entries.Add(fullPath, entry); } } }
/// <summary> /// Called by Unity. /// </summary> public void Start() { // Create domain domain = ScriptDomain.CreateDomain("Example Domain"); // Security load mode // ScriptSecurityMode.EnsureLoad - Do not perform and code validation and just load the assembly // ScriptSecurityMode.EnsureSecurity - Perform full code validation and discard the assembly if verification fails // ScriptSecurityMode.UseSettings - Use the RoslynC# settings to determine which action to take ScriptSecurityMode securityMode = ScriptSecurityMode.UseSettings; // Load an assembly - The assembly may be verified using active security restriction depending upon the security mod specified // If an assembly fails verification then it will not be loaded and the load method will return null ScriptAssembly assembly = domain.LoadAssembly("path/to/assembly.dll", securityMode); }
public override ScriptCompilerBase CreateCompiler( ScriptAssembly scriptAssembly, MonoIsland island, bool buildingForEditor, BuildTarget targetPlatform, bool runUpdater ) { // This method almost exactly copies CSharpLanguage.CreateCompiler(...) switch (GetCSharpCompiler(targetPlatform, buildingForEditor, scriptAssembly)) { case CSharpCompiler.Microsoft: return(new MicrosoftCSharpCompiler(island, runUpdater)); default: return(new CustomCSharpCompiler(island, runUpdater)); // MonoCSharpCompiler is replaced with CustomCSharpCompiler } }
private void OnCompilationFinished(ScriptAssembly assembly, List <UnityEditor.Scripting.Compilers.CompilerMessage> messages) { if (this.buildFinished != null) { CompilerMessage[] arg = EditorCompilation.ConvertCompilerMessages(messages); try { this.buildFinished(this.assemblyPath, arg); } catch (Exception exception) { Debug.LogException(exception); } } }
private static bool WeaveInto(ScriptAssembly assembly, string assemblyPath, string outputDirectory, string unityEngine, string unityUNet, string[] extraAssemblyPaths, IAssemblyResolver assemblyResolver) { string[] allReferences = assembly.GetAllReferences(); string[] array = new string[allReferences.Count <string>() + ((extraAssemblyPaths == null) ? 0 : extraAssemblyPaths.Length)]; int index = 0; string[] array2 = allReferences; for (int i = 0; i < array2.Length; i++) { string path = array2[i]; array[index++] = Path.GetDirectoryName(path); } if (extraAssemblyPaths != null) { extraAssemblyPaths.CopyTo(array, index); } bool result; try { string[] expr_73 = new string[] { assemblyPath }; string[] arg_B4_4 = array; if (Weaver.< > f__mg$cache0 == null) { Weaver.< > f__mg$cache0 = new Action <string>(Debug.LogWarning); } Action <string> arg_B4_6 = Weaver.< > f__mg$cache0; if (Weaver.< > f__mg$cache1 == null) { Weaver.< > f__mg$cache1 = new Action <string>(Debug.LogError); } if (!Unity.UNetWeaver.Program.Process(unityEngine, unityUNet, outputDirectory, expr_73, arg_B4_4, assemblyResolver, arg_B4_6, Weaver.< > f__mg$cache1)) { Debug.LogError("Failure generating network code."); result = false; return(result); } } catch (Exception ex) { Debug.LogError("Exception generating network code: " + ex.ToString() + " " + ex.StackTrace); } result = true; return(result); }
public static bool WeaveUnetFromEditor(ScriptAssembly assembly, string assemblyDirectory, string outputDirectory, string unityEngine, string unityUNet, bool buildingForEditor) { if ((assembly.Flags & AssemblyFlags.EditorOnly) == AssemblyFlags.EditorOnly) { return(true); } var assemblyPath = Path.Combine(assemblyDirectory, assembly.Filename); ICompilationExtension compilationExtension = GetCompilationExtension(); IAssemblyResolver assemblyResolver; string[] assemblyPaths; QueryAssemblyPathsAndResolver(compilationExtension, assemblyPath, buildingForEditor, out assemblyPaths, out assemblyResolver); return(WeaveInto(assembly, assemblyPath, outputDirectory, unityEngine, unityUNet, assemblyPaths, assemblyResolver)); }
private static void Main(string[] args) { using (var fs = File.OpenRead("../../../ScriptLibrary/bin/Debug/ScriptLibrary.dll")) { var asm = new ScriptAssembly(fs); ScriptContext.Load(asm); var type = asm.TypeSystem.GetType("ScriptLibrary.MyFoo"); var myFoo = type.CreateInstance(); var foo = myFoo.GetHostInstance <Foo <int> >(); foo.VirtualTest("Abc"); var method = type.GetMethod("Test2"); var ret = method.Invoke(myFoo, 10); //ret = type.GetMethod("Test3").Invoke(null, 100); } }
void OnCompilationStarted(ScriptAssembly assembly, int phase) { if (buildStarted == null) { return; } try { buildStarted(assemblyPath); } catch (Exception e) { UnityEngine.Debug.LogException(e); } }
internal static ScriptCompilerBase CreateCompilerInstance(ScriptAssembly scriptAssembly, MonoIsland island, bool buildingForEditor, BuildTarget targetPlatform, bool runUpdater) { if (island._files.Length == 0) { throw new ArgumentException("Cannot compile MonoIsland with no files"); } foreach (var lang in SupportedLanguages) { if (lang.GetExtensionICanCompile() == island.GetExtensionOfSourceFiles()) { return(lang.CreateCompiler(scriptAssembly, island, buildingForEditor, targetPlatform, runUpdater)); } } throw new ApplicationException(string.Format("Unable to find a suitable compiler for sources with extension '{0}' (Output assembly: {1})", island.GetExtensionOfSourceFiles(), island._output)); }
public ScriptAssemblyViewModel(ScriptAssembly scriptAssembly, RootViewModel parent) { if (scriptAssembly is null) { throw new ArgumentNullException(nameof(scriptAssembly)); } if (parent is null) { throw new ArgumentNullException(nameof(parent)); } Parent = parent; this.scriptAssembly = scriptAssembly; UpdateScripts(); }
public ScriptAssemblyViewModel(ScriptAssembly scriptAssembly, RootViewModel parent) { if (scriptAssembly == null) { throw new ArgumentNullException("scriptAssembly"); } if (parent == null) { throw new ArgumentNullException("parent"); } Parent = parent; this.scriptAssembly = scriptAssembly; UpdateScripts(); }
/// <summary> /// Päivittää assemblyn ja lisää sen mahdollisesti muokattujen /// assemblyjen listaan. /// </summary> private void UpdateAssembly(ScriptAssembly scriptAssembly) { scriptAssembly.Update(); if (scriptAssembly.CanBeDisposed && scriptAssembly.CauseToDisposal == CauseToDisposal.Modified) { ScriptAssembly modifiedAssembly = modifiedAssemblies.Find(i => i.FullName == scriptAssembly.FullName); if (modifiedAssembly != null) { int index = modifiedAssemblies.IndexOf(modifiedAssembly); modifiedAssemblies[index] = scriptAssembly; } else { modifiedAssemblies.Add(scriptAssembly); } } }
void OnCompilationFinished(ScriptAssembly assembly, List <UnityEditor.Scripting.Compilers.CompilerMessage> messages) { if (buildFinished == null) { return; } var convertedMessages = EditorCompilation.ConvertCompilerMessages(messages); try { buildFinished(assemblyPath, convertedMessages); } catch (Exception e) { UnityEngine.Debug.LogException(e); } }
public override string[] GetCompilerDefines(BuildTarget targetPlatform, bool buildingForEditor, ScriptAssembly scriptAssembly) { var compiler = GetCSharpCompiler(targetPlatform, buildingForEditor, scriptAssembly); if (compiler == CSharpCompiler.Microsoft) { var defines = new string[] { "CSHARP_7_OR_LATER", // Incremental Compiler adds this. "CSHARP_7_3_OR_NEWER", }; return(defines); } return(new string[0]); }
private static void WriteJsTestFile(string bladeDllPath, string targetPath, IEnumerable <string> searchPaths) { if (!File.Exists(bladeDllPath)) { throw new FileNotFoundException("Unable to locate Blade unit test assembly."); } if (File.Exists(targetPath)) { File.Delete(targetPath); } // add any assembly search paths if (searchPaths != null) { foreach (var path in searchPaths) { ScriptDomain.CurrentDomain.AddSearchDirectory(path); } } // load the unit test script assembly var assembly = ScriptAssembly.Load(bladeDllPath); var dependencies = assembly.GetDependencyChain(); var newline = Encoding.UTF8.GetBytes(Environment.NewLine); // write all script into a single test file using (var stream = File.Create(targetPath)) { // copy dependencies, in executable order foreach (var dep in dependencies.Reverse()) { if (dep.HasScriptResource) { dep.GetScriptResource().CopyTo(stream); stream.Write(newline, 0, newline.Length); } } // finally, copy the unit test script assembly.GetScriptResource().CopyTo(stream); } }
public static bool WeaveUnetFromEditor(ScriptAssembly assembly, string assemblyDirectory, string outputDirectory, string unityEngine, string unityUNet, bool buildingForEditor) { bool result; if ((assembly.Flags & AssemblyFlags.EditorOnly) == AssemblyFlags.EditorOnly) { result = true; } else { string text = Path.Combine(assemblyDirectory, assembly.Filename); ICompilationExtension compilationExtension = Weaver.GetCompilationExtension(); string[] extraAssemblyPaths; IAssemblyResolver assemblyResolver; Weaver.QueryAssemblyPathsAndResolver(compilationExtension, text, buildingForEditor, out extraAssemblyPaths, out assemblyResolver); result = Weaver.WeaveInto(assembly, text, outputDirectory, unityEngine, unityUNet, extraAssemblyPaths, assemblyResolver); } return(result); }
/// <summary> /// Loads assembly as script library, adding all scripts it contains into script library database. /// </summary> /// <param name="realAssembly">Script assembly that is to be loaded.</param> /// <param name="libraryRoot">Root offset of the script library. All scripts will be loaded with this offset. /// Strict behavior forbids conflicts between scriptLibrary and filesystem, all conflicts will be reported as errors. /// This is used in the runtime (dynamic include), compiler currently ignores filesystem. /// </param> public DAssembly LoadScriptLibrary(Assembly /*!*/ realAssembly, string libraryRoot) { ScriptAssembly scriptAssembly; lock (this) { if (loadedAssemblies.ContainsKey(realAssembly)) { return(loadedAssemblies[realAssembly]); } scriptAssembly = ScriptAssembly.LoadFromAssembly(applicationContext, realAssembly, libraryRoot); loadedAssemblies.Add(realAssembly, scriptAssembly); } applicationContext.ScriptLibraryDatabase.ReflectLibraryNoLock(scriptAssembly); return(scriptAssembly); }
/// <summary> /// Used by the builder. /// </summary> public ScriptModule(CompilationUnit/*!*/ unit, ScriptAssembly/*!*/ scriptAssembly, string subnamespace) : base(unit, scriptAssembly) { Debug.Assert(unit != null && scriptAssembly != null); this.userTypesNamespace = subnamespace; this.scriptInfo = null; this.relativeSourcePath = unit.RelativeSourcePath; }
public CacheEntry(Type/*!*/ scriptType, ScriptAssembly/*!*/ scriptAssembly, DateTime buildTimeStamp, string[]/*!*/ includers, string[]/*!*/ includees, bool fileTimeChecked) { Debug.Assert(scriptType != null && scriptAssembly != null && includers != null); this.scriptInfo = new ScriptInfo(scriptType); this.scriptAssembly = scriptAssembly; this.buildTimeStamp = buildTimeStamp; this.includers = new List<string>(includers); this.fileTimeChecked = fileTimeChecked; this.includees = new List<string>(includees); }
/// <summary> /// Used by the loader. /// </summary> /// <param name="relativeSourcePath">Path to the source file which is represented by this script.</param> /// <param name="scriptType">Type which represents script. Implements IPhpScript interface.</param> /// <param name="scriptAssembly">Script assembly this script module belongs to.</param> /// <param name="subnamespace">Namespace where all types statically declared in this script are contained.</param> public ScriptModule(string/*!*/ relativeSourcePath, Type/*!*/ scriptType, ScriptAssembly/*!*/ scriptAssembly, string subnamespace) : base(scriptAssembly) { Debug.Assert(scriptAssembly != null); this.scriptInfo = new ScriptInfo(scriptType); this.userTypesNamespace = subnamespace; this.relativeSourcePath = relativeSourcePath; //FastReflect(); }
private void AddScriptAssembly(ScriptAssembly scriptAssembly) { ScriptAssemblyViewModel vm = null; if (scriptAssembly.Assembly == null) { if (orphanScriptsAssembly == null) { orphanScriptsAssembly = new ScriptAssemblyViewModel(scriptAssembly, this); scriptAssemblies.Add(orphanScriptsAssembly); } vm = orphanScriptsAssembly; } else { vm = new ScriptAssemblyViewModel(scriptAssembly, this); scriptAssemblies.Add(vm); } vm.UpdateScripts(); }
protected ScriptAssemblyBuilder(ScriptAssembly/*!*/ assembly, AssemblyName assemblyName, string directory, string fileName, AssemblyKinds kind, ICollection<ResourceFileReference> resources, bool debug, bool force32bit, bool saveOnlyAssembly, Win32IconResource icon) : base(assembly, assemblyName, ScriptAssembly.RealModuleName, directory, fileName, kind,resources, debug, force32bit, saveOnlyAssembly, icon) { }
public Entry(FullPath path, ScriptModule scriptModule, ScriptAssembly containingAssembly) { ScriptModule = scriptModule; ContainingAssembly = containingAssembly; Path = path; }
private void RemoveScriptAssembly(ScriptAssembly scriptAssembly) { ScriptAssemblyViewModel foundViewModel = scriptAssemblies.Single(item => string.Compare(item.Url, scriptAssembly.Url, true) == 0); scriptAssemblies.Remove(foundViewModel); }