Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Removing GOPATH in source mode #44

Closed
wants to merge 3 commits into from
Closed

Conversation

linzhp
Copy link
Contributor

@linzhp linzhp commented May 19, 2020

After golang/mock#420, GoMock source mode no longer requires full transitive dependency closure in GOPATH. As a result, the gomock rule can avoid calling the gopath rule, it only need to make sure the source file and auxiliary files in the GOPATH.

When building //gomock:mocks from linzhp/bazel_examples@b7f4b75, bazel_gomock (4f2ee84) spent 2.287 seconds on gomock rule:

     538 ms    5.71%   action 'GoPath gomock/mocks_gomock_gopath'
    1.749 s   18.57%   action 'Action gomock/mocks.go'

After applying this patch, it became 1.498 seconds:

    1.498 s   20.77%   action 'Action gomock/mocks.go'

The difference would be more significant for packages with large dependency tree

gomock.bzl Outdated
Comment on lines 77 to 92
doc = "A map from packages to auxilliary Go source files to load for those packages.",
doc = "A map auxilliary Go source files to their packages.",
Copy link
Owner

Choose a reason for hiding this comment

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

Accidental?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Go source files should be referred to as labels, not strings (see the implementation of go_library as an example). Labels allow us to refer source files from different packages. However, there is no way to map a string to label in Bazel rules. We can only map a label to a string. I know this will break existing usage, but what other choice do we have?

gomock.bzl Outdated
Comment on lines 18 to 35
for pkg, files in ctx.attr.aux_files.items():
for f in files:
mapped_f = gopath + "/src/" + ctx.attr.library[GoLibrary].importmap + "/"+ f
aux_files.append("{0}={1}".format(pkg, mapped_f))
for target, pkg in ctx.attr.aux_files.items():
f = target.files.to_list()[0]
aux_files.append("{0}={1}".format(pkg, f.path))
needed_files.append(f)
Copy link
Owner

Choose a reason for hiding this comment

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

This looks like an API break. Why are we doing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refer to my other comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, confirmed with @josmad, who contributed aux_files attribute, that he is not using the attribute anywhere right now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jmhodges Can you make a major version bump for this API break?

@linzhp
Copy link
Contributor Author

linzhp commented Jun 2, 2020

@jmhodges I updated the performance comparison data. Please review.

@linzhp
Copy link
Contributor Author

linzhp commented Dec 21, 2020

@jmhodges Can you take another look at this PR?

@linzhp
Copy link
Contributor Author

linzhp commented Mar 8, 2021

@jmhodges ping...

@linzhp
Copy link
Contributor Author

linzhp commented Apr 18, 2022

Superseded by bazel-contrib/rules_go#3121

@linzhp linzhp closed this Apr 18, 2022
@linzhp linzhp deleted the gopath branch April 18, 2022 04:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants