示例#1
0
        public static void CreateNewTranslationFile(EnvDTE.Project project)
        {
            if (project == null)
            {
                return;
            }

            AddTranslationDialog transDlg = new AddTranslationDialog(project);

            if (transDlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    QtProject qtPro = QtProject.Create(project);
                    VCFile    file  = qtPro.AddFileInFilter(Filters.TranslationFiles(), transDlg.TranslationFile, true);
                    Translation.RunlUpdate(file, project);
                }
                catch (QtVSException e)
                {
                    Messages.DisplayErrorMessage(e.Message);
                }
                catch (System.Exception ex)
                {
                    Messages.DisplayErrorMessage(ex.Message);
                }
            }
        }
        public Boolean RemoveIncludes(VCFile oFile)
        {
            Boolean bRetVal = false;
            if (oFile.Extension != ".cpp" ||
                oFile.Name.ToLowerInvariant().Contains("stdafx.cpp"))
            {
                return bRetVal;
            }

            if (Utilities.IsThirdPartyFile(oFile.FullPath, Utilities.GetCurrentConfiguration((VCProject)oFile.project)))
            {
                return bRetVal;
            }

            if (!Utilities.CompileFile(oFile, true))
            {
                mLogger.PrintMessage("ERROR: File '" + oFile.Name + "' must be in a compilable condition before you proceed! Aborting...");
                return bRetVal;
            }
            try
            {
                SortedDictionary<IncludesKey, VCCodeInclude> oIncludes = new SortedDictionary<IncludesKey, VCCodeInclude>();
                List<String> SkipFiles = new List<String>();
                Utilities.RetrieveIncludes(oFile, ref oIncludes);
                Utilities.RetrieveFilesToSkip(oFile, ref SkipFiles);

                foreach (VCCodeInclude oCI in oIncludes.Values)
                {
                    IncludeStructEx oInc = null;
                    Boolean isLocal = Utilities.IsLocalFile(oCI, ref oInc);
                    if (oInc != null && SkipFiles.Contains(oInc.sFullPath.ToUpperInvariant()))
                    {
                        continue;
                    }
                    String sIncludeFile = oCI.FullName;
                    TextPoint oStartPoint = oCI.StartPoint;
                    EditPoint oEditPoint = oStartPoint.CreateEditPoint();
                    String sOrigText = oEditPoint.GetText(oCI.EndPoint);
                    oEditPoint.Insert("//");
                    Utilities.SaveFile((ProjectItem)oFile.Object);
                    if (!Utilities.CompileFile(oFile))
                    {
                        oEditPoint.ReplaceText(oStartPoint, "", (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
                        Utilities.SaveFile((ProjectItem)oFile.Object);
                    }
                    else
                    {
                        mLogger.PrintMessage("Dirrective " + sOrigText + " in file " + oFile.Name + " has been found as unnesessary and removed.");
                        bRetVal = true;
                    }
                }
                if (bRetVal)
                    bRetVal = RemoveIncludes(oFile);
            }
            catch (SystemException ex)
            {
                String msg = ex.Message;
            }
            return bRetVal;
        }
示例#3
0
        public void AnalyzeFile(Solution solution, VCFile vcFile, VCConfiguration vcConfiguration)
        {
            try
            {
                ts.TraceInformation("AnalyzeFile");
                ts.TraceInformation("AnalyzeFile name " + vcFile.Name);
                ts.TraceInformation("AnalyzeFile item name " + vcFile.ItemName);
                ts.TraceInformation("AnalyzeFile item type " + vcFile.ItemType);
                ts.TraceInformation("AnalyzeFile extension " + vcFile.Extension);
                ts.TraceInformation("AnalyzeFile config name " + vcConfiguration.ConfigurationName);
                ts.TraceInformation("AnalyzeFile config type " + vcConfiguration.ConfigurationType);
                _analyzeType = AnalyzeType.FILE;

                _solution        = solution;
                _vcFile          = vcFile;
                _vcConfiguration = vcConfiguration;
                _report          = Reporting.ReportFactory.CreateReportSingleFile(solution, vcFile);

                OnStartAnalyze();
                DoAnalyzeFile(vcFile, vcConfiguration);
            }

            catch (Exception exception)
            {
                ts.TraceData(TraceEventType.Error, 1, "AnalyzeFile exception: " + exception.Message);
                OnStopFile(true);
            }
        }
示例#4
0
        /// <summary>
        /// Excludes all stubbed hlsl files from building
        /// </summary>
        /// <param name="project">Project to exclude </param>
        public static void DisableHlslFiles(Project project, Action <string> outputFunction = null)
        {
            if (!(project.Object is VCProject))
            {
                return;
            }

            VCProject vcProject = project.Object as VCProject;

            foreach (var item in vcProject.Files)
            {
                if (item is VCFile)
                {
                    VCFile file = item as VCFile;

                    string fileExtension = Path.GetExtension(file.Name.ToLower());
                    if (fileExtension == null || (fileExtension != ".hlsl" && fileExtension != ".hlsli"))
                    {
                        continue;
                    }

                    if (!Utils.FileContainsSolution(file.FullPath))
                    {
                        continue;
                    }

                    if (outputFunction != null)
                    {
                        outputFunction("Setting item type to None for: " + file.Name + "\n");
                    }

                    file.ItemType = "None";
                }
            }
        }
示例#5
0
        public void Compile(VCFile file)
        {
            VCConfiguration     configuration     = file.project.ActiveConfiguration;
            VCFileConfiguration fileConfiguration = file.GetFileConfigurationForProjectConfiguration(configuration);

            string toolchainConfDirs = configuration.Platform.ExecutableDirectories;

            toolchainConfDirs = configuration.Evaluate(toolchainConfDirs);

            string[] toolchainDirs = toolchainConfDirs.Split(ConfigurationSeparators,
                                                             StringSplitOptions.RemoveEmptyEntries);

            VCCLCompilerTool cl = fileConfiguration.Tool;

            foreach (string dir in toolchainDirs)
            {
                string compilerPath = Path.Combine(dir, cl.ToolPath);
                if (File.Exists(compilerPath))
                {
                    EnsureAsmDirectoryExists(configuration);

                    string compilerQuotedPath = CLCommandLineBuilder.SurroundWithQuotes(compilerPath);
                    string filePath           = CLCommandLineBuilder.SurroundWithQuotes(file.FullPath);
                    string args = ComposeCommandLine(file, cl);
                    Compile(compilerQuotedPath, args + " " + filePath, file);
                    return;
                }
            }

            OnMissingCompiler();
        }
示例#6
0
        public static bool RunlRelease(VCFile vcFile)
        {
            bool success = true;

            try
            {
                VCProject vcProject = vcFile.project as VCProject;
                string    cmdLine   = "";
                if (HelperFunctions.IsQtProject(vcProject))
                {
                    string options = QtVSIPSettings.GetLReleaseOptions();
                    if (!string.IsNullOrEmpty(options))
                    {
                        cmdLine += options + " ";
                    }
                }
                EnvDTE.Project project = vcProject.Object as EnvDTE.Project;
                Messages.PaneMessage(project.DTE,
                                     "--- (lrelease) file: " + vcFile.FullPath);

                cmdLine += vcFile.RelativePath;
                HelperFunctions.StartExternalQtApplication(Resources.lreleaseCommand, cmdLine,
                                                           vcProject.ProjectDirectory, HelperFunctions.GetSelectedQtProject(project.DTE), true,
                                                           null);
            }
            catch (QtVSException e)
            {
                success = false;
                Messages.DisplayErrorMessage(e.Message);
            }

            return(success);
        }
示例#7
0
        private void AnalyzeCurrentFile()
        {
            ts.TraceInformation("AnalyzeCurrentFile");

            try
            {
                VCFile vcFile = DTE2Utils.GetVcCppFile(_applicationObject.ActiveDocument);
                if (vcFile == null)
                {
                    return;
                }

                VCConfiguration vcConfiguration = DTE2Utils.GetVcConfigurationForDocument(_applicationObject.ActiveDocument, vcFile.project);
                if (vcConfiguration == null)
                {
                    return;
                }

                ClangAnalyzer.AnalyzeFile(_applicationObject.Solution, vcFile, vcConfiguration);
            }
            catch (Exception exception)
            {
                ts.TraceData(TraceEventType.Error, 1, "AnalyzeFile exception: " + exception.Message);
                MessageBox.Show(exception.Message, _addInName + " System Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
示例#8
0
        public static bool RunlRelease(VCFile vcFile)
        {
            if (vcFile == null)
            {
                return(false);
            }

            var success = true;

            try {
                var vcProject = vcFile.project as VCProject;
                var cmdLine   = string.Empty;
                if (HelperFunctions.IsQtProject(vcProject))
                {
                    var options = QtVSIPSettings.GetLReleaseOptions();
                    if (!string.IsNullOrEmpty(options))
                    {
                        cmdLine += options + " ";
                    }
                }
                var project = vcProject.Object as EnvDTE.Project;
                Messages.PaneMessage(project.DTE,
                                     "--- (lrelease) file: " + vcFile.FullPath);

                cmdLine += vcFile.RelativePath.Quoute();
                StartProcess(Resources.lreleaseCommand, cmdLine, vcProject.ProjectDirectory,
                             HelperFunctions.GetSelectedQtProject(project.DTE));
            } catch (QtVSException e) {
                success = false;
                Messages.DisplayErrorMessage(e.Message);
            }

            return(success);
        }
示例#9
0
        /// <summary>
        /// Finds the collection of source files in the project.
        /// </summary>
        private void parseProject_SourceFiles()
        {
            // We loop through the collection of files in the project...
            IVCCollection files    = Utils.call(() => (m_vcProject.Files as IVCCollection));
            int           numFiles = Utils.call(() => (files.Count));

            for (int i = 1; i <= numFiles; ++i)
            {
                // We get one file...
                VCFile file      = Utils.call(() => (files.Item(i) as VCFile));
                string path      = Utils.call(() => (file.FullPath));
                string extension = Path.GetExtension(path).ToLower();

                // We check if the file has a custom build rule...
                parseCustomBuildRule(file);

                // We find the extension, and see if it is one we treat
                // as a source file...
                switch (extension)
                {
                // It looks like a source file...
                case ".cpp":
                case ".c":
                case ".cc":
                case ".cp":
                case ".cxx":
                case ".c++":
                    // We add it to the project...
                    string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, path);
                    m_projectInfo.addFile(relativePath);
                    break;
                }
            }
        }
示例#10
0
        void Compile(string cl, string args, VCFile file)
        {
            Process process = new Process();

            process.StartInfo.FileName               = cl;
            process.StartInfo.Arguments              = args;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.WorkingDirectory       = Path.GetDirectoryName(m_dte.Solution.FullName);

            EnvDTE.Window           window       = m_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
            EnvDTE.OutputWindow     outputWindow = (EnvDTE.OutputWindow)window.Object;
            EnvDTE.OutputWindowPane buildPane    = outputWindow.OutputWindowPanes.Item(BuildPaneName);
            buildPane.Clear();
            buildPane.Activate();

            process.OutputDataReceived += (sender, eventArgs) => BuildOutputReceived(buildPane, eventArgs);

            process.Start();
            process.BeginOutputReadLine();

            OnCompilationStart();
            System.Threading.Tasks.Task.Run(() => BuildTask(process, file));
        }
示例#11
0
        static public VCFile GetVcCppFile(Document document)
        {
            if (document == null)
            {
                ts.TraceData(TraceEventType.Verbose, 1, "GetCppFile no active document");
                return(null);
            }

            ts.TraceData(TraceEventType.Verbose, 1, "GetCppFile full name " + document.FullName);

            if (document.Language != "C/C++")
            {
                ts.TraceData(TraceEventType.Verbose, 1, "GetCppFile not a C/C++ but " + document.Language);
                return(null);
            }

            ProjectItem projectItem = document.ProjectItem;
            VCFile      vcFile      = projectItem.Object as VCFile;

            if (vcFile == null)
            {
                ts.TraceData(TraceEventType.Verbose, 1, "GetCppFile not a VCFile");
                return(null);
            }

            if (vcFile.FileType != eFileType.eFileTypeCppCode)
            {
                ts.TraceData(TraceEventType.Verbose, 1, "GetCppFile not a C++ file : " + vcFile.FileType);
                return(null);
            }

            ts.TraceData(TraceEventType.Verbose, 1, "GetCppFile found cpp");
            return(vcFile);
        }
示例#12
0
        void OnCompilationSuccess(VCFile file)
        {
            OnCompilationEnd("Asm compilation successful.");

            VCProject project = file.project;

            string dir         = project.ActiveConfiguration.Evaluate(OutputAsmDir);
            string filename    = Path.ChangeExtension(file.Name, "asm");
            string solutionDir = Path.GetDirectoryName(m_dte.Solution.FullName);

            string path = Path.Combine(solutionDir, dir, filename);
            string text = File.ReadAllText(path);

            CLx64AsmParser parser  = new CLx64AsmParser();
            AsmUnit        asmUnit = parser.Parse(text);

            foreach (KeyValuePair <string, AsmFile> filePair in asmUnit.Files)
            {
                string  fileName = filePair.Key;
                AsmFile asmFile  = filePair.Value;

                if (m_asm.ContainsKey(fileName))
                {
                    UpdateFile(m_asm[fileName], asmFile);
                }
                else
                {
                    m_asm[fileName] = asmFile;
                }
            }

            m_view.OnDocumentChanged();
        }
示例#13
0
        /// <summary>
        /// compile a single VCFile, do nothing with the OBJ
        /// </summary>
        public bool CompileSingleFile(VCFile vcFile, VCProject vcProject, VCConfiguration vcCfg,
                                      String additionalCmds = "")
        {
            CVXBuildSystem buildSystem;

            try
            {
                buildSystem = new CVXBuildSystem(_vsOutputWindow, _outputPane);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ClangVSx Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            String prevEnv = Environment.CurrentDirectory;

            try
            {
                Environment.CurrentDirectory = vcProject.ProjectDirectory;
                WriteToOutputPane("Project Directory : " + Environment.CurrentDirectory + "\n");

                return(buildSystem.CompileSingleFile(vcFile, vcProject, vcCfg, additionalCmds));
            }
            catch (Exception ex)
            {
                WriteToOutputPane("Exception During File Compile : \n" + ex.Message + "\n");
            }
            finally
            {
                Environment.CurrentDirectory = prevEnv;
            }

            return(false);
        }
示例#14
0
        /// <summary>
        /// compile a single VCFile, do nothing with the OBJ
        /// </summary>
        public bool CompileSingleFile(VCFile vcFile, VCProject vcProject, VCConfiguration vcCfg, String additionalCmds = "")
        {
            CVXBuildSystem buildSystem;

            try
            {
                buildSystem = new CVXBuildSystem(_vsOutputWindow, _outputPane);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "ClangVSx Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            try
            {
                return(buildSystem.CompileSingleFile(vcFile, vcProject, vcCfg, additionalCmds));
            }
            catch (System.Exception ex)
            {
                WriteToOutputPane("Exception During File Compile : \n" + ex.Message + "\n");
            }

            return(false);
        }
示例#15
0
        public static void RunlUpdate(EnvDTE.Project project)
        {
            QtProject qtPro = QtProject.Create(project);

            if (qtPro == null)
            {
                return;
            }

            FakeFilter ts       = Filters.TranslationFiles();
            VCFilter   tsFilter = qtPro.FindFilterFromGuid(ts.UniqueIdentifier);

            if (tsFilter == null)
            {
                return;
            }

            IVCCollection files = tsFilter.Files as IVCCollection;

            foreach (VCFile file in files)
            {
                VCFile vcFile = file as VCFile;
                if (HelperFunctions.IsTranslationFile(vcFile))
                {
                    if (!RunlUpdate(vcFile, project))
                    {
                        return;
                    }
                }
            }
        }
示例#16
0
        private String GetProcessArgument(VCFile vcFile, VCConfiguration vcConfiguration)
        {
            VCFileConfiguration vcFileConfiguration = DTE2Utils.GetVcFileConfiguration(vcFile, vcConfiguration);

            if (vcFileConfiguration == null)
            {
                ts.TraceData(TraceEventType.Error, 1, "GetProcessArgument cannot get VcFileConfiguration ");
                return("");
            }

            StringBuilder stringBuilder = new StringBuilder();

            //stringBuilder.Append(" -Xclang -analyzer-display-progress ");
            stringBuilder.Append(" --analyze ");


            //stringBuilder.Append(" -o " + GetReportFile() + " ");

            if (!vcFile.Name.EndsWith(".c"))
            {
                stringBuilder.Append(" -x c++ ");
            }
            stringBuilder.Append(DTE2Utils.GetIncludesForProject(vcConfiguration));
            stringBuilder.Append(DTE2Utils.GetDefinesForProject(vcConfiguration));
            stringBuilder.Append(DTE2Utils.GetIncludesForFile(vcFileConfiguration));
            stringBuilder.Append(DTE2Utils.GetDefinesForFile(vcFileConfiguration));
            stringBuilder.Append(GetArgumentMicrosoftCompilerSpecific());

            stringBuilder.Append(" -pedantic ");
            stringBuilder.Append(" -ferror-limit=0 ");

            stringBuilder.Append("\"" + vcFile.FullPath + "\"");
            return(stringBuilder.ToString());
        }
示例#17
0
        /// <summary>
        /// Get the active code file, project and configuration
        /// </summary>
        /// <returns>true if we have found an active C/C++ document</returns>
        private bool GetActiveVCFile(out VCFile vcFile, out VCProject vcProject, out VCConfiguration vcCfg)
        {
            vcFile    = null;
            vcProject = null;
            vcCfg     = null;

            if (_applicationObject.ActiveDocument != null)
            {
                // GUID equates to 'code file' as far as I can make out
                if (_applicationObject.ActiveDocument.Kind == "{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}" &&
                    _applicationObject.ActiveDocument.Language == "C/C++")
                {
                    // GUID equates to physical file on disk [http://msdn.microsoft.com/en-us/library/z4bcch80(VS.80).aspx]
                    if (_applicationObject.ActiveDocument.ProjectItem.Kind == "{6BB5F8EE-4483-11D3-8BCF-00C04F8EC28C}")
                    {
                        // leap of faith
                        vcFile    = (VCFile)_applicationObject.ActiveDocument.ProjectItem.Object;
                        vcProject = (VCProject)vcFile.project;

                        if (vcFile.FileType != eFileType.eFileTypeCppCode && // *.cpp
                            vcFile.FileType != eFileType.eFileTypeCppHeader) // *.h
                        {
                            return(false);
                        }

                        // save the file (should be optional!)
                        if (!_applicationObject.ActiveDocument.Saved)
                        {
                            _applicationObject.ActiveDocument.Save(vcFile.FullPath);
                        }

                        // get current configuration to pass to the bridge
                        Configuration cfg =
                            _applicationObject.ActiveDocument.ProjectItem.ConfigurationManager.ActiveConfiguration;

                        try
                        {
                            var cfgArray = (IVCCollection)vcProject.Configurations;
                            foreach (VCConfiguration vcr in cfgArray)
                            {
                                if (vcr.ConfigurationName == cfg.ConfigurationName &&
                                    vcr.Platform.Name == cfg.PlatformName)
                                {
                                    vcCfg = vcr;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            return(false);
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
示例#18
0
 static public void SaveCurrentDocument(Document document, VCFile vcFile)
 {
     ts.TraceInformation("Save " + vcFile.FullPath);
     if (!document.Saved)
     {
         document.Save(vcFile.FullPath);
     }
 }
示例#19
0
 public VCFile(VCFile template)
 {
     mFileState1 = template.fileState1;
     mFileState2 = template.fileState2;
     mName1      = template.name1;
     mName2      = template.name2;
     mPath1      = template.path1;
     mPath2      = template.path2;
 }
示例#20
0
        public void Move(ContainerWrapper newParent)
        {
            if (!VCFile.CanMove(newParent.VCProjectItem))
            {
                throw new InvalidOperationException();
            }

            VCFile.Move(newParent.VCProjectItem);
        }
示例#21
0
 public VCFile(VCFile template)
 {
     mFileState1 = template.fileState1;
     mFileState2 = template.fileState2;
     mName1 = template.name1;
     mName2 = template.name2;
     mPath1 = template.path1;
     mPath2 = template.path2;
 }
示例#22
0
        public static void SetExcludedFromBuild(VCFile file, string config, bool excluded)
        {
            VCFileConfiguration cfg = Connect.GetFileConfiguration(file, config);

            if (cfg != null)
            {
                cfg.ExcludedFromBuild = excluded;
            }
        }
示例#23
0
        public List <string> FindListOfIncludeDirectories()
        {
            List <string> files = new List <string>();

            IEnumerator e = GetVCProjectRefs();

            e.Reset();
            while (e.MoveNext())
            {
                VCProject     actVCP          = (VCProject)e.Current;
                IVCCollection filesCollection = (IVCCollection)actVCP.Files;
                if (filesCollection != null)
                {
                    for (int item_idx = 0; item_idx < filesCollection.Count + 1; ++item_idx)
                    {
                        try
                        {
                            VCFile file = (VCFile)(filesCollection.Item(item_idx));

                            if (file != null)
                            {
                                switch (file.FileType)
                                {
                                default:
                                    break;

                                case eFileType.eFileTypeCppHeader:
                                {
                                    string path  = System.IO.Path.GetDirectoryName(file.FullPath);
                                    bool   found = false;
                                    foreach (string item in files)
                                    {
                                        if (item.ToLower() == path.ToLower())
                                        {
                                            found = true;
                                            break;
                                        }
                                    }
                                    if (!found)
                                    {
                                        files.Add(path);
                                    }
                                }
                                break;
                                }
                            }
                        }
                        catch (Exception exp)
                        {
                            Debug(exp);
                        }
                    }
                }
            }
            return(files);
        }
示例#24
0
        public static void RunlUpdate(VCFile vcFile)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var vcProj  = vcFile.project as VCProject;
            var project = vcProj?.Object as EnvDTE.Project;

            RunTranslationTarget(BuildAction.Update,
                                 project, new[] { vcFile.RelativePath });
        }
示例#25
0
 private void QueueFile(List <QueueEntry> queue, VCFile src)
 {
     if (src.Parent as VCFilter != null)
     {
         queue.Add(new QueueEntry()
         {
             _vcfile = src, _vcfilter = src.Parent as VCFilter
         });
     }
 }
示例#26
0
 public RccOptions(EnvDTE.Project pro, VCFile qrcFile)
 {
     project = pro;
     id = qrcFile.RelativePath;
     qrcFileName = qrcFile.FullPath;
     name = id;
     if (id.StartsWith(".\\"))
         name = name.Substring(2);
     if (name.EndsWith(".qrc"))
         name = name.Substring(0, name.Length-4);
 }
示例#27
0
        public static string GetMocDirectory(
            EnvDTE.Project project,
            string configName,
            string platformName, VCFile vCFile)
        {
            string filePath = null;

            if (vCFile != null)
            {
                filePath = vCFile.FullPath;
            }
            return(GetMocDirectory(project, configName, platformName, filePath));
        }
示例#28
0
        public void AddGeneratedFiles(EnvDTE.Project dteProject, EnvDTE.Configuration config, string filterName,
                                      List <string> paths, bool generatedFilesPerConfiguration)
        {
            VCProject project = dteProject.Object as VCProject;

            VCFilter filter = FindOrCreateFilter(project, filterName);

            if (generatedFilesPerConfiguration)
            {
                filter = FindOrCreateFilter(filter, config.PlatformName);
                filter = FindOrCreateFilter(filter, config.ConfigurationName);
            }

            string configurationName = config.ConfigurationName;
            string platformName      = config.PlatformName;

            foreach (string path in paths)
            {
                if (!File.Exists(path))
                {
                    File.Create(path).Dispose();
                }

                VCFile file = filter.AddFile(path);

                try
                {
                    //
                    // Remove the file otherwise it will be considered up to date.
                    //
                    File.Delete(path);
                }
                catch (Exception)
                {
                }
                //
                // Exclude the file from all other configurations
                //
                if (generatedFilesPerConfiguration)
                {
                    foreach (VCFileConfiguration c in file.FileConfigurations)
                    {
                        if (!c.ProjectConfiguration.ConfigurationName.Equals(configurationName) ||
                            !c.ProjectConfiguration.Platform.Name.Equals(platformName))
                        {
                            c.ExcludedFromBuild = true;
                        }
                    }
                }
            }
        }
示例#29
0
        public void AddGeneratedFile(IVsProject project, VCFilter filter, string path, EnvDTE.Configuration config)
        {
            int  found;
            uint id;

            VSDOCUMENTPRIORITY[] priority = new VSDOCUMENTPRIORITY[1];
            project.IsDocumentInProject(path, out found, priority, out id);
            if (found == 0)
            {
                if (!Directory.Exists(Path.GetDirectoryName(path)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                }

                if (!File.Exists(path))
                {
                    File.Create(path).Dispose();
                }

                VCFile file = null;
                if (config == null)
                {
                    file = filter.AddFile(path);
                }
                else
                {
                    filter = FindOrCreateFilter(filter, config.PlatformName);
                    filter = FindOrCreateFilter(filter, config.ConfigurationName);
                    file   = filter.AddFile(path);
                    foreach (VCFileConfiguration c in file.FileConfigurations)
                    {
                        if (!c.ProjectConfiguration.ConfigurationName.Equals(config.ConfigurationName) ||
                            !c.ProjectConfiguration.Platform.Name.Equals(config.PlatformName))
                        {
                            c.ExcludedFromBuild = true;
                        }
                    }
                }

                try
                {
                    //
                    // Remove the file otherwise it will be considered up to date.
                    //
                    File.Delete(path);
                }
                catch (Exception)
                {
                }
            }
        }
示例#30
0
 private void AnalyseNextFile()
 {
     ts.TraceInformation("AnalyseNextFile project " + _vcProject.Name + ", #files still to be processed " + _vcFileQueue.Count);
     if (_vcFileQueue.Count == 0)
     {
         OnStopProject(false);
     }
     else
     {
         VCFile vcFile = _vcFileQueue.Dequeue();
         _report.NextFile();
         DoAnalyzeFile(vcFile, _vcConfiguration);
     }
 }
        private async Task <ProjectItemType> getTypeOfProjectItemAsync(ProjectItem item)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            var itemKind = item.Kind;
            var itemName = item.Name;

            switch (itemKind)
            {
            case VSConstants.ItemTypeGuid.PhysicalFolder_string:
            case VSConstants.ItemTypeGuid.VirtualFolder_string:
                return(ProjectItemType.folder);

            case "{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}":
            case VSConstants.ItemTypeGuid.PhysicalFile_string:
                if (item.ConfigurationManager != null)
                {
                    try
                    {
                        VCFile              vcFile     = item.Object as VCFile;
                        VCProject           vcProject  = item.ContainingProject.Object as VCProject;
                        VCFileConfiguration fileConfig = vcFile.FileConfigurations.Item(vcProject.ActiveConfiguration.Name);

                        if (!fileConfig.ExcludedFromBuild)
                        {
                            if (item.FileCodeModel != null && item.FileCodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVC)
                            {
                                switch (vcFile.ItemType)
                                {
                                case "ClInclude":
                                    return(ProjectItemType.headerFile);

                                case "ClCompile":
                                    return(ProjectItemType.cppFile);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                return(ProjectItemType.other);

            default:
                return(ProjectItemType.other);
            }
        }
示例#32
0
 public RccOptions(EnvDTE.Project pro, VCFile qrcFile)
 {
     project     = pro;
     id          = qrcFile.RelativePath;
     qrcFileName = qrcFile.FullPath;
     name        = id;
     if (id.StartsWith(".\\", StringComparison.Ordinal))
     {
         name = name.Substring(2);
     }
     if (HelperFunctions.IsQrcFile(name))
     {
         name = name.Substring(0, name.Length - 4);
     }
 }
示例#33
0
 public RccOptions(EnvDTE.Project pro, VCFile qrcFile)
 {
     project     = pro;
     id          = qrcFile.RelativePath;
     qrcFileName = qrcFile.FullPath;
     name        = id;
     if (id.StartsWith(".\\"))
     {
         name = name.Substring(2);
     }
     if (name.EndsWith(".qrc"))
     {
         name = name.Substring(0, name.Length - 4);
     }
 }
示例#34
0
 public void SortIncludes(VCFile oFile)
 {
     try
     {
         if (Utilities.IsThirdPartyFile(oFile.FullPath, Utilities.GetCurrentConfiguration((VCProject)oFile.project)))
         {
             return;
         }
         IncludeComparer comparer = new IncludeComparer();
         SortedDictionary<IncludesKey, VCCodeInclude> oIncludes = new SortedDictionary<IncludesKey, VCCodeInclude>(comparer);
         mLogger.PrintMessage("Processing file ..::" + oFile.FullPath + "::..");
         Utilities.RetrieveIncludes(oFile, ref oIncludes);
         SortInclude(oIncludes);
     }
     catch (SystemException ex)
     {
         mLogger.PrintMessage("Failed when processing file " + oFile.Name + ". Reason: " + ex.Message);
     }
 }
示例#35
0
        public void Load(VCFile file)
        {
            this.FileName = file.FullPath;
            this.Cpps = new Dictionary<string, Cpp>();

            string[] lines = File.ReadAllLines(file.FullPath);

            for (int i = 0; i < lines.Length; i++)
            {
                Match match = Utils.IncludeRegex.Match(lines[i]);
                if (match.Success && match.Groups["Include"].Captures.Count > 0)
                {
                    string include = match.Groups["Include"].Captures[0].Value;
                    if (include.EndsWith(".cpp", true, null))
                    {
                        Cpp cpp;

                        VCFile f = Connect.GetVCFile(file.project as VCProject, include);
                        if (f != null)
                        {
                            cpp = new Cpp(f);
                        }
                        else
                        {
                            cpp = new Cpp(include);
                        }

                        if (i > 0 && lines[i - 1].StartsWith("#if"))
                        {
                            cpp.Condition = lines[i - 1].Substring(4);
                        }

                        cpp.Unity = this;
                        this.Cpps.Add(cpp.Name, cpp);
                    }
                }
            }
        }
示例#36
0
 /// <summary>
 /// Helper function for Refresh/UpdateMocStep.
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 private VCFile GetCppFileForMocStep(VCFile file)
 {
     string fileName = null;
     if (HelperFunctions.HasHeaderFileExtension(file.Name) || file.Name.EndsWith(".moc"))
         fileName = file.Name.Remove(file.Name.LastIndexOf('.')) + ".cpp";
     if (fileName != null && fileName.Length > 0)
     {
         foreach (VCFile f in (IVCCollection)vcPro.Files)
         {
             if (f.FullPath.ToLower().EndsWith("\\" + fileName.ToLower()))
                 return f;
         }
     }
     return null;
 }
示例#37
0
        private string GetPCHMocOptions(VCFile file, CompilerToolWrapper compiler)
        {
            // As .moc files are included, we should not add anything there
            if (!HelperFunctions.HasHeaderFileExtension(file.Name))
                return "";

            string additionalMocOptions = "\"-f" + compiler.GetPrecompiledHeaderThrough().Replace('\\', '/') + "\" ";
            //Get mocDir without .\\ at the beginning of it
            string mocDir = QtVSIPSettings.GetMocDirectory(envPro);
            if (mocDir.StartsWith(".\\"))
                mocDir = mocDir.Substring(2);

            //Get the absolute path
            mocDir = vcPro.ProjectDirectory + mocDir;
            string relPathToFile = HelperFunctions.GetRelativePath(mocDir, file.FullPath).Replace('\\', '/');
            additionalMocOptions += "\"-f" + relPathToFile + "\"";
            return additionalMocOptions;
        }
示例#38
0
        /// <summary>
        /// Removes the custom build step of a given file.
        /// </summary>
        /// <param name="file">file</param>
        public void RemoveMocStep(VCFile file)
        {
            try
            {
                if (!HasMocStep(file))
                    return;

                if (HelperFunctions.HasHeaderFileExtension(file.Name))
                {
                    foreach (VCFileConfiguration config in (IVCCollection)file.FileConfigurations)
                    {
                        VCCustomBuildTool tool = HelperFunctions.GetCustomBuildTool(config);
                        if (tool == null)
                            continue;

                        string cmdLine = tool.CommandLine;
                        if (cmdLine.Length > 0)
                        {
                            Regex rex = new Regex(@"(\S*moc.exe|""\S+:\\\.*moc.exe"")");
                            while (true)
                            {
                                Match m = rex.Match(cmdLine);
                                if (!m.Success)
                                    break;

                                int start = m.Index;
                                int end = cmdLine.IndexOf("&&", start);
                                int a = cmdLine.IndexOf("\r\n", start);
                                if ((a > -1 && a < end) || (end < 0 && a > -1))
                                    end = a;
                                if (end < 0)
                                    end = cmdLine.Length;

                                cmdLine = cmdLine.Remove(start, end - start).Trim();
                                if (cmdLine.StartsWith("&&"))
                                    cmdLine = cmdLine.Remove(0, 2).Trim();
                            }
                            tool.CommandLine = cmdLine;
                        }

                        Regex reg = new Regex("Moc'ing .+\\.\\.\\.");
                        string addDepends = tool.AdditionalDependencies;
                        addDepends = System.Text.RegularExpressions.Regex.Replace(addDepends,
                            @"(\S*moc.exe|""\S+:\\\.*moc.exe"")", "");
                        addDepends = addDepends.Replace(file.RelativePath, "");
                        tool.AdditionalDependencies = "";
                        tool.Description = reg.Replace(tool.Description, "");
                        tool.Description = tool.Description.Replace("MOC " + file.Name, "");
                        string baseFileName = file.Name.Remove(file.Name.LastIndexOf('.'));
                        string pattern = "(\"(.*\\\\" + GetMocFileName(file.FullPath)
                            + ")\"|(\\S*" + GetMocFileName(file.FullPath) + "))";
                        string outputMocFile = null;
                        System.Text.RegularExpressions.Regex regExp = new Regex(pattern);
                        tool.Outputs = tool.Outputs.Replace(ProjectMacros.Name, baseFileName);
                        MatchCollection matchList = regExp.Matches(tool.Outputs);
                        if (matchList.Count > 0)
                        {
                            if (matchList[0].Length > 0)
                            {
                                outputMocFile = matchList[0].ToString();
                            }
                            else if (matchList[1].Length > 1)
                            {
                                outputMocFile = matchList[1].ToString();
                            }
                        }
                        tool.Outputs = System.Text.RegularExpressions.Regex.Replace(tool.Outputs, pattern, "",
                            RegexOptions.Multiline|RegexOptions.IgnoreCase);
                        tool.Outputs = System.Text.RegularExpressions.Regex.Replace(tool.Outputs,
                            @"\s*;\s*;\s*", ";", RegexOptions.Multiline);
                        tool.Outputs = System.Text.RegularExpressions.Regex.Replace(tool.Outputs,
                            @"(^\s*;|\s*;\s*$)", "", RegexOptions.Multiline);

                        if (outputMocFile != null)
                        {
                            if (outputMocFile.StartsWith("\""))
                                outputMocFile = outputMocFile.Substring(1);
                            if (outputMocFile.EndsWith("\""))
                                outputMocFile = outputMocFile.Substring(0, outputMocFile.Length-1);
                            outputMocFile = outputMocFile.Replace("$(ConfigurationName)",
                                config.Name.Substring(0, config.Name.IndexOf('|')));
                            outputMocFile = outputMocFile.Replace("$(PlatformName)",
                                config.Name.Remove(0, config.Name.IndexOf('|') + 1));
                        }
                        VCFile mocFile = GetFileFromProject(outputMocFile);
                        if (mocFile != null)
                            RemoveFileFromFilter(mocFile, Filters.GeneratedFiles());
                    }
                    file.ItemType = "ClInclude";
                }
                else
                {
                    if (QtVSIPSettings.HasDifferentMocFilePerConfig(envPro)
                        || QtVSIPSettings.HasDifferentMocFilePerPlatform(envPro))
                    {
                        foreach (VCFileConfiguration config in (IVCCollection)file.FileConfigurations)
                        {
                            string mocFileName = GetMocFileName(file.Name);
                            VCFile mocFile = GetGeneratedMocFile(mocFileName, config);
                            if (mocFile != null)
                                RemoveFileFromFilter(mocFile, Filters.GeneratedFiles());
                        }
                    }
                    else
                    {
                        string mocFileName = GetMocFileName(file.Name);
                        VCFile mocFile = GetGeneratedMocFile(mocFileName, null);
                        if (mocFile != null)
                            RemoveFileFromFilter(mocFile, Filters.GeneratedFiles());
                    }
                }
            }
            catch
            {
                throw new Qt4VSException(SR.GetString("QtProject_CannotRemoveMocStep", file.FullPath));
            }
        }
示例#39
0
 public static void SetPCHOption(VCFile vcFile, pchOption option)
 {
     foreach (VCFileConfiguration config in vcFile.FileConfigurations as IVCCollection)
     {
         CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
         compiler.SetUsePrecompiledHeader(option);
     }
 }
示例#40
0
        /// <summary>
        /// Get the active code file, project and configuration 
        /// </summary>
        /// <returns>true if we have found an active C/C++ document</returns>
        private bool GetActiveVCFile(out VCFile vcFile, out VCProject vcProject, out VCConfiguration vcCfg)
        {
            vcFile = null;
              vcProject = null;
              vcCfg = null;

              if (_applicationObject.ActiveDocument != null)
              {
            // GUID equates to 'code file' as far as I can make out
            if (_applicationObject.ActiveDocument.Kind == "{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}" &&
            _applicationObject.ActiveDocument.Language == "C/C++")
            {
              // GUID equates to physical file on disk [http://msdn.microsoft.com/en-us/library/z4bcch80(VS.80).aspx]
              if (_applicationObject.ActiveDocument.ProjectItem.Kind == "{6BB5F8EE-4483-11D3-8BCF-00C04F8EC28C}")
              {
            // leap of faith
            vcFile = (VCFile)_applicationObject.ActiveDocument.ProjectItem.Object;
            vcProject = (VCProject)vcFile.project;

            if (vcFile.FileType != eFileType.eFileTypeCppCode)
              return false;

            // save the file (should be optional!)
            if (!_applicationObject.ActiveDocument.Saved)
              _applicationObject.ActiveDocument.Save(vcFile.FullPath);

            // get current configuration to pass to the bridge
            Configuration cfg =
                _applicationObject.ActiveDocument.ProjectItem.ConfigurationManager.ActiveConfiguration;

            try
            {
              var cfgArray = (IVCCollection)vcProject.Configurations;
              foreach (VCConfiguration vcr in cfgArray)
              {
                if (vcr.ConfigurationName == cfg.ConfigurationName &&
                    vcr.Platform.Name == cfg.PlatformName)
                {
                  vcCfg = vcr;
                }
              }
            }
            catch (Exception)
            {
              return false;
            }

            return true;
              }
            }
              }

              return false;
        }
示例#41
0
        public void OnExcludedFromBuildChanged(VCFile vcFile, VCFileConfiguration vcFileCfg)
        {
            // Update the ExcludedFromBuild flags of the mocced file
            // according to the ExcludedFromBuild flag of the mocable source file.
            string moccedFileName = GetMocFileName(vcFile.Name);
            if (string.IsNullOrEmpty(moccedFileName))
                return;

            VCFile moccedFile = GetGeneratedMocFile(moccedFileName, vcFileCfg);

            if (moccedFile != null)
            {
                VCFile cppFile = null;
                if (HelperFunctions.HasHeaderFileExtension(vcFile.Name))
                    cppFile = GetCppFileForMocStep(vcFile);

                VCFileConfiguration moccedFileConfig = GetVCFileConfigurationByName(moccedFile, vcFileCfg.Name);
                if (moccedFileConfig != null)
                {
                    if (cppFile != null && IsMoccedFileIncluded(cppFile))
                    {
                        if (!moccedFileConfig.ExcludedFromBuild)
                        {
                            moccedFileConfig.ExcludedFromBuild = true;
                        }
                    }
                    else if (moccedFileConfig.ExcludedFromBuild != vcFileCfg.ExcludedFromBuild)
                        moccedFileConfig.ExcludedFromBuild = vcFileCfg.ExcludedFromBuild;
                }
            }
        }
示例#42
0
 public static bool HasUicStep(VCFile file)
 {
     return CheckForCommand(file, Resources.uic4Command);
 }
示例#43
0
 public static VCFile Update(QtProject qtPrj, VCFile vcFile)
 {
     qtPrj.VCProject.Save();
     string prjPath = qtPrj.Project.FullName;
     string itemPath = vcFile.FullPath;
     var documents = new List<string>();
     foreach (Document document in qtPrj.dte.Documents)
     {
         if (document.Path != itemPath)
         {
             documents.Add(document.Path);
         }
     }
     instances.Remove(qtPrj.envPro);
     qtPrj.dte.Solution.Remove(qtPrj.Project);
     qtPrj.envPro = qtPrj.dte.Solution.AddFromFile(prjPath, false);
     instances.Add(qtPrj.envPro, qtPrj);
     foreach (string document in documents)
     {
         if (document != itemPath)
         {
             qtPrj.dte.ItemOperations.OpenFile(document);
         }
     }
     qtPrj.dte.ItemOperations.OpenFile(itemPath);
     qtPrj.vcPro = qtPrj.envPro.Object as VCProject;
     vcFile = (qtPrj.vcPro.Files as IVCCollection).Item(itemPath) as VCFile;
     return vcFile;
 }
示例#44
0
        /// <summary>
        /// Removes a file from the filter.
        /// This file will be deleted!
        /// </summary>
        /// <param name="project">project</param>
        /// <param name="file">file</param>
        public void RemoveFileFromFilter(VCFile file, FakeFilter filter)
        {
            try
            {
                VCFilter vfilt = FindFilterFromGuid(filter.UniqueIdentifier);

                if (vfilt == null)
                    vfilt = FindFilterFromName(filter.Name);

                if (vfilt == null)
                    return;

                RemoveFileFromFilter(file, vfilt);
            }
            catch
            {
                throw new Qt4VSException(SR.GetString("QtProject_CannotRemoveFile", file.Name));
            }
        }
示例#45
0
        public void UpdateRccStep(VCFile qrcFile, RccOptions rccOpts)
        {
            VCProject vcpro = (VCProject)qrcFile.project;
            EnvDTE.DTE dteObject = ((EnvDTE.Project)vcpro.Object).DTE;

            QtProject qtPro = QtProject.Create(vcpro);
            QrcParser parser = new QrcParser(qrcFile.FullPath);
            string filesInQrcFile = ProjectMacros.Path;

            if (parser.parse())
            {
                FileInfo fi = new FileInfo(qrcFile.FullPath);
                string qrcDir = fi.Directory.FullName + "\\";

                foreach (QrcPrefix prfx in parser.Prefixes)
                {
                    foreach (QrcItem itm in prfx.Items)
                    {
                        string relativeQrcItemPath = HelperFunctions.GetRelativePath(this.vcPro.ProjectDirectory,
                            qrcDir + itm.Path);
                        filesInQrcFile += ";" + relativeQrcItemPath;
                        try
                        {
                            VCFile addedFile = qtPro.AddFileInFilter(Filters.ResourceFiles(), relativeQrcItemPath, true);
                            QtProject.ExcludeFromAllBuilds(addedFile);
                        }
                        catch { /* it's not possible to add all kinds of files */ }
                    }
                }
            }

            string nameOnly = HelperFunctions.RemoveFileNameExtension(new FileInfo(qrcFile.FullPath));
            string qrcCppFile = QtVSIPSettings.GetRccDirectory(envPro) + "\\" + "qrc_" + nameOnly + ".cpp";

            try
            {
                foreach (VCFileConfiguration vfc in (IVCCollection)qrcFile.FileConfigurations)
                {
                    RccOptions rccOptsCfg = rccOpts;
                    string cmdLine = "";

                    VCCustomBuildTool cbt = HelperFunctions.GetCustomBuildTool(vfc);

                    cbt.AdditionalDependencies = filesInQrcFile;

                    cbt.Description = "Rcc'ing " + ProjectMacros.FileName + "...";

                    cbt.Outputs = qrcCppFile.Replace(nameOnly, ProjectMacros.Name);

                    cmdLine += "\"" + Resources.rcc4Command + "\""
                        + " -name \"" + ProjectMacros.Name + "\"";

                    if (rccOptsCfg == null)
                        rccOptsCfg = HelperFunctions.ParseRccOptions(cbt.CommandLine, qrcFile);

                    if (rccOptsCfg.CompressFiles)
                    {
                        cmdLine += " -threshold " + rccOptsCfg.CompressThreshold.ToString();
                        cmdLine += " -compress " + rccOptsCfg.CompressLevel.ToString();
                    }
                    else
                    {
                        cmdLine += " -no-compress";
                    }
                    cmdLine += " \"" + ProjectMacros.Path + "\" -o " + cbt.Outputs;
                    cbt.CommandLine = cmdLine;
                }
                AddFileInFilter(Filters.GeneratedFiles(), qrcCppFile, true);
            }
            catch(System.Exception /*e*/)
            {
                Messages.PaneMessage(dteObject, "*** WARNING (RCC): Couldn't add rcc step");
            }
        }
示例#46
0
文件: CVXOps.cs 项目: tritao/ClangVSx
        /// <summary>
        /// compile a single VCFile, do nothing with the OBJ
        /// </summary>
        public bool CompileSingleFile(VCFile vcFile, VCProject vcProject, VCConfiguration vcCfg, String additionalCmds = "")
        {
            CVXBuildSystem buildSystem;
              try
              {
            buildSystem = new CVXBuildSystem(_vsOutputWindow, _outputPane);
              }
              catch (System.Exception ex)
              {
            MessageBox.Show(ex.Message, "ClangVSx Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
              }

              try
              {
            return buildSystem.CompileSingleFile(vcFile, vcProject, vcCfg, additionalCmds);
              }
              catch (System.Exception ex)
              {
            WriteToOutputPane("Exception During File Compile : \n" + ex.Message + "\n");
              }

              return false;
        }
示例#47
0
 public void RemoveUic4BuildStep(VCFile file)
 {
     if (file == null)
         return;
     foreach (VCFileConfiguration config in (IVCCollection)file.FileConfigurations)
     {
         VCCustomBuildTool tool = HelperFunctions.GetCustomBuildTool(config);
         tool.AdditionalDependencies = "";
         tool.Description = "";
         tool.CommandLine = "";
         tool.Outputs = "";
     }
     RemoveUiHeaderFile(file);
 }
示例#48
0
 public void RemoveRccStep(VCFile file)
 {
     if (file == null)
         return;
     try
     {
         string relativeQrcFilePath = file.RelativePath;
         FileInfo qrcFileInfo = new FileInfo(ProjectDir + "\\" + relativeQrcFilePath);
         if (qrcFileInfo.Exists)
         {
             RccOptions opts = new RccOptions(Project, file);
             string qrcCppFile = QtVSIPSettings.GetRccDirectory(envPro) + "\\" + opts.OutputFileName;
             VCFile generatedFile = GetFileFromProject(qrcCppFile);
             if (generatedFile != null)
                 RemoveFileFromFilter(generatedFile, Filters.GeneratedFiles());
         }
     }
     catch (System.Exception e)
     {
         Messages.DisplayWarningMessage(e);
     }
 }
示例#49
0
 /// <summary>
 /// Helper function for RefreshMocStep.
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 private VCFile GetSourceFileForMocStep(VCFile file)
 {
     if (HelperFunctions.HasHeaderFileExtension(file.Name))
         return file;
     string fileName = file.Name;
     if (fileName.ToLower().EndsWith(".moc"))
     {
         fileName = fileName.Substring(0, fileName.Length - 4) + ".cpp";
         if (fileName.Length > 0)
         {
             foreach (VCFile f in (IVCCollection)vcPro.Files)
             {
                 if (f.FullPath.ToLower().EndsWith("\\" + fileName.ToLower()))
                     return f;
             }
         }
     }
     return null;
 }
示例#50
0
        public void UpdateUicSteps(string oldUicDir, bool update_inc_path)
        {
            Messages.PaneMessage(dte, "\r\n=== Update uic steps ===");
            VCFilter vcFilter = FindFilterFromGuid(Filters.GeneratedFiles().UniqueIdentifier);
            if (vcFilter != null)
            {
                IVCCollection filterFiles = (IVCCollection)vcFilter.Files;
                for (int i = filterFiles.Count; i > 0; i--)
                {
                    VCFile file = (VCFile)filterFiles.Item(i);
                    if (file.Name.ToLower().StartsWith("ui_"))
                    {
                        RemoveFileFromFilter(file, vcFilter);
                        HelperFunctions.DeleteEmptyParentDirs(file);
                    }
                }
            }

            int updatedFiles = 0;
            int j = 0;

            VCFile[] files = new VCFile[((IVCCollection)vcPro.Files).Count];
            foreach (VCFile file in (IVCCollection)vcPro.Files)
            {
                files[j++] = file;
            }

            foreach (VCFile file in files)
            {
                if (file.Name.EndsWith(".ui") && !IsUic3File(file))
                {
                    AddUic4BuildStep(file);
                    Messages.PaneMessage(dte, "Update uic step for " + file.Name + ".");
                    ++updatedFiles;
                }
            }
            if (update_inc_path)
            {
                UpdateCompilerIncludePaths(oldUicDir, QtVSIPSettings.GetUicDirectory(envPro));
            }

            Messages.PaneMessage(dte, "\r\n=== " + updatedFiles.ToString()
                + " uic steps updated. ===\r\n");
        }
示例#51
0
        /// <summary>
        /// Updates the moc command line for the given header or source file
        /// containing the Q_OBJECT macro.
        /// If the function is called from a property change for a single file
        /// (singleFile =  true) we may have to look for the according header
        /// file and refresh the moc step for this file, if it contains Q_OBJECT.
        /// </summary>
        /// <param name="vcfile"></param>
        private void RefreshMocStep(VCFile vcfile, bool singleFile)
        {
            bool isHeaderFile = HelperFunctions.HasHeaderFileExtension(vcfile.FullPath);
            if (!isHeaderFile && !HelperFunctions.HasSourceFileExtension(vcfile.FullPath))
                return;

            if (mocCmdChecker == null)
                mocCmdChecker = new MocCmdChecker();

            foreach (VCFileConfiguration config in (IVCCollection)vcfile.FileConfigurations)
            {
                try
                {
                    VCCustomBuildTool tool = null;
                    VCFile mocable = null;
                    if (isHeaderFile)
                    {
                        mocable = vcfile;
                        tool = HelperFunctions.GetCustomBuildTool(config);
                    }
                    else
                    {
                        string mocFileName = GetMocFileName(vcfile.FullPath);
                        VCFile mocFile = GetGeneratedMocFile(mocFileName, config);
                        if (mocFile != null)
                        {
                            VCFileConfiguration mocFileConfig = GetVCFileConfigurationByName(mocFile, config.Name);
                            tool = HelperFunctions.GetCustomBuildTool(mocFileConfig);
                            mocable = mocFile;
                        }
                        // It is possible that the function was called from a source file's property change, it is possible that
                        // we have to obtain the tool from the according header file
                        if (tool == null && singleFile)
                        {
                            string headerName = vcfile.FullPath.Remove(vcfile.FullPath.LastIndexOf('.')) + ".h";
                            mocFileName = GetMocFileName(headerName);
                            mocFile = GetGeneratedMocFile(mocFileName, config);
                            if (mocFile != null)
                            {
                                mocable = GetFileFromProject(headerName);
                                VCFileConfiguration customBuildConfig = GetVCFileConfigurationByName(mocable, config.Name);
                                tool = HelperFunctions.GetCustomBuildTool(customBuildConfig);
                            }
                        }
                    }
                    if (tool == null  || tool.CommandLine.ToLower().IndexOf("moc.exe") == -1)
                        continue;

                    VCFile srcMocFile = GetSourceFileForMocStep(mocable);
                    VCFile cppFile = GetCppFileForMocStep(mocable);
                    if (srcMocFile == null)
                        continue;
                    bool mocableIsCPP = (srcMocFile == cppFile);

                    string pchParameters = null;
                    VCFileConfiguration cppConfig = GetVCFileConfigurationByName(cppFile, config.Name);
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(cppConfig);
                    if (compiler.GetUsePrecompiledHeader() != pchOption.pchNone)
                        pchParameters = GetPCHMocOptions(srcMocFile, compiler);

                    string outputFileName = QtVSIPSettings.GetMocDirectory(envPro) + "\\";
                    if (mocableIsCPP)
                    {
                        outputFileName += ProjectMacros.Name;
                        outputFileName += ".moc";
                    }
                    else
                    {
                        outputFileName += "moc_";
                        outputFileName += ProjectMacros.Name;
                        outputFileName += ".cpp";
                    }

                    string newCmdLine = mocCmdChecker.NewCmdLine(tool.CommandLine,
                        GetIncludes(cppConfig),
                        GetDefines(cppConfig),
                        QtVSIPSettings.GetMocOptions(envPro), srcMocFile.RelativePath,
                        pchParameters,
                        outputFileName);

                    // The tool's command line automatically gets a trailing "\r\n".
                    // We have to remove it to make the check below work.
                    string origCommandLine = tool.CommandLine;
                    if (origCommandLine.EndsWith("\r\n"))
                        origCommandLine = origCommandLine.Substring(0, origCommandLine.Length - 2);

                    if (newCmdLine != null && newCmdLine != origCommandLine)
                    {
                        // We have to delete the old moc file in order to trigger custom build step.
                        string configName = config.Name.Remove(config.Name.IndexOf("|"));
                        string platformName = config.Name.Substring(config.Name.IndexOf("|") + 1);
                        string projectPath = envPro.FullName.Remove(envPro.FullName.LastIndexOf('\\'));
                        string mocRelPath = GetRelativeMocFilePath(srcMocFile.FullPath, configName, platformName);
                        string mocPath = Path.Combine(projectPath, mocRelPath);
                        if (File.Exists(mocPath))
                            File.Delete(mocPath);
                        tool.CommandLine = newCmdLine;
                    }
                }
                catch
                {
                    Messages.PaneMessage(dte, "ERROR: failed to refresh moc step for " + vcfile.ItemName);
                }
            }
        }
示例#52
0
 private static bool CheckForCommand(VCFile file, string cmd)
 {
     if (file == null)
         return false;
     foreach (VCFileConfiguration config in (IVCCollection)file.FileConfigurations)
     {
         VCCustomBuildTool tool = HelperFunctions.GetCustomBuildTool(config);
         if (tool == null)
             return false;
         if (tool.CommandLine != null && tool.CommandLine.Contains(cmd))
             return true;
     }
     return false;
 }
示例#53
0
        /// <summary>
        /// Adds a moc step to a given file for this project.
        /// </summary>
        /// <param name="file">file</param>
        public void AddMocStep(VCFile file)
        {
            string oldItemType = file.ItemType;
            try
            {
                string mocFileName = GetMocFileName(file.FullPath);
                if (mocFileName == null)
                    return;

                bool hasDifferentMocFilePerConfig = QtVSIPSettings.HasDifferentMocFilePerConfig(envPro);
                bool hasDifferentMocFilePerPlatform = QtVSIPSettings.HasDifferentMocFilePerPlatform(envPro);
                bool mocableIsCPP = mocFileName.ToLower().EndsWith(".moc");

            #if (VS2010 || VS2012 || VS2013)
                if (!mocableIsCPP && file.ItemType != "CustomBuild")
                {
                    file.ItemType = "CustomBuild";
                }
            #endif

            #if VS2013
                file = Update(this, file);
            #endif

            #region Add moc for each configuration
                foreach (VCFileConfiguration config in (IVCCollection)file.FileConfigurations)
                {
                    string name = ((VCCustomBuildTool)config.Tool).toolName;
                    VCConfiguration vcConfig = config.ProjectConfiguration as VCConfiguration;
                    VCPlatform platform = vcConfig.Platform as VCPlatform;
                    string platformName = platform.Name;

                    string mocRelPath = GetRelativeMocFilePath(file.FullPath, vcConfig.ConfigurationName, platformName);
                    string platformFilterName = null;
                    string configFilterName = null;

                    if (mocRelPath.Contains(platformName))
                    {
                        platformFilterName = platformName;
                    }

                    if (mocRelPath.Contains(vcConfig.ConfigurationName))
                    {
                        configFilterName = vcConfig.ConfigurationName;
                    }

                    VCFile mocFile = GetFileFromProject(mocRelPath);
                    if (mocFile == null)
                    {
                        FileInfo fi = new FileInfo(this.VCProject.ProjectDirectory + "\\" + mocRelPath);
                        if (!fi.Directory.Exists)
                            fi.Directory.Create();
                        mocFile = AddFileInSubfilter(Filters.GeneratedFiles(), platformFilterName, configFilterName, mocRelPath);
            #if (VS2010 || VS2012 || VS2013)
                        if (mocFileName.ToLower().EndsWith(".moc"))
                        {
                            ProjectItem mocFileItem = mocFile.Object as ProjectItem;
                            if (mocFileItem != null)
                                HelperFunctions.EnsureCustomBuildToolAvailable(mocFileItem);
                        }
            #endif
                    }

                    if (mocFile == null)
                        throw new Qt4VSException(SR.GetString("QtProject_CannotAddMocStep", file.FullPath));

                    VCCustomBuildTool tool = null;

                    string fileToMoc = null;
                    if (!mocableIsCPP)
                    {
                        tool = HelperFunctions.GetCustomBuildTool(config);
                        fileToMoc = ProjectMacros.Path;
                    }
                    else
                    {
                        VCFileConfiguration mocConf = GetVCFileConfigurationByName(mocFile, vcConfig.Name);
                        tool = HelperFunctions.GetCustomBuildTool(mocConf);
                        fileToMoc = HelperFunctions.GetRelativePath(vcPro.ProjectDirectory, file.FullPath);
                    }

                    if (tool == null)
                        throw new Qt4VSException(SR.GetString("QtProject_CannotFindCustomBuildTool", file.FullPath));

                    if (hasDifferentMocFilePerPlatform && hasDifferentMocFilePerConfig)
                    {
                        foreach (VCFileConfiguration mocConf in (IVCCollection)mocFile.FileConfigurations)
                        {
                            VCConfiguration projectCfg = mocConf.ProjectConfiguration as VCConfiguration;
                            if (projectCfg.Name != vcConfig.Name || (IsMoccedFileIncluded(file) && !mocableIsCPP))
                            {
                                if (!mocConf.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = true;
                            }
                            else
                            {
                                if (mocConf.ExcludedFromBuild != config.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = config.ExcludedFromBuild;
                            }
                        }
                    }
                    else if (hasDifferentMocFilePerPlatform)
                    {
                        foreach (VCFileConfiguration mocConf in (IVCCollection)mocFile.FileConfigurations)
                        {
                            VCConfiguration projectCfg = mocConf.ProjectConfiguration as VCConfiguration;
                            VCPlatform mocConfPlatform = projectCfg.Platform as VCPlatform;
                            if (projectCfg.ConfigurationName != vcConfig.ConfigurationName)
                                continue;

                            bool exclude = mocConfPlatform.Name != platformName || (IsMoccedFileIncluded(file) && !mocableIsCPP);
                            if (exclude)
                            {
                                if (mocConf.ExcludedFromBuild != exclude)
                                    mocConf.ExcludedFromBuild = exclude;
                            }
                            else
                            {
                                if (mocConf.ExcludedFromBuild != config.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = config.ExcludedFromBuild;
                            }
                        }
                    }
                    else if (hasDifferentMocFilePerConfig)
                    {
                        foreach (VCFileConfiguration mocConf in (IVCCollection)mocFile.FileConfigurations)
                        {
                            VCConfiguration projectCfg = mocConf.ProjectConfiguration as VCConfiguration;
                            VCPlatform mocConfPlatform = projectCfg.Platform as VCPlatform;
                            if (platformName != mocConfPlatform.Name)
                                continue;

                            if (projectCfg.Name != vcConfig.Name || (IsMoccedFileIncluded(file) && !mocableIsCPP))
                            {
                                if (!mocConf.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = true;
                            }
                            else
                            {
                                if (mocConf.ExcludedFromBuild != config.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = config.ExcludedFromBuild;
                            }
                        }
                    }
                    else
                    {
                        VCFileConfiguration moccedFileConfig = GetVCFileConfigurationByName(mocFile, config.Name);
                        if (moccedFileConfig != null)
                        {
                            VCFile cppFile = GetCppFileForMocStep(file);
                            if (cppFile != null && IsMoccedFileIncluded(cppFile))
                            {
                                if (!moccedFileConfig.ExcludedFromBuild)
                                {
                                    moccedFileConfig.ExcludedFromBuild = true;
                                }
                            }
                            else if (moccedFileConfig.ExcludedFromBuild != config.ExcludedFromBuild)
                                moccedFileConfig.ExcludedFromBuild = config.ExcludedFromBuild;
                        }
                    }

                    string dps = tool.AdditionalDependencies;
                    if (dps.IndexOf("\"" + Resources.moc4Command + "\"") < 0)
                    {
                        if (dps.Length > 0 && !dps.EndsWith(";"))
                            dps += ";";
                        tool.AdditionalDependencies = dps + "\"" + Resources.moc4Command + "\";" + fileToMoc;
                    }

                    tool.Description = "Moc'ing " + file.Name + "...";

                    string inputMocFile = ProjectMacros.Path;
                    if (mocableIsCPP)
                        inputMocFile = file.RelativePath;
                    string output = tool.Outputs;
                    string outputMocFile = "";
                    string outputMocMacro = "";
                    string baseFileName = file.Name.Remove(file.Name.LastIndexOf('.'));
                    string pattern = "(\"(.*\\\\" + mocFileName + ")\"|(\\S*"
                        + mocFileName + "))";
                    System.Text.RegularExpressions.Regex regExp = new Regex(pattern);
                    MatchCollection matchList = regExp.Matches(tool.Outputs.Replace(ProjectMacros.Name, baseFileName));
                    if (matchList.Count > 0)
                    {
                        if (matchList[0].Length > 0)
                        {
                            outputMocFile = matchList[0].ToString();
                        }
                        else if (matchList[1].Length > 1)
                        {
                            outputMocFile = matchList[1].ToString();
                        }
                        if (outputMocFile.StartsWith("\""))
                            outputMocFile = outputMocFile.Substring(1);
                        if (outputMocFile.EndsWith("\""))
                            outputMocFile = outputMocFile.Substring(0, outputMocFile.Length-1);
                        string outputMocPath = Path.GetDirectoryName(outputMocFile);
                        string stringToReplace = Path.GetFileName(outputMocFile);
                        outputMocMacro = outputMocPath + "\\" + stringToReplace.Replace(baseFileName, ProjectMacros.Name);
                    }
                    else
                    {
                        outputMocFile = GetRelativeMocFilePath(file.FullPath);
                        string outputMocPath = Path.GetDirectoryName(outputMocFile);
                        string stringToReplace = Path.GetFileName(outputMocFile);
                        outputMocMacro = outputMocPath + "\\" + stringToReplace.Replace(baseFileName, ProjectMacros.Name);
                        if (output.Length > 0 && !output.EndsWith(";"))
                            output += ";";
                        tool.Outputs = output + "\"" + outputMocMacro + "\"";
                    }

                    string newCmdLine = "\"" + Resources.moc4Command + "\" " + QtVSIPSettings.GetMocOptions(envPro)
                        + " \"" + inputMocFile + "\" -o \""
                        + outputMocMacro + "\"";

                    // Tell moc to include the PCH header if we are using precompiled headers in the project
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(vcConfig);
                    if (compiler.GetUsePrecompiledHeader() != pchOption.pchNone)
                    {
                        newCmdLine += " " + GetPCHMocOptions(file, compiler);
                    }

                    QtVersionManager versionManager = QtVersionManager.The();
                    VersionInformation versionInfo = new VersionInformation(versionManager.GetInstallPath(envPro));
                    bool mocSupportsIncludes = (versionInfo.qtMajor == 4 && versionInfo.qtMinor >= 2)
                        || versionInfo.qtMajor >= 5;

                    string strDefinesIncludes = "";
                    VCFile cppPropertyFile;
                    if (!mocableIsCPP)
                        cppPropertyFile = GetCppFileForMocStep(file);
                    else
                        cppPropertyFile = GetCppFileForMocStep(mocFile);
                    VCFileConfiguration defineIncludeConfig;
                    if (cppPropertyFile != null)
                        defineIncludeConfig = GetVCFileConfigurationByName(cppPropertyFile, config.Name);
                    else
                        // No file specific defines/includes but at least the project defines/includes are added
                        defineIncludeConfig = config;
                    strDefinesIncludes += GetDefines(defineIncludeConfig);
                    strDefinesIncludes += GetIncludes(defineIncludeConfig);
                    int cmdLineLength = newCmdLine.Length + strDefinesIncludes.Length + 1;
                    if (cmdLineLength > HelperFunctions.GetMaximumCommandLineLength() && mocSupportsIncludes)
                    {
                        // Command line is too long. We must use an options file.
                        string mocIncludeCommands = "";
                        string mocIncludeFile = "\"" + outputMocFile + ".inc\"";
                        string redirectOp = " > ";
                        int maxCmdLineLength = HelperFunctions.GetMaximumCommandLineLength() - (mocIncludeFile.Length + 1);

                        string[] options = strDefinesIncludes.Split(' ');

                        int i = options.Length - 1;
                        for (; i >= 0; --i)
                        {
                            if (options[i].Length == 0)
                                continue;
                            mocIncludeCommands += "echo " + options[i] + redirectOp + mocIncludeFile + "\r\n";
                            cmdLineLength -= options[i].Length + 1;
                            if (cmdLineLength < maxCmdLineLength)
                                break;
                            if (i == options.Length - 1)    // first loop
                                redirectOp = " >> ";
                        }
                        strDefinesIncludes = "@" + mocIncludeFile;
                        for (int k = 0; k < i; ++k)
                            if (options[k].Length > 0)
                                strDefinesIncludes += " " + options[k];

                        newCmdLine = mocIncludeCommands + newCmdLine + " " + strDefinesIncludes;
                    }
                    else
                    {
                        newCmdLine = newCmdLine + " " + strDefinesIncludes;
                    }

                    if (tool.CommandLine.Trim().Length > 0)
                    {
                        string cmdLine = tool.CommandLine;

                        // remove the moc option file commands
                        {
                            Regex rex = new Regex("^echo.+[.](moc|cpp)[.]inc\"\r\n", RegexOptions.Multiline);
                            cmdLine = rex.Replace(cmdLine, "");
                        }

                        Match m = System.Text.RegularExpressions.Regex.Match(cmdLine,
                            @"(\S*moc.exe|""\S+:\\\.*moc.exe"")");

                        if (m.Success)
                        {
                            int start = m.Index;
                            int end = cmdLine.IndexOf("&&", start);
                            int a = cmdLine.IndexOf("\r\n", start);
                            if ((a > -1 && a < end) || (end < 0 && a > -1))
                                end = a;
                            if (end < 0)
                                end = cmdLine.Length;
                            tool.CommandLine = cmdLine.Replace(cmdLine.Substring(start, end - start), newCmdLine);
                        }
                        else
                        {
                            tool.CommandLine = cmdLine + "\r\n" + newCmdLine;
                        }
                    }
                    else
                    {
                        tool.CommandLine = newCmdLine;
                    }
                }
            #endregion
            }
            catch
            {
                file.ItemType = oldItemType;
                throw new Qt4VSException(SR.GetString("QtProject_CannotAddMocStep", file.FullPath));
            }
        }
示例#54
0
 private static VCFileConfiguration GetVCFileConfigurationByName(VCFile file, string configName)
 {
     foreach (VCFileConfiguration cfg in (IVCCollection)file.FileConfigurations)
     {
         if (cfg.Name == configName)
             return cfg;
     }
     return null;
 }
示例#55
0
 public void RefreshMocStep(VCFile vcfile)
 {
     RefreshMocStep(vcfile, true);
 }
示例#56
0
 private static bool IsUic3File(VCFile file)
 {
     foreach (VCFileConfiguration config in (IVCCollection)file.FileConfigurations)
     {
         VCCustomBuildTool tool = HelperFunctions.GetCustomBuildTool(config);
         if (tool == null)
             return false;
         if (tool.CommandLine.IndexOf("uic3.exe") > -1)
             return true;
     }
     return false;
 }
示例#57
0
        public void RemoveUiHeaderFile(VCFile file)
        {
            if (file == null)
                return;
            try
            {
                string headerFile = GetUiGeneratedFileName(file.Name);
                VCFile hFile = GetFileFromProject(headerFile);

                if (hFile != null)
                    RemoveFileFromFilter(hFile, Filters.GeneratedFiles());
            }
            catch (System.Exception e)
            {
                Messages.DisplayWarningMessage(e);
            }
        }
示例#58
0
        /// <summary>
        /// Removes a file from the filter.
        /// This file will be deleted!
        /// </summary>
        /// <param name="project">project</param>
        /// <param name="file">file</param>
        public void RemoveFileFromFilter(VCFile file, VCFilter filter)
        {
            try
            {
                filter.RemoveFile(file);
                FileInfo fi = new FileInfo(file.FullPath);
                if (fi.Exists)
                    fi.Delete();
            }
            catch
            {
            }

            IVCCollection subfilters = (IVCCollection)filter.Filters;
            for (int i = subfilters.Count; i > 0; i--)
            {
                try
                {
                    VCFilter subfilter = (VCFilter)subfilters.Item(i);
                    RemoveFileFromFilter(file, subfilter);
                }
                catch
                {
                }
            }
        }
示例#59
0
        /// <summary>
        /// Checks the file passes in to see if it has a custom build rule set up,
        /// and parses it if it does.
        /// </summary>
        private void parseCustomBuildRule(VCFile file)
        {
            // We find the relative path to the file from the project root...
            string path = Utils.call(() => (file.FullPath));
            string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, path);

            // The custom build rules (if there are any) are per configuration. So
            // we loop through the configurations for this file...
            IVCCollection configurations = Utils.call(() => (file.FileConfigurations as IVCCollection));
            int numConfigurations = Utils.call(() => (configurations.Count));
            for (int i = 1; i <= numConfigurations; ++i)
            {
                // We check if there is a rule for each configuration...
                VCFileConfiguration configuration = Utils.call(() => (configurations.Item(i) as VCFileConfiguration));
                parseCustomBuildRule_Configuration(configuration, relativePath); ;
            }
        }
示例#60
0
 public static void ExcludeFromAllBuilds(VCFile file)
 {
     if (file == null)
         return;
     foreach (VCFileConfiguration conf in (IVCCollection)file.FileConfigurations)
         if (!conf.ExcludedFromBuild)
             conf.ExcludedFromBuild = true;
 }