Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions qt-core/src/qtcli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as fs from 'fs/promises';
import * as path from 'path';
import * as vscode from 'vscode';

import { exists, IsArm64 } from 'qt-lib';
import { exists, IsArm64, IsLinux, IsMacOS, IsWindows } from 'qt-lib';
import { EXTENSION_ID } from '@/constants';
import {
qtcliExeName,
Expand Down Expand Up @@ -53,16 +53,14 @@ function getDefaultProjectDir(): string | undefined {
}

function findQtcliOsPrefix(): string {
const platform = process.platform;

if (platform === 'win32') {
if (IsWindows) {
return `qtcli-windows-${IsArm64 ? 'arm64-' : 'amd64-'}`;
} else if (platform === 'linux') {
} else if (IsLinux) {
return `qtcli-linux-${IsArm64 ? 'arm64-' : 'amd64-'}`;
} else if (platform === 'darwin') {
} else if (IsMacOS) {
return 'qtcli-darwin-all-';
} else {
throw new Error(`Platform '${platform}' is not supported`);
throw new Error(`Platform '${process.platform}' is not supported`);
}
}

Expand Down
5 changes: 2 additions & 3 deletions qt-core/src/qtcli/common.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import * as os from 'os';
import * as fs from 'fs/promises';
import * as fsSync from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';

import { createLogger, OSExeSuffix } from 'qt-lib';
import { createLogger, Home, OSExeSuffix } from 'qt-lib';

export const qtcliExeName = 'qtcli' + OSExeSuffix;
const logger = createLogger('qtcli');

export function fallbackWorkingDir(): string {
const docs = path.join(os.homedir(), 'Documents');
const docs = path.join(Home, 'Documents');
const settings =
vscode.workspace
.getConfiguration('files')
Expand Down
10 changes: 4 additions & 6 deletions qt-core/src/qtcli/rest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import os from 'os';
import * as vscode from 'vscode';
import * as childProcess from 'child_process';
import { randomUUID } from 'crypto';
import axios, { AxiosRequestConfig, isAxiosError } from 'axios';

import { createLogger } from 'qt-lib';
import { createLogger, IsWindows } from 'qt-lib';
import { findQtcliExePath } from '@/qtcli/commands';
import { isErrorResponse, Issue } from '@/webview/shared/message';

Expand All @@ -33,10 +32,9 @@ export class QtcliRestClient {
this._api = axios.create({
baseURL: 'http://unix',
timeout: 15 * 1000,
socketPath:
os.platform() !== 'win32'
? `/tmp/qtcli/${socketName}.sock`
: String.raw`\\.\pipe\qtcli` + `\\${socketName}.pipe`
socketPath: !IsWindows
? `/tmp/qtcli/${socketName}.sock`
: String.raw`\\.\pipe\qtcli` + `\\${socketName}.pipe`
});

this._timerId = setInterval(() => {
Expand Down
4 changes: 2 additions & 2 deletions qt-core/src/ui-designer/locator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (C) 2026 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import * as os from 'os';
import * as fs from 'fs';
import * as fsp from 'fs/promises';
import * as path from 'path';
import * as vscode from 'vscode';

import {
IsMacOS,
IsWindows,
OSExeSuffix,
createWrappedLogger,
resolveConfiguration,
Expand Down Expand Up @@ -204,7 +204,7 @@ async function checkExeStatus(input: string): Promise<ExeCheckResult> {
return ExeCheckResult.NotAFile;
}

if (os.platform() === 'win32') {
if (IsWindows) {
const args = ['.exe', '.cmd', '.bat', '.com'];
if (!args.includes(path.extname(normalized).toLowerCase())) {
return ExeCheckResult.NotExecutableExtension;
Expand Down
8 changes: 2 additions & 6 deletions qt-core/src/webview/ex-browser/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from 'lodash';
import * as path from 'path';
import * as vscode from 'vscode';

import { createLogger } from 'qt-lib';
import { createLogger, normalizeDriveLetter } from 'qt-lib';
import { WebviewChannel } from '@/webview/channel';
import {
Command,
Expand Down Expand Up @@ -229,11 +229,7 @@ export class ExBrowserDispatcher {

const folderUri = await vscode.window.showOpenDialog(options);
if (folderUri && folderUri.length > 0) {
let folder = folderUri[0]?.fsPath ?? '';
if (process.platform === 'win32' && /^[a-z]:/.test(folder)) {
folder = folder.charAt(0).toUpperCase() + folder.slice(1);
}

const folder = normalizeDriveLetter(folderUri[0]?.fsPath ?? '');
this._comm.postDataReply(cmd, folder);
}
};
Expand Down
8 changes: 2 additions & 6 deletions qt-core/src/webview/new-item/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from 'lodash';
import * as path from 'path';
import * as vscode from 'vscode';

import { createLogger, telemetry } from 'qt-lib';
import { createLogger, normalizeDriveLetter, telemetry } from 'qt-lib';
import * as texts from '@/texts';
import { QtcliRestClient, QtcliRestError } from '@/qtcli/rest';
import { openFilesUnder, openUri } from '@/qtcli/common';
Expand Down Expand Up @@ -227,11 +227,7 @@ export class NewItemDispatcher {

const folderUri = await vscode.window.showOpenDialog(options);
if (folderUri && folderUri.length > 0) {
let folder = folderUri[0]?.fsPath ?? '';
if (process.platform === 'win32' && /^[a-z]:/.test(folder)) {
folder = folder.charAt(0).toUpperCase() + folder.slice(1);
}

const folder = normalizeDriveLetter(folderUri[0]?.fsPath ?? '');
this._comm?.postDataReply(cmd, folder);
}
};
Expand Down
8 changes: 2 additions & 6 deletions qt-core/src/webview/qml-trace/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from 'lodash';
import * as path from 'path';
import * as vscode from 'vscode';

import { createLogger, getQtQmlApi } from 'qt-lib';
import { createLogger, getQtQmlApi, normalizeDriveLetter } from 'qt-lib';
import {
Command,
CommandId,
Expand Down Expand Up @@ -105,11 +105,7 @@ export class QmlTraceController {

const folderUri = await vscode.window.showOpenDialog(options);
if (folderUri && folderUri.length > 0) {
let folder = folderUri[0]?.fsPath ?? '';
if (process.platform === 'win32' && /^[a-z]:/.test(folder)) {
folder = folder.charAt(0).toUpperCase() + folder.slice(1);
}

const folder = normalizeDriveLetter(folderUri[0]?.fsPath ?? '');
this._postReply(cmd, { folders: [folder] });
}
};
Expand Down
4 changes: 2 additions & 2 deletions qt-core/test/suite/commands.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { expect } from 'chai';
import * as sinon from 'sinon';
import * as vscode from 'vscode';
import {
Home,
isMultiWorkspace,
QtAdditionalPath,
AdditionalQtPathsName,
QtInsRootConfigName,
generateDefaultQtPathsName
} from 'qt-lib';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import {
addQtPathToSettings,
Expand Down Expand Up @@ -373,7 +373,7 @@ describe('command: registerQt', () => {

// Pick one candidate and pretend it exists
const candidates = getDefaultQtRootCandidates();
const portable = path.join(os.homedir(), 'Qt');
const portable = path.join(Home, 'Qt');
// Guard to ensure test stays aligned with production candidates
expect(
candidates.includes(portable),
Expand Down
17 changes: 7 additions & 10 deletions qt-cpp/test/configure-build-helper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import * as cp from 'child_process';
import { delay } from 'qt-lib';
import { delay, IsMacOS, IsWindows, OSExeSuffix } from 'qt-lib';

import {
waitForVSCodeIdle,
Expand Down Expand Up @@ -89,9 +89,7 @@ type ConfigureResult = {
export function materializeSnippetConfigForCurrentPlatform(
base: vscode.DebugConfiguration
): vscode.DebugConfiguration {
const isWin = process.platform === 'win32';
const isMac = process.platform === 'darwin';
const platformKey = isWin ? 'windows' : isMac ? 'osx' : 'linux';
const platformKey = IsWindows ? 'windows' : IsMacOS ? 'osx' : 'linux';

const platformOverrides = (base as any)[platformKey] as
| Record<string, unknown>
Expand Down Expand Up @@ -133,7 +131,7 @@ function dumpConfigureOutput(
const res = cp.spawnSync('cmake', ['--preset', presetName], {
cwd: projectDir,
encoding: 'utf-8',
shell: process.platform === 'win32'
shell: IsWindows
});
if (res.error) {
console.log(
Expand Down Expand Up @@ -178,7 +176,7 @@ function dumpBuildOutput(logPrefix: string, buildDir: string): void {
try {
const res = cp.spawnSync('cmake', ['--build', buildDir], {
encoding: 'utf-8',
shell: process.platform === 'win32'
shell: IsWindows
});
if (res.error) {
console.log(
Expand Down Expand Up @@ -308,7 +306,6 @@ export async function configureAndBuildMinimalQtProject(
// `cmake.useVsDeveloperEnvironment: 'always'`. The `architecture` field
// uses the presets-spec "external" strategy: CMake ignores it, but CMake
// Tools reads it to pick the environment's target architecture.
const isWin = process.platform === 'win32';
const presets = {
version: 3,
configurePresets: [
Expand All @@ -317,7 +314,7 @@ export async function configureAndBuildMinimalQtProject(
displayName: 'Qt Debug Configuration',
description: 'Debug build using Qt with CMake Presets',
binaryDir: buildDir,
...(isWin
...(IsWindows
? {
generator: 'Ninja',
architecture: { value: 'x64', strategy: 'external' }
Expand All @@ -326,7 +323,7 @@ export async function configureAndBuildMinimalQtProject(
cacheVariables: {
CMAKE_BUILD_TYPE: 'Debug',
CMAKE_PREFIX_PATH: qtEnv.leaf,
...(isWin
...(IsWindows
? {
CMAKE_C_COMPILER: 'clang-cl',
CMAKE_CXX_COMPILER: 'clang-cl'
Expand Down Expand Up @@ -399,7 +396,7 @@ export async function configureAndBuildMinimalQtProject(

// Ninja (single-config) is pinned on Windows, so the binary lands directly
// in the build directory on every platform.
const bin = process.platform === 'win32' ? 'hello.exe' : 'hello';
const bin = 'hello' + OSExeSuffix;
const outPath = path.join(buildDir, bin);
dlog(`${logPrefix} Checking for binary at`, outPath);

Expand Down
23 changes: 10 additions & 13 deletions qt-cpp/test/debug-helper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import * as vscode from 'vscode';
import * as path from 'path';

import { IsLinux, IsMacOS, IsWindows } from 'qt-lib';

/**
* Debug-session utilities for qt-cpp NatVis integration tests.
*
Expand Down Expand Up @@ -125,10 +127,7 @@ export function addBreakpoints(bps: vscode.SourceBreakpoint[]) {
* @throws Error if required launch paths or the NatVis file cannot be resolved.
*/
export async function makeCppDebugConfig(): Promise<vscode.DebugConfiguration> {
const isWin = process.platform === 'win32';
const isMac = process.platform === 'darwin';
const isLinux = process.platform === 'linux';
const miMode = process.env.MIMODE || (isMac ? 'lldb' : 'gdb');
const miMode = process.env.MIMODE || (IsMacOS ? 'lldb' : 'gdb');

// Resolve what ${command:...} would have produced
const program = await vscode.commands.executeCommand<string>(
Expand All @@ -151,9 +150,9 @@ export async function makeCppDebugConfig(): Promise<vscode.DebugConfiguration> {
}
const cfg: vscode.DebugConfiguration = {
name: 'natvis-test-launch',
type: isWin ? 'cppvsdbg' : 'cppdbg',
type: IsWindows ? 'cppvsdbg' : 'cppdbg',
request: 'launch',
...(isWin ? {} : { MIMode: miMode }),
...(IsWindows ? {} : { MIMode: miMode }),
// Always the correct binary/dir for the *selected configuration* and *build type*
program: program, //'${command:cmake.launchTargetPath}', // built binary
cwd: cwd, //'${command:cmake.getLaunchTargetDirectory}', // correct working dir
Expand All @@ -166,11 +165,11 @@ export async function makeCppDebugConfig(): Promise<vscode.DebugConfiguration> {
};

// Non-Windows: set MI mode, and on Linux also force the debugger path.
if (!isWin) {
if (!IsWindows) {
(cfg as any).MIMode = miMode;

// On Ubuntu CI, cpptools can't infer the MI debugger, so we point it at gdb explicitly.
if (isLinux && !(cfg as any).miDebuggerPath) {
if (IsLinux && !(cfg as any).miDebuggerPath) {
(cfg as any).miDebuggerPath = 'gdb';
}
}
Expand Down Expand Up @@ -366,7 +365,7 @@ export async function warmUpNatvisDisplay(
session: vscode.DebugSession,
frameId: number
): Promise<void> {
if (process.platform !== 'win32') return;
if (!IsWindows) return;

const topLocals = await getLocals(session, frameId);

Expand Down Expand Up @@ -584,11 +583,9 @@ export function getQtCppSnippetDebugConfiguration(): vscode.DebugConfiguration {
);
}

const isWin = process.platform === 'win32';

let snippet: DebugConfigurationSnippet | undefined;

if (isWin) {
if (IsWindows) {
// Windows: use the Visual Studio debugger snippet
snippet = allSnippets.find((s) => s.body?.type === 'cppvsdbg');
} else {
Expand All @@ -614,7 +611,7 @@ export function getQtCppSnippetDebugConfiguration(): vscode.DebugConfiguration {
if (!normalized.name) {
normalized.name =
snippet.label ??
(isWin ? 'Qt snippet (cppvsdbg)' : 'Qt snippet (cppdbg)');
(IsWindows ? 'Qt snippet (cppvsdbg)' : 'Qt snippet (cppdbg)');
}

return normalized;
Expand Down
4 changes: 2 additions & 2 deletions qt-cpp/test/suite/build.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';

import { delay } from 'qt-lib';
import { delay, OSExeSuffix } from 'qt-lib';
import {
setupSandboxLifecycleHooks,
waitForVSCodeIdle,
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('build: minimal Qt project (index-build)', function () {

await delay(400); // flush to disk

const bin = process.platform === 'win32' ? 'hello.exe' : 'hello';
const bin = 'hello' + OSExeSuffix;
const outPath = path.join(buildDir, bin);
console.log('Checking for binary at', outPath);

Expand Down
4 changes: 2 additions & 2 deletions qt-cpp/test/suite/commands.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expect } from 'chai';
import * as sinon from 'sinon';
import * as vscode from 'vscode';

import { delay } from 'qt-lib';
import { delay, IsWindows } from 'qt-lib';

import {
setupSandboxLifecycleHooks,
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('command: scanForQtKits', () => {
}

it('calls for cmake scan for kits command, on Windows', async function () {
if (process.platform !== 'win32') {
if (!IsWindows) {
this.skip(); // Only meaningful on Windows
}

Expand Down
Loading
Loading