From 3b324cb32e6872d0e6a21898cfe63b9d78cc04db Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 16 Jul 2015 17:27:52 -0700 Subject: [PATCH] Build with kati+ninja when USE_NINJA=true If USE_NINJA=true, use kati to translate makefiles into ninja files, and then execute them with ninja. Builds kati from source using simplified versions of the rules in binary.mk and definitions.mk. Adds two new goals when USE_NINJA=true: generateonly will regenerate build.ninja but not rebuild (useful for comparing build.ninja output between runs), and fastincremental will skip regenerating build.ninja and go directly to running ninja, providing ~5 second incremental builds. Change-Id: Ib85399e730f1fbb1be7371fafeee7d1c31080771 --- core/main.mk | 5 +++++ core/ninja.mk | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 core/ninja.mk diff --git a/core/main.mk b/core/main.mk index ffff1f7015..1931ea9b2c 100644 --- a/core/main.mk +++ b/core/main.mk @@ -93,6 +93,10 @@ include $(BUILD_SYSTEM)/help.mk # and host information. include $(BUILD_SYSTEM)/config.mk +ifeq ($(USE_NINJA),true) +include build/core/ninja.mk +else # !USE_NINJA + # Write the build number to a file so it can be read back in # without changing the command line every time. Avoids rebuilds # when using ninja. @@ -1065,3 +1069,4 @@ showcommands: .PHONY: nothing nothing: @echo Successfully read the makefiles. +endif # !USE_NINJA diff --git a/core/ninja.mk b/core/ninja.mk new file mode 100644 index 0000000000..05498d8bed --- /dev/null +++ b/core/ninja.mk @@ -0,0 +1,50 @@ +KATI ?= $(HOST_OUT_EXECUTABLES)/ckati + +KATI_OUTPUTS := $(PRODUCT_OUT)/build.ninja $(PRODUCT_OUT)/ninja.sh +NINJA_GOALS := fastincremental generateonly droid showcommands + +ANDROID_TARGETS := $(filter-out $(KATI_OUTPUTS) $(NINJA_GOALS),$(MAKECMDGOALS)) + +ifeq (,$(NINJA_STATUS)) +NINJA_STATUS := [%p %s/%t]$(space) +endif + +ifneq (,$(filter showcommands,$(MAKECMDGOALS))) +NINJA_ARGS += "-v" +PHONY: showcommands +showcommands: droid +endif + +ifeq (,$(filter generateonly,$(MAKECMDGOALS))) +fastincremental droid $(ANDROID_TARGETS): ninja.intermediate + @#empty + +.INTERMEDIATE: ninja.intermediate +ninja.intermediate: $(KATI_OUTPUTS) + @echo Starting build with ninja + @PATH=prebuilts/ninja/$(HOST_PREBUILT_TAG)/:$$PATH NINJA_STATUS="$(NINJA_STATUS)" $(PRODUCT_OUT)/ninja.sh -C $(TOP) $(NINJA_ARGS) $(ANDROID_TARGETS) +else +generateonly droid $(ANDROID_TARGETS): $(KATI_OUTPUTS) + @#empty +endif + +ifeq (,$(filter fastincremental,$(MAKECMDGOALS))) +KATI_FORCE := FORCE +endif + +$(KATI_OUTPUTS): kati.intermediate $(KATI_FORCE) + +.INTERMEDIATE: kati.intermediate +kati.intermediate: $(KATI) + @echo Running kati to generate build.ninja... + @#TODO: use separate ninja file for mm or single target build + @$(KATI) --ninja --ninja_dir=$(PRODUCT_OUT) --ignore_optional_include=out/%.P --detect_android_echo --use_find_emulator -f build/core/main.mk $(ANDROID_TARGETS) USE_NINJA=false + +KATI_CXX := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_CPPFLAGS) +KATI_LD := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_LDFLAGS) +KATI_INTERMEDIATES_PATH := $(HOST_OUT_INTERMEDIATES)/EXECUTABLES/ckati_intermediates +KATI_BIN_PATH := $(HOST_OUT_EXECUTABLES) +include build/kati/Makefile.ckati + +.PHONY: FORCE +FORCE: