public static IVCProjectWrapper create(object wrapped) { if (modules == null) { modules = new Queue <IFactoryModule>(); // One of these modules will be working for each version of Visual Studio. modules.Enqueue(new FactoryModule2017()); modules.Enqueue(new FactoryModule2015()); modules.Enqueue(new FactoryModule2013()); modules.Enqueue(new FactoryModule2012()); } IVCProjectWrapper wrapper = null; int testedModuleCount = 0; while (wrapper == null && testedModuleCount < modules.Count) { try { wrapper = modules.Peek().Create(wrapped); } catch (Exception) { wrapper = null; } testedModuleCount++; if (wrapper == null || !wrapper.isValid()) { // Moving the failing module to the end of the queue. // This causes the working module to finall end up in front. IFactoryModule failedModule = modules.Dequeue(); Logging.LogInfo("Discarcing " + failedModule.GetType().Name + " while creating project wrapper."); modules.Enqueue(failedModule); wrapper = null; } } return(wrapper); }
private void buttonSelectReferencing_Click(object sender, EventArgs e) { List <Utility.SolutionUtility.SolutionStructure.Node> projectNodes = getTreeViewProjectNodes(); List <string> selectedProjects = new List <string>(); foreach (Utility.SolutionUtility.SolutionStructure.Node projectNode in projectNodes) { if ((projectNode.UserData as TreeNode).Checked) { selectedProjects.Add(projectNode.Name); } } bool stateChanged = true; while (stateChanged) { stateChanged = false; foreach (Utility.SolutionUtility.SolutionStructure.Node projectNode in projectNodes) { if (!(projectNode.UserData as TreeNode).Checked) { IVCProjectWrapper vcProject = VCProjectWrapperFactory.create(projectNode.Project.Object); if (vcProject != null && vcProject.isValid()) { foreach (string referencedProjectName in vcProject.GetReferencedProjectNames()) { if (selectedProjects.Contains(referencedProjectName)) { (projectNode.UserData as TreeNode).Checked = true; selectedProjects.Add(projectNode.Name); stateChanged = true; } } } } } } }
public void CreateCompileCommands(Project project, string solutionConfigurationName, string solutionPlatformName, string cStandard, string additionalClangOptions, Action <CompileCommand, bool> lambda) { Logging.Logging.LogInfo("Creating command objects for project \"" + Logging.Obfuscation.NameObfuscator.GetObfuscatedName(project.Name) + "\"."); DTE dte = project.DTE; Guid projectGuid = Utility.ProjectUtility.ReloadProject(project); IVCProjectWrapper vcProject = VCProjectEngineWrapper.VCProjectWrapperFactory.create(project.Object); if (vcProject != null && vcProject.isValid()) { Logging.Logging.LogInfo("Project \"" + Logging.Obfuscation.NameObfuscator.GetObfuscatedName(project.Name) + "\" has been converted to VCProject " + vcProject.GetWrappedVersion() + "."); } else { Logging.Logging.LogWarning("Project \"" + Logging.Obfuscation.NameObfuscator.GetObfuscatedName(project.Name) + "\" could not be converted to VCProject, skipping."); return; } string projectConfigurationName = ""; string projectPlatformName = ""; foreach (SolutionConfiguration2 solutionConfiguration in SolutionUtility.GetSolutionBuild2(dte).SolutionConfigurations) { if (solutionConfiguration.Name == solutionConfigurationName && solutionConfiguration.PlatformName == solutionPlatformName) { foreach (SolutionContext solutionContext in solutionConfiguration.SolutionContexts) { if (vcProject.GetProjectFile().EndsWith(solutionContext.ProjectName)) { projectConfigurationName = solutionContext.ConfigurationName; projectPlatformName = solutionContext.PlatformName; } } } } if (projectConfigurationName.Length == 0 || projectPlatformName.Length == 0) { Logging.Logging.LogWarning("No project configuration found for solution configuration, trying to use solution configuration on project."); projectConfigurationName = solutionConfigurationName; projectPlatformName = solutionPlatformName; } IVCConfigurationWrapper vcProjectConfiguration = vcProject.getConfiguration(projectConfigurationName, projectPlatformName); if (vcProjectConfiguration != null && vcProjectConfiguration.isValid()) { SetCompatibilityVersionFlag(vcProject, vcProjectConfiguration); string commandFlags = ""; { // gather include paths and preprocessor definitions of the project List <string> includeDirectories = ProjectUtility.GetIncludeDirectories(vcProject, vcProjectConfiguration, _pathResolver); List <string> preprocessorDefinitions = ProjectUtility.GetPreprocessorDefinitions(vcProject, vcProjectConfiguration); List <string> forcedIncludeFiles = ProjectUtility.GetForcedIncludeFiles(vcProject, vcProjectConfiguration, _pathResolver); foreach (string flag in _compatibilityFlags) { commandFlags += flag + " "; } commandFlags += _compatibilityVersionFlag + " "; if (!string.IsNullOrWhiteSpace(additionalClangOptions)) { commandFlags += additionalClangOptions; } foreach (string dir in includeDirectories) { commandFlags += " -isystem \"" + dir + "\" "; // using '-isystem' because it allows for use of quotes and pointy brackets in source files. In other words it's more robust. It's slower than '-I' though } foreach (string prepDef in preprocessorDefinitions) { commandFlags += " -D " + prepDef + " "; } foreach (string file in forcedIncludeFiles) { commandFlags += " -include \"" + file + "\" "; } } string cppStandard = Utility.ProjectUtility.GetCppStandardForProject(vcProject); Logging.Logging.LogInfo("Found C++ standard " + cppStandard + "."); bool isMakefileProject = vcProjectConfiguration.isMakefileConfiguration(); // create command objects for all applicable project items { List <CompileCommand> compileCommands = Utility.ProjectUtility.GetProjectItems(project).Select(item => { return(CreateCompileCommand(item, commandFlags, cppStandard, cStandard, isMakefileProject)); }).Where(command => command != null).ToList(); for (int i = 0; i < compileCommands.Count; i++) { lambda(compileCommands[i], i == compileCommands.Count - 1); } } if (projectGuid != Guid.Empty) { Utility.ProjectUtility.UnloadProject(projectGuid, dte); } } else { Logging.Logging.LogError("No project configuration found. Skipping this project"); } }
public void CreateCompileCommands(Project project, string solutionConfigurationName, string solutionPlatformName, string cStandard, string additionalClangOptions, bool nonSystemIncludesUseAngleBrackets, Action <CompileCommand> lambda) { Logging.Logging.LogInfo("Creating command objects for project \"" + Logging.Obfuscation.NameObfuscator.GetObfuscatedName(project.Name) + "\"."); DTE dte = project.DTE; Guid projectGuid = Utility.ProjectUtility.ReloadProject(project); IVCProjectWrapper vcProject = VCProjectEngineWrapper.VCProjectWrapperFactory.create(project.Object); if (vcProject != null && vcProject.isValid()) { Logging.Logging.LogInfo("Project \"" + Logging.Obfuscation.NameObfuscator.GetObfuscatedName(project.Name) + "\" has been converted to VCProject " + vcProject.GetWrappedVersion() + "."); } else { Logging.Logging.LogWarning("Project \"" + Logging.Obfuscation.NameObfuscator.GetObfuscatedName(project.Name) + "\" could not be converted to VCProject, skipping."); return; } string projectConfigurationName = ""; string projectPlatformName = ""; foreach (SolutionConfiguration2 solutionConfiguration in SolutionUtility.GetSolutionBuild2(dte).SolutionConfigurations) { if (solutionConfiguration.Name == solutionConfigurationName && solutionConfiguration.PlatformName == solutionPlatformName) { foreach (SolutionContext solutionContext in solutionConfiguration.SolutionContexts) { if (vcProject.GetProjectFile().EndsWith(solutionContext.ProjectName)) { projectConfigurationName = solutionContext.ConfigurationName; projectPlatformName = solutionContext.PlatformName; } } } } if (projectConfigurationName.Length == 0 || projectPlatformName.Length == 0) { Logging.Logging.LogWarning("No project configuration found for solution configuration, trying to use solution configuration on project."); projectConfigurationName = solutionConfigurationName; projectPlatformName = solutionPlatformName; } IVCConfigurationWrapper vcProjectConfiguration = vcProject.getConfiguration(projectConfigurationName, projectPlatformName); if (vcProjectConfiguration != null && vcProjectConfiguration.isValid()) { SetCompatibilityVersionFlag(vcProject, vcProjectConfiguration); string commandFlags = ""; { // gather include paths and preprocessor definitions of the project List <string> projectIncludeDirectories = ProjectUtility.GetProjectIncludeDirectories(vcProject, vcProjectConfiguration, _pathResolver); List <string> systemIncludeDirectories = ProjectUtility.GetSystemIncludeDirectories(vcProject, vcProjectConfiguration, _pathResolver); List <string> preprocessorDefinitions = ProjectUtility.GetPreprocessorDefinitions(vcProject, vcProjectConfiguration); List <string> forcedIncludeFiles = ProjectUtility.GetForcedIncludeFiles(vcProject, vcProjectConfiguration, _pathResolver); foreach (string flag in _compatibilityFlags) { commandFlags += flag + " "; } commandFlags += _compatibilityVersionFlag + " "; if (!string.IsNullOrWhiteSpace(additionalClangOptions)) { commandFlags += additionalClangOptions; } if (nonSystemIncludesUseAngleBrackets) { systemIncludeDirectories.InsertRange(0, projectIncludeDirectories); projectIncludeDirectories.Clear(); } foreach (string dir in projectIncludeDirectories) { commandFlags += " -I \"" + dir + "\" "; } foreach (string dir in systemIncludeDirectories) { commandFlags += " -isystem \"" + dir + "\" "; } foreach (string prepDef in preprocessorDefinitions) { commandFlags += " -D " + prepDef + " "; } foreach (string file in forcedIncludeFiles) { commandFlags += " -include \"" + file + "\" "; } } string cppStandard = Utility.ProjectUtility.GetCppStandardForProject(vcProject); Logging.Logging.LogInfo("Found C++ standard " + cppStandard + "."); bool isMakefileProject = vcProjectConfiguration.isMakefileConfiguration(); // create command objects for all applicable project items { foreach (ProjectItem item in Utility.ProjectUtility.GetProjectItems(project)) { CompileCommand command = CreateCompileCommand(item, commandFlags, cppStandard, cStandard, isMakefileProject); if (command == null) { continue; } lambda(command); } } if (projectGuid != Guid.Empty) { Utility.ProjectUtility.UnloadProject(projectGuid, dte); } } else { Logging.Logging.LogError("No project configuration found. Skipping this project"); } }