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

Convert absolute paths used in ci:validate task to Windows format #796

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Oct 16, 2024

The Task task runner tool uses an integrated Bash shell interpreter to allow the use of standard POSIX/Bash syntax and built-in utilities while providing cross-platform support for users who have made the poor choice of the non-standard Windows cmd or PowerShell shells.

While this is a nice feature of Task, distinguishing it from other alternatives, it is still often necessary to use non-built-in utilities. So use of a Bash shell is a requirement to run our tasks even the developers using Windows.

Although high quality Bash shells for Windows such as the Git Bash included as part of the Git for Windows installation generally provide a seamless experience, there is the occasional "gotcha".

Relative paths work the same for POSIX and Windows, but absolute POSIX format paths may not. These paths are handled as expected by Task's integrated shell interpreter and by Bash, but when these paths are used outside that context they may no longer be correct.

For example:

  foo:
    cmds:
      - mkdir "/tmp/posix-path-test-dir"
      - touch "/tmp/posix-path-test-dir/posix-path-test-file"
      - ls "/tmp/posix-path-test-dir"
      - cd "/tmp/posix-path-test-dir"

The first three commands work as expected, but the cd command fails:

$ task foo
task: [foo] mkdir "/tmp/posix-path-test-dir"
task: [foo] touch "/tmp/posix-path-test-dir/posix-path-test-file"
task: [foo] ls "/tmp/posix-path-test-dir"
posix-path-test-file
task: [foo] cd "/tmp/posix-path-test-dir"
task: Failed to run task "foo": exit status 1

The POSIX format /tmp is actually set to the system temporary directory:

$ cygpath -w "/tmp/posix-path-test-dir"
C:\Users\per\AppData\Local\Temp\posix-path-test-dir

But if treated as a Windows format path, this would be the tmp subfolder of the root of the current drive (e.g., C:\tmp). Even though the command was run from Git Bash, which provides a cd that handles this absolute path perfectly, when run from Task the Windows native cd is used instead.

This resulted in the ci:validate validation task, which downloads the JSON schema to the temporary folder, to fail when ran on Windows.

The solution is to convert the absolute paths to Windows format (which is handled fine by both the integrated, Bash, and external applications) when the task is ran on a Windows machine. The cygpath utility provides this capability:

$ task foo
task: [foo] mkdir "C:\Users\per\AppData\Local\Temp/posix-path-test-dir"
task: [foo] touch "C:\Users\per\AppData\Local\Temp/posix-path-test-dir/posix-path-test-file"
task: [foo] ls "C:\Users\per\AppData\Local\Temp/posix-path-test-dir"
posix-path-test-file
task: [foo] cd "C:\Users\per\AppData\Local\Temp/posix-path-test-dir"

The Task task runner tool uses an integrated Bash shell interpreter to allow the use of standard POSIX/Bash syntax and
built-in utilities while providing cross-platform support for users who have made the poor choice of the non-standard
Windows cmd or PowerShell shells.

While this is a nice feature of Task, distinguishing it from other alternatives, it is still often necessary to use
non-built-in utilities. So use of a Bash shell is a requirement to run our tasks even the developers using Windows.

Although high quality Bash shells for Windows such as the Git Bash included as part of the Git for Windows installation
generally provide a seamless experience, there is the occasional "gotcha".

Relative paths work the same for POSIX and Windows, but absolute POSIX format paths may not. These paths are handled as
expected by Task's integrated shell interpreter and by Bash, but when these paths are used outside that context they may
no longer be correct.

For example:

```
  foo:
    cmds:
      - mkdir "/tmp/posix-path-test-dir"
      - touch "/tmp/posix-path-test-dir/posix-path-test-file"
      - ls "/tmp/posix-path-test-dir"
      - cd "/tmp/posix-path-test-dir"
```

The first three commands work as expected, but the `cd` command fails:

```
$ task foo
task: [foo] mkdir "/tmp/posix-path-test-dir"
task: [foo] touch "/tmp/posix-path-test-dir/posix-path-test-file"
task: [foo] ls "/tmp/posix-path-test-dir"
posix-path-test-file
task: [foo] cd "/tmp/posix-path-test-dir"
task: Failed to run task "foo": exit status 1
```

The POSIX format `/tmp` is actually set to the system temporary directory:

```
$ cygpath -w "/tmp/posix-path-test-dir"
C:\Users\per\AppData\Local\Temp\posix-path-test-dir
```

But if treated as a Windows format path, this would be the `tmp` subfolder of the root of the current drive (e.g.,
`C:\tmp`). Even though the command was run from Git Bash, which provides a `cd` that handles this absolute path
perfectly, when run from Task the Windows native `cd` is used instead.

This resulted in the `ci:validate` validation task, which downloads the JSON schema to the temporary folder, to fail
when ran on Windows.

The solution is to convert the absolute paths to Windows format (which is handled fine by both the integrated, Bash, and
external applications) when the task is ran on a Windows machine. The cygpath utility provides this capability:

```
$ task foo
task: [foo] mkdir "C:\Users\per\AppData\Local\Temp/posix-path-test-dir"
task: [foo] touch "C:\Users\per\AppData\Local\Temp/posix-path-test-dir/posix-path-test-file"
task: [foo] ls "C:\Users\per\AppData\Local\Temp/posix-path-test-dir"
posix-path-test-file
task: [foo] cd "C:\Users\per\AppData\Local\Temp/posix-path-test-dir"
```
@per1234 per1234 added topic: infrastructure Related to project infrastructure os: windows Specific to Windows operating system type: imperfection Perceived defect in any part of project labels Oct 16, 2024
@per1234 per1234 self-assigned this Oct 16, 2024
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.05%. Comparing base (a74131a) to head (1123c4a).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #796   +/-   ##
=======================================
  Coverage   90.05%   90.05%           
=======================================
  Files          44       44           
  Lines        6800     6800           
=======================================
  Hits         6124     6124           
  Misses        553      553           
  Partials      123      123           
Flag Coverage Δ
unit 90.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@per1234 per1234 merged commit cf59441 into arduino:main Oct 16, 2024
70 checks passed
@per1234 per1234 deleted the ci_validate-windows branch October 16, 2024 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os: windows Specific to Windows operating system topic: infrastructure Related to project infrastructure type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant