Ejemplo n.º 1
0
        public override ProjectInfo ReadWrite(string projectFileName, SolutionInfo solutionInfo, XDocument projectDocument, bool performReadOnly)
        {
            SolutionConfigManager.ProjectConfig projectConfig = solutionInfo.ConfigManager.GetProjectByFileName(projectFileName);
            if (null == projectConfig)
            {
                throw new InvalidDataException("Couldn't find project " + projectFileName + " in solution " + solutionInfo.Name);
            }

            XNamespace ns             = projectDocument.Root.Name.Namespace;
            XElement   projectElement = GetProjectElement(projectFileName, ns, projectDocument);

            // Determine the project name and ensure the generated RudeBuild project has a ProjectName element.
            string   projectName = Path.GetFileNameWithoutExtension(projectFileName);
            XElement globalPropertyGroupElement = GetGlobalProjectPropertyGroupElement(projectFileName, ns, projectElement);
            XElement projectNameElement         = globalPropertyGroupElement.Element(ns + "ProjectName");

            if (projectNameElement == null)
            {
                globalPropertyGroupElement.Add(new XElement(ns + "ProjectName", projectName));
            }
            else
            {
                projectName = projectNameElement.Value;
            }

            var compileItemGroupElements    = GetCompileItemGroupElements(ns, projectElement);
            var mergableCppFileNames        = new List <string>();
            var mergableCppFileNameElements = new List <XElement>();

            foreach (var compileItemGroupElement in compileItemGroupElements)
            {
                mergableCppFileNameElements.AddRange(
                    from compileElement in compileItemGroupElement.Elements(ns + "ClCompile")
                    where IsMergableCppFileElement(projectConfig, ns, compileElement, "Include")
                    select compileElement);
            }
            mergableCppFileNames.AddRange(
                from compileElement in mergableCppFileNameElements
                select compileElement.Attribute("Include").Value);

            IList <string> allCppFileNames       = GetAllCppFileNames(ns, projectElement);
            IList <string> allIncludeFileNames   = GetAllIncludeFileNames(ns, projectElement);
            string         precompiledHeaderName = GetPrecompiledHeader(projectConfig, projectDocument, ns);
            var            projectInfo           = new ProjectInfo(solutionInfo, projectName, projectFileName, mergableCppFileNames, allCppFileNames, allIncludeFileNames, precompiledHeaderName);

            if (!performReadOnly)
            {
                var merger = new UnityFileMerger(_settings);
                merger.Process(projectInfo);

                foreach (XElement cppFileNameElement in mergableCppFileNameElements)
                {
                    string cppFileName = cppFileNameElement.Attribute("Include").Value;
                    if (merger.MergedCppFileNames.Contains(cppFileName))
                    {
                        AddExcludedFromBuild(ns, cppFileNameElement);
                    }
                }

                if (compileItemGroupElements.Count() > 0)
                {
                    compileItemGroupElements.First().Add(
                        from unityFileName in merger.UnityFilePaths
                        select new XElement(ns + "ClCompile", new XAttribute("Include", unityFileName)));
                }

                if (ShouldDisablePrecompiledHeaders(projectInfo))
                {
                    DisablePrecompiledHeaders(projectDocument, ns);
                }
                if (_settings.SolutionSettings.SetBigObjCompilerFlag)
                {
                    SetBigObjCompilerFlag(projectDocument, ns);
                }

                if (!string.IsNullOrEmpty(_settings.GlobalSettings.IntDirSuffix))
                {
                    SetIntDir(ns, projectElement, _settings.GlobalSettings.IntDirSuffix);
                }

                FixupProjectReferences(projectDocument, ns, _settings);

                ReadWriteFilters(projectFileName, projectConfig, merger);
            }

            return(projectInfo);
        }
Ejemplo n.º 2
0
        public override ProjectInfo ReadWrite(string projectFileName, SolutionInfo solutionInfo, XDocument projectDocument, bool performReadOnly)
        {
            SolutionConfigManager.ProjectConfig projectConfig = solutionInfo.ConfigManager.GetProjectByFileName(projectFileName);
            if (null == projectConfig)
            {
                throw new InvalidDataException("Couldn't find project " + projectFileName + " in solution " + solutionInfo.Name);
            }

            XNamespace ns = projectDocument.Root.Name.Namespace;

            var fileElements            = projectDocument.Descendants(ns + "File").ToList();
            var mergableCppFileElements =
                (from element in fileElements
                 where IsMergableCppFileElement(projectConfig, ns, element, "RelativePath")
                 select element).ToList();
            var mergableCppFileNames =
                from cppFileElement in mergableCppFileElements
                select cppFileElement.Attribute("RelativePath").Value;

            var allCppFileNames =
                from element in fileElements
                where IsValidCppFileElement(ns, element, "RelativePath")
                select element.Attribute("RelativePath").Value;

            var allIncludeFileNames =
                from element in fileElements
                where IsValidIncludeFileElement(ns, element, "RelativePath")
                select element.Attribute("RelativePath").Value;

            string projectName           = Path.GetFileNameWithoutExtension(projectFileName);
            string precompiledHeaderName = GetPrecompiledHeader(projectConfig, projectDocument, ns);
            var    projectInfo           = new ProjectInfo(solutionInfo, projectName, projectFileName, mergableCppFileNames.ToList(), allCppFileNames.ToList(), allIncludeFileNames.ToList(), precompiledHeaderName);

            if (!performReadOnly)
            {
                var merger = new UnityFileMerger(_settings);
                merger.Process(projectInfo);

                foreach (XElement cppFileNameElement in mergableCppFileElements)
                {
                    string cppFileName = cppFileNameElement.Attribute("RelativePath").Value;
                    if (merger.MergedCppFileNames.Contains(cppFileName))
                    {
                        cppFileNameElement.Remove();
                    }
                }

                XElement filesElement = projectDocument.Descendants(ns + "Files").Single();
                filesElement.Add(
                    from unityFileName in merger.UnityFilePaths
                    select new XElement(ns + "File", new XAttribute("RelativePath", unityFileName)));

                if (ShouldDisablePrecompiledHeaders(projectInfo))
                {
                    DisablePrecompiledHeaders(projectDocument, ns);
                }
                if (_settings.SolutionSettings.SetBigObjCompilerFlag)
                {
                    SetBigObjCompilerFlag(projectDocument, ns);
                }
            }

            return(projectInfo);
        }
Ejemplo n.º 3
0
        private void ReadWriteFilters(string projectFileName, SolutionConfigManager.ProjectConfig projectConfig, UnityFileMerger merger)
        {
            string projectFiltersFileName = projectFileName + ".filters";

            if (!File.Exists(projectFiltersFileName))
            {
                return;
            }

            XDocument projectFiltersDocument = XDocument.Load(projectFiltersFileName);

            if (null == projectFiltersDocument)
            {
                throw new InvalidDataException("Couldn't load project filters file '" + projectFiltersFileName + "'.");
            }

            XNamespace ns                       = projectFiltersDocument.Root.Name.Namespace;
            XElement   projectElement           = GetProjectElement(projectFileName, ns, projectFiltersDocument);
            var        compileItemGroupElements = GetCompileItemGroupElements(ns, projectElement);

            if (compileItemGroupElements.Count() > 0)
            {
                compileItemGroupElements.First().Add(
                    from unityFileName in merger.UnityFilePaths
                    select new XElement(ns + "ClCompile", new XAttribute("Include", unityFileName)));
            }

            string destProjectFiltersFileName = _settings.ModifyFileName(projectFiltersFileName);
            var    writer = new ModifiedTextFileWriter(destProjectFiltersFileName, _settings.BuildOptions.ShouldForceWriteCachedFiles());

            if (writer.Write(projectFiltersDocument.ToString()))
            {
                _settings.Output.WriteLine("Creating project filters file " + destProjectFiltersFileName);
            }
        }