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

Miscellaneous keyboard.json migrations #23486

Merged
merged 1 commit into from
Apr 13, 2024
Merged

Miscellaneous keyboard.json migrations #23486

merged 1 commit into from
Apr 13, 2024

Conversation

zvecr
Copy link
Member

@zvecr zvecr commented Apr 12, 2024

Description

Migrations preparing for post #22891 where these rules.mk files are now redundant.

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 | wc -l)
    enables=$(grep -c _ENABLE $rule)
    lto=$(grep -c LTO_ENABLE $rule)
    if [[ $lines == 0 && $lto == 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
            km_json=$(dirname -- $rule)/keyboard.json
            parent_rule=$(dirname -- $rule)/../rules.mk
            if [[ -f $info && ! -f $parent_rule ]]; 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 ) )

                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"
                elif grep -q '"matrix_pins"' $info; then
                    git mv $info $km_json
                    sed -i "/\"matrix_pins\"/i\\${temp}" $km_json
                    git add $km_json

                    git rm $rule
                elif grep -q '"usb"' $info; then
                    git mv $info $km_json
                    sed -i "/\"usb\"/i\\${temp}" $km_json
                    git add $km_json

                    git rm $rule
                else
                    echo "$info needs manual moving"
                fi
            fi
        fi
    fi
done

Note: injected location isn't always perfect, but hopefully soon we can mass format the entire repo.

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 requested a review from a team April 12, 2024 18:42
@zvecr zvecr force-pushed the migrate_rules_mk12 branch 2 times, most recently from 967d2c2 to 1e45d1a Compare April 13, 2024 05:34
@zvecr zvecr force-pushed the migrate_rules_mk12 branch from 1e45d1a to f0b6846 Compare April 13, 2024 05:40
@zvecr zvecr merged commit 2eea2cd into develop Apr 13, 2024
1 of 3 checks passed
@zvecr zvecr deleted the migrate_rules_mk12 branch April 13, 2024 07:45
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