Skip to content

Support for multi-root .code-workspace workspaces #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions .vscode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,42 @@ module.exports = defineConfig({
reuseMachineInstall: !isCIBuild,
installExtensions,
},
{
label: "codeWorkspaceTests",
files: [
"dist/test/common.js",
"dist/test/integration-tests/extension.test.js",
"dist/test/integration-tests/WorkspaceContext.test.js",
"dist/test/integration-tests/tasks/**/*.test.js",
"dist/test/integration-tests/commands/build.test.js",
"dist/test/integration-tests/testexplorer/TestExplorerIntegration.test.js",
"dist/test/integration-tests/commands/dependency.test.js",
],
version: process.env["VSCODE_VERSION"] ?? "stable",
workspaceFolder: "./assets/test.code-workspace",
launchArgs,
extensionDevelopmentPath: vsixPath
? [`${__dirname}/.vscode-test/extensions/${publisher}.${name}-${version}`]
: undefined,
mocha: {
ui: "tdd",
color: true,
timeout,
forbidOnly: isCIBuild,
grep: isFastTestRun ? "@slow" : undefined,
invert: isFastTestRun,
slow: 10000,
retries: 1,
reporter: path.join(__dirname, ".mocha-reporter.js"),
reporterOptions: {
jsonReporterOptions: {
output: path.join(__dirname, "test-results", "code-workspace-tests.json"),
},
},
},
reuseMachineInstall: !isCIBuild,
installExtensions,
},
{
label: "unitTests",
files: ["dist/test/common.js", "dist/test/unit-tests/**/*.test.js"],
Expand Down
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
},
"preLaunchTask": "compile-tests"
},
{
"name": "Code Workspace Tests",
"type": "extensionHost",
"request": "launch",
"testConfiguration": "${workspaceFolder}/.vscode-test.js",
"testConfigurationLabel": "codeWorkspaceTests",
"args": ["--profile=testing-debug"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"env": {
"VSCODE_DEBUG": "1"
},
"preLaunchTask": "compile-tests"
},
{
"name": "Unit Tests",
"type": "extensionHost",
Expand Down
144 changes: 144 additions & 0 deletions assets/test.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"folders": [
{
"name": "diagnostics",
"path": "./test/diagnostics"
},
{
"name": "dependencies",
"path": "./test/dependencies"
},
{
"name": "command-plugin",
"path": "./test/command-plugin"
},
{
"name": "defaultPackage",
"path": "./test/defaultPackage"
}
],
"settings": {
"swift.disableAutoResolve": true,
"swift.autoGenerateLaunchConfigurations": false,
"swift.debugger.debugAdapter": "lldb-dap",
"swift.debugger.setupCodeLLDB": "alwaysUpdateGlobal",
"swift.additionalTestArguments": [
"-Xswiftc",
"-DTEST_ARGUMENT_SET_VIA_TEST_BUILD_ARGUMENTS_SETTING"
],
"lldb.verboseLogging": true,
"lldb.launch.terminal": "external",
"lldb-dap.detachOnError": true,
"swift.sourcekit-lsp.backgroundIndexing": "off"
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"type": "swift",
"args": [
"build",
"--build-tests",
"--verbose",
"-Xswiftc",
"-DBAR"
],
"cwd": "${workspaceFolder:defaultPackage}",
"group": {
"kind": "build",
"isDefault": true
},
"label": "swift: Build All (defaultPackage) (workspace)",
"detail": "swift build --build-tests --verbose -Xswiftc -DBAR"
},
{
"type": "swift",
"args": [
"build",
"--show-bin-path"
],
"cwd": "${workspaceFolder:defaultPackage}",
"group": "build",
"label": "swift: Build All from code workspace",
"detail": "swift build --show-bin-path"
},
{
"type": "swift-plugin",
"command": "command_plugin",
"args": [
"--foo"
],
"cwd": "${workspaceFolder:command-plugin}",
"disableSandbox": true,
"label": "swift: command-plugin from code workspace",
"detail": "swift package command_plugin --foo"
},
{
"type": "swift",
"args": [
"build",
"--product",
"PackageExe",
"-Xswiftc",
"-diagnostic-style=llvm",
"-Xswiftc",
"-DBAR"
],
"cwd": "${workspaceFolder:defaultPackage}",
"group": "build",
"label": "swift: Build Debug PackageExe (defaultPackage) (workspace)",
"detail": "swift build --product PackageExe -Xswiftc -diagnostic-style=llvm -Xswiftc -DBAR"
},
{
"type": "swift",
"args": [
"build",
"-c",
"release",
"--product",
"PackageExe",
"-Xswiftc",
"-diagnostic-style=llvm",
"-Xswiftc",
"-DBAR"
],
"cwd": "${workspaceFolder:defaultPackage}",
"group": "build",
"label": "swift: Build Release PackageExe (defaultPackage) (workspace)",
"detail": "swift build -c release --product PackageExe -Xswiftc -diagnostic-style=llvm -Xswiftc -DBAR"
}
]
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"type": "swift",
"request": "launch",
"name": "Debug PackageExe (defaultPackage) (workspace)",
"program": "${workspaceFolder:defaultPackage}/.build/debug/PackageExe",
"args": [],
"cwd": "${workspaceFolder:defaultPackage}",
"preLaunchTask": "swift: Build Debug PackageExe (defaultPackage) (workspace)",
"disableASLR": false,
"initCommands": [
"settings set target.disable-aslr false"
]
},
{
"type": "swift",
"request": "launch",
"name": "Release PackageExe (defaultPackage) (workspace)",
"program": "${workspaceFolder:defaultPackage}/.build/release/PackageExe",
"args": [],
"cwd": "${workspaceFolder:defaultPackage}",
"preLaunchTask": "swift: Build Release PackageExe (defaultPackage) (workspace)",
"disableASLR": false,
"initCommands": [
"settings set target.disable-aslr false"
]
}
],
"compounds": []
}
}
10 changes: 7 additions & 3 deletions assets/test/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
"args": [
"build",
"--build-tests",
"--verbose"
"--verbose",
"-Xswiftc",
"-DFOO"
],
"cwd": "defaultPackage",
"problemMatcher": [
"$swiftc"
],
"group": "build",
"label": "swift: Build All (defaultPackage)",
"detail": "swift build --build-tests --verbose"
"detail": "swift build --build-tests --verbose -Xswiftc -DFOO"
},
{
"type": "swift",
Expand All @@ -33,7 +35,9 @@
{
"type": "swift-plugin",
"command": "command_plugin",
"args": ["--foo"],
"args": [
"--foo"
],
"cwd": "command-plugin",
"disableSandbox": true,
"problemMatcher": [
Expand Down
62 changes: 62 additions & 0 deletions assets/test/defaultPackage/.vscode/launch copy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"configurations": [
{
"type": "swift",
"request": "launch",
"name": "Attach to Swift Executable",
"program": "${workspaceFolder}/.build/aarch64-unknown-linux-gnu/debug/PackageExe",
// "attachCommands": [
// // "gdb-remote 1234",
// // "process launch"
// "platform select remote-linux",
// "platform connect connect://127.0.0.1:1234"
// ],
// "initCommands": [
// "target create .build/aarch64-unknown-linux-gnu/debug/PackageExe",
// "b main.swift:7",
// ]
"initCommands": [
"platform select remote-linux",
// "platform connect connect://127.0.0.1:1234",
"gdb-remote 1234",
"settings set target.inherit-env false"
]
},
{
"type": "swift",
"request": "launch",
"name": "Debug package1",
"program": "${workspaceFolder:defaultPackage}/.build/debug/package1",
"args": [],
"cwd": "${workspaceFolder:defaultPackage}",
"preLaunchTask": "swift: Build Debug package1"
},
{
"type": "swift",
"request": "launch",
"name": "Release package1",
"program": "${workspaceFolder:defaultPackage}/.build/release/package1",
"args": [],
"cwd": "${workspaceFolder:defaultPackage}",
"preLaunchTask": "swift: Build Release package1"
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:defaultPackage}",
"name": "Debug PackageExe",
"program": "${workspaceFolder:defaultPackage}/.build/debug/PackageExe",
"preLaunchTask": "swift: Build Debug PackageExe"
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:defaultPackage}",
"name": "Release PackageExe",
"program": "${workspaceFolder:defaultPackage}/.build/release/PackageExe",
"preLaunchTask": "swift: Build Release PackageExe"
}
]
}
19 changes: 19 additions & 0 deletions scripts/test_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
function Update-SwiftBuildAndPackageArguments {
param (
[string]$jsonFilePath = "./assets/test/.vscode/settings.json",
[string]$codeWorkspaceFilePath = "./assets/test.code-workspace",
[string]$windowsSdkVersion = "10.0.22000.0",
[string]$vcToolsVersion = "14.43.34808"
)
Expand All @@ -28,9 +29,17 @@ function Update-SwiftBuildAndPackageArguments {
exit 1
}

try {
$codeWorkspaceContent = Get-Content -Raw -Path $codeWorkspaceFilePath | ConvertFrom-Json
} catch {
Write-Host "Invalid JSON content in $codeWorkspaceFilePath"
exit 1
}

if ($jsonContent.PSObject.Properties['swift.buildArguments']) {
$jsonContent.PSObject.Properties.Remove('swift.buildArguments')
}


$jsonContent | Add-Member -MemberType NoteProperty -Name "swift.buildArguments" -Value @(
"-Xbuild-tools-swiftc", "-windows-sdk-root", "-Xbuild-tools-swiftc", $windowsSdkRoot,
Expand All @@ -54,10 +63,20 @@ function Update-SwiftBuildAndPackageArguments {
"-Xswiftc", "-visualc-tools-version", "-Xswiftc", $vcToolsVersion
)


$codeWorkspaceContent.PSObject.Properties.Remove('settings')
$codeWorkspaceContent | Add-Member -MemberType NoteProperty -Name "settings" -Value $jsonContent

$jsonContent | ConvertTo-Json -Depth 32 | Set-Content -Path $jsonFilePath


$codeWorkspaceContent | ConvertTo-Json -Depth 32 | Set-Content -Path $codeWorkspaceFilePath

Write-Host "Contents of ${jsonFilePath}:"
Get-Content -Path $jsonFilePath

Write-Host "Contents of ${codeWorkspaceFilePath}:"
Get-Content -Path $codeWorkspaceFilePath
}

$swiftVersionOutput = & swift --version
Expand Down
5 changes: 3 additions & 2 deletions src/TestExplorer/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { reduceTestItemChildren } from "./TestUtils";
import { CompositeCancellationToken } from "../utilities/cancellation";
// eslint-disable-next-line @typescript-eslint/no-require-imports
import stripAnsi = require("strip-ansi");
import { packageName, resolveScope } from "../utilities/tasks";

export enum TestLibrary {
xctest = "XCTest",
Expand Down Expand Up @@ -773,8 +774,8 @@ export class TestRunner {
`Building and Running Tests${kindLabel}`,
{
cwd: this.folderContext.folder,
scope: this.folderContext.workspaceFolder,
prefix: this.folderContext.name,
scope: resolveScope(this.folderContext.workspaceFolder),
packageName: packageName(this.folderContext),
presentationOptions: { reveal: vscode.TaskRevealKind.Never },
},
this.folderContext.toolchain,
Expand Down
9 changes: 7 additions & 2 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { debugLaunchConfig, getLaunchConfiguration } from "../debugger/launch";
import { executeTaskWithUI } from "./utilities";
import { FolderContext } from "../FolderContext";
import { Target } from "../SwiftPackage";
import { packageName } from "../utilities/tasks";

/**
* Executes a {@link vscode.Task task} to run swift target.
Expand Down Expand Up @@ -56,7 +57,7 @@ export async function folderCleanBuild(folderContext: FolderContext) {
{
cwd: folderContext.folder,
scope: folderContext.workspaceFolder,
prefix: folderContext.name,
packageName: packageName(folderContext),
presentationOptions: { reveal: vscode.TaskRevealKind.Silent },
group: vscode.TaskGroup.Clean,
},
Expand Down Expand Up @@ -111,7 +112,11 @@ export async function debugBuildWithOptions(
const launchConfig = getLaunchConfiguration(target.name, current);
if (launchConfig) {
ctx.buildStarted(target.name, launchConfig, options);
const result = await debugLaunchConfig(current.workspaceFolder, launchConfig, options);
const result = await debugLaunchConfig(
vscode.workspace.workspaceFile ? undefined : current.workspaceFolder,
launchConfig,
options
);
ctx.buildFinished(target.name, launchConfig, options);
return result;
}
Expand Down
Loading