Fix the use of go-use (Go Workspaces) when using dependencies that include replace <dep> => <relative path in the go.mod file
#1391
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
Currently, if you want to use a submodule as a dependency in Go, you would import the source (from the root module) and then using
source-subdirpoint to the submodule. However, there is a problem. In thego.modfiles for these modules, there sometimes arereplacestatements that point to relative paths (within its own repository structure)When Go tries to resolve these dependencies, the replace statements look to a relative path, but because of the parts structure ($CRAFT_BACKSTAGE/go-use/), when the Go plugin does a
go work use <>on this path, the directory structure has changed, and therefore Go will error, saying that it can't find a dependency.In order to solve this, we have removed the replace statements directly from the dependency's go.mod file. However, this shouldn't be the case as then it cannot be built from scratch (without a craft tool).
The Solution
The source of the issue is that the paths that
go work usecalls is a symlink. If we resolve the symlink to the absolute link, this solves the problem & we do not have to remove the replace statements from the go.mod file.Additional Issues
When running
make test-fast, there is a test that fails (test_get_build_commands_go_use_with_go_dependencyintests/unit/plugins/test_go_plugin). However, because of the solution, the expected behavior that this test tests for has changed.Some of the integration tests fail, but they were failing before I made my change.
There's no issue for this. If this problem statement should be moved into an issue let's create that (I just didn't feel comfortable if I didn't do something according to protocol)
(Future Fix) Want to add a feature for go-use, but I think that's another PR
From The Template
…work use
make lint && make test?docs/reference/changelog.rst)?