diff options
| author | Orkun Tokdemir <orkun.tokdemir@qt.io> | 2024-11-25 15:36:19 +0100 |
|---|---|---|
| committer | Orkun Tokdemir <orkun.tokdemir@qt.io> | 2024-12-02 15:04:34 +0000 |
| commit | 32607fc7721c62f3d123276224ab2d3e4229b068 (patch) | |
| tree | 1b7e7741a6a50f685bc8331fc90fffdbbe337bb6 | |
| parent | aa67881c5a8878e5621526e9eda1797368468105 (diff) | |
qt-cpp: Analyze selected kit & send telemetry data
* Analyze the selected kit toolchain and the Qt version and send
telemetry data to the server.
* Introduce `QtVersionFromKit()` to reduce code duplication.
Change-Id: Ia92f03f0c1bb18d3c69db5c7b0b485a6d8cd9099
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
| -rw-r--r-- | qt-cpp/src/commands/natvis.ts | 26 | ||||
| -rw-r--r-- | qt-cpp/src/kit-manager.ts | 54 | ||||
| -rw-r--r-- | qt-cpp/src/project.ts | 4 | ||||
| -rw-r--r-- | qt-cpp/src/util/util.ts | 23 | ||||
| -rw-r--r-- | qt-lib/src/telemetry.ts | 2 |
5 files changed, 88 insertions, 21 deletions
diff --git a/qt-cpp/src/commands/natvis.ts b/qt-cpp/src/commands/natvis.ts index 00a0525..e68e082 100644 --- a/qt-cpp/src/commands/natvis.ts +++ b/qt-cpp/src/commands/natvis.ts @@ -5,15 +5,10 @@ import * as vscode from 'vscode'; import * as path from 'path'; import * as fs from 'fs'; -import { - getQtInsRoot, - getQtPathsExe, - getSelectedKit, - IsQtKit -} from '@cmd/register-qt-path'; +import { getSelectedKit, IsQtKit } from '@cmd/register-qt-path'; import { createLogger, telemetry } from 'qt-lib'; import { EXTENSION_ID } from '@/constants'; -import { coreAPI } from '@/extension'; +import { QtVersionFromKit } from '@/util/util'; const logger = createLogger('natvis'); @@ -56,16 +51,13 @@ export function registerNatvisCommand() { const error = `${kit?.name} is not a Qt kit`; throw new Error(error); } - const qtInsRoot = getQtInsRoot(kit); - if (qtInsRoot) { - const qtVersion = qtInsRoot.includes('6.') ? '6' : '5'; - return getNatvis(qtVersion); - } - const qtPathsExe = getQtPathsExe(kit); - if (qtPathsExe) { - const qtInfo = coreAPI?.getQtInfoFromPath(qtPathsExe); - const qtVersion = qtInfo?.get('QT_VERSION')?.includes('6.') ? '6' : '5'; - return getNatvis(qtVersion); + const version = QtVersionFromKit(kit); + if (version) { + const majorVersion = version.split('.')[0]; + if (!majorVersion) { + throw new Error('Could not determine the major version'); + } + return getNatvis(majorVersion); } return undefined; } diff --git a/qt-cpp/src/kit-manager.ts b/qt-cpp/src/kit-manager.ts index 8765e8c..c10cf2d 100644 --- a/qt-cpp/src/kit-manager.ts +++ b/qt-cpp/src/kit-manager.ts @@ -21,7 +21,9 @@ import { QtAdditionalPath, generateDefaultQtPathsName, IsWindows, - getVCPKGRoot + getVCPKGRoot, + telemetry, + TelemetryEventProperties } from 'qt-lib'; import * as qtPath from '@util/get-qt-paths'; import { CppProject } from '@/project'; @@ -29,6 +31,7 @@ import { coreAPI } from '@/extension'; import { GlobalStateManager } from '@/state'; import { IsQtKit } from '@cmd/register-qt-path'; import { EXTENSION_ID } from '@/constants'; +import { QtVersionFromKit } from '@util/util'; const logger = createLogger('kit-manager'); @@ -870,7 +873,56 @@ export async function tryToUseCMakeFromQtTools() { } }); } +export function analyzeKit(kit: Kit) { + let result: TelemetryEventProperties | undefined; + const toolchainType = analyzeToolchain(kit); + if (toolchainType) { + result = { + toolchainType: toolchainType + }; + } + const version = QtVersionFromKit(kit); + if (version) { + result = { + ...result, + version: version + }; + } + if (result) { + telemetry.sendConfig('kitInfo', result); + } +} + +function analyzeToolchain(kit: Kit) { + const insPath = kit.environmentVariables?.VSCODE_QT_INSTALLATION; + const qtpaths = kit.environmentVariables?.VSCODE_QT_QTPATHS_EXE; + + let toolchainType: string | undefined; + + if (insPath) { + const split = insPath.split(path.sep); + toolchainType = split[split.length - 1]; + } else if (qtpaths) { + // If the toolchain file is vcpkg.cmake, we can infer that it's a vcpkg toolchain + if (kit.toolchainFile) { + const parsed = path.parse(kit.toolchainFile); + if (parsed.base === 'vcpkg.cmake') { + toolchainType = 'vcpkg'; + } + } + // TODO: parse qconfig.pri to get more detailed info + if (!toolchainType) { + const qtInfo = coreAPI?.getQtInfoFromPath(qtpaths); + toolchainType = qtInfo?.get('QMAKE_XSPEC'); + } + } + if (toolchainType) { + return toolchainType; + } + + return undefined; +} async function setDoNotAskForCMakePath(value: boolean) { await vscode.workspace .getConfiguration(EXTENSION_ID) diff --git a/qt-cpp/src/project.ts b/qt-cpp/src/project.ts index 762d00f..23d45fc 100644 --- a/qt-cpp/src/project.ts +++ b/qt-cpp/src/project.ts @@ -13,6 +13,7 @@ import { getQtPathsExe, getSelectedKit } from '@cmd/register-qt-path'; +import { analyzeKit } from '@/kit-manager'; const logger = createLogger('project'); @@ -54,6 +55,9 @@ export class CppProject implements Project { async (configurationType: cmakeApi.ConfigurationType) => { if (configurationType === cmakeApi.ConfigurationType.Kit) { const kit = await getSelectedKit(this.folder); + if (kit) { + analyzeKit(kit); + } const selectedKitPath = kit ? getQtInsRoot(kit) : undefined; const message = new QtWorkspaceConfigMessage(this.folder); message.config.set('selectedKitPath', selectedKitPath); diff --git a/qt-cpp/src/util/util.ts b/qt-cpp/src/util/util.ts index 55496d0..2830415 100644 --- a/qt-cpp/src/util/util.ts +++ b/qt-cpp/src/util/util.ts @@ -1,6 +1,9 @@ // Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only +import { getQtInsRoot, getQtPathsExe } from '@/commands/register-qt-path'; +import { coreAPI } from '@/extension'; +import { Kit } from '@/kit-manager'; import * as path from 'path'; /** @@ -15,10 +18,24 @@ export function getFilenameWithoutExtension(filename: string): string { if (!separatedPath) { throw new Error('Filename is empty'); } - const splittedPath = separatedPath.split('.')[0]; - if (splittedPath === undefined) { + const splitPath = separatedPath.split('.')[0]; + if (splitPath === undefined) { throw new Error('Filename is empty'); } - return splittedPath; + return splitPath; +} + +export function QtVersionFromKit(kit: Kit) { + const qtInsRoot = getQtInsRoot(kit); + if (qtInsRoot) { + const split = qtInsRoot.split(path.sep); + return split[split.length - 2]; + } + const qtPathsExe = getQtPathsExe(kit); + if (qtPathsExe) { + const qtInfo = coreAPI?.getQtInfoFromPath(qtPathsExe); + return qtInfo?.get('QT_VERSION'); + } + return undefined; } diff --git a/qt-lib/src/telemetry.ts b/qt-lib/src/telemetry.ts index dcdbf9a..631db5b 100644 --- a/qt-lib/src/telemetry.ts +++ b/qt-lib/src/telemetry.ts @@ -7,6 +7,8 @@ import TelemetryReporter, { TelemetryEventProperties } from '@vscode/extension-telemetry'; +export { TelemetryEventProperties }; + const globalConnectionString = 'InstrumentationKey=09d5f9a1-0532-4146-b158-a653220b28b6;IngestionEndpoint=https://germanywestcentral-1.in.applicationinsights.azure.com/;LiveEndpoint=https://germanywestcentral.livediagnostics.monitor.azure.com/;ApplicationId=8758b8d8-22d0-459d-b1b4-1689a3a350d5'; export let reporter: TelemetryReporter; |
