-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
add vs code launch.json auto generation in waf configure #28839
Open
Huibean
wants to merge
1
commit into
ArduPilot:master
Choose a base branch
from
Huibean:pr-add-vs-code-launch-auto-generation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+127
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import os | ||
import json | ||
import shutil | ||
|
||
H7_DUAL_BANK_LIST = [ | ||
"STM32H7A3xx", | ||
"STM32H7A3xxq", | ||
"STM32H7B3xx", | ||
"STM32H7B3xxq", | ||
"STM32H742xx", | ||
"STM32H743xx", | ||
"STM32H745xg", | ||
"STM32H745xx", | ||
"STM32H747xg", | ||
"STM32H747xx", | ||
"STM32H753xx", | ||
"STM32H755xx", | ||
"STM32H755xx", | ||
"STM32H757xx", | ||
] # List of H7 boards with dual bank | ||
|
||
ELF_NAME_MAPPING = { | ||
'copter': 'arducopter', | ||
'plane': 'arduplane', | ||
'rover': 'ardurover', | ||
'sub': 'ardusub', | ||
'blimp': 'blimp', | ||
'antennatracker': 'antennatracker', | ||
'bootloader': 'AP_Bootloader', | ||
'AP_Periph': 'AP_Periph', | ||
} | ||
|
||
def update_settings(bld): | ||
if not bld.cmd in ELF_NAME_MAPPING: | ||
return | ||
board_name = bld.env.BOARD | ||
elf_file_name = ELF_NAME_MAPPING.get(bld.cmd, bld.cmd) | ||
if elf_file_name == 'ap_bootloader': | ||
elf_file_path = os.path.join("${workspaceFolder}", "build", board_name, "bootloader", elf_file_name) | ||
else: | ||
elf_file_path = os.path.join("${workspaceFolder}", "build", board_name, "bin", elf_file_name) | ||
vscode_setting_json_path = os.path.join(bld.srcnode.abspath(), '.vscode', 'settings.json') | ||
|
||
if not os.path.exists(vscode_setting_json_path): | ||
with open(vscode_setting_json_path, 'w') as f: | ||
json.dump({}, f, indent=4) | ||
|
||
try: | ||
with open(vscode_setting_json_path, 'r') as f: | ||
content = f.read().strip() | ||
if content: | ||
settings_json = json.loads(content) | ||
else: | ||
settings_json = {} | ||
except json.JSONDecodeError: | ||
print(f"VS-LAUNCH: \033[91m Error: invalid JSON in .vscode/settings.json, please fix it and try again.\033[0m") | ||
return | ||
|
||
settings_json['wscript.elf_file_path'] = elf_file_path | ||
settings_json['wscript.board'] = board_name | ||
if board_name == 'sitl': | ||
if os.uname().sysname == 'Darwin': | ||
settings_json['wscript.MIMode'] = "lldb" | ||
else: | ||
settings_json['wscript.MIMode'] = "gdb" | ||
|
||
with open(vscode_setting_json_path, 'w') as f: | ||
json.dump(settings_json, f, indent=4) | ||
|
||
def update_openocd_cfg(cfg): | ||
if cfg.options.board != 'sitl': | ||
openocd_cfg_path = os.path.join(cfg.srcnode.abspath(), 'build', cfg.options.board, 'openocd.cfg') | ||
mcu_type = cfg.env.get_flat('APJ_BOARD_TYPE') | ||
openocd_target = '' | ||
if mcu_type.startswith("STM32H7"): | ||
if mcu_type in H7_DUAL_BANK_LIST: | ||
openocd_target = 'stm32h7_dual_bank.cfg' | ||
else: | ||
openocd_target = 'stm32h7x.cfg' | ||
elif mcu_type.startswith("STM32F7"): | ||
openocd_target = 'stm32f7x.cfg' | ||
elif mcu_type.startswith("STM32F4"): | ||
openocd_target = 'stm32f4x.cfg' | ||
elif mcu_type.startswith("STM32F3"): | ||
openocd_target = 'stm32f3x.cfg' | ||
elif mcu_type.startswith("STM32L4"): | ||
openocd_target = 'stm32l4x.cfg' | ||
elif mcu_type.startswith("STM32G4"): | ||
openocd_target = 'stm32g4x.cfg' | ||
|
||
if openocd_target: | ||
with open(openocd_cfg_path, 'w+') as f: | ||
f.write("source [find interface/stlink.cfg]\n") | ||
f.write(f"source [find target/{openocd_target}]\n") | ||
f.write("init\n") | ||
f.write("$_TARGETNAME configure -rtos auto\n") | ||
|
||
def init_launch_json_if_not_exist(cfg): | ||
launch_json_path = os.path.join(cfg.srcnode.abspath(), '.vscode', 'launch.json') | ||
launch_default_json_path = os.path.join(cfg.srcnode.abspath(),'.vscode', 'launch.default.json') | ||
|
||
if not os.path.exists(launch_json_path): | ||
if os.path.exists(launch_default_json_path): | ||
print(f"Copying {launch_default_json_path} to {launch_json_path}") | ||
shutil.copy(launch_default_json_path, launch_json_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to use something that supports comments. Something like this: https://github.com/Kijewski/pyjson5
Otherwise, you will pretty much always get a parse failure and will delete the user's existing launch.json.