Skip to content

Commit

Permalink
DAOS-1310 Build raft using the Makefile target
Browse files Browse the repository at this point in the history
Currently we build raft by [re]defining it's build recipe in an
SConsscript file. This will leave us continually chasing changes
upstream makes in how it's built.

Instead, we should use the make target supplied by the upstream
Makefile.

While we are at it, we might as well use the Makefile to build the
test_main test tool so that it doesn't have to be done at test run-time.

To continue to support our Variant building with scons, add support to
the raft Makefile for building into a separate named directory.

Add a call to "make clean" when scons -c is run to clean up the build
product.

Add the ability to disable gcov support in the raft Makefile and
disable it during our build from scons.
  • Loading branch information
brianjmurrell authored and liw committed Sep 26, 2018
1 parent 19c8593 commit 63d9e07
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
31 changes: 20 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ CONTRIB_DIR = .
TEST_DIR = ./tests
LLQUEUE_DIR = $(CONTRIB_DIR)/CLinkedListQueue
VPATH = src
BUILDDIR ?= .

GCOV_OUTPUT = *.gcda *.gcno *.gcov
GCOV_CCFLAGS = -fprofile-arcs -ftest-coverage
GCOV_OUTPUT = $(BUILDDIR)/*.gcda $(BUILDDIR)/*.gcno $(BUILDDIR)/*.gcov
GCOV_CCFLAGS ?= -fprofile-arcs -ftest-coverage
SHELL = /bin/bash
CFLAGS += -Iinclude -Werror -Werror=return-type -Werror=uninitialized -Wcast-align \
-Wno-pointer-sign -fno-omit-frame-pointer -fno-common -fsigned-char \
Expand All @@ -25,10 +26,16 @@ SHAREDFLAGS = -shared
SHAREDEXT = so
endif

OBJECTS = raft_server.o raft_server_properties.o raft_node.o raft_log.o
OBJECTS = $(BUILDDIR)/raft_server.o $(BUILDDIR)/raft_server_properties.o $(BUILDDIR)/raft_node.o $(BUILDDIR)/raft_log.o

all: static shared

$(BUILDDIR):
mkdir -p $@

$(BUILDDIR)/%.o: %.c | $(BUILDDIR)
$(CC) $(CFLAGS) -c -o $@ $<

clinkedlistqueue:
mkdir -p $(LLQUEUE_DIR)/.git
git --git-dir=$(LLQUEUE_DIR)/.git init
Expand All @@ -45,19 +52,21 @@ $(TEST_DIR)/main_test.c:

.PHONY: shared
shared: $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) $(CFLAGS) -fPIC $(SHAREDFLAGS) -o libraft.$(SHAREDEXT)
$(CC) $(OBJECTS) $(LDFLAGS) $(CFLAGS) -fPIC $(SHAREDFLAGS) -o $(BUILDDIR)/libraft.$(SHAREDEXT)

.PHONY: static
static: $(OBJECTS)
ar -r libraft.a $(OBJECTS)
ar -r $(BUILDDIR)/libraft.a $(OBJECTS)

tests_main: src/raft_server.c src/raft_server_properties.c src/raft_log.c src/raft_node.c $(TEST_DIR)/main_test.c $(TEST_DIR)/test_server.c $(TEST_DIR)/test_node.c $(TEST_DIR)/test_log.c $(TEST_DIR)/test_snapshotting.c $(TEST_DIR)/test_scenario.c $(TEST_DIR)/mock_send_functions.c $(TEST_DIR)/CuTest.c $(LLQUEUE_DIR)/linked_list_queue.c
$(CC) $(CFLAGS) -o $@ $^
$(CC) $(CFLAGS) -o $(BUILDDIR)/$@ $^

.PHONY: tests
tests: tests_main
./tests_main
gcov raft_server.c
if [ -n "$(GCOV_CCFLAGS)" ]; then \
gcov raft_server.c; \
fi

.PHONY: fuzzer_tests
fuzzer_tests:
Expand All @@ -76,7 +85,7 @@ do_infer:
infer -- make static

clean:
@rm -f $(TEST_DIR)/main_test.c *.o $(GCOV_OUTPUT); \
if [ -f "libraft.$(SHAREDEXT)" ]; then rm libraft.$(SHAREDEXT); fi;\
if [ -f libraft.a ]; then rm libraft.a; fi;\
if [ -f tests_main ]; then rm tests_main; fi;
@rm -f $(TEST_DIR)/main_test.c $(BUILDDIR)/*.o $(GCOV_OUTPUT); \
if [ -f "$(BUILDDIR)/libraft.$(SHAREDEXT)" ]; then rm $(BUILDDIR)/libraft.$(SHAREDEXT); fi;\
if [ -f $(BUILDDIR)/libraft.a ]; then rm $(BUILDDIR)/libraft.a; fi;\
if [ -f $(BUILDDIR)/tests_main ]; then rm $(BUILDDIR)/tests_main; fi;
19 changes: 16 additions & 3 deletions src/SConscript
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Import('env')
env = env.Clone()
env.AppendUnique(CPPPATH = ['../include'])
env.Library('raft',
['raft_server.c', 'raft_server_properties.c', 'raft_node.c',
'raft_log.c'])
topdir = env.Dir("#").abspath
builddir = env.Dir('.').abspath
libraft = env.Command('libraft.a', '', 'make -C src/rdb/raft/ BUILDDIR=%s GCOV_CCFLAGS= static' % builddir)
test_main = env.Command('tests_main', libraft, 'make -C src/rdb/raft/ BUILDDIR=%s GCOV_CCFLAGS= tests_main' % builddir)
# even though these are AlwaysBuild() they are still inexpensive as the
# make to build them will bail out if they don't actually need rebuilding
AlwaysBuild(libraft)
AlwaysBuild(test_main)

def CleanAction(env, action):
if env.GetOption('clean'):
env.Execute(action)

env.AddMethod(CleanAction, 'CleanAction')

env.CleanAction(Action(['make -C %s/src/rdb/raft/ BUILDDIR=%s clean' % (topdir, builddir)]))

0 comments on commit 63d9e07

Please sign in to comment.