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

[POC] go.mod replace with ModulePath #3

Open
wants to merge 4 commits into
base: hack-duplicate-go-deps-from-file
Choose a base branch
from

Conversation

stefanpenner
Copy link
Owner

@stefanpenner stefanpenner commented Feb 22, 2024

What type of PR is this?
Feature

What package or component does this PR mostly affect?
language/go

What does this PR do? Why is it needed?

This builds on the go.work support PR and the new rctx.watch_files support to add support for FilePath ReplaceDirective, in go.mod and go.work files when using bzlmod go_deps extension.

For example, now the following native go capability works in the bazel world:

module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_mod

go 1.21.5

require (
	example.org/hello v1.0.0
        // ... snip ...
)

// ... snip ...

replace example.org/hello => ../../../fixtures/hello

Which issues(s) does this PR fix?

bazel-contrib#1775

Status

  • make it "work"
  • ensure relative and absolute pathing works
    • /Users/user/path/to/mod
    • ../../path/to/mod
  • test with nightly bazel + rctx.watch_files and verify it fixes "rebuilds"
  • expand bcr tests
    • go.mod
    • go.work
  • add go specific unit tests for new capabilities added to cmd/fetch_repo
  • even less hack and even more quality
  • fix tests that fail on the bazelbuild/bazel-gazelle CI

@stefanpenner stefanpenner changed the title [WIP] go.mod replace with ModulePath [POC] go.mod replace with ModulePath Feb 22, 2024
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch 4 times, most recently from 45a18bb to 068115e Compare February 26, 2024 17:16
@stefanpenner stefanpenner force-pushed the hack-duplicate-go-deps-from-file branch 2 times, most recently from c73e943 to 26bbdba Compare February 26, 2024 17:36
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch from 068115e to 8f7c963 Compare February 26, 2024 18:14
@stefanpenner stefanpenner force-pushed the hack-duplicate-go-deps-from-file branch 8 times, most recently from 6114041 to a2252f8 Compare February 26, 2024 22:26
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch 6 times, most recently from dc4a71d to 3eede5e Compare February 29, 2024 00:07
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch from 3eede5e to cb5dd43 Compare March 16, 2024 20:14
@stefanpenner stefanpenner force-pushed the hack-duplicate-go-deps-from-file branch 4 times, most recently from d083b4b to 8905c11 Compare March 16, 2024 21:06
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch from cb5dd43 to 3a4742e Compare March 16, 2024 21:22
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch from 3a4742e to c04c18a Compare March 18, 2024 22:01
@stefanpenner stefanpenner force-pushed the hack-duplicate-go-deps-from-file branch 4 times, most recently from 0de3150 to b6802f2 Compare April 15, 2024 20:14
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch from 15bede3 to 6200b94 Compare April 15, 2024 20:50
@stefanpenner stefanpenner force-pushed the hack-duplicate-go-deps-from-file branch from ae2935a to c292df3 Compare April 18, 2024 18:01
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch 2 times, most recently from 5e9efed to 9dd906d Compare April 18, 2024 18:43
* adds go_deps.from_file(go_work = "//:go.work")
* adds ability to op-out of version conflict failures go_deps.from_file(go_work = "//:go.work, fail_on_version_conflict = False)
* parses go.work files to discover used go modules and replace statements
* generates repos for all deps specified in go.mod's referenced by the //:go.work
* handle replace statements (both at the go.work and the go.mod level)
* Errors with actionable error message if duplicate dependencies with differing versions arise (Question: can we do better?)
* expand BCR test coverage to include both go.work and go.mod scenarios

Caveats:
* allows for dependency bleed between different go modules in the workspace - this is sorta by design for this stepping stone, but is ideal
* doesn't support replace statements in go.work yet (but that shouldn't be to hard to add in a follow up)
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch 4 times, most recently from f46021b to 92a2a0d Compare April 24, 2024 17:36
mortenmj and others added 2 commits April 25, 2024 12:36
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch 13 times, most recently from 5ce68df to 2da0494 Compare May 1, 2024 12:52
@stefanpenner stefanpenner force-pushed the go-deps-replace-with-module-path branch from 2da0494 to 21b9b48 Compare May 1, 2024 15:19
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.

3 participants