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

cmd/errtrace: Add toolexec mode for automatic rewriting #90

Merged
merged 14 commits into from
Feb 18, 2024

Conversation

prashantv
Copy link
Contributor

@prashantv prashantv commented Feb 18, 2024

Fixes #17

The go command supports -toolexec to intercept calls to the underlying compile/link tools.
By intercepting compile commands, we can modify the .go files passed to it to rewrite as
part of the build process.

There are some limitations: we can't add new dependencies to a package, so this initial version
only rewrites packages that already import errtrace, acting as an opt-in to rewriting.

We automatically determine if we're in toolexec mode based on the arguments/environment.
This simplifies usage,

# pass -toolexec=errtrace, can use absolute paths if errtrace is not in PATH
$ go build -toolexec=errtrace pkg/to/build

# also compatible with go run, which is used by tests
$ go run -toolexec=errtrace pkg/to/run

Use TOOLEXEC_IMPORTPATH to determine if we're running in toolexec mode.

In toolexec mode, all go tool executions are intercepted, though only
compile commands interacting with .go files are modified.

Only .go files that import errtrace are rewritten to a temporary file
and passed to compile instead of the original path.
@prashantv prashantv requested a review from abhinav February 18, 2024 02:11
Copy link
Contributor

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

Nice! No blockers. Left a few comments.

@prashantv prashantv merged commit 2fb2821 into main Feb 18, 2024
12 checks passed
@prashantv prashantv deleted the prashant/toolexec-1 branch February 18, 2024 06:33
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.

cmd: -toolexec support
2 participants