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 - 0-9 #23202

Merged
merged 1 commit into from
Mar 14, 2024
Merged

Conversation

zvecr
Copy link
Member

@zvecr zvecr commented Mar 3, 2024

Description

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

Script used

for rule in $(find keyboards/{0,1,2,3,4,5,6,7,8,9}* -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).

Copy link
Member

@noroadsleft noroadsleft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistically, I think I'd prefer to have a subset of features that are always present in features even if disabled, and then other features be present only if enabled, but if the collaborators have a preference for going minimal all the time, I'm okay with that.

@zvecr zvecr force-pushed the migrate_rules_mk1 branch 2 times, most recently from 5e77861 to bd114d0 Compare March 9, 2024 05:31
@zvecr zvecr changed the title Migrate features from rules.mk to info.json Migrate features from rules.mk to info.json - 0-9 Mar 9, 2024
@zvecr zvecr changed the title Migrate features from rules.mk to info.json - 0-9 Migrate features from rules.mk to data driven - 0-9 Mar 10, 2024
@zvecr zvecr merged commit f1a2798 into develop Mar 14, 2024
2 of 3 checks passed
@zvecr zvecr deleted the migrate_rules_mk1 branch March 14, 2024 03:57
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
0x647262 pushed a commit to 0x647262/qmk_firmware that referenced this pull request Apr 26, 2024
PepperLola pushed a commit to PepperLola/qmk_firmware that referenced this pull request May 29, 2024
whoisjordangarcia pushed a commit to whoisjordangarcia/qmk_firmware that referenced this pull request Jun 8, 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.

None yet

2 participants