Ejemplo n.º 1
0
        internal bool CompileScripts(ScriptAssemblySettings scriptAssemblySettings, string tempBuildDirectory, BuildFlags buildflags, ref EditorBuildRules.TargetAssembly[] notCompiledTargetAssemblies)
        {
            this.DeleteUnusedAssemblies();
            this.allScripts.RemoveWhere((string path) => !File.Exists(Path.Combine(this.projectDirectory, path)));
            this.StopAllCompilation();
            if (!Directory.Exists(scriptAssemblySettings.OutputDirectory))
            {
                Directory.CreateDirectory(scriptAssemblySettings.OutputDirectory);
            }
            if (!Directory.Exists(tempBuildDirectory))
            {
                Directory.CreateDirectory(tempBuildDirectory);
            }
            IEnumerable <string> enumerable = (!this.areAllScriptsDirty) ? this.dirtyScripts.ToArray <string>() : this.allScripts.ToArray <string>();

            this.areAllScriptsDirty = false;
            this.dirtyScripts.Clear();
            bool result;

            if (!enumerable.Any <string>() && this.runScriptUpdaterAssemblies.Count == 0)
            {
                result = false;
            }
            else
            {
                EditorBuildRules.CompilationAssemblies assemblies = new EditorBuildRules.CompilationAssemblies
                {
                    UnityAssemblies          = this.unityAssemblies,
                    PrecompiledAssemblies    = this.precompiledAssemblies,
                    CustomTargetAssemblies   = this.customTargetAssemblies,
                    EditorAssemblyReferences = ModuleUtils.GetAdditionalReferencesForUserScripts()
                };
                EditorBuildRules.GenerateChangedScriptAssembliesArgs generateChangedScriptAssembliesArgs = new EditorBuildRules.GenerateChangedScriptAssembliesArgs
                {
                    AllSourceFiles       = this.allScripts,
                    DirtySourceFiles     = enumerable,
                    ProjectDirectory     = this.projectDirectory,
                    BuildFlags           = buildflags,
                    Settings             = scriptAssemblySettings,
                    Assemblies           = assemblies,
                    RunUpdaterAssemblies = this.runScriptUpdaterAssemblies
                };
                ScriptAssembly[] array = EditorBuildRules.GenerateChangedScriptAssemblies(generateChangedScriptAssembliesArgs);
                notCompiledTargetAssemblies = generateChangedScriptAssembliesArgs.NotCompiledTargetAssemblies.ToArray <EditorBuildRules.TargetAssembly>();
                if (!array.Any <ScriptAssembly>())
                {
                    result = false;
                }
                else
                {
                    this.compilationTask = new CompilationTask(array, tempBuildDirectory, buildflags, SystemInfo.processorCount);
                    this.compilationTask.OnCompilationStarted += delegate(ScriptAssembly assembly, int phase)
                    {
                        Console.WriteLine("- Starting compile {0}", Path.Combine(scriptAssemblySettings.OutputDirectory, assembly.Filename));
                    };
                    IEnumerable <MonoIsland> compilingMonoIslands = from i in this.GetAllMonoIslands()
                                                                    where 0 < i._files.Length
                                                                    select i;
                    this.compilationTask.OnCompilationFinished += delegate(ScriptAssembly assembly, List <CompilerMessage> messages)
                    {
                        Console.WriteLine("- Finished compile {0}", Path.Combine(scriptAssemblySettings.OutputDirectory, assembly.Filename));
                        if (this.runScriptUpdaterAssemblies.Contains(assembly.Filename))
                        {
                            this.runScriptUpdaterAssemblies.Remove(assembly.Filename);
                        }
                        if (!messages.Any((CompilerMessage m) => m.type == CompilerMessageType.Error))
                        {
                            string engineAssemblyPath = InternalEditorUtility.GetEngineAssemblyPath();
                            string unityUNet          = EditorApplication.applicationContentsPath + "/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll";
                            if (!Weaver.WeaveUnetFromEditor(compilingMonoIslands, Path.Combine(tempBuildDirectory, assembly.Filename), Path.Combine(EditorCompilation.EditorTempPath, assembly.Filename), engineAssemblyPath, unityUNet, (buildflags & BuildFlags.BuildingForEditor) != BuildFlags.None))
                            {
                                messages.Add(new CompilerMessage
                                {
                                    message = "UNet Weaver failed",
                                    type    = CompilerMessageType.Error,
                                    file    = assembly.FullPath,
                                    line    = -1,
                                    column  = -1
                                });
                                this.StopAllCompilation();
                            }
                            else
                            {
                                EditorCompilation.CopyAssembly(Path.Combine(tempBuildDirectory, assembly.Filename), assembly.FullPath);
                            }
                        }
                    };
                    this.compilationTask.Poll();
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static ScriptAssembly[] GenerateChangedScriptAssemblies(EditorBuildRules.GenerateChangedScriptAssembliesArgs args)
        {
            bool flag = (args.BuildFlags & BuildFlags.BuildingForEditor) == BuildFlags.BuildingForEditor;
            Dictionary <EditorBuildRules.TargetAssembly, HashSet <string> > dictionary = new Dictionary <EditorBuildRules.TargetAssembly, HashSet <string> >();

            EditorBuildRules.TargetAssembly[] array = (args.Assemblies.CustomTargetAssemblies != null) ? EditorBuildRules.predefinedTargetAssemblies.Concat(args.Assemblies.CustomTargetAssemblies).ToArray <EditorBuildRules.TargetAssembly>() : EditorBuildRules.predefinedTargetAssemblies;
            if (args.RunUpdaterAssemblies != null)
            {
                using (HashSet <string> .Enumerator enumerator = args.RunUpdaterAssemblies.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        string assemblyFilename             = enumerator.Current;
                        EditorBuildRules.TargetAssembly key = array.First((EditorBuildRules.TargetAssembly a) => a.FilenameWithSuffix(args.Settings.FilenameSuffix) == assemblyFilename);
                        dictionary[key] = new HashSet <string>();
                    }
                }
            }
            foreach (string current in args.DirtySourceFiles)
            {
                EditorBuildRules.TargetAssembly targetAssembly = EditorBuildRules.GetTargetAssembly(current, args.ProjectDirectory, args.Assemblies.CustomTargetAssemblies);
                if (flag || !targetAssembly.EditorOnly)
                {
                    string            extensionOfSourceFile = ScriptCompilers.GetExtensionOfSourceFile(current);
                    SupportedLanguage languageFromExtension = ScriptCompilers.GetLanguageFromExtension(extensionOfSourceFile);
                    HashSet <string>  hashSet;
                    if (!dictionary.TryGetValue(targetAssembly, out hashSet))
                    {
                        hashSet = new HashSet <string>();
                        dictionary[targetAssembly] = hashSet;
                        if (targetAssembly.Type == EditorBuildRules.TargetAssemblyType.Custom)
                        {
                            targetAssembly.Language = languageFromExtension;
                        }
                    }
                    hashSet.Add(Path.Combine(args.ProjectDirectory, current));
                    if (languageFromExtension != targetAssembly.Language)
                    {
                        args.NotCompiledTargetAssemblies.Add(targetAssembly);
                    }
                }
            }
            bool flag2 = dictionary.Any((KeyValuePair <EditorBuildRules.TargetAssembly, HashSet <string> > entry) => entry.Key.Type == EditorBuildRules.TargetAssemblyType.Custom);

            if (flag2)
            {
                EditorBuildRules.TargetAssembly[] array2 = EditorBuildRules.predefinedTargetAssemblies;
                for (int i = 0; i < array2.Length; i++)
                {
                    EditorBuildRules.TargetAssembly targetAssembly2 = array2[i];
                    if (flag || !targetAssembly2.EditorOnly)
                    {
                        if (!dictionary.ContainsKey(targetAssembly2))
                        {
                            dictionary[targetAssembly2] = new HashSet <string>();
                        }
                    }
                }
            }
            int num;

            do
            {
                num = 0;
                EditorBuildRules.TargetAssembly[] array3 = array;
                for (int j = 0; j < array3.Length; j++)
                {
                    EditorBuildRules.TargetAssembly targetAssembly3 = array3[j];
                    if (flag || !targetAssembly3.EditorOnly)
                    {
                        if (!dictionary.ContainsKey(targetAssembly3))
                        {
                            foreach (EditorBuildRules.TargetAssembly current2 in targetAssembly3.References)
                            {
                                if (dictionary.ContainsKey(current2))
                                {
                                    dictionary[targetAssembly3] = new HashSet <string>();
                                    num++;
                                    break;
                                }
                            }
                        }
                    }
                }
            }while (num > 0);
            foreach (string current3 in args.AllSourceFiles)
            {
                EditorBuildRules.TargetAssembly targetAssembly4 = EditorBuildRules.GetTargetAssembly(current3, args.ProjectDirectory, args.Assemblies.CustomTargetAssemblies);
                if (flag || !targetAssembly4.EditorOnly)
                {
                    string            extensionOfSourceFile2 = ScriptCompilers.GetExtensionOfSourceFile(current3);
                    SupportedLanguage languageFromExtension2 = ScriptCompilers.GetLanguageFromExtension(extensionOfSourceFile2);
                    if (targetAssembly4.Language == null && targetAssembly4.Type == EditorBuildRules.TargetAssemblyType.Custom)
                    {
                        targetAssembly4.Language = languageFromExtension2;
                    }
                    if (languageFromExtension2 != targetAssembly4.Language)
                    {
                        args.NotCompiledTargetAssemblies.Add(targetAssembly4);
                    }
                    HashSet <string> hashSet2;
                    if (dictionary.TryGetValue(targetAssembly4, out hashSet2))
                    {
                        hashSet2.Add(Path.Combine(args.ProjectDirectory, current3));
                    }
                }
            }
            dictionary = (from e in dictionary
                          where e.Value.Count > 0
                          select e).ToDictionary((KeyValuePair <EditorBuildRules.TargetAssembly, HashSet <string> > e) => e.Key, (KeyValuePair <EditorBuildRules.TargetAssembly, HashSet <string> > e) => e.Value);
            foreach (EditorBuildRules.TargetAssembly current4 in args.NotCompiledTargetAssemblies)
            {
                dictionary.Remove(current4);
            }
            return(EditorBuildRules.ToScriptAssemblies(dictionary, args.Settings, args.BuildFlags, args.Assemblies, args.RunUpdaterAssemblies));
        }