diff --git a/.gitignore b/.gitignore index 3b1f85b10..57f0179c2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ /*.dsc /*.xz /*.gz +/venv __pycache__ plugins/acpi-dmar/tests/ plugins/acpi-facp/tests/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..fe9b899b7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,37 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: no-commit-to-branch + args: [--branch, master, --pattern, 1_.*_X] + - id: check-yaml + - id: check-json + - id: check-symlinks + - id: check-xml + - id: end-of-file-fixer + types_or: [c, shell, python] + - id: trailing-whitespace + types_or: [c, shell, python] + - id: check-docstring-first + - id: check-merge-conflict + - id: mixed-line-ending + args: [--fix=lf] +- repo: https://github.com/ambv/black + rev: 20.8b1 + hooks: + - id: black +- repo: local + hooks: + - id: check-deprecated + name: check for use of any deprecated items + language: script + entry: ./contrib/ci/check-deprecated.sh + - id: check-null-false-returns + name: check for null / false return mistmatch + language: script + entry: ./contrib/ci/check-null-false-returns.py + - id: shellcheck + name: check shellscript style + language: system + entry: shellcheck --severity=error -e SC2068 + types: [shell] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 71a93a6fd..2f8fa01cf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,16 @@ +Getting started +=============== +To set up your local environment, from the top level of the checkout run +``` +./contrib/setup +``` + +This will create pre-commit hooks to fixup many code style issues before your +code is submitted. + +On some Linux distributions this will install all build dependencies needed +to compile fwupd as well. + Coding Style ============ diff --git a/contrib/ci/check-deprecated.sh b/contrib/ci/check-deprecated.sh new file mode 100755 index 000000000..78b0d1915 --- /dev/null +++ b/contrib/ci/check-deprecated.sh @@ -0,0 +1,15 @@ +#!/bin/sh -e +set -e + +# these are deprecated in favor of INTERNAL flags +deprecated="FWUPD_DEVICE_FLAG_NO_AUTO_INSTANCE_IDS + FWUPD_DEVICE_FLAG_ONLY_SUPPORTED + FWUPD_DEVICE_FLAG_MD_SET_NAME + FWUPD_DEVICE_FLAG_MD_SET_VERFMT + FWUPD_DEVICE_FLAG_NO_GUID_MATCHING + FWUPD_DEVICE_FLAG_MD_SET_ICON" +for val in $deprecated; do + if grep -- $val plugins/*/*.c ; then + exit 1 + fi +done diff --git a/contrib/setup b/contrib/setup new file mode 100755 index 000000000..3b0b92880 --- /dev/null +++ b/contrib/setup @@ -0,0 +1,41 @@ +#!/bin/bash -e +# Setup the repository. + +cd "$(dirname "$0")/.." + +# Add default vscode settings if not existing +SETTINGS_FILE=./.vscode/settings.json +SETTINGS_TEMPLATE_FILE=./contrib/vscode/settings.json +if [ ! -f "$SETTINGS_FILE" ]; then + mkdir ./.vscode + echo "Copy $SETTINGS_TEMPLATE_FILE to $SETTINGS_FILE." + cp "$SETTINGS_TEMPLATE_FILE" "$SETTINGS_FILE" +fi + +#if interactive install build deps +if [ -n "$PS1" ] || [[ $- == *i* ]] || [ -f /dev/.cros_milestone ]; then + read -p "Install build dependencies? (y/n) " question + if [ "$question" = "y" ]; then + DEPS=$(./contrib/ci/generate_dependencies.py) + if ! which shellcheck >/dev/null 2>&1; then + DEPS="$DEPS shellcheck" + fi + OS=$(python3 -c "import distro; print(distro.linux_distribution()[0].split()[0].lower())") + if [ "$OS" = "debian" ] || [ "$OS" = "ubuntu" ]; then + if ! python3 -c "import venv"; then + DEPS="python3-venv" + fi + sudo apt install $DEPS + elif [ "$OS" = "fedora" ]; then + sudo dnf install $DEPS + elif [ "$OS" = "arch" ]; then + pacman -Syu --noconfirm --needed $DEPS + fi + fi +fi + +python3 -m venv venv +source venv/bin/activate + +python3 -m pip install pre-commit +pre-commit install diff --git a/contrib/vscode/settings.json b/contrib/vscode/settings.json new file mode 100644 index 000000000..2d7962155 --- /dev/null +++ b/contrib/vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.tabSize": 8, + "mesonbuild.buildFolder": "build" +}