Confused about the `Bundle.main.bundlePath` when creating a SPM executable

I wrote a Swift command line tool using SPM's executable type. Bundle.main.bundlePath always returns the built binary file's directory path during development stage (debug build).

Then, I release built the binary to foo/my-binary, and added a symbolic link at /usr/local/bin/my-binary. Now if I call my binary from an arbitrary location (say ~), Bundle.main.bundlePath actually gives me the path of /usr/local/bin/my-binary.

Is this expected? Is it possible to get foo/my-binary when I call its symbolic link?

/cc @Tony_Parker

The main bundle path should always reflect the actual location on disk; I’m pretty sure we realpath it.

Are you just trying to find the path that you were launched from? Maybe you need the working directory instead?