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 #23302

Merged
merged 2 commits into from
Mar 30, 2024
Merged

Conversation

zvecr
Copy link
Member

@zvecr zvecr commented Mar 17, 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 == 1 && $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 ) )

                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
                    git mv -f $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 -f $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 force-pushed the migrate_rules_mk10 branch from eaa95bc to 0f6a6b2 Compare March 17, 2024 00:54
@zvecr zvecr force-pushed the migrate_rules_mk10 branch from 0f6a6b2 to 349e928 Compare March 17, 2024 00:56
@github-actions github-actions bot added python cli qmk cli command labels Mar 17, 2024
@zvecr zvecr merged commit 426bb9c into develop Mar 30, 2024
4 of 6 checks passed
@zvecr zvecr deleted the migrate_rules_mk10 branch March 30, 2024 10:43
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
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