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 from rules.mk to data driven - IJK #23276

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Conversation

zvecr
Copy link
Member

@zvecr zvecr commented Mar 14, 2024

Description

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

Script used

for rule in $(find keyboards/{i,j,k}* -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 changed the title Migrate features from rules.mk to DD - IJK Migrate features from rules.mk to data driven - IJK Mar 14, 2024
@zvecr zvecr requested a review from a team March 14, 2024 04:14
@zvecr zvecr merged commit 539fa21 into develop Mar 15, 2024
2 of 3 checks passed
@zvecr zvecr deleted the migrate_rules_mk4 branch March 15, 2024 01:42
mechlovin pushed a commit to mechlovin/qmk_firmware that referenced this pull request Apr 4, 2024
mechlovin pushed a commit to mechlovin/qmk_firmware that referenced this pull request Apr 4, 2024
mechlovin pushed a commit to mechlovin/qmk_firmware that referenced this pull request Apr 15, 2024
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.

3 participants