From b87c74f07e541fe18471f619c53a404f8566f122 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 18 Sep 2018 13:39:32 -0400 Subject: [PATCH] build: build release/CI on non-Windows with code cache This is the minimal change to enable code cache in CI/release builds on non-Windows. (Needs another PR to vcbuild.bat to enable it on Windows). The normal dev flow is unaltered because currently `make test` does not run configure automatically. To enable code cache locally (so that the tests run faster) one will need to run `make with-code-cache` first to persist the configure options to `./config.status`. If that target has never been run, the build flow is the same as before except that the code cache test will be skipped instead of being ignored. --- Makefile | 39 ++++++++++++++++++++++++------ test/code-cache/test-code-cache.js | 6 ++++- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 5fc2bb0c58f553..cb7e1ed14ec34b 100644 --- a/Makefile +++ b/Makefile @@ -109,14 +109,18 @@ CODE_CACHE_FILE ?= $(CODE_CACHE_DIR)/node_code_cache.cc ifeq ($(BUILDTYPE),Debug) CONFIG_FLAGS += --debug endif + +.PHONY: generate-code-cache +generate-code-cache: all + mkdir -p $(CODE_CACHE_DIR) + out/$(BUILDTYPE)/$(NODE_EXE) --expose-internals tools/generate_code_cache.js $(CODE_CACHE_FILE) + .PHONY: with-code-cache with-code-cache: @echo $(CONFIG_FLAGS) $(PYTHON) ./configure $(CONFIG_FLAGS) - $(MAKE) - mkdir -p $(CODE_CACHE_DIR) - out/$(BUILDTYPE)/$(NODE_EXE) --expose-internals tools/generate_code_cache.js $(CODE_CACHE_FILE) - $(PYTHON) ./configure --code-cache-path $(CODE_CACHE_FILE) $(CONFIG_FLAGS) + $(MAKE) generate-code-cache + $(PYTHON) ./configure $(CONFIG_FLAGS) --code-cache-path $(CODE_CACHE_FILE) $(MAKE) .PHONY: test-code-cache @@ -475,9 +479,7 @@ test-ci: | clear-stalled build-addons build-addons-napi doc-only .PHONY: build-ci # Prepare the build for running the tests. # Related CI jobs: most CI tests, excluding node-test-commit-arm-fanned -build-ci: - $(PYTHON) ./configure $(CONFIG_FLAGS) - $(MAKE) +build-ci: with-code-cache .PHONY: run-ci # Run by CI tests, exceptions: @@ -870,12 +872,23 @@ $(PKG): release-only | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \ >$(MACOSOUTDIR)/installer/productbuild/Resources/$$lang/conclusion.html ; \ done + + # Pass 1: build the binary without empty code cache to generate code cache $(PYTHON) ./configure \ --dest-cpu=x64 \ --tag=$(TAG) \ --release-urlbase=$(RELEASE_URLBASE) \ $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS) + $(MAKE) generate-code-cache + # Pass 2: build the binary with the code cache + $(PYTHON) ./configure \ + --dest-cpu=x64 \ + --tag=$(TAG) \ + --release-urlbase=$(RELEASE_URLBASE) \ + $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS) \ + --code-cache-path $(CODE_CACHE_FILE) $(MAKE) install V=$(V) DESTDIR=$(MACOSOUTDIR)/dist/node + SIGN="$(CODESIGN_CERT)" PKGDIR="$(MACOSOUTDIR)/dist/node/usr/local" bash \ tools/osx-codesign.sh mkdir -p $(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules @@ -1005,13 +1018,25 @@ endif $(BINARYTAR): release-only $(RM) -r $(BINARYNAME) $(RM) -r out/deps out/Release + + # Pass 1: build the binary without empty code cache to generate code cache $(PYTHON) ./configure \ --prefix=/ \ --dest-cpu=$(DESTCPU) \ --tag=$(TAG) \ --release-urlbase=$(RELEASE_URLBASE) \ $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS) + $(MAKE) generate-code-cache + # Pass 2: build the binary with the code cache + $(PYTHON) ./configure \ + --prefix=/ \ + --dest-cpu=$(DESTCPU) \ + --tag=$(TAG) \ + --release-urlbase=$(RELEASE_URLBASE) \ + $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS) \ + --code-cache-path $(CODE_CACHE_FILE) $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1 + cp README.md $(BINARYNAME) cp LICENSE $(BINARYNAME) cp CHANGELOG.md $(BINARYNAME) diff --git a/test/code-cache/test-code-cache.js b/test/code-cache/test-code-cache.js index b05e764e8ad290..59cfa0a1828cbc 100644 --- a/test/code-cache/test-code-cache.js +++ b/test/code-cache/test-code-cache.js @@ -4,7 +4,7 @@ // This test verifies that the binary is compiled with code cache and the // cache is used when built in modules are compiled. -require('../common'); +const common = require('../common'); const assert = require('assert'); const { types: { @@ -18,6 +18,10 @@ const { compiledWithoutCache } = require('internal/bootstrap/cache'); +if (process.config.variables.node_code_cache_path === undefined) { + common.skip('Not configured with --code-cache-path'); +} + assert.strictEqual( typeof process.config.variables.node_code_cache_path, 'string'