EDK2 PyTool Extensions

0.31.0 · active · verified Thu Apr 16

EDK2 PyTool Extensions is a collection of Python-based tools designed to support the development of UEFI EDK2 firmware. It orchestrates common build tasks, manages external dependencies, and provides a programmatic interface for EDK2 builds. The current version is 0.31.0, with an active development cadence featuring frequent updates and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates both the command-line usage of the `edk2_setup` tool (by showing its help) and the programmatic instantiation of the core `UefiBuilder` class. It sets up a minimal dummy EDK2 environment to ensure the code is runnable, but a full EDK2 build requires a properly configured external EDK2 source tree and toolchain.

import os
import tempfile
import shutil
from pathlib import Path
import subprocess
import sys

# --- Create a dummy EDK2 environment for demonstration ---
# In a real scenario, EDK2_PATH and WORKSPACE would point to
# your actual EDK2 source code and build workspace.

temp_dir = Path(tempfile.mkdtemp())
edk2_path = temp_dir / "edk2"
workspace_path = temp_dir / "MyWorkspace"

edk2_path.mkdir(exist_ok=True)
workspace_path.mkdir(exist_ok=True)

# Simulate minimal EDK2 structure needed for some checks
(edk2_path / "MdePkg").mkdir(exist_ok=True)
(edk2_path / "MdePkg" / "MdePkg.dsc").write_text("# Dummy DSC file")
(workspace_path / "MyPlatformPkg").mkdir(exist_ok=True)
(workspace_path / "MyPlatformPkg" / "MyPlatform.dsc").write_text("# Dummy Platform DSC file")

os.environ['EDK2_PATH'] = str(edk2_path)
os.environ['WORKSPACE'] = str(workspace_path)

try:
    # --- 1. Demonstrate using the EDK2 setup tool (command-line) ---
    # This tool helps download external dependencies for EDK2 builds.
    print("\n--- Running EDK2 Setup Tool (displaying help) ---")
    setup_result = subprocess.run(
        [sys.executable, "-m", "edk2toolext.invocables.edk2_setup", "--help"],
        capture_output=True, text=True, check=False
    )
    print("EDK2 Setup Tool Help Output (truncated):\n" + setup_result.stdout[:500] + "...")
    if setup_result.returncode != 0:
        print(f"Error running setup tool help: {setup_result.stderr}")

    # --- 2. Demonstrate programmatic use of UefiBuilder ---
    # UefiBuilder is a core class for orchestrating EDK2 builds.
    print("\n--- Demonstrating programmatic import of UefiBuilder ---")
    from edk2toolext.environment.uefi_build import UefiBuilder

    builder_instance = UefiBuilder()
    print(f"Successfully instantiated UefiBuilder: {builder_instance.__class__.__name__}")
    print("Note: A real build would require valid EDK2 source, toolchains, ")
    print("and potentially specific platform configuration files, which are ")
    print("outside the scope of this minimal quickstart example.")

except ImportError as e:
    print(f"Error importing EDK2 PyTool Extensions. Ensure it's installed: {e}")
except Exception as e:
    print(f"An unexpected error occurred during quickstart: {e}")
finally:
    # Clean up dummy environment
    if temp_dir.exists():
        shutil.rmtree(temp_dir)
    print("\n--- Quickstart demonstration complete. --- ")

view raw JSON →