Esempio n. 1
0
        /// <summary>
        /// Syncs the scripting solution if any affected files are relevant.
        /// </summary>
        /// <returns>
        /// Whether the solution was synced.
        /// </returns>
        /// <param name='affectedFiles'>
        /// A set of files whose status has changed
        /// </param>
        /// <param name="reimportedFiles">
        /// A set of files that got reimported
        /// </param>
        public bool SyncIfNeeded(List <string> affectedFiles, string[] reimportedFiles)
        {
            Profiler.BeginSample("SolutionSynchronizerSync");
            SetupProjectSupportedExtensions();

            if (!HasFilesBeenModified(affectedFiles, reimportedFiles))
            {
                Profiler.EndSample();
                return(false);
            }

            var assemblies           = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);
            var allProjectAssemblies = RelevantAssembliesForMode(assemblies).ToList();

            SyncSolution(allProjectAssemblies);

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var affectedNames         = affectedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)).Where(name => !string.IsNullOrWhiteSpace(name)).Select(name => name.Split(new [] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
            var reimportedNames       = reimportedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)).Where(name => !string.IsNullOrWhiteSpace(name)).Select(name => name.Split(new [] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
            var affectedAndReimported = new HashSet <string>(affectedNames.Concat(reimportedNames));

            foreach (var assembly in allProjectAssemblies)
            {
                if (!affectedAndReimported.Contains(assembly.name))
                {
                    continue;
                }

                SyncProject(assembly, allAssetProjectParts, ParseResponseFileData(assembly));
            }

            Profiler.EndSample();
            return(true);
        }
        /// <summary>
        /// Syncs the scripting solution if any affected files are relevant.
        /// </summary>
        /// <returns>
        /// Whether the solution was synced.
        /// </returns>
        /// <param name='affectedFiles'>
        /// A set of files whose status has changed
        /// </param>
        /// <param name="reimportedFiles">
        /// A set of files that got reimported
        /// </param>
        public bool SyncIfNeeded(List <string> affectedFiles, string[] reimportedFiles)
        {
            Profiler.BeginSample("SolutionSynchronizerSync");
            SetupProjectSupportedExtensions();

            // Don't sync if we haven't synced before
            if (SolutionExists() && HasFilesBeenModified(affectedFiles, reimportedFiles))
            {
                var assemblies           = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);
                var allProjectAssemblies = RelevantAssembliesForMode(assemblies).ToList();
                var allAssetProjectParts = GenerateAllAssetProjectParts();

                var affectedNames         = affectedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)?.Split(new [] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                var reimportedNames       = reimportedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)?.Split(new [] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                var affectedAndReimported = new HashSet <string>(affectedNames.Concat(reimportedNames));
                var assemblyNames         = new HashSet <string>(allProjectAssemblies.Select(assembly => Path.GetFileName(assembly.outputPath)));

                foreach (var assembly in allProjectAssemblies)
                {
                    if (!affectedAndReimported.Contains(assembly.name))
                    {
                        continue;
                    }

                    SyncProject(assembly, allAssetProjectParts, ParseResponseFileData(assembly), assemblyNames);
                }

                Profiler.EndSample();
                return(true);
            }

            Profiler.EndSample();
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Syncs the scripting solution if any affected files are relevant.
        /// </summary>
        /// <returns>
        /// Whether the solution was synced.
        /// </returns>
        /// <param name='affectedFiles'>
        /// A set of files whose status has changed
        /// </param>
        /// <param name="reimportedFiles">
        /// A set of files that got reimported
        /// </param>
        public bool SyncIfNeeded(IEnumerable <string> affectedFiles, IEnumerable <string> reimportedFiles)
        {
            using (solutionSyncMarker.Auto())
            {
                // We need the exact VS version/capabilities to tweak project generation (analyzers/langversion)
                RefreshCurrentInstallation();

                SetupProjectSupportedExtensions();

                // See https://devblogs.microsoft.com/setup/configure-visual-studio-across-your-organization-with-vsconfig/
                // We create a .vsconfig file to make sure our ManagedGame workload is installed
                CreateVsConfigIfNotFound();

                // Don't sync if we haven't synced before
                var affected   = affectedFiles as ICollection <string> ?? affectedFiles.ToArray();
                var reimported = reimportedFiles as ICollection <string> ?? reimportedFiles.ToArray();
                if (!HasFilesBeenModified(affected, reimported))
                {
                    return(false);
                }

                var assemblies           = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);
                var allProjectAssemblies = RelevantAssembliesForMode(assemblies).ToList();
                SyncSolution(allProjectAssemblies);

                var allAssetProjectParts = GenerateAllAssetProjectParts();

                var affectedNames = affected
                                    .Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset))
                                    .Where(name => !string.IsNullOrWhiteSpace(name)).Select(name =>
                                                                                            name.Split(new[] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                var reimportedNames = reimported
                                      .Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset))
                                      .Where(name => !string.IsNullOrWhiteSpace(name)).Select(name =>
                                                                                              name.Split(new[] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                var affectedAndReimported = new HashSet <string>(affectedNames.Concat(reimportedNames));

                foreach (var assembly in allProjectAssemblies)
                {
                    if (!affectedAndReimported.Contains(assembly.name))
                    {
                        continue;
                    }

                    SyncProject(assembly,
                                allAssetProjectParts,
                                responseFilesData: ParseResponseFileData(assembly).ToArray());
                }

                return(true);
            }
        }
Esempio n. 4
0
        Dictionary <string, string> GenerateAllAssetProjectParts()
        {
            Dictionary <string, StringBuilder> stringBuilders = new Dictionary <string, StringBuilder>();

            foreach (string asset in m_assemblyNameProvider.GetAllAssetPaths())
            {
                // Exclude files coming from packages except if they are internalized.
                if (!m_ShouldGenerateAll && IsNonInternalizedPackagePath(asset))
                {
                    continue;
                }
                string extension = Path.GetExtension(asset);
                if (IsSupportedExtension(extension) && ScriptingLanguage.None == ScriptingLanguageFor(extension))
                {
                    // Find assembly the asset belongs to by adding script extension and using compilation pipeline.
                    var assemblyName = m_assemblyNameProvider.GetAssemblyNameFromScriptPath(asset + ".cs");
                    assemblyName = assemblyName ?? m_assemblyNameProvider.GetAssemblyNameFromScriptPath(asset + ".js");
                    assemblyName = assemblyName ?? m_assemblyNameProvider.GetAssemblyNameFromScriptPath(asset + ".boo");

                    if (string.IsNullOrEmpty(assemblyName))
                    {
                        continue;
                    }

                    assemblyName = Utility.FileNameWithoutExtension(assemblyName);

                    StringBuilder projectBuilder = null;

                    if (!stringBuilders.TryGetValue(assemblyName, out projectBuilder))
                    {
                        projectBuilder = new StringBuilder();
                        stringBuilders[assemblyName] = projectBuilder;
                    }

                    projectBuilder.Append("     <None Include=\"").Append(EscapedRelativePathFor(asset)).Append("\" />").Append(WindowsNewline);
                }
            }

            var result = new Dictionary <string, string>();

            foreach (var entry in stringBuilders)
            {
                result[entry.Key] = entry.Value.ToString();
            }

            return(result);
        }
        private Dictionary <string, string> GenerateAllAssetProjectParts()
        {
            var stringBuilders = new Dictionary <string, StringBuilder>();

            foreach (var asset in m_AssemblyNameProvider.GetAllAssetPaths())
            {
                // Exclude files coming from packages except if they are internalized.
                if (m_AssemblyNameProvider.IsInternalizedPackagePath(asset))
                {
                    continue;
                }

                var extension = Path.GetExtension(asset);
                if (IsSupportedExtension(extension) && !extension.Equals(".cs", StringComparison.OrdinalIgnoreCase))
                {
                    // Find assembly the asset belongs to by adding script extension and using compilation pipeline.
                    var assemblyName = m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset + ".cs");

                    if (string.IsNullOrEmpty(assemblyName))
                    {
                        continue;
                    }

                    assemblyName = FileSystemUtil.FileNameWithoutExtension(assemblyName);

                    if (!stringBuilders.TryGetValue(assemblyName, out var projectBuilder))
                    {
                        projectBuilder = new StringBuilder();
                        stringBuilders[assemblyName] = projectBuilder;
                    }

                    projectBuilder.Append("     <None Include=\"").Append(EscapedRelativePathFor(asset)).Append("\" />")
                    .Append(Environment.NewLine);
                }
            }

            var result = new Dictionary <string, string>();

            foreach (var entry in stringBuilders)
            {
                result[entry.Key] = entry.Value.ToString();
            }

            return(result);
        }