Skip to main content

A comprehensive Rust project analyzer for Solana development

Project description

Solana Analyzer

一个用于分析 Solana/Rust 项目的 Python 包,基于 rust-analyzer 提供强大的代码分析功能。

功能特性

  • 符号查找: 在 Rust 项目中查找特定符号(函数、结构体等)
  • 结构体分析: 分析项目中的所有结构体定义
  • 调用图分析: 生成函数调用关系图
  • 多种使用方式: 支持 Python API 和命令行接口

安装

1. 构建 rust-analyzer

cargo build --release

2. 安装 Python 包

pip install -e .

使用方法

Python API

from solana_fcg_tool import SolanaAnalyzer

# 创建分析器实例
analyzer = SolanaAnalyzer("/path/to/your/rust/project")

# 查找符号
symbols = analyzer.find_symbols("main")

# 分析结构体
structs = analyzer.analyze_structs()

# 分析调用图
call_graph = analyzer.analyze_call_graph()

便捷函数

from solana_fcg_tool import find_symbols, analyze_structs, analyze_call_graph

# 直接使用便捷函数
symbols = find_symbols("/path/to/project", "main")
structs = analyze_structs("/path/to/project")
call_graph = analyze_call_graph("/path/to/project")

命令行接口

# 查找符号
solana-fcg-tool source-finder main /path/to/project

# 分析结构体
solana-fcg-tool struct-analyzer /path/to/project

# 分析调用图
solana-fcg-tool call-graph /path/to/project

示例

运行示例代码:

python example_usage.py

项目结构

RustGraph/
├── solana_fcg_tool/          # Python 包源码
│   ├── __init__.py          # 包初始化和 API 导出
│   ├── cli.py               # 命令行接口
│   ├── interface.py         # 核心分析器类
│   └── ...
├── crates/                  # Rust 源码
│   └── rust-analyzer/       # rust-analyzer 可执行文件
├── lib/                     # 依赖库
├── setup.py                 # 包配置
├── pyproject.toml          # 现代 Python 包配置
└── example_usage.py        # 使用示例

依赖关系

  • Python: >= 3.7
  • Rust: 用于构建 rust-analyzer
  • rust-analyzer: 核心分析引擎

开发

安装

pip install -e .

重新构建

# 重新构建 rust-analyzer
cargo build --release

# 重新安装包
pip install -e . --force-reinstall

测试

python example_usage.py

故障排除

常见问题

  1. rust-analyzer 未找到

    • 确保已运行 cargo build --release
    • 检查 target/release/rust-analyzer 是否存在
  2. 导入错误

    • 确保包已正确安装:pip list | grep solana-fcg-tool
    • 尝试重新安装:pip install -e . --force-reinstall
  3. 权限问题

    • 确保 rust-analyzer 二进制文件有执行权限
    • 运行:chmod +x target/release/rust-analyzer

调试模式

import logging
logging.basicConfig(level=logging.DEBUG)

from solana_fcg_tool import SolanaAnalyzer
analyzer = SolanaAnalyzer("/path/to/project", debug=True)

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solana_fcg_tool-1.0.1.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solana_fcg_tool-1.0.1-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file solana_fcg_tool-1.0.1.tar.gz.

File metadata

  • Download URL: solana_fcg_tool-1.0.1.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.16

File hashes

Hashes for solana_fcg_tool-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c5a77b00da0eab916eef678f871f150d44a58909b458cfdba1ed2bf1a2bb3350
MD5 ecfe079854d1278bb3c19339e8f245b3
BLAKE2b-256 7461758e2baa41c9183dcaeee6fd4bae60bb796219829b94186a44a92eb0ad61

See more details on using hashes here.

File details

Details for the file solana_fcg_tool-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for solana_fcg_tool-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2191543b147478f151c2d6da425cf62d6519b96c10a561401a1642cd6447d30
MD5 5ec5676ece34f175509f683f0aa7d762
BLAKE2b-256 9543a84200bff8b43292b6e1982708c17a27f400054696fbd854b7fda34bc6dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page