From cca78cfcfdda7700dc3e5659ef68cadedaef136b Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Sat, 9 Jun 2012 12:52:43 +0800 Subject: Modify Makefile to allow insertion of mock modules When we need to mock modules in a unit test, we need a way to mock the actual modules. This CL enables mock of given source files. For example, if we need to mock watchdog for test 'foo', we can add to test/build.mk: "core-mock-foo-watchdog.o=fake_watchdog.o", and then implement its own watchdog in fake_watchdog.c. Signed-off-by: Vic Yang BUG=chrome-os-partner:10356 TEST=Set a mock fake_watchdog.c and check the test is compiled with fake_watchdog.c instead of watchdog.c. Change-Id: I4a0afb589a49dad7c4d6faf8926438085cdc46cf Reviewed-on: https://gerrit.chromium.org/gerrit/24942 Reviewed-by: Vincent Palatin Commit-Ready: Vic Yang Tested-by: Vic Yang --- Makefile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ee86da1881..80566276e2 100644 --- a/Makefile +++ b/Makefile @@ -40,16 +40,17 @@ include util/build.mk includes+=$(includes-y) -objs_from_dir=$(foreach obj,$(2), $(out)/$(1)/$(obj)) +objs_from_dir=$(foreach obj, $($(2)-y), \ + $(out)/$(1)/$(firstword $($(2)-mock-$(PROJECT)-$(obj)) $(obj))) # Get all sources to build -all-y=$(call objs_from_dir,core/$(CORE),$(core-y)) -all-y+=$(call objs_from_dir,chip/$(CHIP),$(chip-y)) -all-y+=$(call objs_from_dir,board/$(BOARD),$(board-y)) -all-y+=$(call objs_from_dir,private,$(private-y)) -all-y+=$(call objs_from_dir,common,$(common-y)) -all-y+=$(call objs_from_dir,test,$($(PROJECT)-y)) -all-y+=$(call objs_from_dir,vboot,$(vboot-y)) +all-y=$(call objs_from_dir,core/$(CORE),core) +all-y+=$(call objs_from_dir,chip/$(CHIP),chip) +all-y+=$(call objs_from_dir,board/$(BOARD),board) +all-y+=$(call objs_from_dir,private,private) +all-y+=$(call objs_from_dir,common,common) +all-y+=$(call objs_from_dir,test,$(PROJECT)) +all-y+=$(call objs_from_dir,vboot,vboot) dirs=core/$(CORE) chip/$(CHIP) board/$(BOARD) private common test util include Makefile.rules -- cgit v1.2.1