Beispiel #1
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();
            }
        }
        private static Assembly[] GetPlayerAssemblies(BuildReport report)
        {
            // We need to build the list of root assemblies based from the "PlayerScriptAssemblies" folder.
            // This is so we compile the versions of the library built for the individual platforms, not the editor version.
            var oldOutputDir = EditorCompilationInterface.GetCompileScriptsOutputDirectory();

            try
            {
                EditorCompilationInterface.SetCompileScriptsOutputDirectory(LibraryPlayerScriptAssemblies);

                var shouldIncludeTestAssemblies = report.summary.options.HasFlag(BuildOptions.IncludeTestAssemblies);

#if UNITY_2019_3_OR_NEWER
                return(CompilationPipeline.GetAssemblies(shouldIncludeTestAssemblies ? AssembliesType.Player : AssembliesType.PlayerWithoutTestAssemblies));
#else
                var compilationOptions = EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions();
                if (shouldIncludeTestAssemblies)
                {
                    compilationOptions |= EditorScriptCompilationOptions.BuildingIncludingTestAssemblies;
                }

#if UNITY_2019_2_OR_NEWER
                return(CompilationPipeline.GetPlayerAssemblies(EditorCompilationInterface.Instance, compilationOptions, null));
#else
                return(CompilationPipeline.GetPlayerAssemblies(EditorCompilationInterface.Instance, compilationOptions));
#endif
#endif
            }
            finally
            {
                EditorCompilationInterface.SetCompileScriptsOutputDirectory(oldOutputDir);  // restore output directory back to original value
            }
        }
        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.ResponseFilename);

            var monoIslands = islands.ToList();


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

            foreach (MonoIsland island in allProjectIslands)
            {
                var responseFileData = parseResponseFileData(island, responseFilePath);
                SyncProject(island, allAssetProjectParts, responseFileData, allProjectIslands);
            }

            if (scriptEditor == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
            {
                WriteVSCodeSettingsFiles();
            }
        }
        private static Assembly[] GetPlayerAssemblies(BuildReport report)
        {
            // We need to build the list of root assemblies based from the "PlayerScriptAssemblies" folder.
            // This is so we compile the versions of the library built for the individual platforms, not the editor version.
            var oldOutputDir = EditorCompilationInterface.GetCompileScriptsOutputDirectory();

            try
            {
                EditorCompilationInterface.SetCompileScriptsOutputDirectory(LibraryPlayerScriptAssemblies);

                // We can't use CompilationPipeline.GetAssemblies(AssembliesType.Player)
                // because when you click "Run all in player" in the Test Runner window, PlayMode tab,
                // we need to include the test assembly.

                var compilationOptions = EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions();

                if (report.summary.options.HasFlag(BuildOptions.IncludeTestAssemblies))
                {
                    compilationOptions |= EditorScriptCompilationOptions.BuildingIncludingTestAssemblies;
                }

#if UNITY_2019_2_OR_NEWER
                return(CompilationPipeline.GetPlayerAssemblies(EditorCompilationInterface.Instance, compilationOptions, null));
#else
                return(CompilationPipeline.GetPlayerAssemblies(EditorCompilationInterface.Instance, compilationOptions));
#endif
            }
            finally
            {
                EditorCompilationInterface.SetCompileScriptsOutputDirectory(oldOutputDir);  // restore output directory back to original value
            }
        }
Beispiel #5
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();
 }
Beispiel #6
0
        private static JSONValue JsonForProject()
        {
            List <ProjectStateRestHandler.Island> list = (from i in EditorCompilationInterface.GetAllMonoIslands()
                                                          select new ProjectStateRestHandler.Island
            {
                MonoIsland = i,
                Name = Path.GetFileNameWithoutExtension(i._output),
                References = i._references.ToList <string>()
            }).ToList <ProjectStateRestHandler.Island>();

            foreach (ProjectStateRestHandler.Island current in list)
            {
                List <string> list2 = new List <string>();
                List <string> list3 = new List <string>();
                foreach (string current2 in current.References)
                {
                    string refName = Path.GetFileNameWithoutExtension(current2);
                    if (current2.StartsWith("Library/") && list.Any((ProjectStateRestHandler.Island i) => i.Name == refName))
                    {
                        list2.Add(refName);
                        list3.Add(current2);
                    }
                    if (current2.EndsWith("/UnityEditor.dll") || current2.EndsWith("/UnityEngine.dll") || current2.EndsWith("\\UnityEditor.dll") || current2.EndsWith("\\UnityEngine.dll"))
                    {
                        list3.Add(current2);
                    }
                }
                current.References.Add(InternalEditorUtility.GetEditorAssemblyPath());
                current.References.Add(InternalEditorUtility.GetEngineAssemblyPath());
                foreach (string current3 in list2)
                {
                    current.References.Add(current3);
                }
                foreach (string current4 in list3)
                {
                    current.References.Remove(current4);
                }
            }
            string[]  array   = list.SelectMany((ProjectStateRestHandler.Island i) => i.MonoIsland._files).Concat(ProjectStateRestHandler.GetAllSupportedFiles()).Distinct <string>().ToArray <string>();
            string[]  strings = ProjectStateRestHandler.RelativeToProjectPath(ProjectStateRestHandler.FindEmptyDirectories(ProjectStateRestHandler.AssetsPath, array));
            JSONValue result  = default(JSONValue);

            result["islands"] = new JSONValue((from i in list
                                               select ProjectStateRestHandler.JsonForIsland(i) into i2
                                               where !i2.IsNull()
                                               select i2).ToList <JSONValue>());
            result["basedirectory"] = ProjectStateRestHandler.ProjectPath;
            JSONValue value = default(JSONValue);

            value["files"]            = JSONHandler.ToJSON(array);
            value["emptydirectories"] = JSONHandler.ToJSON(strings);
            result["assetdatabase"]   = value;
            return(result);
        }
        /// <summary>
        /// Method called by the UI when the "Build" or "Build and Run" buttons are pressed.
        /// </summary>
        /// <param name="defaultBuildOptions"></param>
        internal static void CallBuildMethods(bool askForBuildLocation, BuildOptions defaultBuildOptions)
        {
            if (EditorCompilationInterface.IsCompiling())
            {
                Debug.LogWarning("Cannot build player while editor is compiling scripts.");
                return;
            }

            // One build at a time!
            if (m_Building)
            {
                return;
            }
            try
            {
                m_Building = true;
                BuildPlayerOptions options = new BuildPlayerOptions();
                options.options = defaultBuildOptions;

                if (getBuildPlayerOptionsHandler != null)
                {
                    options = getBuildPlayerOptionsHandler(options);
                }
                else
                {
                    options = DefaultBuildMethods.GetBuildPlayerOptionsInternal(askForBuildLocation, options);
                }

                if (buildPlayerHandler != null)
                {
                    buildPlayerHandler(options);
                }
                else
                {
                    DefaultBuildMethods.BuildPlayer(options);
                }
            }
            catch (BuildMethodException e)
            {
                if (!string.IsNullOrEmpty(e.Message))
                {
                    Debug.LogError(e);
                }
            }
            finally
            {
                m_Building = false;
            }
        }
        public static Assembly[] GetAssemblies(AssembliesType assembliesType)
        {
            var options = EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions();

            switch (assembliesType)
            {
            case AssembliesType.Editor:
                return(GetEditorAssemblies(EditorCompilationInterface.Instance, options, null));

            case AssembliesType.Player:
                return(GetPlayerAssemblies(EditorCompilationInterface.Instance, options, null));

            default:
                throw new ArgumentOutOfRangeException("assembliesType");
            }
        }
Beispiel #9
0
        internal static Assembly[] GetAssemblies(EditorCompilation editorCompilation, AssembliesType assembliesType)
        {
            var options = EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions();

            switch (assembliesType)
            {
            case AssembliesType.Editor:
                return(GetEditorAssemblies(editorCompilation, options | EditorScriptCompilationOptions.BuildingIncludingTestAssemblies, null));

            case AssembliesType.Player:
                return(GetPlayerAssemblies(editorCompilation, options | EditorScriptCompilationOptions.BuildingIncludingTestAssemblies, null));

            case AssembliesType.PlayerWithoutTestAssemblies:
                return(GetPlayerAssemblies(editorCompilation, options, null));

            default:
                throw new ArgumentOutOfRangeException("assembliesType");
            }
        }
Beispiel #10
0
        private static JSONValue JsonForProject()
        {
            var islands = EditorCompilationInterface.GetAllMonoIslands().Select(i => new Island
            {
                MonoIsland = i,
                Name       = Path.GetFileNameWithoutExtension(i._output),
                References = i._references.ToList()
            }).ToList();

            // Mono islands have references to each others output location. For MD we want to have the reference
            // be to the actual project, so we are going to update the references here
            foreach (Island island in islands)
            {
                var toAdd    = new List <string>();
                var toRemove = new List <string>();

                foreach (var reference in island.References)
                {
                    var refName = Path.GetFileNameWithoutExtension(reference);

                    if (reference.StartsWith("Library/") && islands.Any(i => i.Name == refName))
                    {
                        toAdd.Add(refName);
                        toRemove.Add(reference);
                    }

                    if (reference.EndsWith("/UnityEditor.dll") || reference.EndsWith("/UnityEngine.dll") ||
                        reference.EndsWith("\\UnityEditor.dll") || reference.EndsWith("\\UnityEngine.dll"))
                    {
                        toRemove.Add(reference);
                    }
                }

                island.References.Add(InternalEditorUtility.GetEditorAssemblyPath());
                island.References.Add(InternalEditorUtility.GetEngineAssemblyPath());

                foreach (var a in toAdd)
                {
                    island.References.Add(a);
                }

                foreach (var r in toRemove)
                {
                    island.References.Remove(r);
                }
            }

            var files            = islands.SelectMany(i => i.MonoIsland._files).Concat(GetAllSupportedFiles()).Distinct().ToArray();
            var emptyDirectories = RelativeToProjectPath(FindEmptyDirectories(AssetsPath, files));

            var result = new JSONValue();

            result["islands"]       = new JSONValue(islands.Select(i => JsonForIsland(i)).Where(i2 => !i2.IsNull()).ToList());
            result["basedirectory"] = ProjectPath;

            var assetDatabase = new JSONValue();

            assetDatabase["files"]            = ToJSON(files);
            assetDatabase["emptydirectories"] = ToJSON(emptyDirectories);

            result["assetdatabase"] = assetDatabase;
            return(result);
        }
Beispiel #11
0
 public IEnumerable <MonoIsland> GetAllScriptAssemblies(Func <string, bool> shouldFileBePartOfSolution, string projectDirectory)
 {
     return(EditorCompilationInterface.Instance.GetAllScriptAssemblies(EditorScriptCompilationOptions.BuildingForEditor | EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions(), null)
            .Where(i => 0 < i.Files.Length && i.Files.Any(shouldFileBePartOfSolution))
            .Select(x => x.ToMonoIsland(EditorScriptCompilationOptions.BuildingForEditor, string.Empty, projectDirectory)).ToList());
 }
Beispiel #12
0
 public ScriptAssembly[] GetAllEditorScriptAssemblies()
 {
     return(EditorCompilationInterface.Instance.GetAllEditorScriptAssemblies(EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions()));
 }
        internal static ScriptAssembly[] GetScriptAssemblies(IEditorCompilation editorCompilation, AssembliesType assembliesType, string[] extraScriptingDefines = null)
        {
            var options = EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions(assembliesType);

            return(GetScriptAssemblies(editorCompilation, options, extraScriptingDefines));
        }
Beispiel #14
0
        public static Assembly[] GetAssemblies()
        {
            var options = EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions();

            return(GetAssemblies(EditorCompilationInterface.Instance, options));
        }
 // Do not remove. Called through reflection by Visual Studio Tools for Unity.
 // Use EditorCompilationInterface.GetAllMonoIslands internally instead of this method.
 internal static UnityEditor.Scripting.MonoIsland[] GetMonoIslands()
 {
     return(EditorCompilationInterface.GetAllMonoIslands());
 }
Beispiel #16
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.Instance.GetAllScriptAssemblies(EditorScriptCompilationOptions.BuildingForEditor | EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions())
                                               .Where(i => 0 < i.Files.Length && i.Files.Any(ShouldFileBePartOfSolution))
                                               .Select(x => x.ToMonoIsland(EditorScriptCompilationOptions.BuildingForEditor, string.Empty, _projectDirectory)).ToList();

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var monoIslands = islands.ToList();

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

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

            if (scriptEditor == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
            {
                WriteVSCodeSettingsFiles();
            }
        }
Beispiel #17
0
        private string ProjectText(MonoIsland island, SolutionSynchronizer.Mode mode, string allAssetsProject, string[] additionalDefines)
        {
            StringBuilder stringBuilder           = new StringBuilder(this.ProjectHeader(island, additionalDefines));
            List <string> list                    = new List <string>();
            List <Match>  list2                   = new List <Match>();
            bool          isBuildingEditorProject = island._output.EndsWith("-Editor.dll");

            string[] files = island._files;
            for (int i = 0; i < files.Length; i++)
            {
                string text  = files[i];
                string b     = Path.GetExtension(text).ToLower();
                string text2 = (!Path.IsPathRooted(text)) ? Path.Combine(this._projectDirectory, text) : text;
                if (".dll" != b)
                {
                    string arg = "Compile";
                    stringBuilder.AppendFormat("     <{0} Include=\"{1}\" />{2}", arg, this.EscapedRelativePathFor(text2), SolutionSynchronizer.WindowsNewline);
                }
                else
                {
                    list.Add(text2);
                }
            }
            stringBuilder.Append(allAssetsProject);
            List <string> list3 = new List <string>();

            foreach (string current in list.Union(island._references))
            {
                if (!current.EndsWith("/UnityEditor.dll") && !current.EndsWith("/UnityEngine.dll") && !current.EndsWith("\\UnityEditor.dll") && !current.EndsWith("\\UnityEngine.dll"))
                {
                    Match match = SolutionSynchronizer.scriptReferenceExpression.Match(current);
                    if (match.Success)
                    {
                        SupportedLanguage languageFromExtension = ScriptCompilers.GetLanguageFromExtension(island.GetExtensionOfSourceFiles());
                        ScriptingLanguage scriptingLanguage     = (ScriptingLanguage)Enum.Parse(typeof(ScriptingLanguage), languageFromExtension.GetLanguageName(), true);
                        if (mode == SolutionSynchronizer.Mode.UnityScriptAsUnityProj || scriptingLanguage == ScriptingLanguage.CSharp)
                        {
                            list2.Add(match);
                            continue;
                        }
                    }
                    string text3 = (!Path.IsPathRooted(current)) ? Path.Combine(this._projectDirectory, current) : current;
                    if (AssemblyHelper.IsManagedAssembly(text3))
                    {
                        if (AssemblyHelper.IsInternalAssembly(text3))
                        {
                            if (!SolutionSynchronizer.IsAdditionalInternalAssemblyReference(isBuildingEditorProject, text3))
                            {
                                continue;
                            }
                            string fileName = Path.GetFileName(text3);
                            if (list3.Contains(fileName))
                            {
                                continue;
                            }
                            list3.Add(fileName);
                        }
                        text3 = text3.Replace("\\", "/");
                        text3 = text3.Replace("\\\\", "/");
                        stringBuilder.AppendFormat(" <Reference Include=\"{0}\">{1}", Path.GetFileNameWithoutExtension(text3), SolutionSynchronizer.WindowsNewline);
                        stringBuilder.AppendFormat(" <HintPath>{0}</HintPath>{1}", text3, SolutionSynchronizer.WindowsNewline);
                        stringBuilder.AppendFormat(" </Reference>{0}", SolutionSynchronizer.WindowsNewline);
                    }
                }
            }
            if (0 < list2.Count)
            {
                stringBuilder.AppendLine("  </ItemGroup>");
                stringBuilder.AppendLine("  <ItemGroup>");
                foreach (Match current2 in list2)
                {
                    EditorBuildRules.TargetAssembly targetAssemblyDetails = EditorCompilationInterface.GetTargetAssemblyDetails(current2.Groups["dllname"].Value);
                    ScriptingLanguage language = ScriptingLanguage.None;
                    if (targetAssemblyDetails != null)
                    {
                        language = (ScriptingLanguage)Enum.Parse(typeof(ScriptingLanguage), targetAssemblyDetails.Language.GetLanguageName(), true);
                    }
                    string value = current2.Groups["project"].Value;
                    stringBuilder.AppendFormat("    <ProjectReference Include=\"{0}{1}\">{2}", value, SolutionSynchronizer.GetProjectExtension(language), SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendFormat("      <Project>{{{0}}}</Project>", this.ProjectGuid(Path.Combine("Temp", current2.Groups["project"].Value + ".dll")), SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendFormat("      <Name>{0}</Name>", value, SolutionSynchronizer.WindowsNewline);
                    stringBuilder.AppendLine("    </ProjectReference>");
                }
            }
            stringBuilder.Append(this.ProjectFooter(island));
            return(stringBuilder.ToString());
        }