-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/mod/modfile: AddNewRequire doesn't put direct dependencies in the first block #69050
Comments
See #68593, just parsing the modfile doesn't provide enough information for if a module should be direct or indirect, and the default addition is to mark it as indirect. |
I'm not sure you correctly understood what I reported, What it's not doing is adding it to the correct block. |
Ah sorry. |
FYI I have some code which I believe fixes the behaviour, just need to get a PR created from it. |
Change https://go.dev/cl/608056 mentions this issue: |
AddNewRequire is documented to add the require to the last block and I think we should be careful when making changes to behavior like this. The go command only creates the two blocks for go modules declaring Take a look at the code here: src/cmd/go/internal/modload/init.go#1846 The go command decides to call SetRequire or SetRequireSeparateIndirect based on the module's |
Thanks for the link, to clarify are users of |
SetRequire and SetRequireSeparateIndirect are meant to be used by the go command. I think users that need to manually edit a We should fix the problems with tidy: Tidy shouldn't split a two-group |
To confirm my understanding, AddRequire and AddNewRequire should ideally maintain the status? If so this is what exactly golang/mod#21 targets to do. However it does always look to create two groups so if we want it to only create one per 1.17 then it would need tweaking. |
I don't think AddRequire should maintain the It should be okay to had AddRequire add an |
The problem with that is it means you add a dependency on the If For reference the use case I'm working with is automating the correction of modules which create plugins, which have the requirement that they use identical module versions, specifically for krakend, which is typically used in a docker container that doesn't have |
We expect the If the edited modules are being released I'd strongly recommend running go mod tidy before releasing them. I think for what you're trying to your best bet is probably to use |
Totally agree that We have already made the switch to From a users perspective the If In short all methods should result in a file that would require minimal changes that Thoughts? |
I agree that the methods should result in a file that But I think it's okay that
We do plan to fix the |
Go version
go version go1.23.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Use AddNewRequire to add new requires.
What did you see happen?
Direct requires should be added to first require block, indirect requires should be added to second block.
What did you expect to see?
When using
AddNewRequire
, requires are added to the last block. This is the documented behaviour, but other go tools such asgo mod tidy
maintain two blocks, so this use the same approach.It seems possible to use
SetRequireSeparateIndirect
to replicate the desired behaviour but that was far from obvious.If nothing else reference in
AddNewRequire
andAddequire
toSetRequireSeparateIndirect
would help users fine the right functionality, but ideallyAddNewRequire
andAddRequire
should function as expected.If a user isn't aware of the two block rule then using this will result in a file that
go mod tidy
handles badly, in some cases resulting in three blocks instead of two.The text was updated successfully, but these errors were encountered: