-
-
Notifications
You must be signed in to change notification settings - Fork 150
Fix failure to execute tool post-install script on Windows #897
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
Conversation
Background ---------- Tool Dependency Installation ---------------------------- "Arduino Create Agent" performs installation and updates of the tool dependencies required for direct communication between the local machine and the target board. It might be necessary to execute some sort of installation process in addition to placing the files from the tool archive on the user's hard drive. This capability is provided by a "post-install script" system. If a post-install script file (`post_install.bat` on Windows, `post_install.sh` other host operating systems) is found in the tool installation, "Arduino Create Agent" automatically executes it as part of the tool installation operation. One of the tool dependencies is `arduino:windows-drivers`, which provides the Windows device drivers for the official Arduino boards. This tool contains a post-install script that installs the drivers from the tool archive. It is essential for this script to be executed as the presence of the driver files alone doesn't have any effect. Go `exec` Package ----------------- From the Go 1.19 release, the behavior of the `exec` package was changed to make it more secure: https://pkg.go.dev/os/exec#hdr-Executables_in_the_current_directory > as of Go 1.19, this package will not resolve a program using an implicit or explicit path entry relative to the > current directory. That is, if you run exec.LookPath("go"), it will not successfully return ./go on Unix nor .\go.exe > on Windows, no matter how the path is configured. Instead, if the usual path algorithms would result in that answer, > these functions return an error err satisfying errors.Is(err, ErrDot). Problem ------- The code that executes the post-install script on Windows depended on the previous behavior of the `exec` package. Ever since the version of Go used to build "Arduino Create Agent" was updated to 1.19, the script has not been executed: ``` { "DownloadStatus": "Error", "Msg": "exec: \"post_install.bat\": cannot run executable found relative to current directory" } ``` This means "Arduino Create Agent" never installed the drivers from the `arduino:windows-drivers` tool on the machines who weren't using it before the 1.3.0 release. The failure to execute the post-install script results in **Arduino Create Agent** attempting installation of the `arduino:windows-drivers` tool on every Arduino Cloud session. Even if the user is not impacted by the lack of drivers (either because it is not required for their board, or because they installed the drivers via some other mechanism), they will still be annoyed and confused by the frequent appearance of the "**Installing drivers**" dialog that is produced by **Arduino Create Agent**'s post-install script execution code.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #897 +/- ##
==========================================
- Coverage 20.93% 20.91% -0.02%
==========================================
Files 43 43
Lines 3153 3160 +7
==========================================
+ Hits 660 661 +1
- Misses 2397 2403 +6
Partials 96 96
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Great! Thanks Per
Background
Tool Dependency Installation
Arduino Create Agent performs installation and updates of the tool dependencies required for direct communication between the local machine and the target board.
It might be necessary to execute some sort of installation process in addition to placing the files from the tool archive on the user's hard drive. This capability is provided by a "post-install script" system. If a post-install script file (
post_install.bat
on Windows,post_install.sh
other host operating systems) is found in the tool installation, Arduino Create Agent automatically executes it as part of the tool installation operation.One of the tool dependencies is
arduino:windows-drivers
, which provides the Windows device drivers for the official Arduino boards. This tool contains a post-install script that installs the drivers from the tool archive. It is essential for this script to be executed as the presence of the driver files alone doesn't have any effect.Go
exec
PackageFrom the Go 1.19 release, the behavior of the
exec
package was changed to make it more secure:https://pkg.go.dev/os/exec#hdr-Executables_in_the_current_directory
Problem
The code that executes the post-install script on Windows depended on the previous permissive behavior of the
exec
package. Ever since the version of Go used to build Arduino Create Agent was updated to 1.19 (#744), the script has not been executed.This means Arduino Create Agent never installed the drivers from the
arduino:windows-drivers
tool on the machines who weren't using it before the 1.3.0 release.The failure to execute the post-install script results in Arduino Create Agent attempting installation of the
arduino:windows-drivers
tool on every Arduino Cloud session. Even if the user is not impacted by the lack of drivers (either because it is not required for their board, or because they installed the drivers via some other mechanism), they will still be annoyed and confused by the frequent appearance of the "Installing drivers" dialog that is produced by Arduino Create Agent's post-install script execution code.Demonstration
arduino:windows-drivers
tool even if you already have the latest version installed.🐛 Arduino Create Agent does not execute the
post_install.bat
batch file. You can see the cause in the Arduino Create Agent debug console:Additional Context
I planned to add test coverage for
github.com/arduino/arduino-create-agent/tools.Tools.installDrivers
in order to avoid another such regression in the future. However, this is challenging to do for Windows due to the "Installing drivers" dialog. It seems it would be necessary to mockgithub.com/arduino/arduino-create-agent/tools.MessageBox
, which would require selecting a mocking framework for the project.I chose the approach that followed the system previously established in the code. A more elegant solution would be possible through the use of the the
github.com/arduino/go-paths-helper
module, which is already used elsewhere in the project. However, I feel that should be done as part of comprehensive migration to using the module for all path-related operations, which is out of scope for this PR.I didn't have time to investigate it, but it is possible this will fix #856.
Originally reported at: