-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
[BUG FIX] Fix path resolution for executables #328
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,24 @@ fun computeWorkingDir(nodeProjectDir: DirectoryProperty, execConfiguration: Exec | |
return workingDir | ||
} | ||
|
||
/** | ||
* Helper function to find the best matching executable in the system PATH. | ||
* | ||
* @param executableName The name of the executable to search for. | ||
* @return The best matching executable path as a String. | ||
*/ | ||
fun findBestExecutableMatch(executableName: String): String { | ||
val pathVariable = System.getenv("PATH") ?: return executableName | ||
val paths = pathVariable.split(File.pathSeparator) | ||
for (path in paths) { | ||
val executableFile = File(path, executableName) | ||
if (executableFile.exists() && executableFile.canExecute()) { | ||
return executableFile.absolutePath | ||
} | ||
} | ||
return executableName // Return the original executable if no match is found | ||
} | ||
|
||
/** | ||
* Basic execution runner that runs a given ExecConfiguration. | ||
* | ||
|
@@ -43,8 +61,9 @@ fun computeWorkingDir(nodeProjectDir: DirectoryProperty, execConfiguration: Exec | |
*/ | ||
class ExecRunner { | ||
fun execute(projectHelper: ProjectApiHelper, extension: NodeExtension, execConfiguration: ExecConfiguration): ExecResult { | ||
val executablePath = findBestExecutableMatch(execConfiguration.executable) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a quick glance it looks like this will break the download functionality entirely by only using already installed applications There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will address these points. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with tests to validate behaviour (w/ download and without download) |
||
return projectHelper.exec { | ||
executable = execConfiguration.executable | ||
executable = executablePath | ||
args = execConfiguration.args | ||
environment = computeEnvironment(execConfiguration) | ||
isIgnoreExitValue = execConfiguration.ignoreExitValue | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iirc this won't work on windows where environment variables are case-insensitive (and default to
Path
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy to fix, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.