Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate features and LTO from rules.mk to data driven #23307

Merged
merged 1 commit into from
Mar 30, 2024

Conversation

zvecr
Copy link
Member

@zvecr zvecr commented Mar 18, 2024

Description

Migrate those with DEFAULT_FOLDER at the same level as an info.json

Script used

for rule in $(find keyboards/ -name rules.mk | grep -v keymaps); do
    # ignore blank lines, comments -> count lines that are not feature enables
    lines=$(cat $rule | grep . | grep -Ev "^#.*" | grep -v _ENABLE | grep -v DEFAULT_FOLDER | wc -l)
    enables=$(grep -c _ENABLE $rule)
    lto=$(grep -c LTO_ENABLE $rule)
    default_folder=$(grep DEFAULT_FOLDER $rule)
    if [[ ! -z "$default_folder" && $lines == 0 && $enables > 0 ]]; then
        features=$(cat $rule | grep _ENABLE | grep -v LTO | grep -Ev "^#.*" | grep yes | sed 's/_ENABLE.*//' | tr '[:upper:]' '[:lower:]')
        if [[ ! -z "$features" ]]; then
            info=$(dirname -- $rule)/info.json
            if [[ -f $info ]]; then

                # guess indentation
                IND="  "
                if grep -q '    "matrix_pins"' $info; then
                    IND="    "
                fi
                if grep -q '    "usb"' $info; then
                    IND="    "
                fi

                declare -A updates=( ["bootmagic"]="false" ["command"]="false" ["console"]="false" ["extrakey"]="false" ["mousekey"]="false" ["nkro"]="false")

                for feature in $features; do
                    updates[$feature]='true'
                done

                # manually handle space saving options
                if [[ ! -z "$(cat $rule | grep '^GRAVE_ESC_ENABLE' | grep 'no')" ]]; then
                    updates["grave_esc"]='false'
                fi
                if [[ ! -z "$(cat $rule | grep '^MAGIC_ENABLE' | grep 'no')" ]]; then
                    updates["magic"]='false'
                fi
                if [[ ! -z "$(cat $rule | grep '^SPACE_CADET_ENABLE' | grep 'no')" ]]; then
                    updates["space_cadet"]='false'
                fi

                keys=( $( echo ${!updates[@]} | tr ' ' $'\n' | sort ) )

                if grep LTO_ENABLE $rule | grep -q yes; then
                temp="$IND\"build\": {\n"
                temp+="$IND$IND\"lto\": true\n"
                temp+="$IND},\n"
                else
                temp=""
                fi
                temp+="$IND\"features\": {\n"
                for key in ${keys[@]}; do
                    value="${updates[$key]}"
                    temp+="$IND$IND\"$key\": $value,\n"
                done
                temp="${temp::-3}\n"
                temp+="$IND},"

                if grep -q '"features"' $info; then
                    echo "$info needs manual merge - feature"
                elif grep -q '"build"' $info; then
                    echo "$info needs manual merge - build"
                elif grep -q '"matrix_pins"' $info; then
                    sed -i "/\"matrix_pins\"/i\\${temp}" $info
                    git add $info

                    echo "$default_folder" > $rule
                    git add $rule
                elif grep -q '"usb"' $info; then
                    sed -i "/\"usb\"/i\\${temp}" $info
                    git add $info

                    echo "$default_folder" > $rule
                    git add $rule
                else
                    echo "$info needs manual moving"
                fi
            fi
        fi
    fi
done

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@zvecr zvecr merged commit 1c8e99c into develop Mar 30, 2024
2 of 3 checks passed
@zvecr zvecr deleted the migrate_rules_mk11 branch March 30, 2024 10:57
whoisjordangarcia pushed a commit to whoisjordangarcia/qmk_firmware that referenced this pull request Jun 8, 2024
nuess0r pushed a commit to nuess0r/qmk_firmware that referenced this pull request Sep 8, 2024
Ardakilic pushed a commit to Ardakilic/qmk_firmware that referenced this pull request Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants