Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Makefile: Remove clean prerequisites from build targets #950

Merged
merged 1 commit into from
Aug 21, 2018

Conversation

wking
Copy link
Contributor

@wking wking commented Mar 29, 2018

The clean target has been included there since 1f34600 (#46). But clean has been a release prerequisite since 04848d1 (#47), so the .travis.yml entry is redundant.

@coreosbot
Copy link

Can one of the admins verify this patch?

3 similar comments
@coreosbot
Copy link

Can one of the admins verify this patch?

@coreosbot
Copy link

Can one of the admins verify this patch?

@coreosbot
Copy link

Can one of the admins verify this patch?

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 29, 2018
@wking
Copy link
Contributor Author

wking commented Mar 29, 2018

Actually, hold off on this. We may want to keep clean in .travis,yml and drop it from the release prereqs, because having it in the release prereqs may break with parallel make (e.g. -j8).

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 29, 2018
@wking wking changed the title .travis.yml: Drop 'clean' from test script Makefile: Remove clean prerequisites from build targets Mar 29, 2018
@wking
Copy link
Contributor Author

wking commented Mar 29, 2018

We may want to keep clean in .travis,yml and drop it from the release prereqs, because having it in the release prereqs may break with parallel make (e.g. -j8).

And it does introduce a possibly-breaking race in parallel make (although rm is fast, so it wasn't particularly likely to cause problems). I've just pushed e32afd2fb4eb8a removing all of the clean prereqs from all of the build targets, which removes the race. I've also removed some unnecessary cleans, and added VENDOR_GOFILES to the Makefile to close a hole in our rebuild-dependency tracking. Details on the changes in the individual commits, and I'm happy to squash/split/reshuffle those if it would help review.

I've updated the PR title to reflect the broader change, and I'm back to thinking this is ready for review ;).

@rphillips
Copy link
Contributor

ok to test

@@ -26,7 +27,6 @@ cross: \
_output/bin/linux/s390x/checkpoint

release: \
clean \
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't removing this prevent clean from running on all releases?

Copy link
Contributor Author

@wking wking Apr 3, 2018

Choose a reason for hiding this comment

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

Doesn't removing this prevent clean from running on all releases?

Yup, and that avoids a parallel-make race. You can always call make clean first, but I don't think we need to (more on why not in 3136f29).

Copy link
Contributor

Choose a reason for hiding this comment

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

The intent here is to always ensure release is running in a clean workspace. We should keep this dependency, though calling make clean release is redundant in the Travis script.

I'm confused about why this would cause a race. Dependencies always resolve before the block executes, so release will always wait on clean to finish.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intent here is to always ensure release is running in a clean workspace.

I think the release prereq tree is sufficient for this, but if you want to be extra safe we can drop some/all of 3136f29. Let me know how you want that handled.

I'm confused about why this would cause a race. Dependencies always resolve before the block executes, so release will always wait on clean to finish.

Right, but release has no recipe. All of its prereqs will finish before that no-op recipe, but make makes no guarantees about the order in which the prereqs are resolved. For an example using sleep to slant the race odds the other way, see the 9e18c38 commit message.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see.

@@ -47,7 +47,7 @@ install: _output/bin/$(LOCAL_OS)/bootkube
_output/bin/%: GOOS=$(word 1, $(subst /, ,$*))
_output/bin/%: GOARCH=$(word 2, $(subst /, ,$*))
_output/bin/%: GOARCH:=amd64 # default to amd64 to support release scripts
_output/bin/%: $(GOFILES)
_output/bin/%: $(GOFILES) $(VENDOR_GOFILES)
Copy link
Contributor

@ericchiang ericchiang Apr 3, 2018

Choose a reason for hiding this comment

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

Instead of adding VENDOR_GOFILES we can probably just drop the dependencies. go build already caches everything and detects what needs to be recompiled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to leave it as is, but I may do a follow up to remove make dependencies.

Copy link
Contributor

@ericchiang ericchiang left a comment

Choose a reason for hiding this comment

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

Can you please squash your commits?

@wking
Copy link
Contributor Author

wking commented Apr 3, 2018

Can you please squash your commits?

Done with fb4eb8a35a86cf, although the resulting commit message is now getting pretty long ;).

@wking
Copy link
Contributor Author

wking commented Apr 3, 2018

Rebased around #949 and #956 with 35a86cf15fad99.

@wking
Copy link
Contributor Author

wking commented Apr 4, 2018

I dunno what's going on with the Calico failure; looks loke it's missing from S3.

@wking
Copy link
Contributor Author

wking commented May 16, 2018

Rebased onto master (no conflicts) with 15fad99 -> e5ab3ec, in case a retry gets past the previous Calico flake.

@aaronlevy
Copy link
Contributor

aaronlevy commented Aug 16, 2018

Getting around to all the old PRs. Mind resolving conflict?

'clean' has been a prerequisite for:

* conformance-%, since the target landed in 0520bdf (hack: add
  conformance tests for hack builds, 2016-05-26, kubernetes-retired#45).
* release, since the target landed in 04848d1 (Add release build
  process, 2016-05-27, kubernetes-retired#47).

clean-vm-% target has been a prerequisite for run-% since the target
landed in 9e2e89e (run make target, 2016-09-23, kubernetes-retired#141).

But there are two problems with including cleaners are prerequisites
of build steps:

* They are inefficient.  Make is good at rebuilding only things that
  need rebuilding, provided you inform it of your dependencies.
  Cleaning before every build will often lead to unnecessary rebuilds
  of up-to-date content.

* They are racy.  For example, a parallel make invocation may process
  several prerequisites at once.  The current 'clean' recipe will
  execute quickly, which is why it hasn't been much of a problem yet,
  but you can see the race by inserting a delay:

    clean:
      sleep 60
      rm -rf _output

  and running:

    $ make -j8 release
    sleep 60
    mkdir -p _output/bin/darwin/
    GOOS=darwin GOARCH=amd64   go build ...
    ...
    mkdir -p _output/release/
    tar czf _output/release/bootkube.tar.gz -C _output bin/linux/bootkube bin/darwin/bootkube bin/linux/checkpoint
    rm -rf _output

  with the other preqrequisites completing first, clean's rm ends up
  removing everything release generated.

In this commit, I've removed the clean prerequisites from the build
targets to resolve the above issues.  We could also update our
recommended make invocations to add clean as an explicit earlier step,
and I've done that for 'all' and 'run-' to hint at the existence of
the clean targets.  I don't think we need separate clean calls for
'release' or 'conformance-%'

* No need to 'make clean' before calling 'make release'

  For Travis, the test environment should not include anything in
  _output at this point, so there's no need to call clean there.  The
  'clean' target has been included in .travis.yml since 1f34600 (Add
  travis tests, 2016-05-27, kubernetes-retired#46).  And 'clean' had been a 'release'
  prerequisite since 04848d1 (Add release build process, 2016-05-27,
  kubernetes-retired#47).  But neither of those motivate the Travis use-case, so I think
  they were just being overly cautious.

  And for RELEASING, walking the prerequisite chain for release shows
  that a clean all would have no impact:

  * check is verifying the source, and does not care about _output.
  * _output/release/bootkube.tar.gz knows about its dependencies.
    * _output/bin/% (used for _output/bin/.../bootkube) knows about
      its GOFILES and (new in this commit) VENDOR_GOFILES
      dependencies.  This is *overly* broad, because it includes
      cmd/checkpoint/*.go and other non-dependencies, but overly broad
      is still safe.

  * The new VENDOR_GOFILES ensures we rebuild _output/bin/... if a
    vendored dependency is bumped even if no bootkube-specific code is
    bumped.

* No need to 'make clean' before calling 'make conformance-...'

  The hack/ content only depends on _output for
  _output/bin/${local_os}/bootkube and _output/bin/linux/bootkube.
  conformance-% only uses hack/ content, and it depends on all.
  'all', in turn, depends on both _output/bin/$(LOCAL_OS)/bootkube and
  _output/bin/linux/bootkube, and each of those fully specifies their
  build dependencies.  So there's no need for a separate clean step
  before running the conformance-% targets; Make will rebuild anything
  that needs rebuilding already.
@wking
Copy link
Contributor Author

wking commented Aug 17, 2018

Rebased with e5ab3ec -> 15ef313.

Copy link
Contributor

@aaronlevy aaronlevy left a comment

Choose a reason for hiding this comment

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

lgtm

@aaronlevy aaronlevy merged commit 7fef233 into kubernetes-retired:master Aug 21, 2018
@wking wking deleted the travis-drop-clean branch September 23, 2018 22:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants