1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only
import * as path from 'path';
import * as vscode from 'vscode';
import * as commandExists from 'command-exists';
import {
createLogger,
IsLinux,
IsMacOS,
IsWindows,
OSExeSuffix,
QtAdditionalPath,
getVCPKGRoot,
IsArm64,
Isx64,
telemetry
} from 'qt-lib';
import { getQueryOutput } from '@/util';
import { getCurrentGlobalAdditionalQtPaths } from '@/installation-root';
import { EXTENSION_ID } from '@/constants';
import { addQtPathToSettings } from '@/qtpaths';
const logger = createLogger('vcpkg');
export function checkVcpkg() {
if (getDoNotAskForVCPKG()) {
logger.info('Do not ask for vcpkg');
return;
}
if (!isVCPKGInstalled()) {
logger.info('vcpkg is not installed');
return;
}
const vcpkgRoot = getVCPKGRoot();
if (!vcpkgRoot) {
logger.error('VCPKG_ROOT not found');
return;
}
const qtPath = searchForQtPathsInVCPKG(vcpkgRoot);
if (qtPath) {
// Ask for the user to add the paths to the settings
const action = 'Use';
const message = `Qt installation found in vcpkg. Do you want to use it?`;
const doNotShowAgain = 'Do not show again';
const currentQtPaths = getCurrentGlobalAdditionalQtPaths();
if (containsQtPath(qtPath, currentQtPaths)) {
logger.info('Qt path already exists in the settings');
return;
}
void vscode.window
.showInformationMessage(message, action, doNotShowAgain)
.then((value) => {
if (value === action) {
telemetry.sendConfig('useVCPKG');
logger.info('Adding Qt path to settings');
addQtPathToSettings({ path: qtPath, isVCPKG: true });
} else if (value === doNotShowAgain) {
telemetry.sendConfig('doNotAskForVCPKG');
void setDoNotAskForVCPKG(true);
logger.info('setting doNotAskForVCPKG to true');
}
});
}
}
function containsQtPath(qtPath: string, additionalQtPaths: QtAdditionalPath[]) {
for (const p of additionalQtPaths) {
if (p.path === qtPath) {
return true;
}
}
return false;
}
export function isVCPKGInstalled(): boolean {
if (commandExists.sync('vcpkg')) {
return true;
}
return false;
}
function getDoNotAskForVCPKG(): boolean {
return (
vscode.workspace
.getConfiguration(EXTENSION_ID)
.get<boolean>('doNotAskForVCPKG') ?? false
);
}
export async function setDoNotAskForVCPKG(value: boolean) {
await vscode.workspace
.getConfiguration(EXTENSION_ID)
.update('doNotAskForVCPKG', value, vscode.ConfigurationTarget.Global);
}
export function searchForQtPathsInVCPKG(root: string): string | undefined {
if (!root) {
return;
}
const exeNames = [`qtpaths${OSExeSuffix}`, `qmake${OSExeSuffix}`];
if (IsWindows) {
exeNames.push('qmake.bat');
}
const osPath = () => {
const arch = Isx64 ? 'x64' : 'x86';
if (IsLinux) {
return `${arch}-linux`;
} else if (IsMacOS) {
if (IsArm64) {
return 'arm64-osx';
} else {
return `x64-osx`;
}
} else if (IsWindows) {
return `${arch}-windows`;
} else {
throw new Error('Not supported');
}
};
for (const exeName of exeNames) {
const exePath = path.join(
root,
'installed',
osPath(),
'tools',
'Qt6',
'bin',
exeName
);
const ret = getQueryOutput(exePath);
if (ret) {
logger.info(`Found Qt paths in vcpkg: ${exePath}`);
return exePath;
}
}
return undefined;
}
|