Permalink
Browse files

makelib: introduce --enable-incremental-build, enabling "go install"

This change decreases incremental compilation time by 50% on my machine
for stage0 builds.

stage1 binaries are much smaller so there is no significant improvement
in compilation speed.

Small change in rkt/main.go:
```
$ time make
  GO           github.com/coreos/rkt/rkt
  ACTOOL       build-rkt/target/bin/stage1-coreos.aci

real    0m13.086s
user    0m11.797s
sys 0m1.323s
```

Small change in stage1/init/init.go:
```
$ time make
  GO           github.com/coreos/rkt/stage1/init
  ACTOOL       build-rkt/target/bin/stage1-coreos.aci

real    0m11.615s
user    0m10.047s
sys 0m1.083s
```

The same with "go build":

Small change in rkt/main.go:
```
$ time make
  GO           github.com/coreos/rkt/rkt
  ACTOOL       build-rkt/target/bin/stage1-coreos.aci

real    0m21.573s
user    0m32.907s
sys 0m2.177s
```

Small change in stage1/init/init.go:
```
$ time make
  GO           github.com/coreos/rkt/stage1/init
  ACTOOL       build-rkt/target/bin/stage1-coreos.aci

real    0m11.365s
user    0m10.777s
sys 0m1.083s
```
  • Loading branch information...
Sergiusz Urbaniak
Sergiusz Urbaniak committed Jan 20, 2017
1 parent 838818d commit 498207d42d996b41395ded870dfe3b7792c665f6
@@ -161,5 +161,15 @@ This option to enable [logging to the TPM][rkt-tpm] is set by default. For loggi
This option to allow building rkt with go having known security issues is unset by default. Use it with caution.
## Development
#### `--enable-incremental-build`
This option enables incremental compilation. This is useful for local development.
In contrast to a release build this option enables `go install` vs `go build`
which decreases incremental compilation time.
Note that this option is not supported in cross-compile builds.
For this reason the incremental build option must not be used for release builds.
[rkt-tpm]: devel/tpm.md
[trousers]: http://trousers.sourceforge.net/
@@ -58,7 +58,7 @@ Run the autogen and configure commands with the relevant arguments, for example
```sh
$ cd ~/Repos/rkt
$ ./autogen.sh && ./configure --enable-functional-tests --with-stage1-flavors=kvm
$ ./autogen.sh && ./configure --enable-functional-tests --enable-incremental-build --with-stage1-flavors=kvm
```
Now build rkt with:
@@ -55,6 +55,8 @@ RKT_DEFINES_FOR_ENTER := @RKT_DEFINES_FOR_ENTER@
RKT_RUN_FUNCTIONAL_TESTS := @RKT_RUN_FUNCTIONAL_TESTS@
INCREMENTAL_BUILD := @INCREMENTAL_BUILD@
GOARCH := @GOARCH@
GOARM := @GOARM@
GOARCH_FOR_BUILD := @GOARCH_FOR_BUILD@
@@ -152,6 +152,13 @@ AC_ARG_ENABLE([functional-tests],
[RKT_RUN_FUNCTIONAL_TESTS="${enableval}"],
[RKT_RUN_FUNCTIONAL_TESTS="no"])
## Incremental build
AC_ARG_ENABLE([incremental-build],
[AS_HELP_STRING([--enable-incremental-build],
[enable incremental build. Note: this does not work for cross compile builds.])],
[INCREMENTAL_BUILD="${enableval}"],
[INCREMENTAL_BUILD="no"])
## TPM
AC_ARG_ENABLE([tpm],
@@ -797,6 +804,7 @@ AC_SUBST(RKT_STAGE1_COREOS_BOARD)
AC_SUBST(RKT_STAGE1_INTERPRETER)
AC_SUBST(RKT_RUN_FUNCTIONAL_TESTS)
AC_SUBST(INCREMENTAL_BUILD)
AC_SUBST(GOARCH)
AC_SUBST(GOARM)
@@ -882,6 +890,7 @@ AC_MSG_RESULT([
other build parameters
functional tests enabled: '${RKT_RUN_FUNCTIONAL_TESTS}'
incremental build: '${INCREMENTAL_BUILD}'
features: '${RKT_FEATURES}'
ACI arch: '${RKT_ACI_ARCH}'
go version: '${GO_VERSION}'
@@ -43,11 +43,23 @@ $(call setup-dep-file,_BGB_KV_DEPMK,$(_BGB_PKG_NAME_)/kv)
$(call forward-vars,$(BGB_BINARY), \
BGB_ADDITIONAL_GO_ENV GO_ENV GO BGB_GO_FLAGS _BGB_PKG_NAME_)
ifeq ($(INCREMENTAL_BUILD),yes)
$(BGB_BINARY): $(_BGB_PATH_) $(_BGB_RKT_SYMLINK_STAMP_)
$(VQ) \
$(call vb,vt,GO,$(call vsg,$(_BGB_PKG_NAME_))) \
$(GO_ENV) $(BGB_ADDITIONAL_GO_ENV) GOBIN=$(dir $(@)) "$(GO)" install -pkgdir $(GOPATH)/pkg $(call v3,-v -x) $(BGB_GO_FLAGS) "$(_BGB_PKG_NAME_)"
else
$(BGB_BINARY): $(_BGB_PATH_) $(_BGB_RKT_SYMLINK_STAMP_)
$(VQ) \
$(call vb,vt,GO,$(call vsg,$(_BGB_PKG_NAME_))) \
$(GO_ENV) $(BGB_ADDITIONAL_GO_ENV) "$(GO)" build $(call v3,-v -x) -o "$@" $(BGB_GO_FLAGS) "$(_BGB_PKG_NAME_)"
endif
$(call generate-go-deps,$(_BGB_GO_DEPMK_STAMP_),$(BGB_BINARY),$(_BGB_GO_DEPMK),$(BGB_PKG_IN_REPO))
$(call generate-kv-deps,$(_BGB_KV_DEPMK_STAMP_),$(BGB_BINARY),$(_BGB_KV_DEPMK),BGB_GO_FLAGS)
@@ -26,8 +26,11 @@ QUICKRMTOOL := $(TOOLSDIR)/quickrm
GO_TEST_PACKAGES ?= ./...
GO_TEST_FUNC_ARGS ?=
GOOS := $(shell "$(GO)" env GOOS)
GO_ENV := $(strip \
GO15VENDOREXPERIMENT=1 \
GOOS="$(GOOS)" \
GOARCH="$(GOARCH)" \
$(if $(GOARM),GOARM="$(GOARM)") \
CGO_ENABLED=1 \
@@ -48,3 +51,7 @@ CREATE_DIRS += \
$(FILELISTDIR) \
$(MAINTEMPDIR) \
$(CLEANDIR)
CLEAN_DIRS += \
$(GOPATH)/bin \
$(GOPATH)/pkg
@@ -22,7 +22,7 @@ FTST_ACE_SIDEKICK_IMAGE_MANIFEST_SRC := vendor/github.com/appc/spec/ace/image_ma
FTST_ACE_SIDEKICK_IMAGE_MANIFEST := $(FTST_ACE_SIDEKICK_IMAGE_DIR)/manifest
FTST_INSPECT_BINARY := $(FTST_TMPDIR)/inspect
FTST_ACI_INSPECT := $(FTST_IMAGE_ROOTFSDIR)/inspect
FTST_ACE_BINARY := $(FTST_TMPDIR)/ace-validator
FTST_ACE_BINARY := $(FTST_TMPDIR)/ace
FTST_ECHO_SERVER_BINARY := $(FTST_TMPDIR)/echo-socket-activated
FTST_ACI_ECHO_SERVER := $(FTST_IMAGE_ROOTFSDIR)/echo-socket-activated
FTST_CNI_PROXY_BINARY := $(FTST_TMPDIR)/cniproxy
@@ -35,6 +35,7 @@ type processor interface {
setWordsNumber(number int)
processWord(word string) error
getList() []string
remove(name string) error
}
// fileProcessor is the simplest from all processor
@@ -61,7 +62,7 @@ type dirProcessor struct {
}
type items struct {
kind string
proc processor
list []string
}
@@ -77,11 +78,11 @@ func main() {
failed := false
for _, i := range allItems {
for _, el := range i.list {
if err := os.Remove(el); err != nil {
if err := i.proc.remove(el); err != nil {
if os.IsNotExist(err) {
continue
}
common.Warn("Failed to remove %s %q: %v", i.kind, el, err)
common.Warn("Failed to remove %s %q: %v", i.proc.kind(), el, err)
failed = true
if infos, err := ioutil.ReadDir(el); err == nil {
var contents []string
@@ -131,7 +132,7 @@ func getItems() []items {
common.Die("Failed to get %s list: %v", k.proc.kind(), err)
}
allItems = append(allItems, items{
kind: k.proc.kind(),
proc: k.proc,
list: l,
})
}
@@ -175,6 +176,10 @@ func (proc *fileProcessor) kind() string {
return "file"
}
func (proc *fileProcessor) remove(name string) error {
return os.Remove(name)
}
func (proc *fileProcessor) setWordsNumber(number int) {
proc.list = make([]string, 0, number)
}
@@ -196,6 +201,10 @@ func (proc *symlinkProcessor) kind() string {
return "symlink"
}
func (proc *symlinkProcessor) remove(name string) error {
return os.Remove(name)
}
func (proc *symlinkProcessor) setWordsNumber(number int) {
proc.list = make([]string, 0, number)
}
@@ -227,6 +236,10 @@ func (proc *dirProcessor) kind() string {
return "directory"
}
func (proc *dirProcessor) remove(name string) error {
return os.RemoveAll(name)
}
func (proc *dirProcessor) setWordsNumber(number int) {
proc.set = make(map[string]struct{}, number)
}

0 comments on commit 498207d

Please sign in to comment.