diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2023-02-06 13:35:26 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2023-02-23 14:28:26 +0000 |
commit | 6cf657cb7eaad0a391e5f9f8d5437bb3c58694c2 (patch) | |
tree | b41bac5d0eb8ef5f2152dd6848fd4117badd5c7e | |
parent | d6336a90746eb4c34f391ce5b1b25575c9de07f6 (diff) |
Remove GetQtDirFromQMakeProject() and releated code
This function was only used to detect the Qt version of qmake
only projects (qmake -tp vc). This is a not supported anymore.
Change-Id: Ibbb510b037b2e687a4390814b8a43aab9385bfbc
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
-rw-r--r-- | QtVsTools.Core/CompilerToolWrapper.cs | 64 | ||||
-rw-r--r-- | QtVsTools.Core/HelperFunctions.cs | 83 | ||||
-rw-r--r-- | QtVsTools.Core/LinkerToolWrapper.cs | 173 | ||||
-rw-r--r-- | QtVsTools.Core/QtVersionManager.cs | 17 | ||||
-rw-r--r-- | QtVsTools.Core/QtVsTools.Core.csproj | 1 | ||||
-rw-r--r-- | QtVsTools.Package/Package/QtHelp.cs | 9 |
6 files changed, 1 insertions, 346 deletions
diff --git a/QtVsTools.Core/CompilerToolWrapper.cs b/QtVsTools.Core/CompilerToolWrapper.cs index ef8186c6..1364757c 100644 --- a/QtVsTools.Core/CompilerToolWrapper.cs +++ b/QtVsTools.Core/CompilerToolWrapper.cs @@ -28,7 +28,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Reflection; using Microsoft.VisualStudio.VCProjectEngine; @@ -100,69 +99,6 @@ namespace QtVsTools.Core return compilerTool == null && compilerObj == null; } - public List<string> AdditionalIncludeDirectories - { - get - { - var directories = GetAdditionalIncludeDirectories(); - if (directories == null) - return new List<string>(); - // double quotes are escaped - directories = directories.Replace("\\\"", "\""); - var dirArray = directories.Split(new[] { ';', ',' }, StringSplitOptions - .RemoveEmptyEntries); - var lst = new List<string>(dirArray); - var i = 0; - while (i < lst.Count) { - var item = lst[i]; - if (item.StartsWith("\"", StringComparison.Ordinal) && item.EndsWith("\"", StringComparison.Ordinal)) { - item = item.Remove(0, 1); - item = item.Remove(item.Length - 1, 1); - lst[i] = item; - } - - if (lst[i].Length > 0) - ++i; - else - lst.RemoveAt(i); - } - return lst; - } - - set - { - if (value == null) { - SetAdditionalIncludeDirectories(null); - return; - } - var newDirectories = string.Empty; - var firstLoop = true; - foreach (var dir in value) { - if (firstLoop) - firstLoop = false; - else - newDirectories += ";"; - - if (dir.IndexOfAny(new[] { ' ', '\t' }) > 0 || !Path.IsPathRooted(dir)) - newDirectories += "\"" + dir + "\""; - else - newDirectories += dir; - } - if (newDirectories != GetAdditionalIncludeDirectories()) - SetAdditionalIncludeDirectories(newDirectories); - } - } - - public void SetAdditionalIncludeDirectories(string value) - { - // Prevent setting of empty substring, as they break the build - value = value.Replace("\"\",", string.Empty); - if (compilerTool != null) - compilerTool.AdditionalIncludeDirectories = value; - else - SetStringProperty("AdditionalIncludeDirectories", value); - } - public List<string> PreprocessorDefinitions { get diff --git a/QtVsTools.Core/HelperFunctions.cs b/QtVsTools.Core/HelperFunctions.cs index bcbbe8b6..9ae489a2 100644 --- a/QtVsTools.Core/HelperFunctions.cs +++ b/QtVsTools.Core/HelperFunctions.cs @@ -233,89 +233,6 @@ namespace QtVsTools.Core } } - public static string GetQtDirFromQMakeProject(Project project) - { - ThreadHelper.ThrowIfNotOnUIThread(); - - var vcProject = project.Object as VCProject; - if (vcProject == null) - return null; - - try { - foreach (VCConfiguration projectConfig in vcProject.Configurations as IVCCollection) { - var compiler = CompilerToolWrapper.Create(projectConfig); - if (compiler != null) { - var additionalIncludeDirectories = compiler.AdditionalIncludeDirectories; - if (additionalIncludeDirectories != null) { - foreach (var dir in additionalIncludeDirectories) { - var subdir = Path.GetFileName(dir); - if (subdir != "QtCore" && subdir != "QtGui") // looking for Qt include directories - continue; - var dirName = Path.GetDirectoryName(dir); // cd .. - dirName = Path.GetDirectoryName(dirName); // cd .. - if (!Path.IsPathRooted(dirName)) { - var projectDir = Path.GetDirectoryName(project.FullName); - dirName = Path.Combine(projectDir, dirName); - dirName = Path.GetFullPath(dirName); - } - return dirName; - } - } - } - - var linker = (VCLinkerTool)((IVCCollection)projectConfig.Tools).Item("VCLinkerTool"); - if (linker != null) { - var linkerWrapper = new LinkerToolWrapper(linker); - var linkerPaths = linkerWrapper.AdditionalDependencies; - if (linkerPaths != null) { - foreach (var library in linkerPaths) { - var idx = library.IndexOf("\\lib\\qtmain.lib", StringComparison.OrdinalIgnoreCase); - if (idx == -1) - idx = library.IndexOf("\\lib\\qtmaind.lib", StringComparison.OrdinalIgnoreCase); - if (idx == -1) - idx = library.IndexOf("\\lib\\qtcore5.lib", StringComparison.OrdinalIgnoreCase); - if (idx == -1) - idx = library.IndexOf("\\lib\\qtcored5.lib", StringComparison.OrdinalIgnoreCase); - if (idx == -1) - continue; - - var dirName = Path.GetDirectoryName(library); - dirName = Path.GetDirectoryName(dirName); // cd .. - if (!Path.IsPathRooted(dirName)) { - var projectDir = Path.GetDirectoryName(project.FullName); - dirName = Path.Combine(projectDir, dirName); - dirName = Path.GetFullPath(dirName); - } - - return dirName; - } - } - - linkerPaths = linkerWrapper.AdditionalLibraryDirectories; - if (linkerPaths != null) { - foreach (var libDir in linkerPaths) { - var dirName = libDir; - if (!Path.IsPathRooted(dirName)) { - var projectDir = Path.GetDirectoryName(project.FullName); - dirName = Path.Combine(projectDir, dirName); - dirName = Path.GetFullPath(dirName); - } - - if (File.Exists(dirName + "\\qtmain.lib") || - File.Exists(dirName + "\\qtmaind.lib") || - File.Exists(dirName + "\\QtCore5.lib") || - File.Exists(dirName + "\\QtCored5.lib")) { - return Path.GetDirectoryName(dirName); - } - } - } - } - } - } catch { } - - return null; - } - /// <summary> /// Return true if the project is a VS tools project; false otherwise. /// </summary> diff --git a/QtVsTools.Core/LinkerToolWrapper.cs b/QtVsTools.Core/LinkerToolWrapper.cs deleted file mode 100644 index dfe9ac0d..00000000 --- a/QtVsTools.Core/LinkerToolWrapper.cs +++ /dev/null @@ -1,173 +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.IO; -using System.Text.RegularExpressions; -using Microsoft.VisualStudio.VCProjectEngine; - -namespace QtVsTools.Core -{ - /// <summary> - /// Adds convenience functions to the VCLinkerTool. - /// </summary> - public class LinkerToolWrapper - { - private readonly VCLinkerTool linker; - - public LinkerToolWrapper(VCLinkerTool linkerTool) - { - linker = linkerTool; - } - - public List<string> AdditionalLibraryDirectories - { - get - { - if (linker.AdditionalLibraryDirectories == null) - return null; - var dirArray = linker.AdditionalLibraryDirectories.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); - var lst = new List<string>(dirArray); - for (var i = 0; i < lst.Count; ++i) { - var item = lst[i]; - if (item.StartsWith("\"", StringComparison.Ordinal) && item.EndsWith("\"", StringComparison.Ordinal)) { - item = item.Remove(0, 1); - item = item.Remove(item.Length - 1, 1); - lst[i] = item; - } - } - return lst; - } - - internal set - { - if (value == null) { - linker.AdditionalLibraryDirectories = null; - return; - } - - var newAdditionalLibraryDirectories = string.Empty; - var firstLoop = true; - foreach (var item in value) { - if (firstLoop) - firstLoop = false; - else - newAdditionalLibraryDirectories += ";"; - - if (!Path.IsPathRooted(item) || item.IndexOfAny(new[] { ' ', '\t' }) > 0) - newAdditionalLibraryDirectories += "\"" + item + "\""; - else - newAdditionalLibraryDirectories += item; - } - if (newAdditionalLibraryDirectories != linker.AdditionalLibraryDirectories) - linker.AdditionalLibraryDirectories = newAdditionalLibraryDirectories; - } - } - - public List<string> AdditionalDependencies - { - get - { - if (linker.AdditionalDependencies == null) - return null; - return splitByWhitespace(linker.AdditionalDependencies); - } - - internal set - { - if (value == null) { - linker.AdditionalDependencies = null; - return; - } - - var newAdditionalDependencies = string.Empty; - var separators = new[] { ' ', '\t' }; - var firstLoop = true; - foreach (var item in value) { - if (firstLoop) - firstLoop = false; - else - newAdditionalDependencies += " "; - - var idx = item.IndexOfAny(separators); - if (idx >= 0) - newAdditionalDependencies += "\"" + item + "\""; - else - newAdditionalDependencies += item; - } - if (newAdditionalDependencies != linker.AdditionalDependencies) - linker.AdditionalDependencies = newAdditionalDependencies; - } - } - - /// <summary> - /// Splits a given string by whitespace characters and takes care of double quotes. - /// </summary> - /// <param name="str">string to be split</param> - /// <returns></returns> - private static List<string> splitByWhitespace(string str) - { - var separators = new[] { ' ', '\t' }; - var i = str.IndexOf('"'); - if (i == -1) - return new List<string>(str.Split(separators, StringSplitOptions.RemoveEmptyEntries)); - - var ret = new List<string>(); - var startIndex = 0; - var r = new Regex(@"""[^""]*"""); - var mc = r.Matches(str); - foreach (Match match in mc) { - var item = match.Value; - item = item.Remove(0, 1); - item = item.Remove(item.Length - 1, 1); - - // Add all items before this match, using standard splitting. - var strBefore = str.Substring(startIndex, match.Index - startIndex); - var lstBefore = strBefore.Split(separators, StringSplitOptions.RemoveEmptyEntries); - ret.AddRange(lstBefore); - startIndex = match.Index + match.Length; - - if (item.Length == 0) - continue; - - ret.Add(item); - } - - if (startIndex < str.Length - 1) { - // Add all items after the quoted match, using standard splitting. - var strBefore = str.Substring(startIndex); - var lstBefore = strBefore.Split(separators, StringSplitOptions.RemoveEmptyEntries); - ret.AddRange(lstBefore); - } - - return ret; - } - - } -} diff --git a/QtVsTools.Core/QtVersionManager.cs b/QtVsTools.Core/QtVersionManager.cs index 5185b25a..70b211ed 100644 --- a/QtVsTools.Core/QtVersionManager.cs +++ b/QtVsTools.Core/QtVersionManager.cs @@ -95,23 +95,6 @@ namespace QtVsTools.Core return GetVersions(Registry.CurrentUser); } - public string GetQtVersionFromInstallDir(string qtDir) - { - if (qtDir == null) - return null; - - var versions = GetVersions(); - foreach (var version in versions) { - var installPath = GetInstallPath(version); - if (installPath == null) - continue; - if (installPath.Equals(qtDir, StringComparison.OrdinalIgnoreCase)) - return version; - } - - return null; - } - public string[] GetVersions(RegistryKey root) { var key = root.OpenSubKey("SOFTWARE\\" + Resources.registryRootPath, false); diff --git a/QtVsTools.Core/QtVsTools.Core.csproj b/QtVsTools.Core/QtVsTools.Core.csproj index 9e1e9f9d..189b491f 100644 --- a/QtVsTools.Core/QtVsTools.Core.csproj +++ b/QtVsTools.Core/QtVsTools.Core.csproj @@ -126,7 +126,6 @@ <Compile Include="FilesToList.cs" /> <Compile Include="Filters.cs" /> <Compile Include="HelperFunctions.cs" /> - <Compile Include="LinkerToolWrapper.cs" /> <Compile Include="Messages.cs" /> <Compile Include="MocCmdChecker.cs" /> <Compile Include="MsBuildProject.cs" /> diff --git a/QtVsTools.Package/Package/QtHelp.cs b/QtVsTools.Package/Package/QtHelp.cs index 0989eceb..f40b6c29 100644 --- a/QtVsTools.Package/Package/QtHelp.cs +++ b/QtVsTools.Package/Package/QtHelp.cs @@ -163,15 +163,8 @@ namespace QtVsTools var qtVersion = "$(DefaultQtVersion)"; var project = HelperFunctions.GetSelectedQtProject(dte); - if (project == null) { - project = HelperFunctions.GetSelectedProject(dte); - if (project != null && HelperFunctions.IsQtProject(project)) { - var qmakeQtDir = HelperFunctions.GetQtDirFromQMakeProject(project); - qtVersion = QtVersionManager.The().GetQtVersionFromInstallDir(qmakeQtDir); - } - } else { + if (project != null) qtVersion = QtVersionManager.The().GetProjectQtVersion(project); - } var info = QtVersionManager.The().GetVersionInfo(qtVersion); var docPath = info?.QtInstallDocs; |