Skip to content

Commit

Permalink
common: add clang-format rule
Browse files Browse the repository at this point in the history
C++ files will be checked for style using clang-format.
C file will continue to use cstyle due to some issues
with libpmemobj macros.
  • Loading branch information
tomaszkapela committed May 9, 2016
1 parent b0b47cd commit 26c44c3
Show file tree
Hide file tree
Showing 61 changed files with 5,076 additions and 4,606 deletions.
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ a pull request. The NVM Library project uses the common
The [Git Workflow blog article](http://pmem.io/2014/09/09/git-workflow.html)
describes our workflow in more detail.

Before contributing please remember to run:
```
$ make cstyle
```

This will check all C/C++ files in the tree for style issues. To check C++
files you have to have clang-format version 3.8+, otherwise they will be
skipped. There is also a target for automatic C++ code formatting, to do this
run:
```
$ make format
```

If you are actively working on an NVM Library feature, please let other
developers know by [creating an issue](https://github.com/pmem/issues/issues).
Use the label `Type: Feature` and assign it to yourself (due to the way
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ cstyle:
@utils/check_whitespace -g
@echo Done.

format:
$(MAKE) -C src $@
$(MAKE) -C utils $@
@echo Done.

check-license:
$(MAKE) -C utils $@
@utils/check_license/check-headers.sh
Expand All @@ -125,4 +130,4 @@ install uninstall:
$(MAKE) -C doc $@

.PHONY: all clean clobber test check cstyle check-license install uninstall\
source rpm dpkg pkg-clean pcheck check-remote $(SUBDIRS)
source rpm dpkg pkg-clean pcheck check-remote format $(SUBDIRS)
32 changes: 32 additions & 0 deletions src/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: Always
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
AlwaysBreakAfterDefinitionReturnType: true
SpaceBeforeParens: ControlStatements
SpacesBeforeTrailingComments: 1
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
PointerAlignment: Right
ContinuationIndentWidth: 8
AlignOperands: false
IndentCaseLabels: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
AlwaysBreakTemplateDeclarations: true
AccessModifierOffset: -8
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
49 changes: 19 additions & 30 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ include $(TOP)/src/common.inc

TARGETS = libpmem libvmem libpmemblk libpmemlog libpmemobj libvmmalloc tools
ALL_TARGETS = $(TARGETS) librpmem examples benchmarks
CLEAN_TARGETS = $(ALL_TARGETS) test jemalloc
CLOBBER_TARGETS = $(ALL_TARGETS) test jemalloc
CLEAN_NO_JE_TARGETS = $(ALL_TARGETS) test
CLEAN_TARGETS = $(CLEAN_NO_JE_TARGETS) jemalloc
CLOBBER_NO_JE_TARGETS = $(ALL_TARGETS) test
CLOBBER_TARGETS = $(CLOBBER_NO_JE_TARGETS) jemalloc
CSTYLE_TARGETS = $(ALL_TARGETS) common test rpmem_common
INSTALL_TARGETS = $(TARGETS)

Expand Down Expand Up @@ -77,6 +79,7 @@ uninstall: $(INSTALL_TARGETS:=-uninstall)
clean: $(CLEAN_TARGETS:=-clean)
clobber: $(CLOBBER_TARGETS:=-clobber)
cstyle: $(CSTYLE_TARGETS:=-cstyle)
format: $(CSTYLE_TARGETS:=-format)
examples benchmarks: $(TARGETS)
benchmarks: examples

Expand All @@ -89,32 +92,12 @@ libpmemblk libpmemlog libpmemobj: libpmem
pkg-config:
@$(MAKE_PKG_CONFIG) "$(prefix)" "$(libdir)" "$(SRCVERSION)"

%-install: %
$(MAKE) -C $* install
ifeq ($(custom_build),)
$(MAKE) -C $* install DEBUG=1
endif

%-uninstall:
$(MAKE) -C $* uninstall
ifeq ($(custom_build),)
$(MAKE) -C $* uninstall DEBUG=1
endif

%-clean:
$(MAKE) -C $* clean
ifeq ($(custom_build),)
$(MAKE) -C $* clean DEBUG=1
endif

%-clobber:
$(MAKE) -C $* clobber
ifeq ($(custom_build),)
$(MAKE) -C $* clobber DEBUG=1
endif

%-cstyle:
$(MAKE) -C $* cstyle
$(eval $(call sub-target,$(INSTALL_TARGETS),install,y))
$(eval $(call sub-target,$(INSTALL_TARGETS),uninstall,y))
$(eval $(call sub-target,$(CLEAN_NO_JE_TARGETS),clean,y))
$(eval $(call sub-target,$(CLOBBER_NO_JE_TARGETS),clobber,y))
$(eval $(call sub-target,$(CSTYLE_TARGETS),cstyle,n))
$(eval $(call sub-target,$(CSTYLE_TARGETS),format,n))

$(ALL_TARGETS):
$(MAKE) -C $@
Expand Down Expand Up @@ -162,7 +145,13 @@ uninstall:
$(foreach f, $(PKG_CONFIG_FILES), $(RM) $(PKG_CONFIG_DESTDIR)/$(notdir $(f)))

cstyle:
$(CSTYLE) include/*.h
$(STYLE_CHECK) check include/*.h
$(STYLE_CHECK) check include/libpmemobj/*.hpp
$(STYLE_CHECK) check include/libpmemobj/detail/*.hpp

format:
$(STYLE_CHECK) format include/libpmemobj/*.hpp
$(STYLE_CHECK) format include/libpmemobj/detail/*.hpp

cscope:
cscope -q -b $(SCOPEFILES)
Expand All @@ -173,6 +162,6 @@ clean:

.NOTPARALLEL: libvmem libvmmalloc

.PHONY: all install uninstall unistall-cpp install-cpp clean clobber cstyle test check pcheck\
.PHONY: all install uninstall unistall-cpp install-cpp clean clobber cstyle format test check pcheck\
jemalloc jemalloc-clean jemalloc-test jemalloc-check cscope $(ALL_TARGETS)\
pkg-config check-remote
3 changes: 1 addition & 2 deletions src/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ clobber: clean $(EXTRA_TARGETS_CLOBBER)
$(RM) $(LIB_AR) $(LIB_SO_SONAME) $(LIB_SO_REAL) $(LIB_SO)
$(RM) -r $(objdir)/.deps

cstyle:
$(CSTYLE) *.[ch]
$(eval $(cstyle-rule))

$(objdir)/%.o: %.c
@mkdir -p $(objdir)/.deps
Expand Down
5 changes: 1 addition & 4 deletions src/benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,12 @@ clobber: clean
$(RM) *.csv
$(RM) -r .deps

cstyle:
$(CSTYLE) *.[ch]

$(CONFIGS):
LD_LIBRARY_PATH=$(LIBS_PATH) ./$(BENCHMARK) $@.cfg > $@.csv

run: $(BENCHMARK) $(CONFIGS)

.PHONY: all clean clobber run cstyle $(CONFIGS)
.PHONY: all clean clobber run $(CONFIGS)

PMEMOBJ_SYMBOLS=pmalloc pfree lane_hold lane_release

Expand Down
27 changes: 26 additions & 1 deletion src/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ OBJCOPY = objcopy
MKDIR = mkdir
INSTALL = install
CP = cp
CSTYLE = $(TOP)/utils/cstyle -pP
CSTYLE = $(TOP)/utils/cstyle
STYLE_CHECK = $(TOP)/utils/style_check.sh
PKG_CONFIG = pkg-config

ifeq ($(shell command -v $(PKG_CONFIG) && echo y || echo n), n)
Expand Down Expand Up @@ -83,6 +84,7 @@ export mandir := $(datarootdir)/man
export docdir := $(datarootdir)/doc
export man1dir := $(mandir)/man1
export man3dir := $(mandir)/man3
export cstyle_bin := $(CSTYLE)

ifneq ($(wildcard $(exec_prefix)/x86_64-linux-gnu),)
LIB_PREFIX ?= x86_64-linux-gnu/lib
Expand All @@ -94,6 +96,29 @@ endif

LIB_PREFIX ?= lib

all:

cstyle-%:
$(STYLE_CHECK) $* $(wildcard *.[ch]) $(wildcard *.[ch]pp)

cstyle: cstyle-check

format: cstyle-format

define sub-target-foreach
$(1)-$(2):
$$(MAKE) -C $1 $2
ifeq ($(3),y)
ifeq ($(custom_build),)
$$(MAKE) -C $1 $2 DEBUG=1
endif
endif
endef

define sub-target
$(foreach f, $(1), $(eval $(call sub-target-foreach, $f,$(2),$(3))))
endef

ifneq ($(wildcard $(prefix)/x86_64-linux-gnu),)
INC_PREFIX ?= x86_64-linux-gnu/include
endif
Expand Down
3 changes: 0 additions & 3 deletions src/common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@

TOP := $(dir $(lastword $(MAKEFILE_LIST)))../..
include $(TOP)/src/common.inc

cstyle:
$(CSTYLE) *.[ch]
9 changes: 3 additions & 6 deletions src/examples/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ all-dirs: TARGET = all
clean-dirs: TARGET = clean
clobber-dirs: TARGET = clobber
cstyle-dirs: TARGET = cstyle
format-dirs: TARGET = format

all: $(if $(DIRS), all-dirs) $(if $(LIBRARIES), all-libraries) $(if $(PROGS), all-progs)
clean: $(if $(DIRS), clean-dirs) $(if $(PROGS), clean-progs) $(if $(LIBRARIES), clean-libraries)
clobber: $(if $(DIRS), clobber-dirs) $(if $(PROGS), clobber-progs) $(if $(LIBRARIES), clobber-libraries)
cstyle: $(if $(DIRS), cstyle-dirs)
format: $(if $(DIRS), format-dirs)

DYNAMIC_LIBRARIES = $(addprefix lib, $(addsuffix .so, $(LIBRARIES)))
STATIC_LIBRARIES = $(addprefix lib, $(addsuffix .a, $(LIBRARIES)))

all-dirs clean-dirs clobber-dirs cstyle-dirs: $(DIRS)
all-dirs clean-dirs clobber-dirs cstyle-dirs format-dirs: $(DIRS)
all-progs: $(PROGS)
all-libraries: $(DYNAMIC_LIBRARIES) $(STATIC_LIBRARIES)

Expand All @@ -88,11 +90,6 @@ ifneq ($(LIBRARIES),)
$(RM) $(DYNAMIC_LIBRARIES) $(STATIC_LIBRARIES)
endif

cstyle:
ifneq ($(PROGS)$(LIBRARIES),)
$(CSTYLE) *.[ch]
endif

clean-progs clean-libraries:
$(RM) *.o

Expand Down
21 changes: 10 additions & 11 deletions src/examples/libpmemobj/cpp/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
* Please see pmem.io blog posts for more details.
*/

#include <libpmemobj/persistent_ptr.hpp>
#include <iostream>
#include <libpmemobj/make_persistent.hpp>
#include <libpmemobj/p.hpp>
#include <libpmemobj/transaction.hpp>
#include <libpmemobj/persistent_ptr.hpp>
#include <libpmemobj/pool.hpp>
#include <unistd.h>
#include <libpmemobj/transaction.hpp>
#include <math.h>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <stdexcept>
#include <iostream>
#include <sys/stat.h>
#include <unistd.h>

#define LAYOUT "queue"

Expand All @@ -62,7 +62,7 @@ enum queue_op {
QUEUE_POP,
QUEUE_SHOW,

MAX_QUEUE_OP
MAX_QUEUE_OP,
};

/* queue operations strings */
Expand Down Expand Up @@ -91,16 +91,15 @@ using namespace nvml::obj;
* libpmemobj C++ API. It demonstrates the basic features of persistent_ptr<>
* and p<> classes.
*/
class pmem_queue
{
class pmem_queue {

/* entry in the list */
struct pmem_entry {
persistent_ptr<pmem_entry> next;
p<uint64_t> value;
};

public:
public:
/*
* Inserts a new element at the end of the queue.
*/
Expand Down Expand Up @@ -156,7 +155,7 @@ class pmem_queue
std::cout << n->value << std::endl;
}

private:
private:
persistent_ptr<pmem_entry> head;
persistent_ptr<pmem_entry> tail;
};
Expand Down
Loading

0 comments on commit 26c44c3

Please sign in to comment.