Commit dc80fa4d authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Merge branch '121-enforce-code-format' into 'master'

Resolve "Enforce code format"

In discussion with all developers, we decided on a code style, reflected by `clang-format`. The push includes the following changes:

- `clang-format` is now mandatory for development and code must be properly formatted to be able to push to master
- A check if the code is properly formatted by the given `.clang-format` style file, is now part of the CI pipeline test
- The style file was tested on version 10 and 12 with the style file adhering to version 10.
- A new script `scripts/check_format.sh` has been added which is used by CI but can also be used by the user for two tasks:
    - Check if any files need to be formatted
    - Pass `-r` to reformat all files in place with `clang-format`
- All code has been reformatted to the decided style 


Closes #121

See merge request hpc/gekkofs!66
parents c47e1f4c 3ef516c3
Loading
Loading
Loading
Loading
Loading

.clang-format

0 → 100644
+73 −0
Original line number Diff line number Diff line
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: All
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
  AfterCaseLabel: false
  AfterClass: false
  AfterControlStatement: Never
  AfterEnum: false
  AfterFunction: false
  AfterNamespace: false
  AfterUnion: false
  BeforeCatch: false
  BeforeElse: false
  IndentBraces: false
  SplitEmptyFunction: false
  SplitEmptyRecord: true
  SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: false
ColumnLimit: 80
CompactNamespaces: false
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
FixNamespaceComments: true
# IncludeBlocks? TODO
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++14
TabWidth: 4
UseTab: Never
+6 −0
Original line number Diff line number Diff line
stages:
  - check format
  - download deps
  - build deps
  - build
@@ -25,6 +26,11 @@ variables:

image: gekkofs/gekkofs:build_env-0.8.0

check format:
  stage: check format
  script:
    - ${CI_PROJECT_DIR}/scripts/check_format.sh -s "${CI_PROJECT_DIR}/src" -i "${CI_PROJECT_DIR}/src"

compile dependencies:
  stage: build deps
  cache:
+12 −1
Original line number Diff line number Diff line
@@ -41,8 +41,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
		python3-dev \
		python3-venv \
		expect \
		# clang 10 deps
		lsb-release \
		wget \
		software-properties-common \
		gnupg2 \
# add clang-10 repos
&& wget https://apt.llvm.org/llvm.sh -P /tmp && chmod +x /tmp/llvm.sh && /tmp/llvm.sh 10 \
# install clang-format
&& apt-get update && apt-get install -y --no-install-recommends clang-format-10 \
# Clean apt cache to reduce image layer size
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* && rm /tmp/llvm.sh \
# Clean apt caches of packages
&& apt-get clean && apt-get autoclean

## COPY scripts/dl_dep.sh		$SCRIPTS_PATH/
## COPY scripts/compile_dep.sh $SCRIPTS_PATH/
+6 −7
Original line number Diff line number Diff line
@@ -43,4 +43,3 @@ static constexpr auto FORWARDING_MAP_FILE = ADD_PREFIX("FORWARDING_MAP_FILE");
#undef ADD_PREFIX

#endif // GKFS_CLIENT_ENV
+71 −38
Original line number Diff line number Diff line
@@ -25,81 +25,114 @@ struct linux_dirent64;
namespace gkfs {
namespace syscall {

int gkfs_open(const std::string& path, mode_t mode, int flags);
int
gkfs_open(const std::string& path, mode_t mode, int flags);

int gkfs_create(const std::string& path, mode_t mode);
int
gkfs_create(const std::string& path, mode_t mode);

int gkfs_remove(const std::string& path);
int
gkfs_remove(const std::string& path);

// Implementation of access,
// Follow links is true by default
int gkfs_access(const std::string& path, int mask, bool follow_links = true);
int
gkfs_access(const std::string& path, int mask, bool follow_links = true);

// Implementation of stat,
// Follow links is true by default
int gkfs_stat(const std::string& path, struct stat* buf, bool follow_links = true);
int
gkfs_stat(const std::string& path, struct stat* buf, bool follow_links = true);

// Implementation of statx, it uses the normal stat and maps the information to the statx structure
// Follow links is true by default 
// Implementation of statx, it uses the normal stat and maps the information to
// the statx structure Follow links is true by default
#ifdef STATX_TYPE

int gkfs_statx(int dirfd, const std::string& path, int flags, unsigned int mask, struct statx* buf,
               bool follow_links = true);
int
gkfs_statx(int dirfd, const std::string& path, int flags, unsigned int mask,
           struct statx* buf, bool follow_links = true);

#endif

int gkfs_statfs(struct statfs* buf);
int
gkfs_statfs(struct statfs* buf);

int gkfs_statvfs(struct statvfs* buf);
int
gkfs_statvfs(struct statvfs* buf);

off64_t gkfs_lseek(unsigned int fd, off64_t offset, unsigned int whence);
off64_t
gkfs_lseek(unsigned int fd, off64_t offset, unsigned int whence);

off64_t gkfs_lseek(std::shared_ptr<gkfs::filemap::OpenFile> gkfs_fd, off64_t offset, unsigned int whence);
off64_t
gkfs_lseek(std::shared_ptr<gkfs::filemap::OpenFile> gkfs_fd, off64_t offset,
           unsigned int whence);

int gkfs_truncate(const std::string& path, off_t offset);
int
gkfs_truncate(const std::string& path, off_t offset);

int gkfs_truncate(const std::string& path, off_t old_size, off_t new_size);
int
gkfs_truncate(const std::string& path, off_t old_size, off_t new_size);

int gkfs_dup(int oldfd);
int
gkfs_dup(int oldfd);

int gkfs_dup2(int oldfd, int newfd);
int
gkfs_dup2(int oldfd, int newfd);

#ifdef HAS_SYMLINKS

int gkfs_mk_symlink(const std::string& path, const std::string& target_path);
int
gkfs_mk_symlink(const std::string& path, const std::string& target_path);

int gkfs_readlink(const std::string& path, char* buf, int bufsize);
int
gkfs_readlink(const std::string& path, char* buf, int bufsize);

#endif

ssize_t gkfs_pwrite(std::shared_ptr<gkfs::filemap::OpenFile> file,
                    const char* buf, size_t count, off64_t offset);
ssize_t
gkfs_pwrite(std::shared_ptr<gkfs::filemap::OpenFile> file, const char* buf,
            size_t count, off64_t offset);

ssize_t gkfs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset);
ssize_t
gkfs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset);

ssize_t gkfs_write(int fd, const void* buf, size_t count);
ssize_t
gkfs_write(int fd, const void* buf, size_t count);

ssize_t gkfs_pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset);
ssize_t
gkfs_pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset);

ssize_t gkfs_writev(int fd, const struct iovec* iov, int iovcnt);
ssize_t
gkfs_writev(int fd, const struct iovec* iov, int iovcnt);

ssize_t gkfs_pread(std::shared_ptr<gkfs::filemap::OpenFile> file, char* buf, size_t count, off64_t offset);
ssize_t
gkfs_pread(std::shared_ptr<gkfs::filemap::OpenFile> file, char* buf,
           size_t count, off64_t offset);

ssize_t gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset);
ssize_t
gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset);

ssize_t gkfs_read(int fd, void* buf, size_t count);
ssize_t
gkfs_read(int fd, void* buf, size_t count);

ssize_t gkfs_readv(int fd, const struct iovec* iov, int iovcnt);
ssize_t
gkfs_readv(int fd, const struct iovec* iov, int iovcnt);

ssize_t gkfs_preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset);
ssize_t
gkfs_preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset);

int gkfs_opendir(const std::string& path);
int
gkfs_opendir(const std::string& path);

int gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count);
int
gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count);

int gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp, unsigned int count);
int
gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp,
                unsigned int count);

int gkfs_rmdir(const std::string& path);
int
gkfs_rmdir(const std::string& path);

} // namespace syscall
} // namespace gkfs
Loading