| 86 | |
| 87 | # 定义后处理动作 |
| 88 | def write_compile_commands(target, source, env): |
| 89 | print("\n=> [DEBUG] Entering write_compile_commands callback") |
| 90 | print(f" Target: {target}") |
| 91 | print(f" Source: {source}") |
| 92 | |
| 93 | output_path = env.get('COMPILE_COMMANDS_OUT', 'compile_commands.json') |
| 94 | compile_commands = env.get('COMPILE_COMMANDS', []) |
| 95 | |
| 96 | try: |
| 97 | if not compile_commands: |
| 98 | print("Warning: No compile commands collected, skipping file generation") |
| 99 | return |
| 100 | |
| 101 | print(f"\n=> Writing compile_commands.json ({len(compile_commands)} entries)") |
| 102 | with open(output_path, 'w') as f: |
| 103 | json.dump(compile_commands, f, indent=2) |
| 104 | print(f"=> Successfully generated: {os.path.abspath(output_path)}") |
| 105 | |
| 106 | except PermissionError: |
| 107 | print(f"\nError: Permission denied when writing to {output_path}") |
| 108 | print("Please check file permissions and try again") |
| 109 | except Exception as e: |
| 110 | print(f"\nError writing compile_commands.json: {str(e)}") |
| 111 | import traceback |
| 112 | traceback.print_exc() |
| 113 | |
| 114 | # 使用None作为目标以确保总是执行 |
| 115 | print("=> Adding post-build action for compile_commands generation") |