diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2023-02-14 15:10:07 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2023-02-23 14:30:28 +0000 |
commit | ba4fdd2c5c0bc23d1b1bba444526b04f5b897ffd (patch) | |
tree | 8da3ebaa76b499e6b67acbf350eb80ff7bf1cd86 | |
parent | cdd2cfb8a752a1c9c7557f745643b85b1275efbc (diff) |
Cleanup QtConfig reader class
* use some newer language opptions
* remove unused properties and related code
Change-Id: I8e0d2a77532f65cfb23990db1ac1f53253e13df3
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
-rw-r--r-- | QtVsTools.Core/QtConfig.cs | 116 |
1 files changed, 24 insertions, 92 deletions
diff --git a/QtVsTools.Core/QtConfig.cs b/QtVsTools.Core/QtConfig.cs index 8886d62e..80817cb8 100644 --- a/QtVsTools.Core/QtConfig.cs +++ b/QtVsTools.Core/QtConfig.cs @@ -1,43 +1,13 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ +/*************************************************************************************************** + Copyright (C) 2023 The Qt Company Ltd. + SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +***************************************************************************************************/ -using System; using System.IO; using System.Text.RegularExpressions; namespace QtVsTools.Core { - enum BuildType - { - Static, - Shared - } - public enum Platform { x86, @@ -48,42 +18,30 @@ namespace QtVsTools.Core /// <summary> /// A very simple reader for the qconfig.pri file. /// </summary> - class QtConfig + internal class QtConfig { - public BuildType BuildType { get; } - - public string LibInfix { get; } - public Platform Platform { get; } - public string Namespace { get; } - - public uint VersionMajor { get; } - public uint VersionMinor { get; } - public uint VersionPatch { get; } public string VersionString { get; } - public QtConfig(string qtdir) + public QtConfig(string qtDir) { - LibInfix = string.Empty; - - var fi = new FileInfo(qtdir + "\\mkspecs\\qconfig.pri"); + var fi = new FileInfo(qtDir + "\\mkspecs\\qconfig.pri"); if (!fi.Exists) - fi = new FileInfo(qtdir + "\\..\\mkspecs\\qconfig.pri"); + fi = new FileInfo(qtDir + "\\..\\mkspecs\\qconfig.pri"); if (!fi.Exists) return; var qConfig = File.ReadAllText(fi.FullName); - var variableDef = new Regex(@"(\w+)\s*\{|(\})|([\w\.]+)\s*([\+\-]?\=)(.*)\n"); - var lastBlock = string.Empty; - bool inBlock = false; + var variableDef = new Regex(@"(\w+)\s*\{|(\})|([\w\.]+)\s*[\+\-]?\=(.*)\n"); + var lastBlock = ""; + var inBlock = false; foreach (Match match in variableDef.Matches(qConfig)) { var block = match.Groups[1].Value; var blockEnd = match.Groups[2].Value; var name = match.Groups[3].Value; - //var oper = match.Groups[4].Value; - var data = match.Groups[5].Value; + var data = match.Groups[4].Value; if (!string.IsNullOrEmpty(block)) { inBlock = true; @@ -97,47 +55,21 @@ namespace QtVsTools.Core lastBlock = ""; } else if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(data) && (!inBlock || lastBlock == "!host_build")) { - data = data.Replace("\r", "").Trim(); - if (name == "CONFIG") { - var values = data.Split(new char[] { ' ', '\t' }, - StringSplitOptions.RemoveEmptyEntries); - foreach (var value in values) { - if (value == "static") { - BuildType = BuildType.Static; - break; - } else if (value == "shared") { - BuildType = BuildType.Shared; - break; - } - } - } else if (name == "QT_LIBINFIX") { - LibInfix = data; - } else if (name == "QT_ARCH") { - switch (data) { - case "x86_64": - Platform= Platform.x64; - break; - case "arm64": - Platform = Platform.arm64; - break; - default: - Platform = Platform.x86; - break; - } - } else if (name == "QT_NAMESPACE") { + switch (name) { + case "QT_ARCH": + Platform = data switch { + "x86_64" => Platform.x64, + "arm64" => Platform.arm64, + _ => Platform.x86 + }; + break; + case "QT_NAMESPACE": Namespace = data; - } else if (name == "QT_VERSION") { + break; + case "QT_VERSION": VersionString = data; - } else if (name == "QT_MAJOR_VERSION") { - if (uint.TryParse(data, out uint versionMajor)) - VersionMajor = versionMajor; - } else if (name == "QT_MINOR_VERSION") { - if (uint.TryParse(data, out uint versionMinor)) - VersionMinor = versionMinor; - } else if (name == "QT_PATCH_VERSION") { - if (uint.TryParse(data, out uint versionPatch)) - VersionPatch = versionPatch; + break; } } } |