Skip to content

IEP-1471 ESP-IDF Path with whitespaces leads to python error during FLASH#1205

Merged
AndriiFilippov merged 2 commits into
masterfrom
IEP-1471
Apr 23, 2025
Merged

IEP-1471 ESP-IDF Path with whitespaces leads to python error during FLASH#1205
AndriiFilippov merged 2 commits into
masterfrom
IEP-1471

Conversation

@sigmaaa

@sigmaaa sigmaaa commented Apr 22, 2025

Copy link
Copy Markdown
Collaborator

Description

Fixed an issue with flash when esp-idf path contains spaces.

Fixes # (IEP-1471)

Type of change

Please delete options that are not relevant.

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

How has this been tested?

  • Install ESP-IDF to the directory that contains spaces
  • Create a new project
  • build flash using uart
  • build flash using jtag
  • build flash using dfu

Test Configuration:

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

Dependent components impacted by this PR:

  • Launch configuration
  • Flash
  • Dynamic variables

Checklist

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of command-line arguments to better support quoted strings and special characters during flashing operations.
    • Enhanced variable resolution to automatically quote values containing spaces, reducing potential errors in command execution.

@coderabbitai

coderabbitai Bot commented Apr 22, 2025

Copy link
Copy Markdown

Walkthrough

The changes improve the way command-line arguments are parsed and handled across several modules. Instead of splitting command strings by spaces, the code now uses a specialized parsing utility (CommandLineUtil.argumentsToArray) to correctly handle quoted strings and escaped characters. Additionally, variable resolution logic was updated to wrap resolved values containing spaces in quotes, ensuring proper command-line behavior. No public APIs or exported entity signatures were altered.

Changes

File(s) Change Summary
.../idf/core/util/DfuCommandsUtil.java Replaced manual string splitting of command arguments with CommandLineUtil.argumentsToArray for robust parsing.
.../idf/launch/serial/internal/SerialFlashLaunchConfigDelegate.java Switched from splitting arguments by spaces to parsing with CommandLineUtil.argumentsToArray after substitution.
.../idf/launch/serial/ui/IDFDynamicVariableResolver.java Refactored variable resolution to quote values containing spaces; used a local variable for resolved value.
.../idf/launch/serial/ui/BuildFolderVariableResolver.java Added quoting of build folder paths containing spaces before returning the resolved value.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant VariableResolver
    participant CommandBuilder

    User->>VariableResolver: Request variable resolution
    VariableResolver->>VariableResolver: Resolve value
    alt Value contains spaces
        VariableResolver->>VariableResolver: Wrap value in quotes
    end
    VariableResolver-->>User: Return resolved value

    User->>CommandBuilder: Provide command string with variables
    CommandBuilder->>CommandBuilder: Substitute variables
    CommandBuilder->>CommandLineUtil: Parse command string with argumentsToArray
    CommandLineUtil-->>CommandBuilder: Return parsed arguments array
    CommandBuilder-->>User: Use parsed arguments for command execution
Loading

Suggested reviewers

  • alirana01
  • kolipakakondal
  • AndriiFilippov

Poem

In the warren of code where commands used to split,
Now arguments parse with a more careful wit.
Quoted and spaced, no tokens misplaced,
Variables wrapped so nothing’s erased.
With every new hop, our commands run anew—
A rabbit’s delight in a shell that’s true!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8deb3c2 and fdbb1d7.

📒 Files selected for processing (1)
  • bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/BuildFolderVariableResolver.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build_macos
🔇 Additional comments (1)
bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/BuildFolderVariableResolver.java (1)

46-49: Proper handling of paths with spaces by adding quotes

The added code correctly identifies and handles build folder paths containing spaces by wrapping them in double quotes. This addresses the issue where ESP-IDF paths with whitespaces were causing Python errors during the flash process by ensuring command-line arguments are properly parsed.

This change aligns with the PR's objective of fixing issues related to paths with spaces in ESP-IDF projects and supports the related improvements in command-line argument handling across the codebase.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@alirana01 alirana01 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Just a few comments to look at and please see if they need to be addressed @sigmaaa

Comment on lines +49 to +54

// Wrap the resolved value in quotes if it contains spaces or special characters
if (resolvedValue != null && resolvedValue.contains(" ")) //$NON-NLS-1$
{
resolvedValue = "\"" + resolvedValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This generally seems okay we just need to be sure that double quotes work on all platforms. It might be okay because we are running most of these commands through Java not via shell but it should be verified on all platforms note for @AndriiFilippov

@AndriiFilippov

AndriiFilippov commented Apr 22, 2025

Copy link
Copy Markdown
Collaborator

@sigmaaa hi !

Tested under:
OS - Windows 11 / MacOS / Linux
ESP-IDF: v5.4

able to flash if ${BUILD_DIR} wrap in " "
image

without " " -> error:

Usage: idf.py folder [OPTIONS]
Try 'idf.py folder --help' for help.

Error: No such option: -p

@sigmaaa

sigmaaa commented Apr 23, 2025

Copy link
Copy Markdown
Collaborator Author

@sigmaaa hi !

Tested under: OS - Windows 11 / MacOS / Linux ESP-IDF: v5.4

able to flash if ${BUILD_DIR} wrap in " " image

without " " -> error:

Usage: idf.py folder [OPTIONS]
Try 'idf.py folder --help' for help.

Error: No such option: -p

Hi @AndriiFilippov,

Fixed in the last commit, no need for putting quotes manually for the BUILD_DIR variable now

@AndriiFilippov

Copy link
Copy Markdown
Collaborator

@sigmaaa

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants