Exemple #1
0
        public bool LaunchAndDoInject()
        {
            IVsOutputWindowPane output = (IVsOutputWindowPane)Package.GetGlobalService(typeof(SVsGeneralOutputWindowPane));

            String   exepath     = "";
            String   workdir     = "";
            String   environment = "";
            String   addindir    = "";
            Solution sln         = _applicationObject.Solution;
            String   startup     = (String)((Array)sln.SolutionBuild.StartupProjects).GetValue(0);

            foreach (EnvDTE.Project project in sln.Projects)
            {
                if (project.UniqueName == startup)
                {
                    VCProject vcproj = (VCProject)project.Object;
                    if (vcproj == null)
                    {
                        // this is not a visual c++ project
                        continue;
                    }
                    IVCCollection   cfgs = vcproj.Configurations;
                    VCConfiguration cfg  = cfgs.Item(1);
                    exepath     = cfg.Evaluate("$(LocalDebuggerCommand)");
                    workdir     = cfg.Evaluate("$(LocalDebuggerWorkingDirectory)");
                    environment = cfg.Evaluate("$(LocalDebuggerEnvironment)");
                    addindir    = cfg.Evaluate("$(USERPROFILE)\\Documents\\Visual Studio 2012\\Addins");
                    output.OutputString(exepath);
                }
            }

            uint pid = dpVSHelper.ExecuteSuspended(exepath, addindir, environment);

            if (pid != 0)
            {
                VsDebugTargetProcessInfo[] res  = new VsDebugTargetProcessInfo[1];
                VsDebugTargetInfo4[]       info = new VsDebugTargetInfo4[1];
                info[0].bstrExe = exepath;
                info[0].dlo     = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning;
                //info[0].dlo = (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AttachToSuspendedLaunchProcess; // somehow this makes debugger not work
                info[0].dwProcessId = pid;
                info[0].LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd | (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop;

                Guid   guidDbgEngine = VSConstants.DebugEnginesGuids.ManagedAndNative_guid;
                IntPtr pGuids        = Marshal.AllocCoTaskMem(Marshal.SizeOf(guidDbgEngine));
                Marshal.StructureToPtr(guidDbgEngine, pGuids, false);
                info[0].pDebugEngines      = pGuids;
                info[0].dwDebugEngineCount = 1;

                IVsDebugger4 idbg = (IVsDebugger4)Package.GetGlobalService(typeof(SVsShellDebugger));
                idbg.LaunchDebugTargets4(1, info, res);

                dpVSHelper.Resume(pid);
            }

            return(true);
        }
Exemple #2
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();
        }
        /// <summary>
        /// Finds the library path for the configuration passed in.
        /// </summary>
        private void parseLinkerSettings_LibraryPath(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // Get the library paths across all property sheets
            List <string> libraryPaths = ToolPropertyCollector.Get(vcConfiguration, "VCLinkerTool", (tool) =>
            {
                var linkerTool = tool as VCLinkerTool;
                string str     = Utils.call(() => (linkerTool.AdditionalLibraryDirectories));
                if (str == null)
                {
                    return(null);
                }
                // The string may be quoted. We need to remove the quotes.
                // (TODO: We might need to handle quotes in a smarter manner.)
                return(Utils.split(str, ';').Select(s => s.Trim('"')).ToList());
            });

            // Process the library paths
            foreach (string libraryPath in libraryPaths)
            {
                if (libraryPath == "")
                {
                    continue;
                }

                string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(libraryPath)));
                if (resolvedPath == "")
                {
                    continue;
                }

                string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath);
                configurationInfo.addLibraryPath(relativePath);
            }
        }
Exemple #4
0
        /// <summary>
        /// We parse the librarian settings, ie link options for libraries.
        /// </summary>
        private void parseConfiguration_LibrarianSettings(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // We get the librarian 'tool'...
            IVCCollection   tools         = Utils.call(() => (vcConfiguration.Tools as IVCCollection));
            VCLibrarianTool librarianTool = Utils.call(() => (tools.Item("VCLibrarianTool") as VCLibrarianTool));

            if (librarianTool == null)
            {
                // Not all projects have a librarian tool...
                return;
            }

            // We find if this library is set to link together other libraries it depends on...
            // (We are assuming that all configurations of the project have the same link-library-dependencies setting.)
            m_projectInfo.LinkLibraryDependencies = Utils.call(() => (librarianTool.LinkLibraryDependencies));

            // - Target Machine (TODO: complete the machine type)

            string platform = Utils.call(() => (vcConfiguration.Evaluate("$(Platform)")));

            if (!string.IsNullOrEmpty(platform))
            {
                configurationInfo.Platform = platform;
                configurationInfo.addLinkerFlag("/MACHINE:X64");
            }

            // - Import Library
            configurationInfo.DynamicLibOutputPath = configurationInfo.OutputFolderAbsolute + m_projectInfo.Name + ".lib";
        }
        /// <summary>
        /// Finds the collection of include paths for the configuration passed in.
        /// </summary>
        private void parseCompilerSettings_IncludePath(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            List <string> paths = ToolPropertyCollector.Get(vcConfiguration, "VCCLCompilerTool", (tool) =>
            {
                var compilerTool = tool as VCCLCompilerTool;
                string strAdditionalIncludeDirectories = Utils.call(() => (compilerTool.AdditionalIncludeDirectories));
                if (strAdditionalIncludeDirectories == null)
                {
                    return(null);
                }
                // The string may be quoted. We need to remove the quotes.
                // (TODO: We might need to handle quotes in a smarter manner.)
                return(Utils.split(strAdditionalIncludeDirectories, ';', ',').Select(s => s.Trim('"')).ToList());
            });

            foreach (var path in paths)
            {
                // Resolve variables
                string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(path)));
                if (resolvedPath != "")
                {
                    // Make sure all paths are relative to the project root folder
                    string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath);
                    configurationInfo.addIncludePath(relativePath);
                }
            }
        }
Exemple #6
0
        static public string GetIncludesForProject(VCConfiguration vcConfiguration)
        {
            StringBuilder    includes = new StringBuilder();
            VCCLCompilerTool vcCTool  = GetVCCLCompilerToolForProject(vcConfiguration);

            if (String.IsNullOrEmpty(vcCTool.FullIncludePath) == false)
            {
                ts.TraceInformation("GetIncludesForProject: FullIncludePath\n" + vcCTool.FullIncludePath);
                includes.Append(BuildIncludes(vcCTool.FullIncludePath, "-I"));
            }

            if (String.IsNullOrEmpty(vcCTool.AdditionalIncludeDirectories) == false)
            {
                ts.TraceInformation("GetIncludesForProject: AdditionalIncludeDirectories\n" + vcCTool.AdditionalIncludeDirectories);
                includes.Append(BuildIncludes(vcConfiguration.Evaluate(vcCTool.AdditionalIncludeDirectories), "-I"));
            }

            if (String.IsNullOrEmpty(vcCTool.ForcedIncludeFiles) == false)
            {
                ts.TraceInformation("GetIncludesForProject: ForcedIncludeFiles\n" + vcCTool.ForcedIncludeFiles);
                //TODO HEEM
                includes.Append(BuildIncludes(vcCTool.ForcedIncludeFiles, "-include"));
            }

            ts.TraceInformation("GetIncludesForProject: \n" + includes.ToString());

            return(includes.ToString());
        }
Exemple #7
0
        /// <summary>
        /// Finds the collection of include paths for the configuration passed in.
        /// </summary>
        private void parseCompilerSettings_IncludePath(VCConfiguration vcConfiguration, VCCLCompilerTool compilerTool, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // We:
            // 1. Read the additional include paths (which are in a semi-colon-delimited string)
            // 2. Split it into separate paths
            // 3. Resolve any symbols
            // 4. Make sure all paths are relative to the project root folder

            // 1 & 2...
            string strAdditionalIncludeDirectories = Utils.call(() => (compilerTool.AdditionalIncludeDirectories));

            if (strAdditionalIncludeDirectories == null)
            {
                return;
            }

            List <string> additionalIncludeDirectories = Utils.split(strAdditionalIncludeDirectories, ';', ',');

            foreach (string additionalIncludeDirectory in additionalIncludeDirectories)
            {
                // The string may be quoted. We need to remove the quotes...
                string unquotedIncludeDirectory = additionalIncludeDirectory.Trim('"');

                // 3 & 4...
                string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(unquotedIncludeDirectory)));
                if (resolvedPath != "")
                {
                    string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath);
                    configurationInfo.addIncludePath(relativePath);
                }
            }
        }
Exemple #8
0
        public string Evaluate(EnvDTE.Configuration dteConfig, string value)
        {
            EnvDTE.Project  dteProject = dteConfig.Owner as EnvDTE.Project;
            VCProject       project    = dteProject.Object as VCProject;
            VCConfiguration config     = project.Configurations.Item(dteConfig.ConfigurationName + "|" + dteConfig.PlatformName);

            return(config.Evaluate(value));
        }
        private bool IsEnclave(Project project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var             vcProject = project.Object as VCProject;
            VCConfiguration vcConfig  = vcProject.ActiveConfiguration;
            string          oeType    = vcConfig.Evaluate("$(OEType)");

            return(oeType == "Enclave");
        }
        private static void recursiveAddToolDetails(SourceFile sourceForAnalysis, VCConfiguration projectConfig, VCCLCompilerTool tool, dynamic propertySheets, ref bool bInheritDefs, ref bool bInheritUndefs)
        {
            // TODO: If the special keyword "\\\"$(INHERIT)\\\"" appears, we should inherit at that specific point.
            if (bInheritDefs)
            {
                string[] macrosToDefine = tool.PreprocessorDefinitions.Split(';');
                bInheritDefs = !macrosToDefine.Contains("\\\"$(NOINHERIT)\\\"");
                for (int i = 0; i < macrosToDefine.Length; ++i)
                {
                    macrosToDefine[i] = Environment.ExpandEnvironmentVariables(projectConfig.Evaluate(macrosToDefine[i]));
                }

                sourceForAnalysis.addMacros(macrosToDefine);
            }

            if (bInheritUndefs)
            {
                string[] macrosToUndefine = tool.UndefinePreprocessorDefinitions.Split(';');
                bInheritUndefs = !macrosToUndefine.Contains("\\\"$(NOINHERIT)\\\"");
                for (int i = 0; i < macrosToUndefine.Length; ++i)
                {
                    macrosToUndefine[i] = Environment.ExpandEnvironmentVariables(projectConfig.Evaluate(macrosToUndefine[i]));
                }

                sourceForAnalysis.addMacrosToUndefine(macrosToUndefine);
            }

            if (propertySheets != null && (bInheritDefs || bInheritUndefs))
            {
                // Scan any inherited property sheets.
                foreach (var propSheet in propertySheets)
                {
                    VCCLCompilerTool propSheetTool = (VCCLCompilerTool)propSheet.Tools.Item("VCCLCompilerTool");
                    if (propSheetTool != null)
                    {
                        // When looping over the inherited property sheets, don't allow rules to filter back up the way.
                        bool bInheritDefs1 = bInheritDefs, bInheritUndefs1 = bInheritUndefs;
                        recursiveAddToolDetails(sourceForAnalysis, projectConfig, propSheetTool, propSheet.PropertySheets, ref bInheritDefs1, ref bInheritUndefs1);
                    }
                }
            }
        }
Exemple #11
0
        void EnsureAsmDirectoryExists(VCConfiguration configuration)
        {
            string relativeDir = configuration.Evaluate(OutputAsmDir);
            string solutionDir = Path.GetDirectoryName(m_dte.Solution.FullName);

            string dir = Path.Combine(solutionDir, relativeDir);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
        }
        private static async Task <SourceFile> createSourceFileAsync(string filePath, Configuration configuration, Project project)
        {
            try
            {
                await Instance.JoinableTaskFactory.SwitchToMainThreadAsync();

                Debug.Assert(isVisualCppProjectKind(project.Kind));

                VCProject       vcProject = project.Object as VCProject;
                VCConfiguration vcconfig  = vcProject.ActiveConfiguration;

                string toolSetName = ((dynamic)vcconfig).PlatformToolsetFriendlyName;

                string     projectDirectory  = vcProject.ProjectDirectory;
                string     projectName       = project.Name;
                SourceFile sourceForAnalysis = null;
                dynamic    toolsCollection   = vcconfig.Tools;
                foreach (var tool in toolsCollection)
                {
                    // Project-specific includes
                    if (implementsInterface(tool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
                    {
                        if (sourceForAnalysis == null)
                        {
                            sourceForAnalysis = new SourceFile(filePath, projectDirectory, projectName, toolSetName);
                        }

                        string includes         = tool.FullIncludePath;
                        string definitions      = tool.PreprocessorDefinitions;
                        string macrosToUndefine = tool.UndefinePreprocessorDefinitions;

                        string[] includePaths = includes.Split(';');
                        for (int i = 0; i < includePaths.Length; ++i)
                        {
                            includePaths[i] = Environment.ExpandEnvironmentVariables(vcconfig.Evaluate(includePaths[i]));
                        }
                        ;

                        sourceForAnalysis.addIncludePaths(includePaths);
                        sourceForAnalysis.addMacros(definitions.Split(';'));
                        sourceForAnalysis.addMacrosToUndefine(macrosToUndefine.Split(';'));
                    }
                }

                return(sourceForAnalysis);
            }
            catch (Exception ex)
            {
                DebugTracer.Trace(ex);
                return(null);
            }
        }
Exemple #13
0
        /// <summary>
        /// Gets a folder name from the function passed in, and returns it as a path
        /// relative to the project root folder.
        /// </summary>
        private string parseConfiguration_Folder(VCConfiguration vcConfiguration, Func <string> folderFn)
        {
            // We get the folder name, which may contain symbols e.g. £(ConfgurationName)...
            string pathWithSymbols = Utils.call(folderFn);

            // We resolve the symbols...
            string evaluatedPath = Utils.call(() => (vcConfiguration.Evaluate(pathWithSymbols)));

            // Path is absolute or relative to Project folder.
            if (!Path.IsPathRooted(evaluatedPath))
            {
                evaluatedPath = Path.Combine(m_projectInfo.RootFolderAbsolute, evaluatedPath);
            }

            return(evaluatedPath);
        }
Exemple #14
0
        private string[] GetIncludeDirectoriesFromProject(EnvDTE.Project project)
        {
            List <string> includeDirectories = new List <string>();
            VCProject     vcproject          = (VCProject)project.Object;

            IVCCollection configurationsCollection = (IVCCollection)vcproject.Configurations;

            Configuration dteActiveConfiguration = project.ConfigurationManager.ActiveConfiguration;

            VCConfiguration vcActiveConfiguration = null;

            foreach (VCConfiguration configuration in configurationsCollection)
            {
                if (configuration.ConfigurationName == dteActiveConfiguration.ConfigurationName && configuration.Platform.Name == dteActiveConfiguration.PlatformName)
                {
                    vcActiveConfiguration = configuration;
                    break;
                }
            }

            IVCCollection toolsCollection = (IVCCollection)vcActiveConfiguration.Tools;

            foreach (Object toolObject in toolsCollection)
            {
                if (toolObject is VCCLCompilerTool)
                {
                    VCCLCompilerTool compilerTool = (VCCLCompilerTool)toolObject;
                    string           additionalIncludeDirectories = compilerTool.AdditionalIncludeDirectories;
                    includeDirectories.AddRange(additionalIncludeDirectories.Split(';'));
                    break;
                }
            }

            includeDirectories.AddRange(AdditionalIncludeDirectoriesFromAllPropertySheets(vcActiveConfiguration.PropertySheets));

            List <string> evaluatedIncludeDirectories = new List <string>();

            foreach (string includeDirectory in includeDirectories)
            {
                string evaluatedIncludeDirectory = vcActiveConfiguration.Evaluate(includeDirectory);
                if (evaluatedIncludeDirectory != "")
                {
                    evaluatedIncludeDirectories.Add(evaluatedIncludeDirectory);
                }
            }
            return(evaluatedIncludeDirectories.ToArray());
        }
        /// <summary>
        /// Gets a folder name from the function passed in, and returns it as a path
        /// relative to the project root folder.
        /// </summary>
        private string parseConfiguration_Folder(VCConfiguration vcConfiguration, Func <string> folderFn)
        {
            // We get the folder name, which may contain symbols e.g. £(ConfgurationName)...
            string pathWithSymbols = Utils.call(folderFn);

            // We resolve the symbols...
            string evaluatedPath = Utils.call(() => (vcConfiguration.Evaluate(pathWithSymbols)));

            // If we ave an absolute path, we convert it to a relative one...
            string relativePath = evaluatedPath;

            if (Path.IsPathRooted(evaluatedPath))
            {
                relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, evaluatedPath);
            }

            return(relativePath);
        }
Exemple #16
0
        public static string GetPCH(VCProject project, VCConfiguration config)
        {
            string pch = "";

            IVCCollection    tools  = config.Tools as IVCCollection;
            VCCLCompilerTool vctool = tools.Item("VCCLCompilerTool") as VCCLCompilerTool;

            if (vctool != null)
            {
                pch = vctool.PrecompiledHeaderThrough;
            }

            if (pch != "")
            {
                VCFile file = Connect.GetVCFile(project, config.Evaluate(pch));
                if (file != null)
                {
                    pch = file.Name;
                }
            }

            return(pch);
        }
Exemple #17
0
        /// <summary>
        /// Finds the library path for the configuration passed in.
        /// </summary>
        private void parseLinkerSettings_LibraryPath(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // We:
            // 1. Read the additional library paths (which are in a semi-colon-delimited string)
            // 2. Split it into separate paths
            // 3. Resolve any symbols
            // 4. Make sure all paths are relative to the project root folder

            // 1 & 2...
            string strAdditionalLibraryDirectories = Utils.call(() => (linkerTool.AdditionalLibraryDirectories));
            if (strAdditionalLibraryDirectories == null)
            {
                return;
            }

            List<string> additionalLibraryDirectories = Utils.split(strAdditionalLibraryDirectories, ';', ',');
            foreach (string additionalLibraryDirectory in additionalLibraryDirectories)
            {
                // The string may be quoted. We need to remove the quotes...
                string unquotedLibraryDirectory = additionalLibraryDirectory.Trim('"');
                if (unquotedLibraryDirectory == "")
                {
                    continue;
                }

                // 3 & 4...
                string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(unquotedLibraryDirectory)));
                if (resolvedPath != "")
                {
                    string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath);
                    configurationInfo.addLibraryPath(relativePath);
                }
            }
        }
Exemple #18
0
        /// <summary>
        /// Gets a folder name from the function passed in, and returns it as a path
        /// relative to the project root folder.
        /// </summary>
        private string parseConfiguration_Folder(VCConfiguration vcConfiguration, Func<string> folderFn)
        {
            // We get the folder name, which may contain symbols e.g. £(ConfgurationName)...
            string pathWithSymbols = Utils.call(folderFn);

            // We resolve the symbols...
            string evaluatedPath = Utils.call(() => (vcConfiguration.Evaluate(pathWithSymbols)));

            // If we ave an absolute path, we convert it to a relative one...
            string relativePath = evaluatedPath;
            if (Path.IsPathRooted(evaluatedPath))
            {
                relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, evaluatedPath);
            }

            return relativePath;
        }
Exemple #19
0
 public string EvaluateMacro(string macro)
 {
     return(_wrapped.Evaluate(macro));
 }
        /// <summary>
        /// Finds the library path for the configuration passed in.
        /// </summary>
        private void parseLinkerSettings_LibraryPath(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // Get the library paths across all property sheets
            List<string> libraryPaths = ToolPropertyCollector.Get(vcConfiguration, "VCLinkerTool", (tool) =>
                {
                    var linkerTool = tool as VCLinkerTool;
                    string str = Utils.call(() => (linkerTool.AdditionalLibraryDirectories));
                    if (str == null)
                        return null;
                    // The string may be quoted. We need to remove the quotes.
                    // (TODO: We might need to handle quotes in a smarter manner.)
                    return Utils.split(str, ';').Select(s => s.Trim('"')).ToList();
                } );

            // Process the library paths
            foreach (string libraryPath in libraryPaths)
            {
                if (libraryPath == "")
                    continue;

                string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(libraryPath)));
                if (resolvedPath == "")
                    continue;

                string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath);
                configurationInfo.addLibraryPath(relativePath);
            }
        }
Exemple #21
0
 public string Evaluate(string value)
 {
     return(_configuration.Evaluate(value));
 }
Exemple #22
0
        public static string GetPCH(VCProject project, VCConfiguration config)
        {
            string pch = "";

            IVCCollection tools = config.Tools as IVCCollection;
            VCCLCompilerTool vctool = tools.Item("VCCLCompilerTool") as VCCLCompilerTool;
            if (vctool != null)
            {
                pch = vctool.PrecompiledHeaderThrough;
            }

            if (pch != "")
            {
                VCFile file = Connect.GetVCFile(project, config.Evaluate(pch));
                if (file != null)
                {
                    pch = file.Name;
                }
            }

            return pch;
        }
        private static async Task <SourceFile> createSourceFileAsync(ProjectItem item)
        {
            try
            {
                await Instance.JoinableTaskFactory.SwitchToMainThreadAsync();

                Debug.Assert(isVisualCppProjectKind(item.ContainingProject.Kind));

                VCFile              vcFile     = item.Object as VCFile;
                VCProject           vcProject  = item.ContainingProject.Object as VCProject;
                VCConfiguration     vcconfig   = vcProject.ActiveConfiguration;
                VCFileConfiguration fileConfig = vcFile.FileConfigurations.Item(vcconfig.Name);

                string toolSetName = ((dynamic)vcconfig).PlatformToolsetFriendlyName;

                string     projectDirectory  = vcProject.ProjectDirectory;
                string     projectName       = vcProject.Name;
                SourceFile sourceForAnalysis = null;

                if (item.FileCount > 0)
                {
                    bool     bInheritDefs = true, bInheritUndefs = true;
                    string[] includePaths = { };

                    // Do the file-level first in case it disables inheritance. Include files don't have file-level config.
                    if (implementsInterface(fileConfig.Tool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
                    {
                        sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
                        includePaths      = fileConfig.Tool.FullIncludePath.Split(';');

                        // Other details may be gathered from the file, project or any inherited property sheets.
                        recursiveAddToolDetails(sourceForAnalysis, vcconfig, fileConfig.Tool, null, ref bInheritDefs, ref bInheritUndefs);
                    }

                    // Now get the full include path
                    VCCLCompilerTool projectTool = (VCCLCompilerTool)vcconfig.Tools.Item("VCCLCompilerTool");
                    if (projectTool != null && implementsInterface(projectTool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
                    {
                        if (sourceForAnalysis == null)
                        {
                            sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
                            includePaths      = projectTool.FullIncludePath.Split(';');
                        }

                        // Take the full include path from file level, which is already fully resolved.
                        for (int i = 0; i < includePaths.Length; ++i)
                        {
                            includePaths[i] = Environment.ExpandEnvironmentVariables(vcconfig.Evaluate(includePaths[i]));
                        }
                        sourceForAnalysis.addIncludePaths(includePaths);

                        recursiveAddToolDetails(sourceForAnalysis, vcconfig, projectTool, vcconfig.PropertySheets, ref bInheritDefs, ref bInheritUndefs);
                    }
                }

                return(sourceForAnalysis);
            }
            catch (Exception ex)
            {
                DebugTracer.Trace(ex);
                return(null);
            }
        }
Exemple #24
0
        public string ReplaceMacros(string s, VCConfiguration cfg = null)
        {
            if (cfg == null)
                cfg = config;

            //! Replace macros
            foreach (string macro in ProjectMacros.Collection)
            {
                string result = cfg.Evaluate(macro);
                if (result != null)
                    s = s.Replace(macro, result, StringComparison.CurrentCultureIgnoreCase);
            }

            return s;
        }
        /// <summary>
        /// Finds the collection of include paths for the configuration passed in.
        /// </summary>
        private void parseCompilerSettings_IncludePath(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            List<string> paths = ToolPropertyCollector.Get(vcConfiguration, "VCCLCompilerTool", (tool) =>
                {
                    var compilerTool = tool as VCCLCompilerTool;
                    string strAdditionalIncludeDirectories = Utils.call(() => (compilerTool.AdditionalIncludeDirectories));
                    if (strAdditionalIncludeDirectories == null)
                        return null;
                    // The string may be quoted. We need to remove the quotes.
                    // (TODO: We might need to handle quotes in a smarter manner.)
                    return Utils.split(strAdditionalIncludeDirectories, ';', ',').Select(s => s.Trim('"')).ToList();
                } );

            foreach (var path in paths)
            {
                // Resolve variables
                string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(path)));
                if (resolvedPath != "")
                {
                    // Make sure all paths are relative to the project root folder
                    string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath);
                    configurationInfo.addIncludePath(relativePath);
                }
            }
        }
        private void ProjectContextMenuItemCallback(object sender, EventArgs e)
        {
            var          dte          = this.dte.DTE;
            OutputWindow outputWindow = null;

            try
            {
                outputWindow = new OutputWindow(dte);

                OleMenuCommand menuCommand = sender as OleMenuCommand;
                if (menuCommand != null && dte != null)
                {
                    Array selectedProjects = (Array)dte.ActiveSolutionProjects;
                    //only support 1 selected project
                    if (selectedProjects.Length == 1)
                    {
                        EnvDTE.Project project = (EnvDTE.Project)selectedProjects.GetValue(0);
                        var            vcproj  = project.Object as VCProject;
                        if (vcproj != null)
                        {
                            IVCCollection   configs = (IVCCollection)vcproj.Configurations;
                            VCConfiguration cfg     = (VCConfiguration)vcproj.ActiveConfiguration;
                            VCDebugSettings debug   = (VCDebugSettings)cfg.DebugSettings;

                            string command          = null;
                            string arguments        = null;
                            string workingDirectory = null;
                            if (debug != null)
                            {
                                command          = cfg.Evaluate(debug.Command);
                                workingDirectory = cfg.Evaluate(debug.WorkingDirectory);
                                arguments        = cfg.Evaluate(debug.CommandArguments);
                            }

                            VCPlatform currentPlatform = (VCPlatform)cfg.Platform;

                            string platform = currentPlatform == null ? null : currentPlatform.Name;
                            if (platform != null)
                            {
                                platform = platform.ToLower();
                                if (platform.Contains("x64"))
                                {
                                    platform = "x64";
                                }
                                else if (platform.Contains("x86") || platform.Contains("win32"))
                                {
                                    platform = "x86";
                                }
                                else
                                {
                                    throw new NotSupportedException("Platform is not supported.");
                                }
                            }
                            else
                            {
                                cfg      = (VCConfiguration)configs.Item("Debug|x64");
                                platform = "x64";

                                if (cfg == null)
                                {
                                    throw new NotSupportedException("Cannot find x64 platform for project.");
                                }
                            }

                            if (command == null || String.IsNullOrEmpty(command))
                            {
                                command = cfg.PrimaryOutput;
                            }

                            if (command != null)
                            {
                                var solutionFolder = System.IO.Path.GetDirectoryName(dte.Solution.FileName);

                                CoverageExecution executor = new CoverageExecution(dte, outputWindow);
                                executor.Start(
                                    solutionFolder,
                                    platform,
                                    System.IO.Path.GetDirectoryName(command),
                                    System.IO.Path.GetFileName(command),
                                    workingDirectory,
                                    arguments);
                            }
                        }
                    }
                }
            }
            catch (NotSupportedException ex)
            {
                if (outputWindow != null)
                {
                    outputWindow.WriteLine("Error running coverage: {0}", ex.Message);
                }
            }
            catch (Exception ex)
            {
                if (outputWindow != null)
                {
                    outputWindow.WriteLine("Unexpected code coverage failure; error: {0}", ex.ToString());
                }
            }
        }