Skip to content

[hooks_runner] Enforce absolute paths for executables in runProcess - #3480

Merged
dcharkes merged 6 commits into
dart-lang:mainfrom
jakobkordez:fix/relative-runProcess
Jul 22, 2026
Merged

[hooks_runner] Enforce absolute paths for executables in runProcess#3480
dcharkes merged 6 commits into
dart-lang:mainfrom
jakobkordez:fix/relative-runProcess

Conversation

@jakobkordez

Copy link
Copy Markdown
Contributor

@dcharkes

Description

Fix running a relative executable path with a workingDirectory on Windows

Related Issues

PR Checklist

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
  • I've run dart tool/ci.dart --all locally and resolved all issues identified. This ensures the PR is formatted, has no lint errors, and ran all code generators. This applies to the packages part of the toplevel pubspec.yaml workspace.
  • All existing and new tests are passing. I added new tests to check the change I am making.
  • The PR is actually solving the issue. PRs that don't solve the issue will be closed. Please be respectful of the maintainers' time. If it's not clear what the issue is, feel free to ask questions on the GitHub issue before submitting a PR.
  • I have updated CHANGELOG.md for the relevant packages. (Not needed for small changes such as doc typos).
  • I have updated the pubspec package version if necessary.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Health

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
hooks_runner None 1.6.1 1.6.2-wip 1.6.2-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

@dcharkes dcharkes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the quick response @jakobkordez! 🙏

required Uri? workingDirectory,
}) {
final executablePath = executable.toFilePath();
if (workingDirectory == null) return executablePath;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also early return if platform is not Windows?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So basically we cannot do the right thing if (1) the path has spaces, (2) the path is relying on PATHEXT, and (3) we're trying to run with a relative path.

Do I understand this correctly?

I think that's probably fine, I think users relying on PATHEXT is a bad idea anyways.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Within hooks_runner, I think we should only be running absolute paths and not relying on PATH EXT. And if we do, we should fix that.

Within dartdev tests we were running tests that explicitly test PATH EXT and relative paths. And not paths with spaces.

I think it's probably the wrong thing to try to share the implementation if we can't make the implementation universally doing the right thing. So, I'm looking at stopping to rely on this internal lib/src/ function in those tests. https://dart-review.googlesource.com/c/sdk/+/525220

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

And we may also remove that TODO to share it between packages. Maybe the needs inside native_toolchain_c differ again from the needs in hooks_runner

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do I understand this correctly?

Yes

I think it's probably the wrong thing to try to share the implementation

I agree

I think the function should be simplified - revert #3472 and not merge this PR. Let me know how you want me to proceed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay maybe the best way is to indeed revert it. And add a bunch of checks that throw exceptions if (1) the path is not absolute, and (2) doesn't end with an executable with a file extension. And then update the documentation to say that the function supports spaces in executable and does not support relative paths and PATHEXT.

We just need to check that we don't have any tests in package hooks_runner that try to use it.

The package itself should work with absolute paths and no path-ext because we only (1) invoke the Dart compiler and (2) invoke the kernel-files that contain the hook code. Those should work with the absolute Dart path that's passed in. final Uri dartExecutable; And we should also check that that's absolute in the constructor.

I think that's the cleanest approach. WDYT?

I've already landed https://dart-review.googlesource.com/c/sdk/+/525220, so if the CI is green here on GitHub, it should not go red again on the Dart CI.

(Helicopter view: Too much code sharing is bad, because you get too many conflicting requirements and non-local code breakages. You live you learn!)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Do you want a new PR or do I just continue in this one: make two git reverts and proceed with the other changes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Either approach is fine 👍

@jakobkordez
jakobkordez requested a review from dcharkes July 21, 2026 16:57
Comment thread pkgs/hooks_runner/lib/src/build_runner/build_runner.dart Outdated
@dcharkes

Copy link
Copy Markdown
Collaborator

Maybe the PR title needs to be updated as well (squash on merge will take the PR title as commit message).

@jakobkordez jakobkordez changed the title [hooks_runner] Fix relative path executables in runProcess for Windows [hooks_runner] Enforce absolute paths for executables in runProcess Jul 21, 2026
@dcharkes
dcharkes merged commit 88c353f into dart-lang:main Jul 22, 2026
33 of 35 checks passed
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.

2 participants