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

interp: fix a PATH regression on Windows, fix tests on Wine #769

Merged
merged 2 commits into from
Dec 2, 2021

Conversation

mvdan
Copy link
Owner

@mvdan mvdan commented Dec 1, 2021

(see commit messages - please do not squash)

Fixes #768.

mvdan added 2 commits December 1, 2021 16:45
A recent change added the use of "tr" to improve test portability,
as some commands like "wc" print extra whitespace on Mac.

Some versions of Windows, such as Wine, don't ship with "tr".
Just like we do with other commands like "wc" or "sed",
implement a very basic one as a builtin.
A recent commit, 1eb295c, introduced a regression on Windows.
Programs spawned by interp no longer found other programs in PATH.

The reason turns out to be because those programs saw a Unix-like PATH,
with the list separator being ":" rather than ";",
which breaks Windows programs as they see one single mangled directory.

The actual source of the bug is much older, from eb75bb8f7d:

	For better compatibility with non-unix systems, convert $PATH to a
	unix path list when starting the interpreter. This should work with
	Windows, for example.

The recent commit surfaced the bug by tweaking the environment logic.
Before, converting PATH's list separators was an internal detail,
but now we also export this change and it affects spawned programs.

The added test case fails without the fix:

	--- FAIL: TestRunnerRun/#883 (0.19s)
		interp_test.go:3201: wrong output in "GOSH_CMD=lookpath $GOSH_PROG":
			want: "cmd found\n"
			got:  "exec: \"cmd\": executable file not found in %PATH%\nexit status 1"

The fix is relatively simple: stop converting PATH's list separators.
I believe the reason I originally added that code was for compatibility,
so that scripts using Unix-like path list separator, such as

	export PATH="${PATH}:${PWD}"

would work as expected on Windows.
However, I struggle to agree with my past self on that approach.
We had no tests for this behavior,
and any script using Unix-like paths in any non-trivial way
would likely need to be adjusted to be compatible with Windows anyway.

Fixes #768.
@mvdan
Copy link
Owner Author

mvdan commented Dec 1, 2021

FYI @cclerget @riacataquian @andreynering @glumia

Copy link
Collaborator

@riacataquian riacataquian left a comment

Choose a reason for hiding this comment

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

Some versions of Windows, such as Wine, don't ship with "tr".
Just like we do with other commands like "wc" or "sed",
implement a very basic one as a builtin.

Got it! Thanks!

@cclerget
Copy link
Contributor

cclerget commented Dec 2, 2021

Oops sorry for the inconvenience !

We had no tests for this behavior,
and any script using Unix-like paths in any non-trivial way
would likely need to be adjusted to be compatible with Windows anyway.

Yes, handling PATH specifically breaks consistency with other PATH like variables

@mvdan mvdan merged commit e482fb8 into master Dec 2, 2021
@mvdan mvdan deleted the windows-fixes branch December 17, 2021 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

interp: Regression on $PATH handling on Windows
3 participants