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

IEP-1395: Removing system env vars from IDE while executing scripts #1110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alirana01
Copy link
Collaborator

@alirana01 alirana01 commented Jan 8, 2025

Description

The original bug reported here #1105

Fixes # (IEP-1395)

Type of change

Please delete options that are not relevant.

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

How has this been tested?

Please try to put the system env vars in windows as mentioned on original reported issues and then try to install tools to test if they are getting installed with correct path in the IDE.

Test Configuration:

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

Checklist

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

Summary by CodeRabbit

  • Logging Improvements

    • Enhanced logging in tools installation process to capture more detailed status messages
  • Environment Configuration

    • Refined environment variable management for IDF tools
    • Updated Git executable path handling in command execution environment

@alirana01 alirana01 self-assigned this Jan 8, 2025
Copy link

coderabbitai bot commented Jan 8, 2025

Walkthrough

The pull request introduces logging enhancements and environment variable management modifications in the Espressif IDF UI plugin. The changes focus on improving logging in the ToolsInstallationJob class by adding a status message log and refining environment variable handling in the ToolsJob class. The modifications aim to provide better visibility into tool installation processes and streamline environment configuration for IDF-related commands.

Changes

File Change Summary
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationJob.java Added a new logging statement to capture the status message from the tools export operation
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java - Removed specific environment variables from environment map
- Modified addPathToEnvironmentPath to conditionally append Git executable path
- Added a new line at the end of the file

Possibly related PRs

Suggested reviewers

  • kolipakakondal
  • AndriiFilippov
  • sigmaaa

Poem

🐰 In the realm of code, a rabbit's delight,
Logs shine brighter, environment set just right
Variables trimmed, paths carefully placed
IDF tools dancing with newfound grace
A commit of wisdom, clean and so neat! 🛠️


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java (1)

Line range hint 407-427: Consider extracting PATH environment variable handling into a helper method.

The logic for checking and handling PATH/Path environment variables is duplicated in addPathToEnvironmentPath and loadIdfPathWithSystemPath methods. Consider extracting this into a helper method to improve maintainability.

Here's a suggested refactor:

+ private String getSystemPath(Map<String, String> environment) {
+     String pathVar = "PATH";
+     String pathEntry = environment.get(pathVar);
+     if (pathEntry == null) {
+         pathVar = "Path";
+         pathEntry = environment.get(pathVar);
+         if (pathEntry == null) {
+             Logger.log(new Exception("No PATH found in the system environment variables"));
+         }
+     }
+     return pathEntry;
+ }
+
+ private void updateSystemPath(Map<String, String> environment, String newPath) {
+     if (environment.containsKey("PATH")) {
+         environment.put("PATH", newPath);
+     } else {
+         environment.put("Path", newPath);
+     }
+ }

  private void addPathToEnvironmentPath(Map<String, String> environment, String gitExecutablePath) {
      IPath gitPath = new org.eclipse.core.runtime.Path(gitExecutablePath);
      if (gitPath.toFile().exists()) {
          String gitDir = gitPath.removeLastSegments(1).toOSString();
-         String path1 = environment.get("PATH");
-         String path2 = environment.get("Path");
-         if (!StringUtil.isEmpty(path1) && !path1.contains(gitDir)) {
-             path1 = gitDir.concat(";").concat(path1);
-             environment.put("PATH", path1);
-         } else if (!StringUtil.isEmpty(path2) && !path2.contains(gitDir)) {
-             path2 = gitDir.concat(";").concat(path2);
-             environment.put("Path", path2);
-         }
+         String path = getSystemPath(environment);
+         if (!StringUtil.isEmpty(path) && !path.contains(gitDir)) {
+             updateSystemPath(environment, gitDir.concat(";").concat(path));
+         }
      }
  }

Also applies to: 436-458

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationJob.java (1)

78-79: LGTM! Consider adding null check and log level.

The added logging enhances visibility into the tools export process, which aligns well with debugging environment variable issues. Consider these minor improvements:

-		Logger.log(status.getMessage());
+		if (status.getMessage() != null) {
+			Logger.log(Logger.INFO, status.getMessage());
+		}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fc3ab91 and d705b02.

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

407-407: LGTM!

The added newline improves code readability.


352-355: Verify the removal of IDF_PATH environment variable.

While removing IDE-specific environment variables aligns with the bug fix, the removal of IDF_PATH needs verification as it's essential for ESP-IDF tools to locate the framework.

Run this script to check if IDF_PATH is properly set elsewhere:

✅ Verification successful

IDF_PATH removal is safe and intentional

The removal of IDF_PATH from the execution environment is part of a deliberate cleanup pattern. The variable is preserved in the build environment and idfToolSet, and is only temporarily removed to ensure a clean execution environment for IDF Python commands.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if IDF_PATH is set in other locations
# Look for IDF_PATH assignments in Java files
rg -A 3 "IDF_PATH|idfPath" --type java

# Look for environment variable setup in Python scripts
fd -e py -x rg -A 3 "IDF_PATH|idf_path" {}

Length of output: 66522

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationJob.java (1)

78-79: Verify error handling scenarios.

Let's verify that error scenarios are properly logged when environment variables cause issues.

✅ Verification successful

Error handling is properly implemented.

The code demonstrates comprehensive error handling around environment variables and other operations:

  • Status severity checks before proceeding with operations
  • Proper error logging and user feedback through console streams
  • Early returns to prevent cascading issues
  • Exception handling with appropriate logging
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for error handling patterns around environment variables
rg -A 5 "environment|env" --type java

# Look for existing error logging patterns
ast-grep --pattern 'Logger.log($err)'

Length of output: 71426


Script:

#!/bin/bash
# Get the complete file content to understand the context
cat bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationJob.java

# Look for error handling patterns in the same file
rg -A 5 "catch|error|exception|fail" bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationJob.java

# Find the Status class usage
ast-grep --pattern 'new Status($$$)'

Length of output: 26568

Comment on lines +352 to +355
environment.remove(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH);
environment.remove(IDFEnvironmentVariables.ESP_IDF_VERSION);
environment.remove(IDFEnvironmentVariables.IDF_PATH);
environment.remove(IDFEnvironmentVariables.OPENOCD_SCRIPTS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @alirana01,

Do you know why these variables are not replaced with the same ones from the idfToolSet (which, as I understand, should have proper environment variables)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So basically the environment here is taken from System.getEnv() so it loads the system env. The function where the change was done is actually before these variables are even part of the idfToolSet. This function make sures that the correct variables from the idf export script are loaded into the idfToolSet basically it sits before that. Which is the reason we need to make sure that any of these variables from System environment are not loaded here

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.

Unable to install ESP-IDF 5.3.2 via ESP-IDF Manager in Elclipse (IEP-1395)
2 participants