Exemple #1
0
        private static async Task <SourceFile> createSourceFileAsync(string filePath, Configuration targetConfig, dynamic project)
        {
            // TODO:
            //Debug.Assert(isVisualCppProject((object)project));
            try
            {
                await Instance.JoinableTaskFactory.SwitchToMainThreadAsync();

                var     configurationName = targetConfig.ConfigurationName;
                dynamic config            = project.Configurations.Item(configurationName);
                String  toolSetName       = config.PlatformToolsetShortName;
                if (String.IsNullOrEmpty(toolSetName))
                {
                    toolSetName = config.PlatformToolsetFriendlyName;
                }
                String     projectDirectory  = project.ProjectDirectory;
                String     projectName       = project.Name;
                SourceFile sourceForAnalysis = new SourceFile(filePath, projectDirectory, projectName, toolSetName);
                dynamic    toolsCollection   = config.Tools;
                foreach (var tool in toolsCollection)
                {
                    // Project-specific includes
                    if (implementsInterface(tool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
                    {
                        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(config.Evaluate(includePaths[i]));
                        }
                        ;

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

                return(sourceForAnalysis);
            }
            catch (Exception ex)
            {
                DebugTracer.Trace(ex);
                return(null);
            }
        }
Exemple #2
0
        SourceFile createSourceFile(string filePath, Configuration targetConfig, dynamic project)
        {
            Debug.Assert(isVisualCppProject((object)project));
            try
            {
                var     configurationName = targetConfig.ConfigurationName;
                dynamic config            = project.Configurations.Item(configurationName);
                String  toolSetName       = config.PlatformToolsetShortName;
                if (String.IsNullOrEmpty(toolSetName))
                {
                    toolSetName = config.PlatformToolsetFriendlyName;
                }
                String     projectDirectory  = project.ProjectDirectory;
                String     projectName       = project.Name;
                SourceFile sourceForAnalysis = new SourceFile(filePath, projectDirectory, projectName, toolSetName);
                dynamic    toolsCollection   = config.Tools;
                foreach (var tool in toolsCollection)
                {
                    // Project-specific includes
                    Type toolType = tool.GetType();
                    var  compilerToolInterface = toolType.GetInterface("Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool");
                    if (compilerToolInterface != null)
                    {
                        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] = config.Evaluate(includePaths[i]);
                        }

                        sourceForAnalysis.addIncludePaths(includePaths);
                        sourceForAnalysis.addMacros(definitions.Split(';'));
                        sourceForAnalysis.addMacrosToUndefine(macrosToUndefine.Split(';'));
                        break;
                    }
                }
                return(sourceForAnalysis);
            }
            catch (System.Exception ex)
            {
                DebugTracer.Trace(ex);
                return(null);
            }
        }
        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);
                    }
                }
            }
        }
        SourceFile createSourceFile(string filePath, Configuration targetConfig, dynamic project)
        {
            Debug.Assert(isVisualCppProject((object)project));
            try
            {
                var configurationName = targetConfig.ConfigurationName;
                dynamic config = project.Configurations.Item(configurationName);
                String toolSetName = config.PlatformToolsetShortName;
                if (String.IsNullOrEmpty(toolSetName))
                    toolSetName = config.PlatformToolsetFriendlyName;
                String projectDirectory = project.ProjectDirectory;
                String projectName = project.Name;
                SourceFile sourceForAnalysis = new SourceFile(filePath, projectDirectory, projectName, toolSetName);
                dynamic toolsCollection = config.Tools;
                foreach (var tool in toolsCollection)
                {
                    // Project-specific includes
                    Type toolType = tool.GetType();
                    var compilerToolInterface = toolType.GetInterface("Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool");
                    if (compilerToolInterface != null)
                    {
                        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] = config.Evaluate(includePaths[i]);

                        sourceForAnalysis.addIncludePaths(includePaths);
                        sourceForAnalysis.addMacros(definitions.Split(';'));
                        sourceForAnalysis.addMacrosToUndefine(macrosToUndefine.Split(';'));
                        break;
                    }
                }
                return sourceForAnalysis;
            }
            catch (System.Exception ex)
            {
                DebugTracer.Trace(ex);
                return null;
            }
        }