Skip to content

yaskhan/bevy_migrate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bevy Engine Migration Tool

Automated migration tool for Bevy Engine projects between versions 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, and 0.19.

πŸ“‹ Description

This tool automates the migration process for projects using the Bevy game engine between different versions. It supports migrations from version 0.12 to 0.19 using a modular architecture and AST code analysis.

Key Features

  • πŸ”„ Automatic migration between Bevy versions 0.12 β†’ 0.13 β†’ 0.14 β†’ 0.15 β†’ 0.16 β†’ 0.17 β†’ 0.18 β†’ 0.19
  • 🧩 Modular architecture with separate modules for each version
  • πŸ” AST analysis using ast-grep for precise code transformations
  • πŸ“ Smart file management with automatic backups
  • 🎯 Automatic version detection of your project
  • 🧠 Complex logic support via Python callbacks and inline YAML rules
  • πŸ›‘οΈ Safe dry-run mode for previewing changes
  • πŸ“Š Detailed reporting of the migration process

Supported Migrations

  • 0.12 β†’ 0.13: WorldQuery split into QueryData/QueryFilter, Input renamed to ButtonInput, TextureAtlas rework, rendering and UI changes
  • 0.13 β†’ 0.14: Complete Color overhaul (Srgba/LinearRgba), AnimationGraph, SubApp split, Dir2/Dir3, massive rendering changes, winit 0.30, wgpu 0.20
  • 0.15 β†’ 0.16: Plugin system updates, system registration, entity creation improvements (72 transformations)
  • 0.16 β†’ 0.17: Required components system, observer updates, input system changes (130+ transformations in 3 parts)
  • 0.17 β†’ 0.18: Rendering improvements, UI system, window system, new features (105+ transformations)
  • 0.18 β†’ 0.19 (Part 1): Messages API, observer renames, reflect reorganization, and core renames (Manual target only)

πŸ› οΈ Installation

Installing the Package

# Clone the repository
git clone <repository-url>
cd bevy-migration-tool

# Install the package in editable mode (recommend for development)
pip install -e .

# Or install normally
pip install .

This will install the bevymigrate package and the bevymigrate CLI command.

πŸš€ Usage

Basic Usage

After installation, you can run the tool directly using the bevymigrate command:

# Run migration on your project (0.18 is default target)
bevymigrate /path/to/bevy/project

# Migrate to Bevy 0.19 (Part 1) explicitly
bevymigrate /path/to/bevy/project --target-version 0.19-part1

# Run a dry-run to see what would change
bevymigrate /path/to/bevy/project --dry-run
# Migrate project to the latest supported version (0.18)
bevymigrate /path/to/your/bevy/project

# Migrate to a specific version
bevymigrate /path/to/your/bevy/project --target-version 0.17

# Preview changes without modifying files
bevymigrate /path/to/your/bevy/project --dry-run

# Verbose output with debug information
bevymigrate /path/to/your/bevy/project --verbose

Advanced Options

# Migrate with custom backup directory
bevymigrate /path/to/project --backup-dir ./my_backups

# Force migration (if version is not detected automatically)
bevymigrate /path/to/project --force

# Exclude specific files or directories
bevymigrate /path/to/project --exclude "target/**" "*.bak" "custom_dir/**"

# Combined example
bevymigrate ./my_bevy_game --target-version 0.17 --dry-run --verbose --backup-dir ./backups

Command Examples

# Example 1: Migrate a simple project
bevymigrate ./my_game

# Example 2: Preview migration with verbose output
bevymigrate ./my_game --dry-run --verbose

# Example 3: Step-by-step migration to version 0.16
bevymigrate ./my_game --target-version 0.16

# Example 4: Migration with custom settings
bevymigrate ./my_game --backup-dir ./project_backups --exclude "assets/**" --verbose

πŸ“– How to Use

Step-by-Step Guide

  1. Prepare your project

    # Make sure your project is under version control
    cd /path/to/your/bevy/project
    git add .
    git commit -m "Before Bevy migration"
  2. Check current version

    # The tool will auto-detect the version, but you can check Cargo.toml
    cat Cargo.toml | grep bevy
  3. Run migration in preview mode

    bevymigrate . --dry-run --verbose
  4. Execute migration

    bevymigrate .
  5. Verify results

    # Check that the project compiles
    cargo check
    
    # Run tests
    cargo test
    
    # Run the project
    cargo run

Command Line Parameters

Parameter Description Example
project_path Path to Bevy project (required) ./my_game
--target-version Target version for migration --target-version 0.17
--dry-run Preview mode --dry-run
--backup-dir Directory for backups --backup-dir ./backups
--verbose, -v Verbose output --verbose
--force Force migration --force
--exclude Exclude files/directories --exclude "target/**" "*.tmp"

πŸ—οΈ Project Architecture

src/
└── bevymigrate/
    β”œβ”€β”€ __init__.py
    β”œβ”€β”€ main.py                     # Application entry point
    β”œβ”€β”€ core/                       # Core components
    β”‚   β”œβ”€β”€ migration_engine.py     # Migration engine
    β”‚   β”œβ”€β”€ ast_processor.py        # AST processor
    β”‚   └── file_manager.py         # File manager
    β”œβ”€β”€ migrations/                 # Migration modules
    β”‚   β”œβ”€β”€ base_migration.py       # Base migration class
    β”‚   β”œβ”€β”€ v0_12_to_0_13.py        # Migration 0.12 β†’ 0.13
    β”‚   β”œβ”€β”€ v0_13_to_0_14.py        # Migration 0.13 β†’ 0.14
    β”‚   β”œβ”€β”€ v0_14_to_0_15_part1.py  # Migration 0.14 β†’ 0.15 Part 1
    β”‚   β”œβ”€β”€ v0_14_to_0_15_part2.py  # Migration 0.14 β†’ 0.15 Part 2
    β”‚   β”œβ”€β”€ v0_15_to_0_16.py        # Migration 0.15 β†’ 0.16
    β”‚   β”œβ”€β”€ v0_16_to_0_17_part1.py  # Migration 0.16 β†’ 0.17 Part 1
    β”‚   β”œβ”€β”€ v0_16_to_0_17_part2.py  # Migration 0.16 β†’ 0.17 Part 2
    β”‚   β”œβ”€β”€ v0_16_to_0_17_part3.py  # Migration 0.16 β†’ 0.17 Part 3
    β”‚   β”œβ”€β”€ v0_17_to_0_18.py        # Migration 0.17 β†’ 0.18
    β”‚   └── v0_18_to_0_19_part1.py  # Migration 0.18 β†’ 0.19 Part 1
    └── utils/                      # Utilities
        └── version_detector.py     # Version detection

Core Components

  • MigrationEngine: Coordinates the migration process
  • ASTProcessor: Performs code transformations using AST
  • FileManager: Manages file operations and backups
  • VersionDetector: Automatically detects Bevy version in the project
  • BaseMigration: Base class for all migration modules

πŸ“Š Migration Statistics

Migration Transformations Parts Breaking Changes
0.12β†’0.13 ~40 1 40+
0.13β†’0.14 ~60 1 60+
0.14β†’0.15 ~80 2 80+
0.15β†’0.16 72 1 70+
0.16β†’0.17 130+ 3 150+
0.17β†’0.18 105+ 1 80+
0.18β†’0.19 50+ 1 50+
Total 535+ 10 530+

πŸ”§ Configuration

The tool uses a centralized configuration system in src/config/migration_rules.py. You can customize:

  • Transformation rules for each version
  • File patterns to process
  • Exclusions and filters
  • Rule priority levels

Example Custom Rule

# Add a custom migration rule
rule = MigrationRule(
    name="custom_transformation",
    description="Custom transformation",
    pattern=r"old_pattern",
    replacement="new_pattern",
    file_patterns=["**/*.rs"],
    priority=100
)

πŸ›‘οΈ Safety

The tool automatically creates backups before making changes:

  • Automatic backup of all modified files
  • Dry-run mode for safe preview
  • Validation of project structure before migration
  • Rollback in case of errors

Backup Location

By default, backups are saved to:

your_project/
└── migration_backup/
    └── backup_YYYYMMDD_HHMMSS/
        β”œβ”€β”€ Cargo.toml
        β”œβ”€β”€ src/
        └── ...

πŸ“Š Reporting

The tool provides detailed information about the migration process:

  • Number of processed files
  • Applied transformations
  • Warnings and errors
  • Recommendations for manual review

Example Output

2024-02-04 08:07:56 - INFO - Detected Bevy version: 0.15
2024-02-04 08:07:57 - INFO - Starting migration from 0.15 to 0.18
2024-02-04 08:07:58 - INFO - Migration path: 0.15 -> 0.16 -> 0.17 -> 0.18
2024-02-04 08:08:00 - INFO - Files processed: 25
2024-02-04 08:08:00 - INFO - Files modified: 18
2024-02-04 08:08:00 - INFO - Transformations applied: 47
2024-02-04 08:08:00 - INFO - Migration completed successfully!

πŸ” Troubleshooting

Common Issues

  1. ast-grep-py not found

    pip install -r requirements.txt
  2. Cannot detect Bevy version

    # Use the --force flag
    python src/main.py . --force
  3. Compilation errors after migration

    • Check files requiring manual review
    • Refer to Bevy documentation for the specific version
    • Restore from backup if needed

Logging

For detailed debug information:

python src/main.py . --verbose

Logs include:

  • Detected code patterns
  • Applied transformations
  • Warnings about potential issues
  • File processing statistics

🧠 Complex Migrations

For transformations that require more than simple pattern replacement, the tool provides two powerful mechanisms: Python callbacks and inline YAML rules. These are applied directly without creating temporary files on disk.

1. Python Callbacks

Useful for conditional replacements, dynamic string manipulation, or context-aware transformations.

def input_callback(vars, file_path):
    # vars contains captured ast-grep variables (e.g., $T)
    t_type = vars.get("T", "unknown")
    return f"Res<ButtonInput<{t_type}>>"

# In your migration class:
transformations.append(self.create_transformation(
    pattern="Res<Input<$T>>",
    replacement="", # Ignored when callback is present
    description="Complex replacement using Python",
    callback=input_callback
))

2. Inline YAML Rules

Allows using the full power of ast-grep YAML configuration directly.

yaml_rule = """
id: custom-check
language: rust
rule:
  pattern: foo($A)
  inside:
    kind: function_item
    has:
      field: name
      pattern: main
fix: bar($A)
"""

transformations.append(self.create_transformation(
    pattern="", # pattern is ignored when rule_yaml is present
    replacement="",
    description="Advanced YAML rule",
    rule_yaml=yaml_rule
))

🀝 Contributing

Adding a New Migration

  1. Create a new file in src/migrations/
  2. Inherit from BaseMigration
  3. Implement required methods
  4. Register the migration in MigrationEngine

Example Migration Module

from migrations.base_migration import BaseMigration
from core.ast_processor import ASTTransformation

class Migration_0_18_to_0_19(BaseMigration):
    @property
    def from_version(self) -> str:
        return "0.18"
    
    @property
    def to_version(self) -> str:
        return "0.19"
    
    def get_transformations(self) -> List[ASTTransformation]:
        return [
            self.create_transformation(
                pattern="old_pattern",
                replacement="new_pattern",
                description="Transformation description"
            )
        ]

πŸ“ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ†˜ Support

If you encounter issues or have questions:

  1. Check the "Troubleshooting" section
  2. Create an issue in the project repository
  3. Include logs from running with the --verbose flag

πŸ“š Additional Resources


Note: Always create backups of your projects before running migrations. While the tool creates automatic backups, extra precaution never hurts.

About

Bevy engine migration tool

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages