Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Add some dependency logic around generators. #1966

Merged
merged 1 commit into from
Aug 2, 2018

Conversation

vin
Copy link
Contributor

@vin vin commented Apr 20, 2018

This isn't 100% correct, but it's a pretty good approximation.
Specifically, it doesn't know about transitive dependencies from other
go packages. But it'll rebuild a generator if any code inside its
package changes (or build them all if anything in gengo changes).

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 20, 2018
$(BINDIR)/lister-gen: .init
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/vendor/k8s.io/code-generator/cmd/lister-gen
.PHONY: generators
generators: $(GENERATORS)
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this target for? not used anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly a convenience, to be able to say "make generators" from the command line. But I've taken your suggestion to reference it throughout instead of $(GENERATORS).

Makefile Outdated

$(BINDIR)/openapi-gen: vendor/k8s.io/code-generator/cmd/openapi-gen
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/$^
$(BINDIR)/%-gen: $$(shell find vendor/k8s.io/code-generator/cmd/$$*-gen vendor/k8s.io/gengo) .init
Copy link
Contributor

Choose a reason for hiding this comment

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

notes, maybe need some comments to quickstart people's minds when reading

depend on something-gen in gengo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Makefile Outdated
$(BINDIR)/openapi-gen: vendor/k8s.io/code-generator/cmd/openapi-gen
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/$^
$(BINDIR)/%-gen: $$(shell find vendor/k8s.io/code-generator/cmd/$$*-gen vendor/k8s.io/gengo) .init
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/vendor/k8s.io/code-generator/cmd/$*-gen
Copy link
Contributor

Choose a reason for hiding this comment

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

build the something-gen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is now clear, with the comment I've added above. But let me know if you disagree.

Makefile Outdated

.PHONY: $(BINDIR)/e2e.test
$(BINDIR)/e2e.test: .init
$(DOCKER_CMD) go test -c -o $@ $(SC_PKG)/test/e2e

# Regenerate all files if the gen exes changed or any "types.go" files changed
.generate_files: .init .generate_exes $(TYPES_FILES)
.generate_files: .init $(GENERATORS) $(TYPES_FILES)
Copy link
Contributor

Choose a reason for hiding this comment

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

why use the variable vs the target defined above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No strong reason -- generally I was favoring eliminating indirection, but in practice it's no easier to understand. Done.

@MHBauer
Copy link
Contributor

MHBauer commented Apr 25, 2018

if this is an optimization people need, I guess I'm fine with it. I'd prefer to let golang handle the "is it necessary to rebuild" decision. It gets better in v1.10, but we can't move to that yet.

@vin
Copy link
Contributor Author

vin commented Apr 25, 2018

@n3wscott was asking for this; IIRC he had an issue where he accidentally committed code generated by stale generator binaries. This should be more correct than the previous implementation.

This isn't 100% correct, but it's a pretty good approximation.
Specifically, it doesn't know about transitive dependencies from other
go packages.  But it'll rebuild a generator if any code inside its
package changes (or build them all if anything in gengo changes).
@MHBauer
Copy link
Contributor

MHBauer commented Jul 17, 2018

on golang 1.10 and it's handling the binary dependency thing and caching.

# on everything under its source tree as well as gengo's. This uses GNU Make's
# secondary expansion feature to pass $* to `find`.
$(BINDIR)/%-gen: $$(shell find vendor/k8s.io/code-generator/cmd/$$*-gen vendor/k8s.io/gengo) .init
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/vendor/k8s.io/code-generator/cmd/$*-gen
Copy link
Contributor

Choose a reason for hiding this comment

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

nice comment. this is neat. I'm wondering if the find is the right practice vs having golang handle it vs handling it like upstream k/k does with the go2mk generator.

@MHBauer
Copy link
Contributor

MHBauer commented Jul 24, 2018

altogether, I cannot see any reason not to do this.
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 24, 2018
@MHBauer MHBauer added the LGTM1 label Jul 24, 2018
@MHBauer
Copy link
Contributor

MHBauer commented Aug 2, 2018

/assign @jberkhahn
for testing on mac

/assign @jboyd01
as someone who commented in the meeting

@MHBauer
Copy link
Contributor

MHBauer commented Aug 2, 2018

/cc @jberkhahn @jboyd01

@jberkhahn
Copy link
Contributor

this seems to work fine on Mac

/lgtm

@MHBauer MHBauer added the LGTM2 label Aug 2, 2018
@MHBauer
Copy link
Contributor

MHBauer commented Aug 2, 2018

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MHBauer

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@MHBauer
Copy link
Contributor

MHBauer commented Aug 2, 2018

/retest

@k8s-ci-robot k8s-ci-robot merged commit 0591dc4 into kubernetes-retired:master Aug 2, 2018
@MHBauer MHBauer mentioned this pull request Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. LGTM1 LGTM2 size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants