mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-08 05:31:25 +00:00
Start of generating json manifest of macros in userPrefs.h (#4946)
* Start of generating json manifest for userPrefs.h * Just trunk this for now * Add automatic generation of json manifest in GH action * Trunk
This commit is contained in:
parent
0952d1b252
commit
a3a97d3025
33
.github/workflows/generate-userprefs.yml
vendored
Normal file
33
.github/workflows/generate-userprefs.yml
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- userPrefs.h
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
generate-userprefs:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Clang
|
||||||
|
run: sudo apt-get install -y clang
|
||||||
|
|
||||||
|
- name: Install trunk
|
||||||
|
run: curl https://get.trunk.io -fsSL | bash
|
||||||
|
|
||||||
|
- name: Generate userPrefs.jsom
|
||||||
|
run: python3 ./bin/build-userprefs-json.py
|
||||||
|
|
||||||
|
- name: Trunk format json
|
||||||
|
run: trunk format userPrefs.json
|
||||||
|
|
||||||
|
- name: Commit userPrefs.json
|
||||||
|
run: |
|
||||||
|
git config --global user.email "actions@github.com"
|
||||||
|
git config --global user.name "GitHub Actions"
|
||||||
|
git add userPrefs.json
|
||||||
|
git commit -m "Update userPrefs.json"
|
||||||
|
git push
|
48
bin/build-userprefs-json.py
Normal file
48
bin/build-userprefs-json.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import re
|
||||||
|
|
||||||
|
def get_macros_from_header(header_file):
|
||||||
|
# Run clang to preprocess the header file and capture the output
|
||||||
|
result = subprocess.run(['clang', '-E', '-dM', header_file], capture_output=True, text=True)
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise RuntimeError(f"Clang preprocessing failed: {result.stderr}")
|
||||||
|
|
||||||
|
# Extract macros from the output
|
||||||
|
macros = {}
|
||||||
|
macro_pattern = re.compile(r'#define\s+(\w+)\s+(.*)')
|
||||||
|
for line in result.stdout.splitlines():
|
||||||
|
match = macro_pattern.match(line)
|
||||||
|
if match and 'USERPREFS_' in line and '_USERPREFS_' not in line:
|
||||||
|
macros[match.group(1)] = match.group(2)
|
||||||
|
|
||||||
|
return macros
|
||||||
|
|
||||||
|
def write_macros_to_json(macros, output_file):
|
||||||
|
with open(output_file, 'w') as f:
|
||||||
|
json.dump(macros, f, indent=4)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
header_file = 'userPrefs.h'
|
||||||
|
output_file = 'userPrefs.json'
|
||||||
|
# Uncomment all macros in the header file
|
||||||
|
with open(header_file, 'r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
|
||||||
|
uncommented_lines = []
|
||||||
|
for line in lines:
|
||||||
|
stripped_line = line.strip().replace('/*', '').replace('*/', '')
|
||||||
|
if stripped_line.startswith('//') and 'USERPREFS_' in stripped_line:
|
||||||
|
# Replace "//"
|
||||||
|
stripped_line = stripped_line.replace('//', '')
|
||||||
|
uncommented_lines.append(stripped_line + '\n')
|
||||||
|
|
||||||
|
with open(header_file, 'w') as file:
|
||||||
|
for line in uncommented_lines:
|
||||||
|
file.write(line)
|
||||||
|
macros = get_macros_from_header(header_file)
|
||||||
|
write_macros_to_json(macros, output_file)
|
||||||
|
print(f"Macros have been written to {output_file}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
16
userPrefs.json
Normal file
16
userPrefs.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"USERPREFS_CHANNEL_0_NAME": "\"DEFCONnect\"",
|
||||||
|
"USERPREFS_CHANNEL_0_PRECISION": "14",
|
||||||
|
"USERPREFS_CHANNEL_0_PSK": "{ 0x38, 0x4b, 0xbc, 0xc0, 0x1d, 0xc0, 0x22, 0xd1, 0x81, 0xbf, 0x36, 0xb8, 0x61, 0x21, 0xe1, 0xfb, 0x96, 0xb7, 0x2e, 0x55, 0xbf, 0x74, 0x22, 0x7e, 0x9d, 0x6a, 0xfb, 0x48, 0xd6, 0x4c, 0xb1, 0xa1 }",
|
||||||
|
"USERPREFS_CONFIG_LORA_IGNORE_MQTT": "true",
|
||||||
|
"USERPREFS_CONFIG_LORA_REGION": "meshtastic_Config_LoRaConfig_RegionCode_US",
|
||||||
|
"USERPREFS_CONFIG_OWNER_LONG_NAME": "\"My Long Name\"",
|
||||||
|
"USERPREFS_CONFIG_OWNER_SHORT_NAME": "\"MLN\"",
|
||||||
|
"USERPREFS_EVENT_MODE": "1",
|
||||||
|
"USERPREFS_HAS_SPLASH": "",
|
||||||
|
"USERPREFS_LORACONFIG_CHANNEL_NUM": "31",
|
||||||
|
"USERPREFS_LORACONFIG_MODEM_PRESET": "meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST",
|
||||||
|
"USERPREFS_SPLASH_TITLE": "\"DEFCONtastic\"",
|
||||||
|
"USERPREFS_TZ_STRING": "\"tzplaceholder \"",
|
||||||
|
"USERPREFS_USE_ADMIN_KEY": "1"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user