~aleteoryx/muditaos

7e06b0e413ed017eb815f420eeab1293da41cd03 — Mateusz Piesta 3 years ago 10553e0
[MOS-000] Add clang-format support for macOS

* clang-format tools are now correctly fetched
* Fixed some macOS specific issues in bash scripts
2 files changed, 9 insertions(+), 9 deletions(-)

M config/clang/clang-common.sh
M config/style_check_hook.sh
M config/clang/clang-common.sh => config/clang/clang-common.sh +8 -8
@@ 7,11 7,9 @@ set -eo pipefail
verify_clang_format_version()
{
    # check if clang-format in path is in proper version, version is 3rd column in `clang-format --version`
    local clang_format
    clang_format=$( find  /usr/bin/ -regextype egrep -regex ".*/clang-format(-[0-9][0-9])?")
    local clang_format=$(get_clang_format)
    local version
    version=$( [[ $(which $clang_format) ]] && ($clang_format --version | sed "s/.*version \([^ ]*\).*$/\1/" |  cut -d'.' -f1) || echo "0")
    echo $version
    version=$( [[ $clang_format ]] && ($clang_format --version | sed "s/.*version \([^ ]*\).*$/\1/" |  cut -d'.' -f1) || echo "0")
    # check for either clang-format or clang-format-11
    if [[ $version -lt 11 ]]; then
        cat << EOF >&1


@@ 48,10 46,10 @@ get_tool() {
    echo "${tool}"
}

## Search for clang-format.py
## Search for clang-format
get_clang_format() {
    local searchpaths=(
        "$(which "clang-format" 2>/dev/null 1>/dev/null)"  # clang-format in path
        "$(which "clang-format" 2>/dev/null)"  # clang-format in path
        "/usr/bin/clang-format-*"
    )
    get_tool "clang-format" "${searchpaths[@]}"


@@ 60,9 58,10 @@ get_clang_format() {
## Search for clang-format-diff.py
get_clang_format_diff() {
    local searchpaths=(
        "$(which "clang-format-diff.py" 2>/dev/null 1>/dev/null)"  # clang-format-diff in path
        "$(which "clang-format-diff.py" 2>/dev/null)"              # clang-format-diff in path
        "/usr/share/clang/clang-format-*/clang-format-diff.py"     # clang-format-diff location on Ubuntu/Debian
        "/usr/share/clang/clang-format-diff.py"                    # clang-format_diff location on Arch last resort
        "/opt/homebrew/opt/llvm/share/clang/clang-format-diff.py"  # macOS
    )
    get_tool "clang-format-diff.py" "${searchpaths[@]}"
}


@@ 71,11 70,12 @@ get_clang_format_diff() {
get_clang_tidy_diff()
{
    local searchpaths=(
        "$(which "clang-tidy-diff.py" 2>/dev/null 1>/dev/null)"  # clang-format-diff in path
        "$(which "clang-tidy-diff.py" 2>/dev/null)"              # clang-format-diff in path
        "/usr/bin/clang-tidy-diff-10.py"                         # clang-format-diff location on Ubuntu
        "/usr/bin/clang-tidy-diff-12.py"
        "/usr/share/clang/clang-tidy-*/clang-tidy-diff.py"       # clang-format-diff location on Debian
        "/usr/share/clang/clang-tidy-diff.py"                    # clang-format_diff location on Arch last resort
        "/opt/homebrew/opt/llvm/share/clang/clang-tidy-diff.py"  # macOS
    )
    get_tool "clang-tidy-diff.py" "${searchpaths[@]}"
}

M config/style_check_hook.sh => config/style_check_hook.sh +1 -1
@@ 1,4 1,4 @@
#!/bin/bash 
#!/usr/bin/env bash
# Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md