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(); }
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()); }
public void LoadCpps() { this.Cpps = new Dictionary <string, Cpp>(); string config = Connect.GetActiveConfigString(this.Project); VCFilter unityfilter = this.Filter.GetVCFilter(); foreach (VCFile file in this.VCProject.Files as IVCCollection) { if (file.Extension.ToLower() == ".cpp" && file.Parent != unityfilter) { VCFileConfiguration cfg = Connect.GetFileConfiguration(file, config); VCCLCompilerTool vctool = cfg.Tool as VCCLCompilerTool; if (vctool != null) { if (vctool.UsePrecompiledHeader == Microsoft.VisualStudio.VCProjectEngine.pchOption.pchCreateUsingSpecific) { continue; } } Cpp cpp = this.GetCppInUnity(file.RelativePath); if (cpp == null) { cpp = new Cpp(file); } this.Cpps.Add(cpp.Name, cpp); } } }
public CompilerToolWrapper(VCFileConfiguration config) { compilerTool = config.Tool as VCCLCompilerTool; if (compilerTool == null) { compilerObj = config.Tool; compilerType = compilerObj.GetType(); } }
public static void SetExcludedFromBuild(VCFile file, string config, bool excluded) { VCFileConfiguration cfg = Connect.GetFileConfiguration(file, config); if (cfg != null) { cfg.ExcludedFromBuild = excluded; } }
public static CompilerToolWrapper Create(VCFileConfiguration config) { CompilerToolWrapper wrapper = null; try { wrapper = new CompilerToolWrapper(config.Tool); } catch { } return(wrapper.IsNull() ? null : wrapper); }
static public string GetDefinesForFile(VCFileConfiguration vcFileConfiguration) { StringBuilder defines = new StringBuilder(); VCCLCompilerTool vcCTool = (VCCLCompilerTool)vcFileConfiguration.Tool; if (String.IsNullOrEmpty(vcCTool.PreprocessorDefinitions) == false) { ts.TraceInformation("GetDefinesForFile: PreprocessorDefinitions\n" + vcCTool.PreprocessorDefinitions); defines.Append(BuildDefines(vcCTool.PreprocessorDefinitions)); } ts.TraceInformation("GetDefinesForFile PreprocessorDefinitions:\n" + vcCTool.PreprocessorDefinitions); return(defines.ToString()); }
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); } }
/// <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);; } }
static public Queue <VCFile> CreateFileQueue(VCProject vcProject) { ts.TraceInformation("CreateFileQueue"); Queue <VCFile> fileQueue = new Queue <VCFile>(); var vcFileCollection = (IVCCollection)vcProject.Files; if (vcFileCollection == null) { ts.TraceData(TraceEventType.Verbose, 1, "CreateFileList cannot get vc file collection"); return(null); } ts.TraceInformation("CreateFileQueue #vcFileCollection " + vcFileCollection.Count); foreach (VCFile vcFile in vcFileCollection) { try { VCFileConfiguration vcFileConfiguration = DTE2Utils.GetVcFileConfiguration( vcFile, DTE2Utils.GetVcConfiguratioForVcProject(vcProject)); if (vcFileConfiguration != null) { if ((vcFileConfiguration.ExcludedFromBuild == false) && (vcFile.FileType == eFileType.eFileTypeCppCode)) { ts.TraceData(TraceEventType.Verbose, 1, "CreateFileList add " + vcFile.FullPath); fileQueue.Enqueue(vcFile); } else { ts.TraceData(TraceEventType.Verbose, 1, "CreateFileList exclude " + vcFile.FullPath); } } } catch (Exception exception) { ts.TraceData(TraceEventType.Verbose, 1, "CreateFileList exception " + exception.Message); } } ts.TraceInformation("CreateFileList project " + vcProject.Name + " #files " + fileQueue.Count); return(fileQueue); }
private void DisableConfigForEachFile(ref VCProject actVCP, string BuildMode) { Log("\tFile Specific Configuration"); 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) { try { // Preprocessed headers VCFileConfiguration fileConfiguration = (VCFileConfiguration)(((IVCCollection)file.FileConfigurations).Item(BuildMode)); // Access the release configuration of this file. VCCLCompilerTool compilerTool = (VCCLCompilerTool)fileConfiguration.Tool; // Get the compiler tool associated with this file. if (compilerTool.AdditionalOptions != null) { string newargs = DisableCodeCoverageCommandLineArguments(compilerTool.AdditionalOptions); if (compilerTool.AdditionalOptions != newargs) { compilerTool.AdditionalOptions = newargs; Log("\t\tAdditional command line arguments set to '" + newargs + "' for the file '" + file.Name + "'"); } } } catch (Exception e) { Debug(e); } } } catch (Exception e) { Debug(e); } } } }
private VCFileConfiguration GetVCFileConfigForCompilation(Document document, out string reasonForFailure) { if (document == null) { reasonForFailure = "No document."; return(null); } var vcProject = document.ProjectItem.ContainingProject?.Object as VCProject; if (vcProject == null) { reasonForFailure = "The given document does not belong to a VC++ Project."; return(null); } VCFile vcFile = document.ProjectItem?.Object as VCFile; if (vcFile == null) { reasonForFailure = "The given document is not a VC++ file."; return(null); } if (vcFile.FileType != eFileType.eFileTypeCppCode) { reasonForFailure = "The given document is not a compileable VC++ file."; return(null); } IVCCollection fileConfigCollection = vcFile.FileConfigurations as IVCCollection; VCFileConfiguration fileConfig = fileConfigCollection?.Item(vcProject.ActiveConfiguration.Name) as VCFileConfiguration; if (fileConfig == null) { reasonForFailure = "Failed to retrieve file config from document."; return(null); } reasonForFailure = ""; return(fileConfig); }
static public string GetIncludesForFile(VCFileConfiguration vcFileConfiguration) { StringBuilder includes = new StringBuilder(); VCCLCompilerTool vcCTool = (VCCLCompilerTool)vcFileConfiguration.Tool; if (String.IsNullOrEmpty(vcCTool.AdditionalIncludeDirectories) == false) { ts.TraceInformation("GetIncludesForFile: AdditionalIncludeDirectories\n" + vcCTool.AdditionalIncludeDirectories); includes.Append(BuildIncludes(vcFileConfiguration.Evaluate(vcCTool.AdditionalIncludeDirectories), "-D")); } if (String.IsNullOrEmpty(vcCTool.ForcedIncludeFiles) == false) { ts.TraceInformation("GetIncludesForFile: ForcedIncludeFiles\n" + vcCTool.ForcedIncludeFiles); includes.Append(BuildIncludes(vcCTool.ForcedIncludeFiles, "-include")); } ts.TraceInformation("GetIncludesForFile: \n" + includes.ToString()); return(includes.ToString()); }
private static async Task <VCFileConfiguration> GetVCFileConfigForCompilation(Document document) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (document == null) { throw new VCQueryFailure("No document."); } var vcProject = document.ProjectItem?.ContainingProject?.Object as VCProject; if (vcProject == null) { throw new VCQueryFailure("The given document does not belong to a VC++ Project."); } VCFile vcFile = document.ProjectItem?.Object as VCFile; if (vcFile == null) { throw new VCQueryFailure("The given document is not a VC++ file."); } if (vcFile.FileType != eFileType.eFileTypeCppCode) { throw new VCQueryFailure("The given document is not a compileable VC++ file."); } IVCCollection fileConfigCollection = vcFile.FileConfigurations as IVCCollection; VCFileConfiguration fileConfig = fileConfigCollection?.Item(vcProject.ActiveConfiguration.Name) as VCFileConfiguration; if (fileConfig == null) { throw new VCQueryFailure("Failed to retrieve file config from document."); } return(fileConfig); }
private string GetIncludes(VCFileConfiguration conf) { List<string> includeList = GetIncludesFromCompilerTool(CompilerToolWrapper.Create(conf)); VCConfiguration projectConfig = conf.ProjectConfiguration as VCConfiguration; includeList.AddRange(GetIncludesFromCompilerTool(CompilerToolWrapper.Create(projectConfig))); IVCCollection propertySheets = projectConfig.PropertySheets as IVCCollection; if (propertySheets != null) foreach (VCPropertySheet sheet in propertySheets) includeList.AddRange(GetIncludesFromPropertySheet(sheet)); string includes = ""; List<string> alreadyAdded = new List<string>(); foreach (string include in includeList) { if (!alreadyAdded.Contains(include)) { string incl = HelperFunctions.NormalizeRelativeFilePath(include); if (incl.Length > 0) { string cmdline = " "; cmdline += SafelyQuoteCommandLineArgument("-I" + incl); includes += cmdline; } alreadyAdded.Add(include); } } return includes; }
/// <summary> /// Searches for the generated file inside the "Generated Files" filter. /// The function looks for the given filename and uses the fileConfig's /// ConfigurationName and Platform if moc directory contains $(ConfigurationName) /// and/or $(PlatformName). /// Otherwise it just uses the "Generated Files" filter /// </summary> /// <param name="fileName"></param> /// <param name="fileConfig"></param> /// <returns></returns> private VCFile GetGeneratedMocFile(string fileName, VCFileConfiguration fileConfig) { if (QtVSIPSettings.HasDifferentMocFilePerConfig(envPro) || QtVSIPSettings.HasDifferentMocFilePerPlatform(envPro)) { VCConfiguration projectConfig = (VCConfiguration)fileConfig.ProjectConfiguration; string configName = projectConfig.ConfigurationName; string platformName = ((VCPlatform)projectConfig.Platform).Name; VCFilter generatedFiles = FindFilterFromGuid(Filters.GeneratedFiles().UniqueIdentifier); if (generatedFiles == null) return null; foreach (VCFilter filt in (IVCCollection)generatedFiles.Filters) if (filt.Name == configName + "_" + platformName || filt.Name == configName || filt.Name == platformName) foreach (VCFile filtFile in (IVCCollection)filt.Files) if (filtFile.FullPath.EndsWith(fileName)) return filtFile; //If a project from the an AddIn prior to 1.1.0 was loaded, the generated files are located directly //in the generated files filter. string relativeMocPath = QtVSIPSettings.GetMocDirectory(envPro, configName, platformName) + '\\' + fileName; //Remove .\ at the beginning of the mocPath if (relativeMocPath.StartsWith(".\\")) relativeMocPath = relativeMocPath.Remove(0, 2); foreach (VCFile filtFile in (IVCCollection)generatedFiles.Files) if (filtFile.FullPath.EndsWith(relativeMocPath, StringComparison.OrdinalIgnoreCase)) return filtFile; } else { VCFilter generatedFiles = FindFilterFromGuid(Filters.GeneratedFiles().UniqueIdentifier); foreach (VCFile filtFile in (IVCCollection)generatedFiles.Files) if (filtFile.FullPath.EndsWith('\\' + fileName)) return filtFile; } return null; }
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; } } }
public string GetDefines(VCFileConfiguration conf) { List<string> defineList = CompilerToolWrapper.Create(conf).PreprocessorDefinitions; VCConfiguration projectConfig = conf.ProjectConfiguration as VCConfiguration; defineList.AddRange(CompilerToolWrapper.Create(projectConfig).PreprocessorDefinitions); IVCCollection propertySheets = projectConfig.PropertySheets as IVCCollection; if (propertySheets != null) foreach (VCPropertySheet sheet in propertySheets) defineList.AddRange(GetDefinesFromPropertySheet(sheet)); string preprocessorDefines = ""; List<string> alreadyAdded = new List<string>(); Regex rxp = new Regex(@"\s|(\$\()"); foreach (string define in defineList) { if (!alreadyAdded.Contains(define)) { bool mustSurroundByDoubleQuotes = rxp.IsMatch(define); // Yes, a preprocessor definition can contain spaces or a macro name. // Example: PROJECTDIR=$(InputDir) if (mustSurroundByDoubleQuotes) { preprocessorDefines += " "; preprocessorDefines += SafelyQuoteCommandLineArgument("-D" + define); } else { preprocessorDefines += " -D" + define; } alreadyAdded.Add(define); } } return preprocessorDefines; }
/// <summary> /// Since VS2010 it is possible to have VCCustomBuildTools without commandlines /// for certain filetypes. We are not interested in them and thus try to read the /// tool's commandline. If this causes an exception, we ignore it. /// There does not seem to be another way for checking which kind of tool it is. /// </summary> /// <param name="config">File configuration</param> /// <returns></returns> public static VCCustomBuildTool GetCustomBuildTool(VCFileConfiguration config) { VCCustomBuildTool tool = config.Tool as VCCustomBuildTool; if (tool == null) return null; try { string cmdLine = tool.CommandLine; } catch { return null; } return tool; }
public static CompilerToolWrapper Create(VCFileConfiguration config) { CompilerToolWrapper wrapper = null; try { wrapper = new CompilerToolWrapper(config.Tool); } catch { } return wrapper.IsNull() ? null : wrapper; }
private const int timeoutMS = 30000; // 30 seconds public static VCFileConfiguration GetFileConfig(EnvDTE.Document document, out string reasonForFailure, out bool isHeader) { isHeader = false; if (document == null) { reasonForFailure = "No document."; return(null); } string unityPath = document.Path; unityPath = System.IO.Path.Combine(unityPath, "unity"); var project = document.ProjectItem?.ContainingProject; VCProject vcProject = project.Object as VCProject; if (vcProject == null) { reasonForFailure = "The given document does not belong to a VC++ Project."; return(null); } VCFile vcFile = document.ProjectItem?.Object as VCFile; if (vcFile == null) { reasonForFailure = "The given document is not a VC++ file."; return(null); } VCFilter vcFolder = vcFile.Parent as VCFilter; if (vcFolder == null) { reasonForFailure = "Can't get folder for VC++ file."; return(null); } // Replace file with unity file with the same path foreach (VCFile file in vcFolder.Items) { if (file != null) { if (System.IO.Path.GetFileName(file.FullPath).StartsWith("unity_")) { vcFile = file; break; } } } if (vcFile == null) { reasonForFailure = "The given document is not a VC++ file."; return(null); } isHeader = vcFile.FileType == Microsoft.VisualStudio.VCProjectEngine.eFileType.eFileTypeCppHeader; IVCCollection fileConfigCollection = vcFile.FileConfigurations; VCFileConfiguration fileConfig = fileConfigCollection?.Item(vcProject.ActiveConfiguration.Name); if (fileConfig == null) { reasonForFailure = "Failed to retrieve file config from document."; return(null); } reasonForFailure = ""; return(fileConfig); }
static FileCompilationInfo ProcessVCFile(ProgramOptions options, FileCompilationInfo entry, VCFile file, VCFileConfiguration fileConfig, string arch, bool isWin64) { //WriteLine($"{file.RelativePath}: {file.FileType},{file.Kind},{file.SubType},{file.ItemName},{file.UnexpandedRelativePath}"); if (fileConfig.ExcludedFromBuild) { Console.Error.WriteLine($"warning: `{file.Name}` Excluded FromBuild."); return(null); } switch (file.FileType) { case eFileType.eFileTypeCppClass: case eFileType.eFileTypeCppCode: case eFileType.eFileTypeCppControl: case eFileType.eFileTypeCppForm: case eFileType.eFileTypeCppHeader: case eFileType.eFileTypeCppWebService: break; default: return(null); } var isHeader = (file.FileType == eFileType.eFileTypeCppHeader); WriteLine(file.RelativePath); if (options.OnlyConvertToUtf8 || options.ConvertToUtf8OnTheFly) { ConverToUtf8(file.FullPath); if (options.OnlyConvertToUtf8) { return(null); } } entry.file = StripCurrentDir(file.RelativePath); VCConfiguration projectConfig = fileConfig.ProjectConfiguration; var projectTool = projectConfig.Tools.Item(VCCLCompilerToolName) is WCE.VCCLWCECompilerToolBase ? new WCECompilerToolWrapper(projectConfig.Tools.Item(VCCLCompilerToolName)) : projectConfig.Tools.Item(VCCLCompilerToolName) as VCCLCompilerTool; var fileTool = fileConfig.Tool is WCE.VCCLWCECompilerToolBase ? new WCECompilerToolWrapper(fileConfig.Tool) : fileConfig.Tool as VCCLCompilerTool; // if file is header, filetool is null. var tool = fileTool ?? projectTool; if (isHeader && !options.IncludesHeaderFiles) { return(null); } var createPch = tool.UsePrecompiledHeader == pchOption.pchCreateUsingSpecific; var pchFilePath = fileConfig.Evaluate(tool.PrecompiledHeaderFile); entry.AddArg(isWin64 ? "-m64" : "-m32"); entry.AddArg("--target=" + arch + "-pc-windows-msvc"); entry.AddArg("-fshort-wchar"); AddPath(entry, "-D ", fileConfig.Evaluate(projectTool.PreprocessorDefinitions + fileTool?.PreprocessorDefinitions) ?? ""); AddPath(entry, "-U ", fileConfig.Evaluate(projectTool.UndefinePreprocessorDefinitions + fileTool?.UndefinePreprocessorDefinitions) ?? ""); AddPath(entry, "-I ", tool.FullIncludePath); AddPath(entry, "-include ", fileConfig.Evaluate(tool.ForcedIncludeFiles ?? projectTool.ForcedIncludeFiles)); if (createPch) { entry.output = pchFilePath; entry.AddArg("-o"); entry.AddArg(QuatePath(entry.output)); } else if (isHeader) { entry.AddArg("-S"); // Only run preprocess and compilation steps // fsyntax-only } else { entry.AddArg("-c"); // Only run preprocess, compile, and assemble steps entry.output = Path.Combine(fileConfig.Evaluate(tool.ObjectFile), Path.ChangeExtension(file.Name, ".obj")); entry.AddArg("-o"); entry.AddArg(QuatePath(entry.output)); } if (tool.UsePrecompiledHeader == pchOption.pchUseUsingSpecific) { entry.AddArg("-include-pch"); entry.AddArg(QuatePath(pchFilePath)); } switch (tool.WarningLevel) { case warningLevelOption.warningLevel_4: entry.AddArg("-Wall"); entry.AddArg("-Wextra"); entry.AddArg("-Wno-undef"); entry.AddArg("-Wno-c++11-extensions"); entry.AddArg("-Wno-unknown-pragmas"); //entry.AddArg("-Wno-old-style-cast"); //entry.AddArg("-Wno-gnu-anonymous-struct"); //entry.AddArg("-Wno-gnu-zero-variadic-macro-arguments"); //entry.AddArg("-Wno-reserved-id-macro"); //entry.AddArg("-Wno-c++11-long-long"); //entry.AddArg("-Wno-language-extension-token"); //entry.AddArg("-Wno-non-virtual-dtor"); //entry.AddArg("-Wno-dollar-in-identifier-extension"); //entry.AddArg("-Wno-zero-length-array"); break; case warningLevelOption.warningLevel_3: case warningLevelOption.warningLevel_2: case warningLevelOption.warningLevel_1: entry.AddArg("-Wall"); break; } if (!options.NowWarnAsError && tool.WarnAsError) { entry.AddArg("-Werror"); } switch (tool.Optimization) { case optimizeOption.optimizeFull: entry.AddArg("-O3"); break; case optimizeOption.optimizeMaxSpeed: entry.AddArg("-O2"); break; case optimizeOption.optimizeMinSpace: entry.AddArg("-O1"); break; } if (tool.DebugInformationFormat != debugOption.debugDisabled) { entry.AddArg("-g"); } entry.AddArg(tool.RuntimeTypeInfo ? "-frtti" : "-fno-rtti"); switch (tool.ExceptionHandling) { case cppExceptionHandling.cppExceptionHandlingYesWithSEH: entry.AddArg("-fseh-exceptions"); if (tool.CompileAs == CompileAsOptions.compileAsCPlusPlus) { entry.AddArg("-fcxx-exceptions"); } break; case cppExceptionHandling.cppExceptionHandlingYes: entry.AddArg("-fcxx-exceptions"); break; case cppExceptionHandling.cppExceptionHandlingNo: entry.AddArg("-fno-cxx-exceptions"); break; } switch (tool.InlineFunctionExpansion) { case inlineExpansionOption.expandDisable: entry.AddArg("-fno-inline-functions"); break; case inlineExpansionOption.expandOnlyInline: entry.AddArg("-finline-hint-functions"); break; case inlineExpansionOption.expandAnySuitable: entry.AddArg("-finline-functions"); break; } if (tool.EnableIntrinsicFunctions) { entry.AddArg("-fbuiltin"); } switch (tool.CompileAs) { case CompileAsOptions.compileAsC: entry.AddArg("-x c" + (createPch ? "-header" : "")); entry.AddArg("-std=c99"); break; case CompileAsOptions.compileAsCPlusPlus: entry.AddArg("-x c++" + (createPch ? "-header" : "")); entry.AddArg("-std=c++03"); break; } { string msvcVer = default; (file.project as VCProject).Version(out var major, out var minor); switch ($"{ major}.{minor}") { case "8.0": msvcVer = "14.00"; break; case "7.1": msvcVer = "13.10"; break; case "7.0": msvcVer = "13.00"; break; default: case "9.0": msvcVer = "15.00"; break; } entry.AddArg("-fms-compatibility-version=" + msvcVer); } switch (tool.CallingConvention) { case callingConventionOption.callConventionCDecl: //entry.AddArg("-fdefault-calling-conv=cdecl"); break; case callingConventionOption.callConventionStdCall: entry.AddArg("-mrtd"); //entry.AddArg("-fdefault-calling-conv=stdcall"); break; case callingConventionOption.callConventionFastCall: Console.Error.WriteLine($"warning: Not supported CallingConvention: {tool.CallingConvention}."); //entry.AddArg("-fdefault-calling-conv=fastcall"); break; } string crt = default; switch (tool.RuntimeLibrary) { case runtimeLibraryOption.rtMultiThreaded: entry.AddArg("-D_MT"); crt = "--dependent-lib=libcmt"; break; case runtimeLibraryOption.rtMultiThreadedDebug: entry.AddArg("-D_MT"); crt = "--dependent-lib=libcmtd"; break; case runtimeLibraryOption.rtMultiThreadedDLL: entry.AddArg("-D_MT"); entry.AddArg("-D_DLL"); crt = "--dependent-lib=msvcrt"; break; case runtimeLibraryOption.rtMultiThreadedDebugDLL: entry.AddArg("-D_MT"); entry.AddArg("-D_DLL"); crt = "--dependent-lib=msvcrtd"; break; } if (tool.OmitDefaultLibName) { entry.AddArg("-D_VC_NODEFAULTLIB"); } else { //TODO entry.AddArg(crt); } if (!tool.DisableLanguageExtensions) { entry.AddArg("-fms-extensions"); entry.AddArg("-Wno-microsoft-goto"); entry.AddArg("-Wno-microsoft-exception-spec"); entry.AddArg("-Wno-microsoft-enum-value"); entry.AddArg("-Wno-microsoft-comment-paste"); entry.AddArg("-Wno-microsoft-cast"); entry.AddArg("-Wno-microsoft-anon-tag"); } if (tool.BufferSecurityCheck) { entry.AddArg("-fstack-protector"); } if (tool.ShowIncludes) { entry.AddArg("--trace-includes"); } if (tool.UndefineAllPreprocessorDefinitions) { entry.AddArg("-undef"); } if (!tool.StringPooling) { entry.AddArg("-fwritable-strings"); } if (tool.DefaultCharIsUnsigned) { entry.AddArg("-fno-signed-char"); } switch (tool.StructMemberAlignment) { case structMemberAlignOption.alignSingleByte: entry.AddArg("-fpack-struct=1"); break; case structMemberAlignOption.alignTwoBytes: entry.AddArg("-fpack-struct=2"); break; case structMemberAlignOption.alignFourBytes: entry.AddArg("-fpack-struct=4"); break; case structMemberAlignOption.alignEightBytes: entry.AddArg("-fpack-struct=8"); break; case structMemberAlignOption.alignSixteenBytes: entry.AddArg("-fpack-struct=16"); break; case structMemberAlignOption.alignNotSet: break; } if (tool.OmitFramePointers) { entry.AddArg("-momit-leaf-frame-pointer"); } switch (tool.floatingPointModel) { case floatingPointModel.FloatingPointFast: entry.AddArg("-ffast-math"); break; } if (tool.EnablePREfast) { entry.AddArg("--analyze"); } entry.AddArg(QuatePath(entry.file)); if (options.PrintClangCommand) { Console.Error.WriteLine(entry.ToString()); } return(entry); }
// throws COMException if not found static void GetVCToolProps(IVsHierarchy proj, uint itemid, out VCFileConfiguration fcfg, out VCConfiguration cfg, out System.Reflection.IReflect vcrefl, out IVCRulePropertyStorage vcprop) { object ext; if (proj.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out ext) != 0) { throw new COMException(); } object projext; if (proj.GetProperty(_VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out projext) != 0) { throw new COMException(); } var envproj = projext as EnvDTE.Project; if (envproj == null) { throw new COMException(); } var envitem = ext as EnvDTE.ProjectItem; if (envitem == null) { throw new COMException(); } var cfgmgr = envproj.ConfigurationManager; var activecfg = cfgmgr.ActiveConfiguration; var activename = activecfg.ConfigurationName + "|" + activecfg.PlatformName; fcfg = null; cfg = null; var vcfile = envitem.Object as Microsoft.VisualStudio.VCProjectEngine.VCFile; if (vcfile != null) { var vcfconfigs = vcfile.FileConfigurations as IVCCollection; for (int c = 1; c <= vcfconfigs.Count; c++) { var vcfcfg = vcfconfigs.Item(c); fcfg = vcfcfg as Microsoft.VisualStudio.VCProjectEngine.VCFileConfiguration; if (fcfg.Name == activename) { break; } else { fcfg = null; } } if (fcfg == null) { throw new COMException(); } var vcftool = fcfg.Tool as Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCToolBase; vcprop = vcftool as Microsoft.VisualStudio.VCProjectEngine.IVCRulePropertyStorage; if (vcftool != null && vcprop != null && vcftool.ItemType == "DCompile") { vcrefl = vcftool as System.Reflection.IReflect; if (vcrefl != null) { return; } } } var vcproj = envproj.Object as Microsoft.VisualStudio.VCProjectEngine.VCProject; // Project.VisualC.VCProjectEngine.VCProjectShim; if (vcproj == null) { throw new COMException(); } var vcconfigs = vcproj.Configurations as IVCCollection; for (int c = 1; c <= vcconfigs.Count; c++) { var vccfg = vcconfigs.Item(c); cfg = vccfg as Microsoft.VisualStudio.VCProjectEngine.VCConfiguration; if (cfg.Name == activename) { break; } else { cfg = null; } } if (cfg == null) { throw new COMException(); } var tools = cfg.FileTools as IVCCollection; for (int f = 1; f <= tools.Count; f++) { var obj = tools.Item(f); var vctool = obj as Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCToolBase; if (vctool != null && vctool.ItemType == "DCompile") { vcprop = vctool as Microsoft.VisualStudio.VCProjectEngine.IVCRulePropertyStorage; if (vcprop != null) { vcrefl = vctool as System.Reflection.IReflect; if (vcrefl != null) { return; } } } } throw new COMException(); }
private ProjectProperties GetProjectData() { ThreadHelper.ThrowIfNotOnUIThread(); Solution solution = GetActiveSolution(); if (solution == null) { return(null); } Project project = GetActiveProject(); if (project == null) { return(null); } VCProject prj = project.Object as VCProject; if (prj == null) { return(null); } VCConfiguration config = prj.ActiveConfiguration; if (config == null) { return(null); } VCPlatform platform = config.Platform; if (platform == null) { return(null); } var vctools = config.Tools as IVCCollection; if (vctools == null) { return(null); } var midl = vctools.Item("VCMidlTool") as VCMidlTool; ProjectProperties ret = new ProjectProperties(); ret.Target = midl != null && midl.TargetEnvironment == midlTargetEnvironment.midlTargetWin32 ? ProjectProperties.TargetType.x86 : ProjectProperties.TargetType.x64; //Working directory (always local to processed file) ret.WorkingDirectory = Path.GetDirectoryName(project.FullName); //TODO ~ ramonv ~ find a way to extract the /std value //Include dirs / files and preprocessor AppendMSBuildStringToList(ret.IncludeDirectories, platform.Evaluate(platform.IncludeDirectories)); AppendProjectProperties(ret, vctools.Item("VCCLCompilerTool") as VCCLCompilerTool, vctools.Item("VCNMakeTool") as VCNMakeTool, platform); try { //Get settings from the single file (this might fail badly if there are no settings to catpure) var applicationObject = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2; Assumes.Present(applicationObject); ProjectItem item = applicationObject.ActiveDocument.ProjectItem; VCFile vcfile = item.Object as VCFile; IVCCollection fileCfgs = (IVCCollection)vcfile.FileConfigurations; VCFileConfiguration fileConfig = fileCfgs.Item(config.Name) as VCFileConfiguration; AppendProjectProperties(ret, fileConfig.Tool as VCCLCompilerTool, fileConfig.Tool as VCNMakeTool, platform); } catch (Exception) {} SolutionSettings customSettings = SettingsManager.Instance.Settings; if (customSettings != null) { AppendMSBuildStringToList(ret.IncludeDirectories, platform.Evaluate(customSettings.AdditionalIncludeDirs)); AppendMSBuildStringToList(ret.ForceIncludes, platform.Evaluate(customSettings.AdditionalForceIncludes)); AppendMSBuildStringToList(ret.PrepocessorDefinitions, platform.Evaluate(customSettings.AdditionalPreprocessorDefinitions)); ret.ExtraArguments = platform.Evaluate(customSettings.AdditionalCommandLine); ret.ShowWarnings = customSettings.EnableWarnings; } //Exclude directories RemoveMSBuildStringFromList(ret.IncludeDirectories, platform.Evaluate(platform.ExcludeDirectories)); return(ret); }
VCFileConfigurationWrapperVs2017 #endif (object wrapped) { _wrapped = wrapped as VCFileConfiguration; }
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); } }
public override ProjectProperties GetProjectData() { ThreadHelper.ThrowIfNotOnUIThread(); OutputLog.Log("Capturing configuration from VS projects..."); Project project = EditorUtils.GetActiveProject(); VCProject prj = project.Object as VCProject; if (prj == null) { return(null); } VCConfiguration config = prj.ActiveConfiguration; if (config == null) { return(null); } VCPlatform platform = config.Platform; if (platform == null) { return(null); } var vctools = config.Tools as IVCCollection; if (vctools == null) { return(null); } var midl = vctools.Item("VCMidlTool") as VCMidlTool; var evaluator = new MacroEvaluatorVisualPlatform(platform); ProjectProperties ret = new ProjectProperties(); ret.Target = midl != null && midl.TargetEnvironment == midlTargetEnvironment.midlTargetWin32 ? ProjectProperties.TargetType.x86 : ProjectProperties.TargetType.x64; ret.Standard = GetStandardVersion(config); //Working directory (always local to processed file) ret.WorkingDirectory = Path.GetDirectoryName(project.FullName); //Include dirs / files and preprocessor AppendMSBuildStringToList(ret.IncludeDirectories, evaluator.Evaluate(platform.IncludeDirectories)); AppendProjectProperties(ret, vctools.Item("VCCLCompilerTool") as VCCLCompilerTool, vctools.Item("VCNMakeTool") as VCNMakeTool, evaluator); //Get settings from the single file (this might fail badly if there are no settings to catpure) var applicationObject = EditorUtils.ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2; Assumes.Present(applicationObject); ProjectItem item = applicationObject.ActiveDocument.ProjectItem; VCFile vcfile = item != null ? item.Object as VCFile : null; IVCCollection fileCfgs = vcfile != null ? (IVCCollection)vcfile.FileConfigurations : null; VCFileConfiguration fileConfig = fileCfgs != null?fileCfgs.Item(config.Name) as VCFileConfiguration : null; VCCLCompilerTool fileToolCL = null; VCNMakeTool fileToolNMake = null; try { fileToolCL = fileConfig.Tool as VCCLCompilerTool; fileToolNMake = fileConfig.Tool as VCNMakeTool; } catch (Exception e) { //If we really need this data we can always parse the vcxproj as an xml OutputLog.Log("File specific properties not found, only project properties used (" + e.Message + ")"); } AppendProjectProperties(ret, fileToolCL, fileToolNMake, evaluator); CaptureExtraProperties(ret, evaluator); AddCustomSettings(ret, evaluator); RemoveMSBuildStringFromList(ret.IncludeDirectories, evaluator.Evaluate(platform.ExcludeDirectories)); //Exclude directories ProcessPostProjectData(ret); return(ret); }
public string ReplaceMacros( string s, VCFileConfiguration cfg ) { //! 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; }
static async Task <int> MainAsync(ProgramOptions options) { var engine = new VCProjectEngineObject(); if (options.PrintPlatforms) { PrintPlatforms(engine); return(0); } var dir = Path.GetDirectoryName(options.ProjectFilePath); var baseJsonPath = Path.Combine(dir, "compile_commands.base.json"); var baseObj = File.Exists(baseJsonPath) ? JsonSerializer.Deserialize <FileCompilationInfo>(File.ReadAllBytes(baseJsonPath)) : new FileCompilationInfo(); if (baseObj.arguments != null && baseObj.command != null) { Console.Error.WriteLine("You must specify either `arguments` or `command` in compile_commands.base.json. "); return(2); } baseObj.directory = dir; var output = new List <FileCompilationInfo>(); var project = engine.LoadProject(options.ProjectFilePath) as VCProject; if (project == null) { Console.Error.WriteLine("Invalid project file."); return(3); } //var buildTarget = "Release|Win32"; //var buildTarget = "Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"; var buildTarget = options.BuildTarget; foreach (VCFile file in project.Files) { var fileConfigurations = file.FileConfigurations as IVCCollection; VCFileConfiguration fileConfig = fileConfigurations.Item(buildTarget); if (fileConfig == null) { Console.Error.WriteLine($"warning: Build Target [{buildTarget}] Not Found for `{file.Name}`"); continue; } var platform = buildTarget.Split('|')[1]; var m = new Regex(@"\((\w+)\)").Match(platform); var arch = platform == "Win64" ? "x86_64" : m.Success ? m.Groups[1].Value.ToLower() : "i386"; var entry = ProcessVCFile(options, baseObj.Clone(), file, fileConfig, arch, platform == "Win64"); if (entry != null) { output.Add(entry); } } if (options.OnlyConvertToUtf8) { return(0); } using (var stream = File.OpenWrite(Path.Combine(dir, CompileCommandsJson))) { stream.SetLength(0); await JsonSerializer.SerializeAsync(stream, output, new JsonSerializerOptions() { WriteIndented = true, IgnoreNullValues = true, }); } return(0); }
private void CreateConfigForEachFile(ref VCProject actVCP, List <string> additionalParamsList, string BuildMode) { Log("\tFile Specific Configuration"); 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) { try { // Preprocessed headers VCFileConfiguration fileConfiguration = (VCFileConfiguration)(((IVCCollection)file.FileConfigurations).Item(BuildMode)); // Access the release configuration of this file. VCCLCompilerTool compilerTool = (VCCLCompilerTool)fileConfiguration.Tool; // Get the compiler tool associated with this file. switch (compilerTool.UsePrecompiledHeader) { case pchOption.pchCreateUsingSpecific: break; case pchOption.pchUseUsingSpecific: case pchOption.pchNone: if (compilerTool.UsePrecompiledHeader != pchOption.pchNone) { compilerTool.UsePrecompiledHeader = pchOption.pchNone; Log("\t\tPrecompiled headers are deactivated for the file '" + file.Name + "'"); if (compilerTool.PrecompiledHeaderThrough != null) { string directoryToAppend = System.IO.Path.GetDirectoryName(compilerTool.PrecompiledHeaderThrough); if (appendToAdditionalDirectories(ref compilerTool, directoryToAppend)) { Log("\t\tAdditional of '" + directoryToAppend + "'a in the list of additional include directories for the file '" + file.Name + "'"); } } } if (compilerTool.AdditionalOptions == null) { compilerTool.AdditionalOptions = " "; } string additionalParams = generateParamString(additionalParamsList, compilerTool.AdditionalOptions); if (additionalParams.Length > 0) { compilerTool.AdditionalOptions += " " + additionalParams; Log("\t\tAdditional command line arguments '" + additionalParams + "' are appended for the file '" + file.Name + "'"); } break; } } catch (Exception e) { Debug(e); } } } catch (Exception e) { Debug(e); } } } }
static void Main(string[] args) { try { // Create a project engine VCProjectEngine projEngine = new VCProjectEngineObject(); // Load a project, change the name, add a configuration VCProject project = (VCProject)projEngine.LoadProject(@"..\..\..\MyProject\MyProject.vcproj"); if (project != null) { //Change the project's name project.Name = "Voila"; //Add a new configuration project.AddConfiguration("Whichever Name"); // Get the debug configuration and change the type to application VCConfiguration configuration = (VCConfiguration)(((IVCCollection)project.Configurations).Item("Debug")); if (configuration != null) { configuration.ConfigurationType = ConfigurationTypes.typeApplication; } else { Console.WriteLine(@"I Couldn't find the configuration"); } // Get the linker tool from the configration. VCLinkerTool linkerTool = (VCLinkerTool)(((IVCCollection)configuration.Tools).Item("VCLinkerTool")); if (linkerTool != null) { // Change the ShowProgress property to "Display All Progress Messages (/VERBOSE)" linkerTool.ShowProgress = linkProgressOption.linkProgressAll; } else { Console.WriteLine(@"I Couldn't find the linkerTool"); } // Add a cpp file called New.cpp if (project.CanAddFile("New.cpp")) { project.AddFile("New.cpp"); } else { Console.WriteLine(@"I Couldn't add the file"); } // Access the files collection IVCCollection filesCollection = (IVCCollection)project.Files; if (filesCollection != null) { // Access a cpp files called bar.cpp that is already in the project. VCFile file = (VCFile)(filesCollection.Item("Existing.cpp")); if (file != null) { // Access the release configuration of this file. VCFileConfiguration fileConfiguration = (VCFileConfiguration)(((IVCCollection)file.FileConfigurations).Item("Release|Win32")); // Get the compiler tool associated with this file. VCCLCompilerTool compilerTool = (VCCLCompilerTool)fileConfiguration.Tool; // Change the optimization property to Full Optimization (/Ox) compilerTool.Optimization = optimizeOption.optimizeFull; } else { Console.WriteLine(@"I Couldn't find the file"); } // Save the project, then remove it. project.ProjectFile = "MyNewProject.vcproj"; project.Save(); } else { Console.WriteLine(@"I Couldn't find the file collection"); } } else { Console.WriteLine(@"I Couldn't find the project"); } } catch (Exception e) { Console.WriteLine("Operation failed for the following reason: {0}", e.Message); } }
public void PerformCompileUnityFile(EnvDTE.Document document, VCFileConfiguration fileConfig) { if (document == null || fileConfig == null) { return; } if (WorkInProgress) { return; } WorkInProgress = true; // Hook into build events. document.DTE.Events.BuildEvents.OnBuildProjConfigDone += OnBuildConfigFinished; document.DTE.Events.BuildEvents.OnBuildDone += OnBuildFinished; // The rest runs in a separate thread since the compile function is non blocking and we want to use BuildEvents // We are not using Task, since we want to make use of WaitHandles - using this together with Task is a bit more complicated to get right. outputWaitEvent.Reset(); new System.Threading.Thread(() => { try { // Compile - In rare cases VS tells us that we are still building which should not be possible because we have received OnBuildFinished // As a workaround we just try again a few times. { const int maxNumCompileAttempts = 1; for (int numCompileFails = 0; numCompileFails < maxNumCompileAttempts; ++numCompileFails) { try { fileConfig.Compile(true, false); // WaitOnBuild==true always fails. } catch (Exception e) { if (numCompileFails == maxNumCompileAttempts - 1) { Output.Instance.WriteLine("Compile Failed:\n{0}", e); throw e; } else { // Try again. System.Threading.Thread.Sleep(100); continue; } } break; } } // Wait till woken. bool noTimeout = outputWaitEvent.WaitOne(timeoutMS); } catch (Exception ex) { Output.Instance.WriteLine("Unexpected error: {0}", ex); } finally { Application.Current.Dispatcher.Invoke(() => { // Remove build hook again. document.DTE.Events.BuildEvents.OnBuildDone -= OnBuildFinished; document.DTE.Events.BuildEvents.OnBuildProjConfigDone -= OnBuildConfigFinished; // Message. //Output.Instance.OutputToForeground(); // Notify that we are done. WorkInProgress = false; }); } }).Start(); }
private void OnVCProjectEngineItemPropertyChange(object item, object tool, int dispid) { //System.Diagnostics.Debug.WriteLine("OnVCProjectEngineItemPropertyChange " + dispid.ToString()); VCFileConfiguration vcFileCfg = item as VCFileConfiguration; if (vcFileCfg == null) { // A global or project specific property has changed. VCConfiguration vcCfg = item as VCConfiguration; if (vcCfg == null) { return; } VCProject vcPrj = vcCfg.project as VCProject; if (vcPrj == null) { return; } if (!HelperFunctions.IsQtProject(vcPrj)) { return; } if (dispid == dispId_VCCLCompilerTool_UsePrecompiledHeader || dispid == dispId_VCCLCompilerTool_PrecompiledHeaderThrough || dispid == dispId_VCCLCompilerTool_AdditionalIncludeDirectories || dispid == dispId_VCCLCompilerTool_PreprocessorDefinitions) { QtProject qtPrj = QtProject.Create(vcPrj); qtPrj.RefreshMocSteps(); } } else { // A file specific property has changed. VCFile vcFile = vcFileCfg.File as VCFile; if (vcFile == null) { return; } VCProject vcPrj = vcFile.project as VCProject; if (vcPrj == null) { return; } if (!HelperFunctions.IsQtProject(vcPrj)) { return; } if (dispid == dispId_VCFileConfiguration_ExcludedFromBuild) { QtProject qtPrj = QtProject.Create(vcPrj); qtPrj.OnExcludedFromBuildChanged(vcFile, vcFileCfg); } else if (dispid == dispId_VCCLCompilerTool_UsePrecompiledHeader || dispid == dispId_VCCLCompilerTool_PrecompiledHeaderThrough || dispid == dispId_VCCLCompilerTool_AdditionalIncludeDirectories || dispid == dispId_VCCLCompilerTool_PreprocessorDefinitions) { QtProject qtPrj = QtProject.Create(vcPrj); qtPrj.RefreshMocStep(vcFile); } } }
/// <summary> /// Parses one configuration for a custom build rule. /// </summary> private void parseCustomBuildRule_Configuration(VCFileConfiguration configuration, string relativePath) { // We find the custom build rule for this configuration (if there is one)... VCCustomBuildRule rule = Utils.call(() => (configuration.Tool as VCCustomBuildRule)); if (rule == null) { return; } // We will store info about this rule in a CustomBuildRuleInfo_CPP object... CustomBuildRuleInfo_CPP ruleInfo = new CustomBuildRuleInfo_CPP(); ruleInfo.RelativePathToFile = relativePath; // There is a custom build rule, so we parse it... ruleInfo.RuleName = Utils.call(() => (rule.Name)); string commandLine = Utils.call(() => (rule.CommandLine)); string expandedCommandLine = Utils.call(() => (configuration.Evaluate(commandLine))); // We find the collection of output files generated by the rule... string outputs = Utils.call(() => (rule.Outputs)); string expandedOutputs = Utils.call(() => (configuration.Evaluate(outputs))); // The command-line may contain references to custom properties for // the rule. These will be in square brackets,like [property]. We find // these and replace the property markers in the command-line... Dictionary <string, string> properties = getCustomBuildRuleProperties(rule); foreach (KeyValuePair <string, string> property in properties) { // We replace values in the command line, and in the output files... string tokenToReplace = "[" + property.Key + "]"; expandedCommandLine = expandedCommandLine.Replace(tokenToReplace, property.Value); expandedOutputs = expandedOutputs.Replace(tokenToReplace, property.Value); } // We split the command-line to find the executable and the parameters... List <string> splitCommandLine = Utils.split(expandedCommandLine, ' '); // The executable... if (splitCommandLine.Count >= 1) { string ruleExecutable = splitCommandLine[0]; string relativePathToExecutable = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, ruleExecutable); ruleInfo.RelativePathToExecutable = relativePathToExecutable; } // The parameters... for (int j = 1; j < splitCommandLine.Count; ++j) { string parameter = splitCommandLine[j]; // Many parameters will be path names. We cnvert these // to be relative to the project root (and in Linux format). // Non-path parameters should be unaffected... parameter = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, parameter); ruleInfo.addParameter(parameter); } // We store the info in the configuration... m_projectInfo.addCustomBuildRuleInfo(ruleInfo, configuration.Name); }
/// <summary> /// Parses one configuration for a custom build rule. /// </summary> private void parseCustomBuildRule_Configuration(VCFileConfiguration configuration, string relativePath) { // We find the custom build rule for this configuration (if there is one)... VCCustomBuildRule rule = Utils.call(() => (configuration.Tool as VCCustomBuildRule)); if (rule == null) { return; } // We will store info about this rule in a CustomBuildRuleInfo_CPP object... CustomBuildRuleInfo_CPP ruleInfo = new CustomBuildRuleInfo_CPP(); ruleInfo.RelativePathToFile = relativePath; // There is a custom build rule, so we parse it... ruleInfo.RuleName = Utils.call(() => (rule.Name)); string commandLine = Utils.call(() => (rule.CommandLine)); string expandedCommandLine = Utils.call(() => (configuration.Evaluate(commandLine))); // We find the collection of output files generated by the rule... string outputs = Utils.call(() => (rule.Outputs)); string expandedOutputs = Utils.call(() => (configuration.Evaluate(outputs))); // The command-line may contain references to custom properties for // the rule. These will be in square brackets,like [property]. We find // these and replace the property markers in the command-line... Dictionary<string, string> properties = getCustomBuildRuleProperties(rule); foreach (KeyValuePair<string, string> property in properties) { // We replace values in the command line, and in the output files... string tokenToReplace = "[" + property.Key + "]"; expandedCommandLine = expandedCommandLine.Replace(tokenToReplace, property.Value); expandedOutputs = expandedOutputs.Replace(tokenToReplace, property.Value); } // We split the command-line to find the executable and the parameters... List<string> splitCommandLine = Utils.split(expandedCommandLine, ' '); // The executable... if (splitCommandLine.Count >= 1) { string ruleExecutable = splitCommandLine[0]; string relativePathToExecutable = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, ruleExecutable); ruleInfo.RelativePathToExecutable = relativePathToExecutable; } // The parameters... for (int j = 1; j < splitCommandLine.Count; ++j) { string parameter = splitCommandLine[j]; // Many parameters will be path names. We cnvert these // to be relative to the project root (and in Linux format). // Non-path parameters should be unaffected... parameter = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, parameter); ruleInfo.addParameter(parameter); } // We store the info in the configuration... m_projectInfo.addCustomBuildRuleInfo(ruleInfo, configuration.Name); }
public void CreateTestCocoonConfig(String config, string project, List <string> additionalParamsList, List <string> additiona_includes, bool QtConfiguration) { bool foundProject = false; IEnumerator ProjectsEnumaror = GetVCProjectRefs(); ProjectsEnumaror.Reset(); // traverse all projects to find the right one while (ProjectsEnumaror.MoveNext()) { VCProject actVCP = (VCProject)ProjectsEnumaror.Current; if (actVCP.Name == project) { foundProject = true; VCConfiguration vcC = null; //vcC = (VCConfiguration)(((IVCCollection)actVCP.Configurations).Item(config)); IEnumerator ConfigurationEnumarator = ((IVCCollection)actVCP.Configurations).GetEnumerator(); for (ConfigurationEnumarator.Reset(); ConfigurationEnumarator.MoveNext();) { vcC = ConfigurationEnumarator.Current as VCConfiguration; if ((vcC != null) && (vcC.ConfigurationName == config)) { Log("Modifying configuration '" + config + "' for the project '" + project + "' for the platform '" + vcC.Name + "'"); // change settings for sepcified compiler IVCCollection ctools = (IVCCollection)vcC.Tools; VCActiveXReference cVCActiveXReference = ctools.Item("VCActiveXReference") as VCActiveXReference; VCALinkTool cVCALinkTool = ctools.Item("VCALinkTool") as VCALinkTool; VCAppVerifierTool cVCAppVerifierTool = ctools.Item("VCAppVerifierTool") as VCAppVerifierTool; VCAssemblyReference cVCAssemblyReference = ctools.Item("VCAssemblyReference") as VCAssemblyReference; VCBscMakeTool cVCBscMakeTool = ctools.Item("VCBscMakeTool") as VCBscMakeTool; VCCLCompilerTool cVCCLCompilerTool = ctools.Item("VCCLCompilerTool") as VCCLCompilerTool; VCConfiguration cVCConfiguration = ctools.Item("VCConfiguration") as VCConfiguration; VCCustomBuildRule cVCCustomBuildRule = ctools.Item("VCCustomBuildRule") as VCCustomBuildRule; VCCustomBuildTool cVCCustomBuildTool = ctools.Item("VCCustomBuildTool") as VCCustomBuildTool; VCDebugSettings cVCDebugSettings = ctools.Item("VCDebugSettings") as VCDebugSettings; VCFile cVCFile = ctools.Item("VCFile") as VCFile; VCFileConfiguration cVCFileConfiguration = ctools.Item("VCFileConfiguration") as VCFileConfiguration; VCFilter cVCFilter = ctools.Item("VCFilter") as VCFilter; VCFxCopTool cVCFxCopTool = ctools.Item("VCFxCopTool") as VCFxCopTool; VCLibrarianTool cVCLibrarianTool = ctools.Item("VCLibrarianTool") as VCLibrarianTool; VCLinkerTool cVCLinkerTool = ctools.Item("VCLinkerTool") as VCLinkerTool; VCManagedResourceCompilerTool cVCManagedResourceCompilerTool = ctools.Item("VCManagedResourceCompilerTool") as VCManagedResourceCompilerTool; VCManifestTool cVCManifestTool = ctools.Item("VCManifestTool") as VCManifestTool; VCMidlTool cVCMidlTool = ctools.Item("VCMidlTool") as VCMidlTool; VCNMakeTool cVCNMakeTool = ctools.Item("VCNMakeTool") as VCNMakeTool; VCPlatform cVCPlatform = ctools.Item("VCPlatform") as VCPlatform; VCPostBuildEventTool cVCPostBuildEventTool = ctools.Item("VCPostBuildEventTool") as VCPostBuildEventTool; VCPreBuildEventTool cVCPreBuildEventTool = ctools.Item("VCPreBuildEventTool") as VCPreBuildEventTool; VCPreLinkEventTool cVCPreLinkEventTool = ctools.Item("VCPreLinkEventTool") as VCPreLinkEventTool; VCProject cVCProject = ctools.Item("VCProject") as VCProject; VCProjectEngine cVCProjectEngine = ctools.Item("VCProjectEngine") as VCProjectEngine; VCProjectEngineEvents cVCProjectEngineEvents = ctools.Item("VCProjectEngineEvents") as VCProjectEngineEvents; VCProjectEngineObject cVCProjectEngineObject = ctools.Item("VCProjectEngineObject") as VCProjectEngineObject; VCProjectItem cVCProjectItem = ctools.Item("VCProjectItem") as VCProjectItem; VCProjectReference cVCProjectReference = ctools.Item("VCProjectReference") as VCProjectReference; VCPropertySheet cVCPropertySheet = ctools.Item("VCPropertySheet") as VCPropertySheet; VCReference cVCReference = ctools.Item("VCReference") as VCReference; VCReferences cVCReferences = ctools.Item("VCReferences") as VCReferences; VCResourceCompilerTool cVCResourceCompilerTool = ctools.Item("VCResourceCompilerTool") as VCResourceCompilerTool; VCRuntimeBooleanProperty cVCRuntimeBooleanProperty = ctools.Item("VCRuntimeBooleanProperty") as VCRuntimeBooleanProperty; VCRuntimeEnumProperty cVCRuntimeEnumProperty = ctools.Item("VCRuntimeEnumProperty") as VCRuntimeEnumProperty; VCRuntimeEnumValue cVCRuntimeEnumValue = ctools.Item("VCRuntimeEnumValue") as VCRuntimeEnumValue; VCRuntimeIntegerProperty cVCRuntimeIntegerProperty = ctools.Item("VCRuntimeIntegerProperty") as VCRuntimeIntegerProperty; VCRuntimeProperty cVCRuntimeProperty = ctools.Item("VCRuntimeProperty") as VCRuntimeProperty; VCRuntimeStringProperty cVCRuntimeStringProperty = ctools.Item("VCRuntimeStringProperty") as VCRuntimeStringProperty; VCToolFile cVCToolFile = ctools.Item("VCToolFile") as VCToolFile; VCUserMacro cVCUserMacro = ctools.Item("VCUserMacro") as VCUserMacro; VCWebDeploymentTool cVCWebDeploymentTool = ctools.Item("VCWebDeploymentTool") as VCWebDeploymentTool; VCWebServiceProxyGeneratorTool cVCWebServiceProxyGeneratorTool = ctools.Item("VCWebServiceProxyGeneratorTool") as VCWebServiceProxyGeneratorTool; VCXDCMakeTool cVCXDCMakeTool = ctools.Item("VCXDCMakeTool") as VCXDCMakeTool; VCXMLDataGeneratorTool cVCXMLDataGeneratorTool = ctools.Item("VCXMLDataGeneratorTool") as VCXMLDataGeneratorTool; VCLinkerTool linkerTool = ctools.Item("VCLinkerTool") as VCLinkerTool; VCLibrarianTool librarianTool = ctools.Item("VCLibrarianTool") as VCLibrarianTool; VCCLCompilerTool compilerTool = ctools.Item("VCCLCompilerTool") as VCCLCompilerTool; VCCustomBuildTool customBuildTool = ctools.Item("VCCustomBuildTool") as VCCustomBuildTool; string libgen = FindCslibConfig(ref compilerTool); List <string> additionalParamsListLink = new List <string>(additionalParamsList); List <string> additionalParamsListLibrarian = new List <string>(additionalParamsList); if (libgen != null) { additionalParamsListLink.Add("--cs-libgen=" + libgen); additionalParamsListLibrarian.Add("--cs-libgen=" + libgen); } if (compilerTool != null) { CreateClConfig(ref compilerTool, additionalParamsList, additiona_includes, actVCP.ProjectDirectory, config); } if (linkerTool != null) { CreateLinkConfig(ref linkerTool, additionalParamsListLink, config); } if (customBuildTool != null) { CreateCustomBuildConfig(ref customBuildTool, additionalParamsList, config); } if (librarianTool != null) { CreateLibrarianConfig(ref librarianTool, additionalParamsListLibrarian, config); } if (actVCP != null) { CreateConfigForEachFile(ref actVCP, additionalParamsList, config); } } } } } if (!foundProject) { ShowMessageBox("Could not find the project", "Warning"); } }