Skip to content
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

Feature Request: Select Active Folder for Build and Test Tasks #3256

Closed
cvanbeek13 opened this issue Jul 24, 2023 · 3 comments
Closed

Feature Request: Select Active Folder for Build and Test Tasks #3256

cvanbeek13 opened this issue Jul 24, 2023 · 3 comments
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: tasks help wanted we currently are not planning work on this and would like help from the open source community
Milestone

Comments

@cvanbeek13
Copy link
Contributor

Brief Issue Summary

I have a multi-root code-workspace file with my root project folder and a tests folder. I have separate projects because the tests run locally on my windows machine with a msys64 toolchain, but the project itself is built for an ARM microcontroller with the arm-none-eabi toolchain.

I want to create separate tasks to build my project for arm, and to run my unit tests on windows. So far, I'm focusing on running the tests.

I want to note that to do what I want to do manually, I can make sure my tests folder is selected (++ctrl+shift+p++ CMake: Select Active Folder, select Tests) and then run the ++ctrl+shift+p++ CMake: Run Tests command. When I do this, it properly builds my test app and executes the unit tests. The issue is that I manually need to switch back to the project folder to run the build, and if I want to run the tests again, I need to manually switch back to the tests folder. I would like to automatically do that by using tasks to switch the folder and run the build or tests.

Attempt Number 1 - Using cmake Task Type

The first thing I tried was to find a way to adjust the cmake type test to use the tests folder. Here is my .code-workspace file:

{
	"folders": [
		{
			"name": "Project",
			"path": ".."
		},
		{
			"name": "Tests",
			"path": "../tests"
		}
	],
	"tasks": {
		"version": "2.0.0",
		"tasks": [
                         {
				"type": "cmake",
				"command": "test",
				"options": {
					"cwd": "${workspaceFolder}/tests"
				},
				"group": {
					"kind": "test",
					"isDefault": true
				},
				"problemMatcher": [
					"$gcc"
				],
			}
                 ]
         }
}

Adjusting the cwd parameter had no effect though, and the task always executed on the Project folder. I couldn't find another relevant parameter to try to change.

Attempt Number 2 - Using Task to Switch Folders

My second idea was to switch folders using another task which is called as a dependency of my test task. Here is my configuration to do that:

{
	"folders": [
		{
			"name": "Project",
			"path": ".."
		},
		{
			"name": "Tests",
			"path": "../tests"
		}
	],
	"tasks": {
		"version": "2.0.0",
		"tasks": [
			{
				"label": "SwitchToTests",
				"type": "process",
				"command": "${input:switchToTests}",
				"problemMatcher": []
			},
			{
				"label": "CMake Build Tests",
				"type": "cmake",
				"command": "build",
				"dependsOn": [
					"SwitchToTests"
				],
				"dependsOrder": "sequence",
				"problemMatcher": [
					"$gcc"
				]
			},
			{
				"label": "CMake Test",
				"type": "cmake",
				"command": "test",
				"options": {
					"cwd": "${workspaceFolder}/tests"
				},
				"group": {
					"kind": "test",
					"isDefault": true
				},
				"problemMatcher": [
					"$gcc"
				],
				"dependsOn": [
					"CMake Build Tests"
				],
				"dependsOrder": "sequence",
			}
		],
		"inputs": [
			{
				"id": "switchToTests",
				"type": "command",
				"command": "cmake.selectActiveFolder",
				"args": [
					"tests"
				]
			},
		],
         }
}

This almost works, but it always opens up a input window to select with folder to select when the cmake.selectActiveFolder command runs:

image

Is there any way to get VSCode to automatically select the tests folder? I couldn't get this working with the args parameter. Otherwise, is there another way to accomplish what I'm trying to do?

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

@benmcmorran
Copy link
Member

Thanks for the suggestion! I'm not aware of a way to do this right now, but it seems reasonable to allow specifying a folder as a parameter to the cmake.selectActiveFolder command. We likely won't be able to get to this work immediately, but if someone else is interested in contributing a PR, the change needs to happen here in the source code.

@benmcmorran benmcmorran added enhancement an enhancement to the product that is either not present or an improvement to an existing feature help wanted we currently are not planning work on this and would like help from the open source community Feature: tasks labels Jul 25, 2023
@benmcmorran benmcmorran added this to the 1.16 milestone Jul 25, 2023
@cvanbeek13
Copy link
Contributor Author

I added a PR #3258

@benmcmorran benmcmorran modified the milestones: 1.16, 1.15 Jul 26, 2023
@benmcmorran
Copy link
Member

benmcmorran commented Jul 26, 2023

Fixed by #3258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: tasks help wanted we currently are not planning work on this and would like help from the open source community
Projects
None yet
Development

No branches or pull requests

2 participants