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

Go: awkward UX with ./pants check and third-party packages #13175

Closed
Eric-Arellano opened this issue Oct 8, 2021 · 4 comments
Closed

Go: awkward UX with ./pants check and third-party packages #13175

Eric-Arellano opened this issue Oct 8, 2021 · 4 comments

Comments

@Eric-Arellano
Copy link
Contributor

Many third-party packages end up never being used in a Go project. Pants pessimistically uses target generation to create a go_third_party_package target for every package belonging to a third-party module, even if it will never be used:

assert_module(
"github.com/google/go-cmp",
"v0.5.6",
[
"github.com/google/go-cmp/cmp",
"github.com/google/go-cmp/cmp/cmpopts",
"github.com/google/go-cmp/cmp/internal/diff",
"github.com/google/go-cmp/cmp/internal/flags",
"github.com/google/go-cmp/cmp/internal/function",
"github.com/google/go-cmp/cmp/internal/testprotos",
"github.com/google/go-cmp/cmp/internal/teststructs",
"github.com/google/go-cmp/cmp/internal/teststructs/foo1",
"github.com/google/go-cmp/cmp/internal/teststructs/foo2",
"github.com/google/go-cmp/cmp/internal/value",
],
)

This is necessary for dependency inference to work: we need to have a mapping of every possible package used to map back imports.

--

However, this means that ./pants check :: will end up compiling substantially more packages than are actually needed. Not only is this wasted performance, but some packages might not compile such as from us not yet supporting cgo files, c files, etc.

--

It is not acceptable to require the user first do ./pants filter --target-type=go_first_party_package :: | xargs ./pants check.

Instead, I think the solution is to not hook up go_third_party_package to ./pants check. The only way to compile a third-party package is because it's a dependency of a first-party package.

@Eric-Arellano
Copy link
Contributor Author

cc @tdyas @stuhood @patricklaw . What do you think of the proposed solution? Do you have any other ideas?

@tdyas
Copy link
Contributor

tdyas commented Oct 8, 2021

Instead, I think the solution is to not hook up go_third_party_package to ./pants check. The only way to compile a third-party package is because it's a dependency of a first-party package.

I agree with this solution. We are using targets as an implementation detail to make it easier to build third party code, but the user does not expect :: to build that third-party code. At least for me, I presume Pants will only build my first-party code in that case (and whatever is necessary to build that first-party code).

@tdyas
Copy link
Contributor

tdyas commented Oct 8, 2021

Pants pessimistically uses target generation to create a go_third_party_package target for every package belonging to a third-party module, even if it will never be used:

Probably save this as a motivating use case for lazy target generation some time in the future.

@Eric-Arellano
Copy link
Contributor Author

Closing as answered.

Eric-Arellano added a commit that referenced this issue Oct 22, 2021
This lets you compile a package without needing to run tests or package a binary. 

Note that you can only directly compile a first-party package - to check if a third-party package is buildable, it must be a dependency of a first-party package. Works around #13175.

This does not yet have an optimal UX. It's overly chatty:

```
❯ ./pants check testprojects/src/go::
13:36:38.57 [INFO] Initializing scheduler...
13:36:39.20 [INFO] Scheduler initialized.
13:36:39.71 [ERROR] Completed: pants.backend.go.goals.check.check_go - go failed (exit code 1).
Partition #1 - github.com/pantsbuild/pants/testprojects/src/go/pants_test:
./testprojects/src/go/pants_test/foo.go:3:1: syntax error: non-declaration statement outside function body

Partition #2 - github.com/pantsbuild/pants/testprojects/src/go/pants_test/bar:



𐄂 go failed.
```

We also should be streaming the result of each compilation as it happens, which has an added benefit of that output happening when compilation happens as a side effect of `run`, `package`, and `test`. Those fixes will be in a followup.

[ci skip-rust]
[ci skip-build-wheels]
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

No branches or pull requests

2 participants