aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2023-02-07 15:24:25 +0100
committerKarsten Heimrich <karsten.heimrich@qt.io>2023-02-23 14:28:44 +0000
commitbd86d89066b40cc34d5a2676017e256e445fac10 (patch)
tree7485c0a6694f032004c4cfb32d6d791b7e30f004
parent5f2e21d03265e25545c71274c7c3c19750336355 (diff)
Remove dead code related to OnVCProjectEngineItemPropertyChange()
Change-Id: I60ea900dd7bf5fcecaf0b477b2a78b9a504f925b Reviewed-by: Miguel Costa <miguel.costa@qt.io>
-rw-r--r--QtVsTools.Core/CompilerToolWrapper.cs35
-rw-r--r--QtVsTools.Core/HelperFunctions.cs49
-rw-r--r--QtVsTools.Core/MocCmdChecker.cs170
-rw-r--r--QtVsTools.Core/QtProject.cs529
-rw-r--r--QtVsTools.Core/QtVSIPSettings.cs57
-rw-r--r--QtVsTools.Core/QtVsTools.Core.csproj1
-rw-r--r--QtVsTools.Core/Resources.cs2
7 files changed, 1 insertions, 842 deletions
diff --git a/QtVsTools.Core/CompilerToolWrapper.cs b/QtVsTools.Core/CompilerToolWrapper.cs
index 1364757c..af1aca5b 100644
--- a/QtVsTools.Core/CompilerToolWrapper.cs
+++ b/QtVsTools.Core/CompilerToolWrapper.cs
@@ -70,18 +70,6 @@ namespace QtVsTools.Core
return wrapper.IsNull() ? null : wrapper;
}
- public static CompilerToolWrapper Create(VCPropertySheet sheet)
- {
- CompilerToolWrapper wrapper = null;
- try {
- wrapper = new CompilerToolWrapper(((IVCCollection)sheet.Tools)
- .Item("VCCLCompilerTool"));
- } catch {
- }
-
- return wrapper.IsNull() ? null : wrapper;
- }
-
protected CompilerToolWrapper(object tool)
{
if (tool == null)
@@ -127,29 +115,6 @@ namespace QtVsTools.Core
return GetStringProperty("PreprocessorDefinitions");
}
- public string[] GetAdditionalIncludeDirectoriesList()
- {
- var includes = GetAdditionalIncludeDirectories().Split(',', ';');
- var fixedincludes = new string[includes.Length];
- var i = 0;
- foreach (var include in includes) {
- var incl = include;
- if (incl.StartsWith("\\\"", StringComparison.Ordinal) && incl.EndsWith("\\\"", StringComparison.Ordinal)) {
- incl = incl.Remove(0, 2);
- incl = incl.Remove(incl.Length - 2, 2);
- }
- fixedincludes[i++] = incl;
- }
- return fixedincludes;
- }
-
- public string GetAdditionalIncludeDirectories()
- {
- if (compilerTool != null)
- return compilerTool.AdditionalIncludeDirectories;
- return GetStringProperty("AdditionalIncludeDirectories");
- }
-
public string GetPrecompiledHeaderThrough()
{
if (compilerTool != null)
diff --git a/QtVsTools.Core/HelperFunctions.cs b/QtVsTools.Core/HelperFunctions.cs
index 9ae489a2..db7e966f 100644
--- a/QtVsTools.Core/HelperFunctions.cs
+++ b/QtVsTools.Core/HelperFunctions.cs
@@ -29,10 +29,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Drawing;
using System.IO;
using System.Linq;
-using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
@@ -735,53 +733,6 @@ namespace QtVsTools.Core
/// Returns: 'true' if expansion was successful, 'false' otherwise<para/>
/// <paramref name="stringToExpand"/>: The string containing properties and/or metadata to
/// expand. This string is passed by ref and expansion is performed in-place.<para/>
- /// <paramref name="project"/>: Current project.<para/>
- /// <paramref name="configName"/>: Name of selected configuration (e.g. "Debug").<para/>
- /// <paramref name="platformName"/>: Name of selected platform (e.g. "x64").<para/>
- /// <paramref name="filePath"/>(optional): Evaluation context.<para/>
- /// </summary>
- public static bool ExpandString(
- ref string stringToExpand,
- EnvDTE.Project project,
- string configName,
- string platformName,
- string filePath = null)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- if (project == null
- || string.IsNullOrEmpty(configName)
- || string.IsNullOrEmpty(platformName))
- return false;
-
- var vcProject = project.Object as VCProject;
- if (filePath == null) {
- var vcConfig = (from VCConfiguration _config
- in (IVCCollection)vcProject.Configurations
- where _config.Name == configName + "|" + platformName
- select _config).FirstOrDefault();
- return ExpandString(ref stringToExpand, vcConfig);
- } else {
- var vcFile = (from VCFile _file in (IVCCollection)vcProject.Files
- where _file.FullPath == filePath
- select _file).FirstOrDefault();
- if (vcFile == null)
- return false;
-
- var vcFileConfig = (from VCFileConfiguration _config
- in (IVCCollection)vcFile.FileConfigurations
- where _config.Name == configName + "|" + platformName
- select _config).FirstOrDefault();
- return ExpandString(ref stringToExpand, vcFileConfig);
- }
- }
-
- /// <summary>
- /// Performs an in-place expansion of MS Build properties in the form $(PropertyName)
- /// and project item metadata in the form %(MetadataName).<para/>
- /// Returns: 'true' if expansion was successful, 'false' otherwise<para/>
- /// <paramref name="stringToExpand"/>: The string containing properties and/or metadata to
- /// expand. This string is passed by ref and expansion is performed in-place.<para/>
/// <paramref name="config"/>: Either a VCConfiguration or VCFileConfiguration object to
/// use as provider of property expansion (through Evaluate()). Cannot be null.<para/>
/// </summary>
diff --git a/QtVsTools.Core/MocCmdChecker.cs b/QtVsTools.Core/MocCmdChecker.cs
deleted file mode 100644
index 8bc8ec4b..00000000
--- a/QtVsTools.Core/MocCmdChecker.cs
+++ /dev/null
@@ -1,170 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt VS Tools.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-using System;
-using System.Collections.Generic;
-using System.Text.RegularExpressions;
-
-namespace QtVsTools.Core
-{
- class MocCmdChecker
- {
- private readonly Regex backslashRegEx = new Regex(@"\\+\.?\\+");
- private readonly Regex endRegEx = new Regex(@"\\\.?$");
-
- private string NormalizePath(string path)
- {
- var s = path.ToLower().Trim();
- s = backslashRegEx.Replace(s, "\\");
- s = endRegEx.Replace(s, string.Empty);
- return s;
- }
-
- public string NewCmdLine(string cmdLine, string includes, string defines,
- string mocOptions, string mocFile, string newPchParameters,
- string outputFile)
- {
- var inputMocFile = ProjectMacros.Path;
- if (HelperFunctions.IsMocFile(outputFile))
- inputMocFile = mocFile;
- var cmds = SplitIntoCommands(cmdLine);
- var mocPos = MocCommandPosition(cmds);
- if (mocPos < 0)
- return null;
-
- var mocCmd = cmds[mocPos];
- var defs = ExtractDefines(mocCmd);
- var incs = ExtractIncludes(mocCmd);
- var pchParameters = ExtractPCHOptions(mocCmd);
- var newIncludes = ExtractIncludes(includes);
- var newDefines = ExtractDefines(defines);
-
- var equal = true;
- if (newDefines.Count == defs.Count) {
- foreach (var s in newDefines) {
- if (defs.Contains(s)) {
- defs.Remove(s);
- } else {
- equal = false;
- break;
- }
- }
- } else {
- equal = false;
- }
-
- equal = equal && newIncludes.Count == incs.Count;
- if (equal) {
- foreach (var s in newIncludes) {
- if (incs.Contains(s)) {
- incs.Remove(s);
- } else {
- equal = false;
- break;
- }
- }
- }
-
- equal = equal && pchParameters == newPchParameters;
- if (equal)
- return null;
-
- var newCmdLine = string.Empty;
- for (var i = 0; i < cmds.Length; ++i) {
- if (i == mocPos) {
- newCmdLine = newCmdLine + "\"" + Resources.moc4Command + "\" "
- + mocOptions
- + " \"" + inputMocFile + "\" -o \"" + outputFile + "\""
- + " " + defines + " " + includes;
- if (!string.IsNullOrEmpty(newPchParameters) && !newCmdLine.Contains(newPchParameters))
- newCmdLine += " " + newPchParameters;
- } else {
- newCmdLine = newCmdLine + cmds[i];
- }
- if (i < cmds.Length - 1 && !newCmdLine.EndsWith("\r\n", StringComparison.Ordinal))
- newCmdLine = newCmdLine + "\r\n";
- }
- return newCmdLine;
- }
-
- private static string[] SplitIntoCommands(string cmdLine)
- {
- var cmds = cmdLine.Split(new[] { "&&", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
- var res = new string[cmds.Length];
- for (var i = 0; i < cmds.Length; ++i)
- res[i] = cmds[i].Trim();
- return res;
- }
-
- private static int MocCommandPosition(string[] cmds)
- {
- var res = -1;
- var reg = new Regex(@"(\S*moc.exe|""\S+:\\\.*moc.exe"")");
- for (var i = 0; i < cmds.Length; ++i) {
- var m = reg.Match(cmds[i]);
- if (m.Success)
- return i;
- }
- return res;
- }
-
- private static List<string> ExtractDefines(string cmdLine)
- {
- var reg = new Regex(@"-D(\S+)");
- var col = reg.Matches(cmdLine);
- var lst = new List<string>(col.Count);
- for (var i = 0; i < col.Count; ++i)
- lst.Add(col[i].Groups[1].ToString());
- return lst;
- }
-
- private List<string> ExtractIncludes(string cmdLine)
- {
- var reg = new Regex(@"-I([^\s""]+)|-I""([^""]+)""");
- var col = reg.Matches(cmdLine);
- var lst = new List<string>(col.Count);
- for (var i = 0; i < col.Count; ++i) {
- var s = col[i].Groups[1].ToString();
- if (s.Length != 0)
- lst.Add(NormalizePath(s));
- else
- lst.Add(NormalizePath(col[i].Groups[2].ToString()));
- }
- return lst;
- }
-
- private static string ExtractPCHOptions(string cmdLine)
- {
- var reg = new Regex(@"""-f(\S+)"" ""-f(\S+)");
- var col = reg.Matches(cmdLine);
- if (col.Count != 1)
- return null;
- return col[0].ToString();
- }
- }
-}
diff --git a/QtVsTools.Core/QtProject.cs b/QtVsTools.Core/QtProject.cs
index b8425845..76c0f0b6 100644
--- a/QtVsTools.Core/QtProject.cs
+++ b/QtVsTools.Core/QtProject.cs
@@ -30,12 +30,11 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
+using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.VCProjectEngine;
-using EnvDTE;
namespace QtVsTools.Core
{
@@ -51,7 +50,6 @@ namespace QtVsTools.Core
private DTE dte;
private Project envPro;
private VCProject vcPro;
- private MocCmdChecker mocCmdChecker;
private static readonly Dictionary<Project, QtProject> instances = new Dictionary<Project, QtProject>();
private readonly QtMsBuildContainer qtMsBuild;
@@ -164,30 +162,6 @@ namespace QtVsTools.Core
return null;
}
- /// <summary>
- /// Returns the file name of the generated moc file relative to the
- /// project directory.
- /// </summary>
- /// The directory of the moc file depends on the file configuration.
- /// Every appearance of "$(ConfigurationName)" in the path will be
- /// replaced by the value of configName.
- /// <param name="file">full file name of either the header or the source file</param>
- /// <returns></returns>
- private string GetRelativeMocFilePath(string file, string configName = null,
- string platformName = null)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- var fileName = GetMocFileName(file);
- if (fileName == null)
- return null;
- var mocDir = QtVSIPSettings.GetMocDirectory(envPro, configName, platformName, file)
- + Path.DirectorySeparatorChar + fileName;
- if (HelperFunctions.IsAbsoluteFilePath(mocDir))
- mocDir = HelperFunctions.GetRelativePath(vcPro.ProjectDirectory, mocDir);
- return mocDir;
- }
-
public static int GetFormatVersion(VCProject vcPro)
{
ThreadHelper.ThrowIfNotOnUIThread();
@@ -296,175 +270,6 @@ namespace QtVsTools.Core
}
/// <summary>
- /// Surrounds the argument by double quotes.
- /// Makes sure, that the trailing double quote is not escaped by a backslash.
- /// Escapes all quotation mark characters in the argument
- ///
- /// This must follow the format recognized by CommandLineToArgvW:
- /// (https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw)
- ///
- /// CommandLineToArgvW has a special interpretation of backslash characters when they are
- /// followed by a quotation mark character ("). This interpretation assumes that any
- /// preceding argument is a valid file system path, or else it may behave unpredictably.
- ///
- /// This special interpretation controls the "in quotes" mode tracked by the parser. When
- /// this mode is off, whitespace terminates the current argument. When on, whitespace is
- /// added to the argument like all other characters.
- ///
- /// * 2n backslashes followed by a quotation mark produce n backslashes followed by
- /// begin/end quote. This does not become part of the parsed argument, but toggles the
- /// "in quotes" mode.
- ///
- /// * (2n) + 1 backslashes followed by a quotation mark again produce n backslashes
- /// followed by a quotation mark literal ("). This does not toggle the "in quotes" mode.
- ///
- /// * n backslashes not followed by a quotation mark simply produce n backslashes.
- ///
- /// </summary>
- private static string SafelyQuoteCommandLineArgument(string arg)
- {
- var quotedArg = new StringBuilder();
- quotedArg.Append("\"");
-
- // Split argument by quotation mark characters
- // All argument parts except the last are followed by a quotation mark character
- var argParts = arg.Split(new char[] { '\"' });
- for (int i = 0; i < argParts.Length; ++i) {
- var part = argParts[i];
- quotedArg.Append(part);
-
- // Duplicate backslashes immediately preceding quotation mark character
- if (part.EndsWith("\\")) {
- quotedArg.Append(part.Reverse().TakeWhile(c => c == Path.DirectorySeparatorChar)
- .ToArray());
- }
- // Escape all quotation mark characters in argument
- if (i < argParts.Length - 1)
- quotedArg.Append("\\\"");
- }
-
- quotedArg.Append("\"");
- return quotedArg.ToString();
- }
-
- public string GetDefines(VCFileConfiguration conf)
- {
- var defines = string.Empty;
- if (conf.Tool is IVCRulePropertyStorage propsFile) {
- try {
- defines = propsFile.GetUnevaluatedPropertyValue("PreprocessorDefinitions");
- } catch { }
- }
-
- var projectConfig = conf.ProjectConfiguration as VCConfiguration;
- if (string.IsNullOrEmpty(defines)
- && projectConfig?.Rules.Item("CL") is IVCRulePropertyStorage propsProject) {
- try {
- defines = propsProject.GetUnevaluatedPropertyValue("PreprocessorDefinitions");
- } catch { }
- }
-
- if (string.IsNullOrEmpty(defines))
- return string.Empty;
-
- var defineList = defines.Split(
- new char[] { ';' },
- StringSplitOptions.RemoveEmptyEntries)
- .ToList();
-
- var preprocessorDefines = string.Empty;
- var alreadyAdded = new List<string>();
- var rxp = new Regex(@"\s|(\$\()");
- foreach (var define in defineList) {
- if (!alreadyAdded.Contains(define)) {
- var 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;
- }
-
- private string GetIncludes(VCFileConfiguration conf)
- {
- var includeList = GetIncludesFromCompilerTool(CompilerToolWrapper.Create(conf));
-
- var projectConfig = conf.ProjectConfiguration as VCConfiguration;
- includeList.AddRange(GetIncludesFromCompilerTool(CompilerToolWrapper.Create(projectConfig)));
-
- if (projectConfig.PropertySheets is IVCCollection propertySheets) {
- foreach (VCPropertySheet sheet in propertySheets)
- includeList.AddRange(GetIncludesFromPropertySheet(sheet));
- }
-
- var includes = string.Empty;
- var alreadyAdded = new List<string>();
- foreach (var include in includeList) {
- if (!alreadyAdded.Contains(include)) {
- var incl = HelperFunctions.NormalizeRelativeFilePath(include);
- if (incl.Length > 0)
- includes += " " + SafelyQuoteCommandLineArgument("-I" + incl);
- alreadyAdded.Add(include);
- }
- }
- return includes;
- }
-
- private List<string> GetIncludesFromPropertySheet(VCPropertySheet sheet)
- {
- var includeList = GetIncludesFromCompilerTool(CompilerToolWrapper.Create(sheet));
- if (sheet.PropertySheets is IVCCollection propertySheets) {
- foreach (VCPropertySheet subSheet in propertySheets)
- includeList.AddRange(GetIncludesFromPropertySheet(subSheet));
- }
- return includeList;
- }
-
- private static List<string> GetIncludesFromCompilerTool(CompilerToolWrapper compiler)
- {
- try {
- if (!string.IsNullOrEmpty(compiler.GetAdditionalIncludeDirectories())) {
- var includes = compiler.GetAdditionalIncludeDirectoriesList();
- return new List<string>(includes);
- }
- } catch { }
- return new List<string>();
- }
-
- private string GetPCHMocOptions(VCFile file, CompilerToolWrapper compiler)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- // As .moc files are included, we should not add anything there
- if (!HelperFunctions.IsHeaderFile(file.Name))
- return string.Empty;
-
- var additionalMocOptions = "\"-f" + HelperFunctions.FromNativeSeparators(compiler
- .GetPrecompiledHeaderThrough()) + "\" ";
- //Get mocDir without .\\ at the beginning of it
- var mocDir = QtVSIPSettings.GetMocDirectory(envPro);
- if (mocDir.StartsWith(".\\", StringComparison.Ordinal))
- mocDir = mocDir.Substring(2);
-
- //Get the absolute path
- mocDir = vcPro.ProjectDirectory + mocDir;
- var fullPathGeneric = Path.Combine(
- Path.GetDirectoryName(file.FullPath), "%(Filename)%(Extension)");
- var relPathToFile = HelperFunctions.FromNativeSeparators(HelperFunctions
- .GetRelativePath(mocDir, fullPathGeneric));
- additionalMocOptions += "\"-f" + relPathToFile + "\"";
- return additionalMocOptions;
- }
-
- /// <summary>
/// Adds a moc step to a given file for this project.
/// </summary>
/// <param name="file">file</param>
@@ -1092,338 +897,6 @@ namespace QtVsTools.Core
}
}
- private static VCFileConfiguration GetVCFileConfigurationByName(VCFile file, string configName)
- {
- foreach (VCFileConfiguration cfg in (IVCCollection)file.FileConfigurations) {
- if (cfg.Name == configName)
- return cfg;
- }
- return null;
- }
-
- /// <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)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- if (QtVSIPSettings.HasDifferentMocFilePerConfig(envPro)
- || QtVSIPSettings.HasDifferentMocFilePerPlatform(envPro)) {
- var projectConfig = (VCConfiguration)fileConfig.ProjectConfiguration;
- var configName = projectConfig.ConfigurationName;
- var platformName = ((VCPlatform)projectConfig.Platform).Name;
- var 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 (HelperFunctions.PathIsRelativeTo(filtFile.FullPath, 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.
- var relativeMocPath = QtVSIPSettings.GetMocDirectory(
- envPro,
- configName,
- platformName,
- fileConfig.File as VCFile)
- + Path.DirectorySeparatorChar + fileName;
- //Remove .\ at the beginning of the mocPath
- if (relativeMocPath.StartsWith(".\\", StringComparison.Ordinal))
- relativeMocPath = relativeMocPath.Remove(0, 2);
- foreach (VCFile filtFile in (IVCCollection)generatedFiles.Files) {
- if (HelperFunctions.PathIsRelativeTo(filtFile.FullPath, relativeMocPath))
- return filtFile;
- }
- } else {
- var generatedFiles = FindFilterFromGuid(Filters.GeneratedFiles().UniqueIdentifier);
- foreach (VCFile filtFile in (IVCCollection)generatedFiles.Files) {
- if (HelperFunctions.PathIsRelativeTo(filtFile.FullPath, fileName))
- return filtFile;
- }
- }
- return null;
- }
-
- public void RefreshQtMocIncludePath()
- {
- foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations) {
- var propsClCompile = config.Rules.Item("CL") as IVCRulePropertyStorage;
- var ruleName = GetRuleName(config, QtMoc.ItemTypeName);
- var propsQtMoc = config.Rules.Item(ruleName) as IVCRulePropertyStorage;
- if (propsClCompile == null || propsQtMoc == null)
- continue;
- propsQtMoc.SetPropertyValue(QtMoc.Property.IncludePath.ToString(),
- propsClCompile.GetUnevaluatedPropertyValue("AdditionalIncludeDirectories"));
- }
- }
-
- public void RefreshQtMocDefine()
- {
- foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations) {
- var propsClCompile = config.Rules.Item("CL") as IVCRulePropertyStorage;
- var ruleName = GetRuleName(config, QtMoc.ItemTypeName);
- var propsQtMoc = config.Rules.Item(ruleName) as IVCRulePropertyStorage;
- if (propsClCompile == null || propsQtMoc == null)
- continue;
- propsQtMoc.SetPropertyValue(QtMoc.Property.Define.ToString(),
- propsClCompile.GetUnevaluatedPropertyValue("PreprocessorDefinitions"));
- }
- }
-
- public void RefreshMocSteps()
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- // Ignore when using shared compiler properties
- if (GetFormatVersion(vcPro) < Resources.qtMinFormatVersion_ClProperties) {
- // TODO: It would be nice if we can inform the user he's on an old project.
- //if (QtVsToolsPackage.Instance.Options.UpdateProjectFormat)
- // Notifications.UpdateProjectFormat.Show();
- }
- }
-
- public void RefreshMocStep(VCFile vcfile)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
- RefreshMocStep(vcfile, true);
- }
-
- /// <summary>
- /// Updates the moc command line for the given header or source file
- /// containing the Q_OBJECT macro.
- /// If the function is called from a property change for a single file
- /// (singleFile = true) we may have to look for the according header
- /// file and refresh the moc step for this file, if it contains Q_OBJECT.
- /// </summary>
- /// <param name="vcfile"></param>
- private void RefreshMocStep(VCFile vcfile, bool singleFile)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- var isHeaderFile = HelperFunctions.IsHeaderFile(vcfile.FullPath);
- if (!isHeaderFile && !HelperFunctions.IsSourceFile(vcfile.FullPath))
- return;
-
- if (mocCmdChecker == null)
- mocCmdChecker = new MocCmdChecker();
-
- foreach (VCFileConfiguration config in (IVCCollection)vcfile.FileConfigurations) {
- try {
- string commandLine = "";
- VCCustomBuildTool tool = null;
- VCFile mocable = null;
- var customBuildConfig = config;
- if (isHeaderFile || vcfile.ItemType == QtMoc.ItemTypeName) {
- mocable = vcfile;
- if (vcfile.ItemType == "CustomBuild")
- tool = HelperFunctions.GetCustomBuildTool(config);
- } else {
- var mocFileName = GetMocFileName(vcfile.FullPath);
- var mocFile = GetGeneratedMocFile(mocFileName, config);
- if (mocFile == null)
- continue;
-
- var mocFileConfig = GetVCFileConfigurationByName(mocFile, config.Name);
- if (vcfile.ItemType == "CustomBuild")
- tool = HelperFunctions.GetCustomBuildTool(mocFileConfig);
- mocable = mocFile;
- // It is possible that the function was called from a source file's property change, it is possible that
- // we have to obtain the tool from the according header file
- if ((vcfile.ItemType != "CustomBuild" || tool == null) && singleFile) {
- var headerName = vcfile.FullPath.Remove(vcfile.FullPath.LastIndexOf('.')) + ".h";
- mocFileName = GetMocFileName(headerName);
- mocFile = GetGeneratedMocFile(mocFileName, config);
- if (mocFile != null) {
- mocable = GetFileFromProject(headerName);
- customBuildConfig = GetVCFileConfigurationByName(mocable, config.Name);
- if (mocable.ItemType == "CustomBuild")
- tool = HelperFunctions.GetCustomBuildTool(customBuildConfig);
- }
- }
- }
-
- if (mocable.ItemType == "CustomBuild") {
- if (tool != null)
- commandLine = tool.CommandLine;
- } else if (mocable.ItemType == QtMoc.ItemTypeName) {
- commandLine = qtMsBuild.GenerateQtMocCommandLine(customBuildConfig);
- } else {
- continue;
- }
-
- if ((mocable.ItemType == "CustomBuild" && tool == null)
- || commandLine.IndexOf(
- "moc.exe",
- StringComparison.OrdinalIgnoreCase) == -1)
- continue;
-
- VCFile srcMocFile, cppFile;
- if (vcfile.ItemType == QtMoc.ItemTypeName
- && HelperFunctions.IsSourceFile(vcfile.ItemName)) {
- srcMocFile = cppFile = vcfile;
- } else {
- srcMocFile = GetSourceFileForMocStep(mocable);
- cppFile = GetCppFileForMocStep(mocable);
- }
- if (srcMocFile == null)
- continue;
- var mocableIsCPP = (srcMocFile == cppFile);
-
- var cppItemType = (cppFile != null) ? cppFile.ItemType : "";
- if (cppFile != null && cppItemType != "ClCompile")
- cppFile.ItemType = "ClCompile";
-
- string pchParameters = null;
- VCFileConfiguration defineIncludeConfig = null;
- CompilerToolWrapper compiler = null;
- if (cppFile == null) {
- // No file specific defines/includes
- // but at least the project defines/includes are added
- defineIncludeConfig = config;
- compiler = CompilerToolWrapper.Create(config.ProjectConfiguration as VCConfiguration);
- } else {
- defineIncludeConfig = GetVCFileConfigurationByName(cppFile, config.Name);
- compiler = CompilerToolWrapper.Create(defineIncludeConfig);
- }
-
- if (compiler != null && compiler.GetUsePrecompiledHeader() != pchOption.pchNone)
- pchParameters = GetPCHMocOptions(srcMocFile, compiler);
-
- var outputFileName = QtVSIPSettings.GetMocDirectory(envPro)
- + Path.DirectorySeparatorChar;
- if (mocableIsCPP) {
- outputFileName += ProjectMacros.Name;
- outputFileName += ".moc";
- } else {
- outputFileName += "moc_";
- outputFileName += ProjectMacros.Name;
- outputFileName += ".cpp";
- }
-
- var newCmdLine = mocCmdChecker.NewCmdLine(commandLine,
- GetIncludes(defineIncludeConfig),
- GetDefines(defineIncludeConfig),
- QtVSIPSettings.GetMocOptions(envPro), srcMocFile.RelativePath,
- pchParameters,
- outputFileName);
-
- if (cppFile != null && cppItemType != "ClCompile")
- cppFile.ItemType = cppItemType;
-
- // The tool's command line automatically gets a trailing "\r\n".
- // We have to remove it to make the check below work.
- var origCommandLine = commandLine;
- if (origCommandLine.EndsWith("\r\n", StringComparison.Ordinal))
- origCommandLine = origCommandLine.Substring(0, origCommandLine.Length - 2);
-
- if (newCmdLine != null && newCmdLine != origCommandLine) {
- // We have to delete the old moc file in order to trigger custom build step.
- var configName = config.Name.Remove(config.Name.IndexOf('|'));
- var platformName = config.Name.Substring(config.Name.IndexOf('|') + 1);
- var projectPath = envPro.FullName.Remove(envPro.FullName.LastIndexOf(Path
- .DirectorySeparatorChar));
- var mocRelPath = GetRelativeMocFilePath(srcMocFile.FullPath, configName, platformName);
- var mocPath = Path.Combine(projectPath, mocRelPath);
- if (File.Exists(mocPath))
- File.Delete(mocPath);
- if (mocable.ItemType == "CustomBuild") {
- tool.CommandLine = newCmdLine;
- } else {
- qtMsBuild.SetQtMocCommandLine(
- customBuildConfig, newCmdLine, new VCMacroExpander(config));
- }
- }
- } catch {
- Messages.Print("ERROR: failed to refresh moc step for " + vcfile.ItemName);
- }
- }
- }
-
- public void OnExcludedFromBuildChanged(VCFile vcFile, VCFileConfiguration vcFileCfg)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- // Update the ExcludedFromBuild flags of the mocced file
- // according to the ExcludedFromBuild flag of the mocable source file.
- var moccedFileName = GetMocFileName(vcFile.Name);
- if (string.IsNullOrEmpty(moccedFileName))
- return;
-
- var moccedFile = GetGeneratedMocFile(moccedFileName, vcFileCfg);
-
- if (moccedFile != null) {
- VCFile cppFile = null;
- if (HelperFunctions.IsHeaderFile(vcFile.Name))
- cppFile = GetCppFileForMocStep(vcFile);
-
- var 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;
- }
- }
- }
- }
-
- /// <summary>
- /// Helper function for RefreshMocStep.
- /// </summary>
- /// <param name="file"></param>
- /// <returns></returns>
- private VCFile GetSourceFileForMocStep(VCFile file)
- {
- if (HelperFunctions.IsHeaderFile(file.Name))
- return file;
- var fileName = file.Name;
- if (HelperFunctions.IsMocFile(fileName)) {
- fileName = fileName.Substring(0, fileName.Length - 4) + ".cpp";
- if (fileName.Length > 0) {
- foreach (VCFile f in (IVCCollection)vcPro.Files) {
- if (f.FullPath.EndsWith(Path.DirectorySeparatorChar + fileName, StringComparison.OrdinalIgnoreCase))
- return f;
- }
- }
- }
- return null;
- }
-
- /// <summary>
- /// Helper function for Refresh/UpdateMocStep.
- /// </summary>
- /// <param name="file"></param>
- /// <returns></returns>
- private VCFile GetCppFileForMocStep(VCFile file)
- {
- string fileName = file.Name;
- if (fileName.EndsWith(".moc.cbt", StringComparison.OrdinalIgnoreCase))
- fileName = fileName.Remove(fileName.LastIndexOf('.'));
- if (HelperFunctions.IsHeaderFile(fileName) || HelperFunctions.IsMocFile(fileName)) {
- fileName = fileName.Remove(fileName.LastIndexOf('.')) + ".cpp";
- foreach (VCFile f in (IVCCollection)vcPro.Files) {
- if (f.FullPath.EndsWith(Path.DirectorySeparatorChar + fileName, StringComparison.OrdinalIgnoreCase))
- return f;
- }
- }
- return null;
- }
-
public bool HasPlatform(string platformName)
{
foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations) {
diff --git a/QtVsTools.Core/QtVSIPSettings.cs b/QtVsTools.Core/QtVSIPSettings.cs
index 87fb1feb..c61d71c3 100644
--- a/QtVsTools.Core/QtVSIPSettings.cs
+++ b/QtVsTools.Core/QtVSIPSettings.cs
@@ -43,33 +43,6 @@ namespace QtVsTools.Core
return GetDirectory(project, Resources.mocDirKeyword);
}
- public static string GetMocDirectory(
- EnvDTE.Project project,
- string configName,
- string platformName, VCFile vCFile)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- string filePath = null;
- if (vCFile != null)
- filePath = vCFile.FullPath;
- return GetMocDirectory(project, configName, platformName, filePath);
- }
-
- public static string GetMocDirectory(
- EnvDTE.Project project,
- string configName,
- string platformName,
- string filePath = null)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- var dir = GetDirectory(project, Resources.mocDirKeyword);
- if (!string.IsNullOrEmpty(configName) && !string.IsNullOrEmpty(platformName))
- HelperFunctions.ExpandString(ref dir, project, configName, platformName, filePath);
- return dir;
- }
-
public static bool HasDifferentMocFilePerConfig(EnvDTE.Project project)
{
ThreadHelper.ThrowIfNotOnUIThread();
@@ -86,12 +59,6 @@ namespace QtVsTools.Core
return mocDir.Contains("$(PlatformName)");
}
- public static string GetMocOptions(EnvDTE.Project project)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
- return GetOption(project, Resources.mocOptionsKeyword);
- }
-
public static string GetRccDirectory()
{
return GetDirectory(Resources.rccDirKeyword);
@@ -231,30 +198,6 @@ namespace QtVsTools.Core
return Resources.generatedFilesDir;
}
- private static string GetOption(EnvDTE.Project project, string type)
- {
- ThreadHelper.ThrowIfNotOnUIThread();
-
- // check for directory in following order:
- // - stored in project
- // - globally defined default option
- // - empty options
- if (project != null && project.Globals.VariablePersists[type])
- return project.Globals[type] as string;
- return GetOption(type);
- }
-
- private static string GetOption(string type)
- {
- try {
- if (Registry.CurrentUser.OpenSubKey(RegistryPath) is {} key) {
- if (key.GetValue(type, null) is string opt)
- return opt;
- }
- } catch { }
- return null;
- }
-
private static bool GetBoolValue(string key, bool defaultValue)
{
if (Registry.CurrentUser.OpenSubKey(RegistryPath) is {} regKey)
diff --git a/QtVsTools.Core/QtVsTools.Core.csproj b/QtVsTools.Core/QtVsTools.Core.csproj
index db0b5774..1a69a5ee 100644
--- a/QtVsTools.Core/QtVsTools.Core.csproj
+++ b/QtVsTools.Core/QtVsTools.Core.csproj
@@ -126,7 +126,6 @@
<Compile Include="Filters.cs" />
<Compile Include="HelperFunctions.cs" />
<Compile Include="Messages.cs" />
- <Compile Include="MocCmdChecker.cs" />
<Compile Include="MsBuildProject.cs" />
<Compile Include="Observable.cs" />
<Compile Include="OutputWindowPane.cs" />
diff --git a/QtVsTools.Core/Resources.cs b/QtVsTools.Core/Resources.cs
index 50d1fe8b..7ef7bc81 100644
--- a/QtVsTools.Core/Resources.cs
+++ b/QtVsTools.Core/Resources.cs
@@ -58,7 +58,6 @@ namespace QtVsTools.Core
public const string projLabelQtSettings = "QtSettings";
public const string uic4Command = "$(QTDIR)\\bin\\uic.exe";
- public const string moc4Command = "$(QTDIR)\\bin\\moc.exe";
// If those directories do not equal to the project directory
// they have to be added to the include directories for
@@ -66,7 +65,6 @@ namespace QtVsTools.Core
public const string generatedFilesDir = "GeneratedFiles";
public const string mocDirKeyword = "MocDir";
- public const string mocOptionsKeyword = "MocOptions";
public const string uicDirKeyword = "UicDir";
public const string rccDirKeyword = "RccDir";