Skip to content

Normalize expected path for chdir tests #4677

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

QuLogic
Copy link
Contributor

@QuLogic QuLogic commented Dec 31, 2024

The expected path comes from a simple string concatenation in shell, but os.Getwd appears to have the normalized working directory, so this can fail if any parent directory is a symlink.

The expected path comes from a simple string concatenation in shell, but
`os.Getwd` appears to have the normalized working directory, so this can
fail if any parent directory is a symlink.
Copy link
Contributor

@leongross leongross left a comment

Choose a reason for hiding this comment

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

Where/how did you observe this bug? Can you give an example of how to reproduce that?

@QuLogic
Copy link
Contributor Author

QuLogic commented Jul 20, 2025

For compatibility with non-module mode, we create a weird symlink in the equivalent directory path like this:

<mock-chroot> sh-5.3# pwd
/builddir/build/BUILD/tinygo-0.38.0-build/tinygo-0.38.0

<mock-chroot> sh-5.3# ls -lR _build
_build:
total 0
drwxr-xr-x. 1 mockbuild mock 20 Jul 20 15:20 src
_build/src:
total 0
drwxr-xr-x. 1 mockbuild mock 20 Jul 20 15:20 github.com
_build/src/github.com:
total 0
drwxr-xr-x. 1 mockbuild mock 12 Jul 20 15:20 tinygo-org
_build/src/github.com/tinygo-org:
total 4
lrwxrwxrwx. 1 mockbuild mock 55 Jul 20 15:20 tinygo -> /builddir/build/BUILD/tinygo-0.38.0-build/tinygo-0.38.0

That is, the tarball is extracted, and then _build/src/github.com/tinygo-org/tinygo in that same directory points back to it.

So when the smoke test runs, it errors like this:

+ cd _build/src/github.com/tinygo-org/tinygo
+ GOPATH=/builddir/build/BUILD/tinygo-0.38.0-build/tinygo-0.38.0/_build:/builddir/build/BUILD/tinygo-0.38.0-build/BUILDROOT/usr/lib64/tinygo:/usr/share/gocode
+ make smoketest STM32=0 XTENSA=0
# test 'build' command with{,out} -C argument
/builddir/build/BUILD/tinygo-0.38.0-build/BUILDROOT/usr/bin/tinygo build -C tests/testing/chdir chdir.go && rm tests/testing/chdir/chdir
/builddir/build/BUILD/tinygo-0.38.0-build/BUILDROOT/usr/bin/tinygo build ./tests/testing/chdir/chdir.go && rm chdir
# test 'run' command with{,out} -C argument
EXPECT_DIR=/builddir/build/BUILD/tinygo-0.38.0-build/tinygo-0.38.0/_build/src/github.com/tinygo-org/tinygo/tests/testing/chdir /builddir/build/BUILD/tinygo-0.38.0-build/BUILDROOT/usr/bin/tinygo run -C tests/testing/chdir chdir.go
2025/07/20 15:31:39 expected:"/builddir/build/BUILD/tinygo-0.38.0-build/tinygo-0.38.0/_build/src/github.com/tinygo-org/tinygo/tests/testing/chdir" != os.Getwd():"/builddir/build/BUILD/tinygo-0.38.0-build/tinygo-0.38.0/tests/testing/chdir"
failed to run compiled binary /tmp/tinygo295843607/main: exit status 1
make: *** [GNUmakefile:538: testchdir] Error 1

The EXPECT_DIR is generated by the Makefile with $(PWD), which is just the current directory of the shell, with no normalization performed. The docs for os.Getwd are not too specific, but they do say they return the absolute path. Since it is a wrapper for the getcwd call, those docs do state that "The pathname copied to the array shall contain no components that are symbolic links."

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.

None yet

2 participants