Skip to content

Conversation

rrama
Copy link
Contributor

@rrama rrama commented Aug 19, 2025

Previously we were not using the PATH from the user's shell (or Bash), now we will use both.
Plus, refactored to split the functions for shell environment loading and config file loading.
Plus, allowlisted the Homebrew version of Bash.
If JAVA_HOME and/or GOROOT are set in the project env files then we will prepend ${value}/bin to the PATH.

Note, to be merged along with snyk/snyk-ls#969

rrama added 4 commits August 19, 2025 11:12
Previosuly we were not using the PATH from the user's shell (or Bash), now we will use both.
Plus, refactored to split the functions for shell environment loading and config file loading.
Plus, allowlisted the Homebrew version of Bash.
If JAVA_HOME and/or GOROOT are set in the project env files then we will preppend `${value}/bin` to the PATH.
Previously it was being left unset.
Copy link

snyk-io bot commented Aug 19, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

code/snyk check is complete. No issues have been found. (View Details)

Copy link

snyk-io bot commented Aug 19, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

code/snyk check is complete. No issues have been found. (View Details)

@rrama rrama marked this pull request as ready for review August 19, 2025 13:17
@rrama rrama requested review from a team as code owners August 19, 2025 13:17
cursor[bot]

This comment was marked as outdated.

bashOutput := getEnvFromShell("bash")

// Prepend the Bash PATH now, as it is low priority
// We use the Bash shell env as well, since the more info scraping the better to help OSS scans
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change the comment to read "We first read the Bash shell env to use as a fallback...." or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better?


// this is applied at the end always, as it does not overwrite existing variables
// We use the Bash shell env as well, since the more info scraping the better to help OSS scans
defer func() { _ = gotenv.Apply(strings.NewReader(bashOutput)) }() //nolint:errcheck // we can't do anything with the error
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The more potential binary paths we can add to the PATH the better, as its more fallback for OSS scans to look for things like java and mvn.
Or were you wanting me to update the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the comment, is it better?

Plus, refactor for clarity.
Comment on lines 42 to 44
if val, ok := bashEnv[PathEnvVarName]; ok {
UpdatePath(val, false)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: this could be moved into the deferred function

Comment on lines 69 to 75
sdkVarNames := []string{"JAVA_HOME", "GOROOT"}
sdkValues := make(map[string]string)
for _, sdkVar := range sdkVarNames {
sdkValues[sdkVar] = os.Getenv(sdkVar)
// Unset the env var so we can capture if the config file sets it.
_ = os.Unsetenv(sdkVar)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a few more, but we can cover that later. E.g. PYTHONPATH, GRADLE_HOME, MVN_HOME etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like that we unset them. This can affect other threads/goroutines in process space.

rrama added 2 commits August 21, 2025 14:48
The preference is that the envvars funcs should just return maps of read environments instead of actually setting the environment variables in the process.
Made the maps utils exported.
Useful for calling environments
@rrama
Copy link
Contributor Author

rrama commented Aug 21, 2025

I'm going to draft this and put it on hold as it is getting out of hand and we are too close to release to be dealing with it. Instead I have opened #411 for just the bare minimum of changes we need for now.

@rrama rrama marked this pull request as draft August 21, 2025 16:02
@rrama rrama changed the title fix: better env loading [IDE-1314] WIP fix: better env loading [IDE-1314] Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants