Exemple #1
0
 public void Sync()
 {
     this.SetupProjectSupportedExtensions();
     if (!AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles())
     {
         ScriptEditorUtility.ScriptEditor scriptEditorFromPreferences = ScriptEditorUtility.GetScriptEditorFromPreferences();
         if (scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.SystemDefault || scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.Other)
         {
             return;
         }
         IEnumerable <MonoIsland> islands = from i in EditorCompilationInterface.GetAllMonoIslands()
                                            where 0 < i._files.Length && i._files.Any((string f) => this.ShouldFileBePartOfSolution(f))
                                            select i;
         Dictionary <string, string> allAssetsProjectParts = this.GenerateAllAssetProjectParts();
         string[] responseFileDefinesFromFile = ScriptCompilerBase.GetResponseFileDefinesFromFile(MonoCSharpCompiler.ReponseFilename);
         this.SyncSolution(islands);
         List <MonoIsland> list = SolutionSynchronizer.RelevantIslandsForMode(islands, SolutionSynchronizer.ModeForCurrentExternalEditor()).ToList <MonoIsland>();
         foreach (MonoIsland current in list)
         {
             this.SyncProject(current, allAssetsProjectParts, responseFileDefinesFromFile, list);
         }
         if (scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
         {
             this.WriteVSCodeSettingsFiles();
         }
     }
     AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles();
 }
Exemple #2
0
        internal void GenerateAndWriteSolutionAndProjects(ScriptEditorUtility.ScriptEditor scriptEditor)
        {
            // Only synchronize islands that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            IEnumerable <MonoIsland> islands = EditorCompilationInterface.GetAllMonoIslands().
                                               Where(i => 0 < i._files.Length && i._files.Any(f => ShouldFileBePartOfSolution(f)));

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var responseFilePath = Path.Combine("Assets", MonoCSharpCompiler.ReponseFilename);

            var responseFileData = ScriptCompilerBase.ParseResponseFileFromFile(Path.Combine(_projectDirectory, responseFilePath));

            if (responseFileData.Errors.Length > 0)
            {
                foreach (var error in responseFileData.Errors)
                {
                    UnityEngine.Debug.LogErrorFormat("{0} Parse Error : {1}", responseFilePath, error);
                }
            }

            SyncSolution(islands);
            var allProjectIslands = RelevantIslandsForMode(islands, ModeForCurrentExternalEditor()).ToList();

            foreach (MonoIsland island in allProjectIslands)
            {
                SyncProject(island, allAssetProjectParts, responseFileData, allProjectIslands);
            }

            if (scriptEditor == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
            {
                WriteVSCodeSettingsFiles();
            }
        }
 public void Stop()
 {
     if (!this.Stopped)
     {
         foreach (KeyValuePair <ScriptAssembly, ScriptCompilerBase> current in this.compilerTasks)
         {
             ScriptCompilerBase value = current.Value;
             value.Dispose();
         }
         this.compilerTasks.Clear();
         this.Stopped = true;
     }
 }
 private void QueuePendingAssemblies()
 {
     if (this.pendingAssemblies.Count != 0)
     {
         List <ScriptAssembly> list = null;
         foreach (ScriptAssembly current in this.pendingAssemblies)
         {
             bool             flag = true;
             ScriptAssembly[] scriptAssemblyReferences = current.ScriptAssemblyReferences;
             for (int i = 0; i < scriptAssemblyReferences.Length; i++)
             {
                 ScriptAssembly key = scriptAssemblyReferences[i];
                 if (!this.processedAssemblies.ContainsKey(key))
                 {
                     flag = false;
                     break;
                 }
             }
             if (flag)
             {
                 if (list == null)
                 {
                     list = new List <ScriptAssembly>();
                 }
                 list.Add(current);
             }
         }
         if (list != null)
         {
             bool buildingForEditor = (this.options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor;
             foreach (ScriptAssembly current2 in list)
             {
                 this.pendingAssemblies.Remove(current2);
                 MonoIsland         island             = current2.ToMonoIsland(this.options, this.buildOutputDirectory);
                 ScriptCompilerBase scriptCompilerBase = ScriptCompilers.CreateCompilerInstance(island, buildingForEditor, island._target, current2.RunUpdater);
                 this.compilerTasks.Add(current2, scriptCompilerBase);
                 scriptCompilerBase.BeginCompiling();
                 if (this.OnCompilationStarted != null)
                 {
                     this.OnCompilationStarted(current2, this.compilePhase);
                 }
                 if (this.compilerTasks.Count == this.maxConcurrentCompilers)
                 {
                     break;
                 }
             }
             this.compilePhase++;
         }
     }
 }
    private static CompilerMessage[] Compile(ScriptCompilerBase compiler, MonoIsland island)
    {
        var assemblyOutputPath = island._output;

        compiler.BeginCompiling();
        compiler.WaitForCompilationToFinish();

        Assert.IsTrue(compiler.Poll(), "Compilation is not finished");

        var messages = compiler.GetCompilerMessages();

        if (messages.Count(m => m.type == CompilerMessageType.Error) == 0)
        {
            Assert.True(File.Exists(assemblyOutputPath), "Output assembly does not exist after successful compile");
        }

        File.Delete(assemblyOutputPath);

        return(messages);
    }
        ScriptCompilerBase.ResponseFileData parseResponseFileData(MonoIsland island, string responseFilePath)
        {
            var systemReferenceDirectories = CSharpLanguage.GetCSharpCompiler(island._target, true, "Assembly-CSharp") == CSharpCompiler.Microsoft &&
                                             PlayerSettings.GetScriptingBackend(BuildPipeline.GetBuildTargetGroup(island._target)) == ScriptingImplementation.WinRTDotNET
                ? MicrosoftCSharpCompiler.GetClassLibraries(island._target)
                : MonoLibraryHelpers.GetSystemReferenceDirectories(island._api_compatibility_level);

            ScriptCompilerBase.ResponseFileData responseFileData = ScriptCompilerBase.ParseResponseFileFromFile(
                Path.Combine(_projectDirectory, responseFilePath),
                _projectDirectory,
                systemReferenceDirectories);

            if (responseFileData.Errors.Length > 0)
            {
                foreach (var error in responseFileData.Errors)
                {
                    UnityEngine.Debug.LogErrorFormat("{0} Parse Error : {1}", responseFilePath, error);
                }
            }

            return(responseFileData);
        }
Exemple #7
0
 public void Sync()
 {
     this.SetupProjectSupportedExtensions();
     if (!AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles())
     {
         IEnumerable <MonoIsland> islands = from i in InternalEditorUtility.GetMonoIslands()
                                            where 0 < i._files.Length
                                            select i;
         string   otherAssetsProjectPart      = this.GenerateAllAssetProjectPart();
         string[] responseFileDefinesFromFile = ScriptCompilerBase.GetResponseFileDefinesFromFile(MonoCSharpCompiler.ReponseFilename);
         this.SyncSolution(islands);
         foreach (MonoIsland current in SolutionSynchronizer.RelevantIslandsForMode(islands, SolutionSynchronizer.ModeForCurrentExternalEditor()))
         {
             this.SyncProject(current, otherAssetsProjectPart, responseFileDefinesFromFile);
         }
         if (ScriptEditorUtility.GetScriptEditorFromPreferences() == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
         {
             this.WriteVSCodeSettingsFiles();
         }
     }
     AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles();
 }
Exemple #8
0
 public static ResponseFileData ParseResponseFile(string relativePath, string projectDirectory, string[] systemReferenceDirectories)
 {
     return(ScriptCompilerBase.ParseResponseFileFromFile(relativePath, projectDirectory, systemReferenceDirectories));
 }
Exemple #9
0
        IEnumerable <ResponseFileData> ParseResponseFileData(MonoIsland island)
        {
            var systemReferenceDirectories = MonoLibraryHelpers.GetSystemReferenceDirectories(island._api_compatibility_level);

            Dictionary <string, ResponseFileData> responseFilesData = island._responseFiles.ToDictionary(x => x, x => ScriptCompilerBase.ParseResponseFileFromFile(
                                                                                                             x,
                                                                                                             _projectDirectory,
                                                                                                             systemReferenceDirectories
                                                                                                             ));

            Dictionary <string, ResponseFileData> responseFilesWithErrors = responseFilesData.Where(x => x.Value.Errors.Any())
                                                                            .ToDictionary(x => x.Key, x => x.Value);

            if (responseFilesWithErrors.Any())
            {
                foreach (var error in responseFilesWithErrors)
                {
                    foreach (var valueError in error.Value.Errors)
                    {
                        UnityEngine.Debug.LogErrorFormat("{0} Parse Error : {1}", error.Key, valueError);
                    }
                }
            }

            return(responseFilesData.Select(x => x.Value));
        }
Exemple #10
0
        IEnumerable <ScriptCompilerBase.ResponseFileData> ParseResponseFileData(MonoIsland island)
        {
            var systemReferenceDirectories = CSharpLanguage.GetCSharpCompiler(island._target, true, "Assembly-CSharp") == CSharpCompiler.Microsoft &&
                                             PlayerSettings.GetScriptingBackend(BuildPipeline.GetBuildTargetGroup(island._target)) == ScriptingImplementation.WinRTDotNET && !island._editor
                ? MicrosoftCSharpCompiler.GetClassLibraries(island._target, island._editor)
                : MonoLibraryHelpers.GetSystemReferenceDirectories(island._api_compatibility_level);

            Dictionary <string, ScriptCompilerBase.ResponseFileData> responseFilesData = island._responseFiles.ToDictionary(x => x, x => ScriptCompilerBase.ParseResponseFileFromFile(
                                                                                                                                Path.Combine(_projectDirectory, x),
                                                                                                                                _projectDirectory,
                                                                                                                                systemReferenceDirectories
                                                                                                                                ));

            Dictionary <string, ScriptCompilerBase.ResponseFileData> responseFilesWithErrors = responseFilesData.Where(x => x.Value.Errors.Any())
                                                                                               .ToDictionary(x => x.Key, x => x.Value);

            if (responseFilesWithErrors.Any())
            {
                foreach (var error in responseFilesWithErrors)
                {
                    foreach (var valueError in error.Value.Errors)
                    {
                        UnityEngine.Debug.LogErrorFormat("{0} Parse Error : {1}", error.Key, valueError);
                    }
                }
            }

            return(responseFilesData.Select(x => x.Value));
        }
    static string GenerateResponseFileEdited(
        ScriptAssembly assembly,
        EditorScriptCompilationOptions options,
        string tempBuildDirectory)
    {
        bool          buildingForEditor = (options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor;
        bool          flag      = (options & EditorScriptCompilationOptions.BuildingDevelopmentBuild) == EditorScriptCompilationOptions.BuildingDevelopmentBuild;
        List <string> arguments = new List <string>()
        {
            "-target:library",
            "-nowarn:0169",
            "-out:" + PrepareFileName(AssetPath.Combine(tempBuildDirectory, assembly.Filename))
        };

        // added
        arguments.Add("-define:__UNITY_PROCESSID__" + Process.GetCurrentProcess().Id);

        if (assembly.CompilerOptions.AllowUnsafeCode)
        {
            arguments.Add("-unsafe");
        }
        arguments.Add("-debug:portable");
        if (!flag && (!buildingForEditor || !EditorPrefs.GetBool("AllowAttachedDebuggingOfEditor", true)))
        {
            arguments.Add("-optimize+");
        }
        else
        {
            arguments.Add("-optimize-");
        }
        FillCompilerOptionsEdited(arguments, buildingForEditor, assembly.BuildTarget);
        foreach (ScriptAssembly assemblyReference in assembly.ScriptAssemblyReferences)
        {
            arguments.Add("-reference:" + ScriptCompilerBase.PrepareFileName(AssetPath.Combine(assembly.OutputDirectory, assemblyReference.Filename)));
        }
        foreach (string reference in assembly.References)
        {
            arguments.Add("-reference:" + ScriptCompilerBase.PrepareFileName(reference));
        }
        foreach (string str in ((IEnumerable <string>)assembly.Defines).Distinct <string>())
        {
            arguments.Add("-define:" + str);
        }
        foreach (string file in assembly.Files)
        {
            string str = Paths.UnifyDirectorySeparator(ScriptCompilerBase.PrepareFileName(file));
            arguments.Add(str);
        }
        HashSet <string> source = new HashSet <string>((IEnumerable <string>)(assembly.Language?.CreateResponseFileProvider()?.Get(assembly.OriginPath) ?? new List <string>()));
        string           path   = source.SingleOrDefault <string>((Func <string, bool>)(x => ((IEnumerable <string>)CompilerSpecificResponseFiles.MicrosoftCSharpCompilerObsolete).Contains <string>(AssetPath.GetFileName(x))));

        if (!string.IsNullOrEmpty(path))
        {
            UnityEngine.Debug.LogWarning((object)("Using obsolete custom response file '" + AssetPath.GetFileName(path) + "'. Please use 'csc.rsp' instead."));
        }

        // Assembly-CSharp has null OriginPath
        if (assembly.OriginPath?.StartsWith("Assets", StringComparison.Ordinal) ?? true)
        {
            // excludes unity packages
            var rspPath = "Assets/assets-csc.rsp";
            if (File.Exists(rspPath))
            {
                source.Add(rspPath);
            }
        }

        foreach (string responseFileName in source)
        {
            ScriptCompilerBase.AddResponseFileToArguments(arguments, responseFileName, assembly.CompilerOptions.ApiCompatibilityLevel);
        }
        return(CommandLineFormatter.GenerateResponseFile((IEnumerable <string>)arguments));
    }
        public bool Poll()
        {
            bool result;

            if (this.Stopped)
            {
                result = true;
            }
            else
            {
                Dictionary <ScriptAssembly, ScriptCompilerBase> dictionary = null;
                foreach (KeyValuePair <ScriptAssembly, ScriptCompilerBase> current in this.compilerTasks)
                {
                    ScriptCompilerBase value = current.Value;
                    if (value.Poll())
                    {
                        if (dictionary == null)
                        {
                            dictionary = new Dictionary <ScriptAssembly, ScriptCompilerBase>();
                        }
                        ScriptAssembly key = current.Key;
                        dictionary.Add(key, value);
                    }
                }
                if (dictionary != null)
                {
                    foreach (KeyValuePair <ScriptAssembly, ScriptCompilerBase> current2 in dictionary)
                    {
                        ScriptAssembly         key2             = current2.Key;
                        ScriptCompilerBase     value2           = current2.Value;
                        CompilerMessage[]      compilerMessages = value2.GetCompilerMessages();
                        List <CompilerMessage> list             = compilerMessages.ToList <CompilerMessage>();
                        if (this.OnCompilationFinished != null)
                        {
                            this.OnCompilationFinished(key2, list);
                        }
                        this.processedAssemblies.Add(key2, list.ToArray());
                        if (!this.CompileErrors)
                        {
                            this.CompileErrors = compilerMessages.Any((CompilerMessage m) => m.type == CompilerMessageType.Error);
                        }
                        this.compilerTasks.Remove(key2);
                        value2.Dispose();
                    }
                }
                if (this.CompileErrors)
                {
                    if (this.pendingAssemblies.Count > 0)
                    {
                        foreach (ScriptAssembly current3 in this.pendingAssemblies)
                        {
                            this.processedAssemblies.Add(current3, new CompilerMessage[0]);
                        }
                        this.pendingAssemblies.Clear();
                    }
                    result = (this.compilerTasks.Count == 0);
                }
                else
                {
                    if (this.compilerTasks.Count == 0 || (dictionary != null && dictionary.Count > 0))
                    {
                        this.QueuePendingAssemblies();
                    }
                    result = (this.pendingAssemblies.Count == 0 && this.compilerTasks.Count == 0);
                }
            }
            return(result);
        }
 private static bool Prefix(ref ScriptCompilerBase __result, MonoIsland island, bool buildingForEditor, BuildTarget targetPlatform, bool runUpdater)
 {
     __result = new CustomCSharpCompiler(island, runUpdater);
     return(false);
 }