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

[VSC-1573] ensure build directories exist and resolve relative paths #1417

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

radurentea
Copy link
Collaborator

@radurentea radurentea commented Jan 30, 2025

Description

Fixed an issue where relative paths in project configurations were not being handled correctly and build directories were not being created automatically. The extension now properly resolves relative paths to absolute using the workspace folder as the base and ensures build directories exist before build commands are executed.

Fixes #1408
Fixes #1430

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Steps to test this pull request

  1. Create a project using example project "multi_config" in esp_idf_project_configuration.json use relative paths for "buildDirectoryPath" property
{
  "prod1": {
    "build": {
      "compileArgs": [],
      "ninjaArgs": [],
      "buildDirectoryPath": "build.prod1",
      "sdkconfigDefaults": [
        "sdkconfig.prod_common",
        "sdkconfig.prod1"
      ],
      "sdkconfigFilePath": ""
    },
    "env": {},
    "flashBaudRate": "",
    "monitorBaudRate": "",
    "openOCD": {
      "debugLevel": 0,
      "configs": [],
      "args": []
    },
    "tasks": {
      "preBuild": "",
      "preFlash": "",
      "postBuild": "",
      "postFlash": ""
    }
  },
  "prod2": {
    "build": {
      "compileArgs": [],
      "ninjaArgs": [],
      "buildDirectoryPath": "build.prod2",
      "sdkconfigDefaults": [
        "sdkconfig.prod_common",
        "sdkconfig.prod2"
      ],
      "sdkconfigFilePath": ""
    },
    "env": {},
    "flashBaudRate": "",
    "monitorBaudRate": "",
    "openOCD": {
      "debugLevel": 0,
      "configs": [],
      "args": []
    },
    "tasks": {
      "preBuild": "",
      "preFlash": "",
      "postBuild": "",
      "postFlash": ""
    }
  }
}
  1. Select either configuration from the ESP-IDF Project Configuration panel
  2. Try to build the project

Expected behaviour:

  • Build directories should be created automatically if they don't exist
  • Build should succeed using the correct paths
  • No errors about missing directories or invalid paths should occur

How has this been tested?

As described above

Test Configuration:

  • ESP-IDF Version: 5.4
  • OS (Windows,Linux and macOS): Windows 11

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Added Unit Test
  • Verified on all platforms - Windows,Linux and macOS

- Replace forEach with Promise.all for proper async handling
- Automatically create build directories using ensureDir
- Convert relative paths to absolute using workspace folder as base
- Refactor build config access for better readability
@radurentea radurentea self-assigned this Jan 30, 2025
Copy link

github-actions bot commented Jan 30, 2025

Download the artifacts for this pull request:
You can test these changes by installing this VSIX by click menu View -> Command Palette..., type Install from VSIX and then select downloaded esp-idf-extension.vsix file to install the extension.

Copy link
Collaborator

@brianignacio5 brianignacio5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we validate that the given path string be validated to separate and support both relative and absolute paths.

commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
);
if (projectConfExists) {
if (!projectConf) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

projectConf doesn't mean is an error. Means the user has not selected a profile at the moment. Even if ESP.ProjectConfiguration.PROJECT_CONFIGURATION_FILENAME exists.

compileArgs: buildConfig?.compileArgs,
ninjaArgs: buildConfig?.ninjaArgs,
buildDirectoryPath: buildDirPath,
sdkconfigDefaults: (await resolveConfigPaths(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Await is not needed if function is not asynchronous

@brianignacio5 brianignacio5 added the bugfix Fixing some issue and bug in this PR label Mar 6, 2025
@brianignacio5
Copy link
Collaborator

brianignacio5 commented Mar 7, 2025

I've tested this PR with this example config-test project but the build directory resolution is wrong.

Generated build directory is /Users/brainignacio/Downloads/config-test/Users/brainignacio/Downloads/config-test/build_v1 from "buildDirectoryPath": "${workspaceFolder}\\build_v1", in esp_idf_project_configuration.json.

Also if I set the path "buildDirectoryPath": "/Users/brainignacio/Downloads/config-test/build_v1" the resulting build path is still /Users/brainignacio/Downloads/config-test/Users/brainignacio/Downloads/config-test/build_v1

@brianignacio5
Copy link
Collaborator

Project Configuration Editor related bug:

When esp_idf_project_configuration.json is modified, the currently selected profile (which exists in vscode workspace state) is not updated. We need a file watcher for this file to see if it is modified and reload the selected profile. (vscode has file watcher api check sdkconfig file watcher in code, and extension command select current profile function to copy code for reload selected profile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixing some issue and bug in this PR
Projects
None yet
2 participants