MCPcopy Create free account
hub / github.com/apache/fory / compile_file

Function compile_file

compiler/fory_compiler/cli.py:707–844  ·  view source on GitHub ↗

Compile a single IDL file with import resolution. Args: file_path: Path to the IDL file lang_output_dirs: Dictionary mapping language name to output directory import_paths: List of import search paths generated_outputs: output file path -> source IDL path

(
    file_path: Path,
    lang_output_dirs: Dict[str, Path],
    import_paths: Optional[List[Path]] = None,
    go_nested_type_style: Optional[str] = None,
    swift_namespace_style: Optional[str] = None,
    emit_fdl: bool = False,
    emit_fdl_path: Optional[Path] = None,
    resolve_cache: Optional[Dict[Path, Schema]] = None,
    grpc: bool = False,
    grpc_web: bool = False,
    grpc_python_mode: str = "async",
    *,
    generated_outputs: Optional[Dict[Path, Path]] = None,
)

Source from the content-addressed store, hash-verified

705
706
707def compile_file(
708 file_path: Path,
709 lang_output_dirs: Dict[str, Path],
710 import_paths: Optional[List[Path]] = None,
711 go_nested_type_style: Optional[str] = None,
712 swift_namespace_style: Optional[str] = None,
713 emit_fdl: bool = False,
714 emit_fdl_path: Optional[Path] = None,
715 resolve_cache: Optional[Dict[Path, Schema]] = None,
716 grpc: bool = False,
717 grpc_web: bool = False,
718 grpc_python_mode: str = "async",
719 *,
720 generated_outputs: Optional[Dict[Path, Path]] = None,
721) -> bool:
722 """Compile a single IDL file with import resolution.
723
724 Args:
725 file_path: Path to the IDL file
726 lang_output_dirs: Dictionary mapping language name to output directory
727 import_paths: List of import search paths
728 generated_outputs: output file path -> source IDL path
729 """
730 file_path = file_path.resolve()
731 if generated_outputs is None:
732 generated_outputs = {}
733 print(f"Compiling {file_path}...")
734
735 # Parse and resolve imports
736 try:
737 schema = resolve_imports(file_path, import_paths, cache=resolve_cache)
738 except OSError as e:
739 print(f"Error reading {file_path}: {e}", file=sys.stderr)
740 return False
741 except (FrontendError, ValueError) as e:
742 print(f"Error: {e}", file=sys.stderr)
743 return False
744 except ImportError as e:
745 print(f"Import error: {e}", file=sys.stderr)
746 return False
747
748 # Print import info
749 if schema.imports:
750 print(f" Resolved {len(schema.imports)} import(s)")
751
752 if emit_fdl:
753 emitter = FDLEmitter(schema)
754 fdl_content = emitter.emit()
755 if emit_fdl_path:
756 target = emit_fdl_path
757 if target.exists() and target.is_dir():
758 target = target / f"{file_path.stem}.fdl"
759 elif str(target).endswith("/") or str(target).endswith("\\"):
760 target.mkdir(parents=True, exist_ok=True)
761 target = target / f"{file_path.stem}.fdl"
762 target.parent.mkdir(parents=True, exist_ok=True)
763 target.write_text(fdl_content)
764 print(f" Emitted FDL: {target}")

Calls 15

emitMethod · 0.95
validateMethod · 0.95
FDLEmitterClass · 0.90
SchemaValidatorClass · 0.90
GeneratorOptionsClass · 0.90
resolve_importsFunction · 0.85
is_generated_fileFunction · 0.85
itemsMethod · 0.80
extendMethod · 0.80
write_filesMethod · 0.80
getMethod · 0.65
setFunction · 0.50