Skip to content

Commit

Permalink
Support the application of Conan's BuildEnv/RunEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
hackenbergstefan committed Aug 17, 2024
1 parent f452ddb commit a60d210
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 88 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Build & Test'

on:
push:

pull_request:
branches:
- main
Expand All @@ -18,6 +18,8 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: Install and setup conan
run: pip install conan && conan profile detect
- run: npm install
- run: npm run compile
- run: npm run test
- run: npm run test
26 changes: 15 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.3.0 - unreleased

* [#36](https://github.com/afri-bit/vsconan/issues/36) Support the application of Conan's BuildEnv/RunEnv (Conan 2 only)

## 1.2.0 - 2024-08-03

### Added
Expand All @@ -10,18 +14,18 @@

### Added

* [#38](https://github.com/afri-bit/vsconan/issues/38) Support whitespace for project and configuration path
* [#38](https://github.com/afri-bit/vsconan/issues/38) Support whitespace for project and configuration path
You can now use whitespace in your configuration file and *VSConan* can still parse the path and use it for executing conan command.
> Additional to this feature, internal the command builder is changed to separate the command and arguments. For further detail of the issue please refer to [#38](https://github.com/afri-bit/vsconan/issues/38).
> Additional to this feature, internal the command builder is changed to separate the command and arguments. For further detail of the issue please refer to [#38](https://github.com/afri-bit/vsconan/issues/38).
*This change should not affect the current configuration file.*

Thanks to [torsknod-the-caridian](https://github.com/torsknod-the-caridian).

## 1.0.1 - 2024-02-04

### Changed

* [#35](https://github.com/afri-bit/vsconan/issues/35) Extension cannot be activated after installation
* [#35](https://github.com/afri-bit/vsconan/issues/35) Extension cannot be activated after installation
Due to missing dependencies or unability to find the dependencies, the extension cannot be started. So I replaced the small function that I used from this dependency with internal utility function.
> Midnight programming mistake :P
Expand Down Expand Up @@ -58,7 +62,7 @@

Using `vsconan.conan.profile.default` you can switch the profile easily, in case you have multiple conan setup or multiple python virtual environments with different conan versions. `conanUserHome` is optional parameter, in case you want to have a different location for `conan` home folder.

* The workspace configuration to execute conan command, such as `build`, `install`, etc., is slightly changed, but it has a big impact to your workflow / usage of this configuration.
* The workspace configuration to execute conan command, such as `build`, `install`, etc., is slightly changed, but it has a big impact to your workflow / usage of this configuration.
> The `python` attribute is no longer available!

Instead of using hard coded `python` path inside this json file, it will rely on the selected conan configuration profile. So with this change, you can use the same json file but using in the different conan version (Easy switch between conan 1 and 2).
Expand Down Expand Up @@ -163,9 +167,9 @@
## 0.2.0 - 2022-05-30

### Added
* [#10](https://github.com/afri-bit/vsconan/issues/10) Enable option to list dirty packages from a recipe
* [#10](https://github.com/afri-bit/vsconan/issues/10) Enable option to list dirty packages from a recipe
* `vsconan.explorer.treeview.package.showDirtyPackage` is available to set the flag persistent
* [#14](https://github.com/afri-bit/vsconan/issues/14) Support non-pip conan installation
* [#14](https://github.com/afri-bit/vsconan/issues/14) Support non-pip conan installation
* Enable possibility for user to use the extension using alternative conan installation (e.g. conan executable)
* Provide mode switch between python interpreter and conan executable (User can still use the python interpreter to execute conan CLI)
* Configuration for the extension in `settings.json`
Expand All @@ -181,17 +185,17 @@
* Copy editable path to clipboard
* Remove editable package via command and quickpick (simple option)
* Add editable package from the workspace
* Enable layout file input for the editable package
* Enable layout file input for the editable package
**!!!** Currently only supporting the manual input from the user for the layout.


### Changed
* The configuration for extension is migrated to official VS Code `settings.json`. Custom global `config.json` under `~/.vsconan` is now **deprecated**.

### Removed
* `VSConan: Create Global Configuration (JSON)`
* `VSConan: Create Global Configuration (JSON)`
Command to create global configuration file in your home directory
* `VSConan: Open Global Configuration (JSON)`
* `VSConan: Open Global Configuration (JSON)`
Open the global configuration file in editor

## 0.1.0 - 2022-04-21
Expand Down Expand Up @@ -231,4 +235,4 @@
* Create global configuration file
* Open global configuration file
* Create workspace configuration file
* Open workspace configuration file
* Open workspace configuration file
89 changes: 54 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<img src="https://raw.githubusercontent.com/afri-bit/vsconan/main/resources/icon/vsconan-logo.png" width="50%">
</p>

## Introduction
## Introduction

The **VSConan** extension helps you manage the conan local cache on your machine. It gives you easy access to your local cache and allows you to manage it by using integrated explorer in the Visual Studio Code without typing a single line of command in the terminal. **VSConan** provides variety of features, including a quick overview of installed packages, renaming and duplicating profiles, enabling and disabling remotes and more. For more information see [Extension Features](#extension-features).

Expand All @@ -33,7 +33,7 @@ The **VSConan** extension helps you manage the conan local cache on your machine

**VSConan** contributes to official VS Code configurations (`settings.json`), where you can configure the environment to use this extension.
As a starting point you can configure following settings, that are the core settings and provide you a high flexibility to use this extension:
* `vsconan.conan.profile.configurations`
* `vsconan.conan.profile.configurations`
In this section of settings you can store multiple configuration profiles, that contain necessary information to use `conan` from your system. Let's take a look at the following example:
```json
"vsconan.conan.profile.configurations": {
Expand All @@ -53,13 +53,13 @@ As a starting point you can configure following settings, that are the core sett
}
```

In the example above, we defined the `foo` and `bar` profile to start using this extension. Each profile has different configuration for the python interpreter and the conan executable. One thing that we notice here is that we can select the conan version, we want to use, `1` or `2`. This information is crucial for the extension in order to get the correct API.
In the example above, we defined the `foo` and `bar` profile to start using this extension. Each profile has different configuration for the python interpreter and the conan executable. One thing that we notice here is that we can select the conan version, we want to use, `1` or `2`. This information is crucial for the extension in order to get the correct API.

> **NOTE**: Make sure you combine the `conanVersion` and its binary accordingly. Otherwise it will have strange behaviours or things might even not work properly.

Using `conanUserHome` we can overwrite the current conan user home directory. This attribute is optional and has default value of `null`. In the example of `foo`, `conanUserHome` is not defined, which means that the conan user home directory uses the default path or predefined environment variable (See [Environment Variables](https://docs.conan.io/2/reference/environment.html)).
* `vsconan.conan.profile.default`
Using `conanUserHome` we can overwrite the current conan user home directory. This attribute is optional and has default value of `null`. In the example of `foo`, `conanUserHome` is not defined, which means that the conan user home directory uses the default path or predefined environment variable (See [Environment Variables](https://docs.conan.io/2/reference/environment.html)).

* `vsconan.conan.profile.default`
After defining `foo` and `bar` profiles, now it is time for us to choose which configuration we want to use currently.

```json
Expand All @@ -77,18 +77,18 @@ The **VSConan** extension contributes a Conan Explorer view to VS Code. The Cona

#### Conan Recipe

In the Conan Recipe explorer you can have an overview of the installed conan recipe in your local cache.
In the Conan Recipe explorer you can have an overview of the installed conan recipe in your local cache.

![](https://raw.githubusercontent.com/afri-bit/vsconan/main/resources/img/conan_recipe_treeview.png)

As you can see in the picture above, there are several inline options on each item in the treeview.
* _Information_
Open a web view in VS Code editor, that contains information about this selected recipe. Currently the web view only shows a plain JSON text, that is obtained from the Conan CLI.
* _Open in Explorer_
* _Information_
Open a web view in VS Code editor, that contains information about this selected recipe. Currently the web view only shows a plain JSON text, that is obtained from the Conan CLI.
* _Open in Explorer_
Open the the recipe path in the explorer
* _Open in VS Code_
* _Open in VS Code_
Open the selected recipe in a new VS Code window
* _Remove_
* _Remove_
Remove the selected recipe
#### Conan Binary Package

Expand All @@ -97,11 +97,11 @@ By selecting the recipe, the corresponded binary packages will be shown in this
![](https://raw.githubusercontent.com/afri-bit/vsconan/main/resources/img/conan_package_treeview.png)

Each item of this treeview has following options to offer:
* _Open in Explorer_
* _Open in Explorer_
Open the selected binary package in the explorer
* _Open in VS Code_
* _Open in VS Code_
Open the selected binary package in a new VS Code window
* _Remove_
* _Remove_
Remove the selected binary package

#### Conan Profile
Expand All @@ -111,43 +111,43 @@ All the profiles that you saved on your machine will be listed in this explorer.
![](https://raw.githubusercontent.com/afri-bit/vsconan/main/resources/img/conan_profile_treeview.png)

As the other treeviews, each item of this treeview contains several functionalities:
* _Edit_
* _Edit_
Open the selected profile in the VS Code editor
* _Open in Explorer_
* _Open in Explorer_
Open the selected profile in the file explorer
* _Rename_
* _Rename_
Rename the selected profile
* _Duplicate_
* _Duplicate_
If you want to change a small detail from a certain profile but you do not want to lose the original profile, we provide you this duplicate option to fulfill your purpose.
* _Remove_
* _Remove_
Remove the selected profile

#### Conan Remote

Finally we come to the last part of this explorer, which is the explorer of the conan remote.
Finally we come to the last part of this explorer, which is the explorer of the conan remote.
The explorer itself provides you following options:
* _Edit_
* _Edit_
Since the collection of remotes in conan is defined in one file called `remotes.json`, this option is not available of each remote item in the treeview. This will open `remotes.json` file in the VS Code editor instead.
* _Add_
* _Add_
Add a new remote

![](https://raw.githubusercontent.com/afri-bit/vsconan/main/resources/img/conan_remote_treeview.png)

As other treeview, each item is equipped with several options, that you can use to maintain your remotes.
* _Rename Remote_
* _Rename Remote_
Rename the selected remote
* _Update URL_
* _Update URL_
Modify the URL in the selected remote
* _Enable Remote_
Enable the selected remote. Enabled remotes can be seen from the icon next to the remote name. The remote `conancenter` in the picture above is enabled.
* _Disable Remote_
Disable the selected remote. Disabled remotes can be seen from the icon next to the remote name. The remote `anyOtherRemote` in the picture above is disabled.
* _Remove Remote_
* _Enable Remote_
Enable the selected remote. Enabled remotes can be seen from the icon next to the remote name. The remote `conancenter` in the picture above is enabled.
* _Disable Remote_
Disable the selected remote. Disabled remotes can be seen from the icon next to the remote name. The remote `anyOtherRemote` in the picture above is disabled.
* _Remove Remote_
Remove the selected remote

### Conan Workspace

The Conan Workspace feature provides you configuration file, that can be used to execute predefined conan flow command and its arguments. The configuration will be stored under `.vsconan` folder in your workspace.
The Conan Workspace feature provides you configuration file, that can be used to execute predefined conan flow command and its arguments. The configuration will be stored under `.vsconan` folder in your workspace.
If you work a lot with conan and use VS Code as your IDE, this feature can be really beneficial for you. It can spare you some seconds by avoiding to type same command, maybe with different arguments in your terminal over and over again. Instead you can save the command that you want to execute in the configuration and reuse in the next execution. In addition to that, the configuration file is reusable, and can be distributed to other people, if you work in a team.

![Recording of VSConan Workspace](https://raw.githubusercontent.com/afri-bit/vsconan/main/resources/img/demo_workspace.gif)
Expand All @@ -156,7 +156,7 @@ If you work a lot with conan and use VS Code as your IDE, this feature can be re

![](https://raw.githubusercontent.com/afri-bit/vsconan/main/resources/img/prompt_conan_project.png)

If you choose yes, **VSConan** will generate a default configuration file in your workspace to start with.
If you choose yes, **VSConan** will generate a default configuration file in your workspace to start with.
If you want to configure your workspace manually, we also provide you possibility to create a default configuration file using VS Code command `VSConan: Create Workspace Configuration (JSON)`.

Currently supported conan command for configuration file:
Expand All @@ -169,7 +169,7 @@ Currently supported conan command for configuration file:

> The execution of the conan command will be done by the interpreter / conan executable from the profile that you selected. This configuration can be used for Conan version 1 and 2.

The default configuration file can be seen as following. You can extend the list of each command to have different name, description, user, channel and many other details.
The default configuration file can be seen as following. You can extend the list of each command to have different name, description, user, channel and many other details.

```json
{
Expand Down Expand Up @@ -257,11 +257,30 @@ The default configuration file can be seen as following. You can extend the list
}
```

#### Application of Conan's buildEnv/runEnv (currently Conan 2 only)

VSConan provides the commands

* `VSConan: Activate BuildEnv`
* `VSConan: Activate RunEnv`
* `VSConan: Deactivate BuildEnv/RunEnv`

to adjust VSCode's process and terminal environment to the respective Conan environment.

This is useful if you have tool dependencies in your Conanfile, e.g. CMake, a specific Compiler toolchain, etc and want to use these tools also in VSCode, e.g. the [CMake Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools).

##### A note if using the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) in parallel

The [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) overrides the `PATH` environment variable to add the currently selected Python interpreter.
In order to use `PATH` modifications by Conan BuildEnv/RunEnv the VSConan extension provides the option to generate a `.env`-file which is respected by the Python extension.

This option is enabled by default and can be managed by `vsconan.conan.env.dotenv`.

### Additional Support Features

* `VSConan: Create Workspace Configuration (JSON)`
* `VSConan: Create Workspace Configuration (JSON)`
Create workspace configuration file
* `VSConan: Open Workspace Configuration (JSON)`
* `VSConan: Open Workspace Configuration (JSON)`
Open the workspace configuration file in the editor

Further information of current supported features is available [here](doc/FEATURES.md).
Expand Down
7 changes: 4 additions & 3 deletions doc/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Remove recipe from local cache
* Remove editable package recipe from editable mode
* Filter list of recipe based on a remote

### Conan - Package
* Show list of binary packages from a recipe
* Open in Explorer
Expand All @@ -41,7 +41,7 @@
* Edit profile in VS Code editor
* Open in Explorer
* Rename profile
* Duplicate profile
* Duplicate profile
* Remove profile

### Conan - Remote
Expand All @@ -63,6 +63,7 @@
* Add editable package
* Remove editable package
* Automatic selection of Python interpreter using the ms-python.python extension
* Application of Conan's buildEnv/runEnv

## General
* Define multiple conan profiles inside `settings.json` that you can use for the extension.
Expand All @@ -87,4 +88,4 @@
}
```
* Overwrite conan home folder inside the profile with `conanUserHome`
* Status bar to ease the switching between your predefined profiles
* Status bar to ease the switching between your predefined profiles
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vsconan",
"displayName": "VSConan",
"description": "Conan local cache and workspace manager.",
"version": "1.2.0",
"version": "1.3.0",
"publisher": "afri-bit",
"repository": {
"type": "git",
Expand Down Expand Up @@ -122,6 +122,18 @@
"command": "vsconan.conan.profile.switch",
"title": "VSConan: Switch Conan Profile"
},
{
"command": "vsconan.conan.buildenv",
"title": "VSConan: Activate BuildEnv"
},
{
"command": "vsconan.conan.runenv",
"title": "VSConan: Activate RunEnv"
},
{
"command": "vsconan.conan.deactivateenv",
"title": "VSConan: Deactivate BuildEnv/RunEnv"
},
{
"command": "vsconan.config.workspace.create",
"title": "VSConan: Create Workspace Configuration (JSON)"
Expand Down Expand Up @@ -786,6 +798,11 @@
"type": "string",
"default": "default",
"markdownDescription": "Conan profile default / selection"
},
"vsconan.conan.env.dotenv": {
"markdownDescription": "Manage `.env` file when activating Conan environments using `vsconan.conan.buildenv` or `vsconan.conan.runenv`. This is required if `ms-python.python` extension manages your terminal environment.",
"type": "boolean",
"default": true
}
}
},
Expand Down
Loading

0 comments on commit a60d210

Please sign in to comment.