Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions cmake/CompileVexillographer.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
# Python vexillographer source files
set(VEXILLOGRAPHER_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/c.cs
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/cpp.cs
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/java.cs
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/python.cs
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/ruby.cs
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/vexillographer.cs)
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/__init__.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/__main__.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/models.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/parser.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/utils.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/generators/__init__.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/generators/base.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/generators/c.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/generators/cpp.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/generators/java.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/generators/python_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/generators/ruby.py
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/templates/c.h.j2
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/templates/cpp_header.h.j2
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/templates/cpp_impl.cpp.j2
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/templates/java_enum.java.j2
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/templates/java_exception.java.j2
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/templates/java_options.java.j2
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/templates/python.py.j2
${CMAKE_CURRENT_SOURCE_DIR}/fdbclient/vexillographer/templates/ruby.rb.j2)

if(WIN32)
add_executable(vexillographer ${VEXILLOGRAPHER_SRCS})
target_compile_options(vexillographer PRIVATE "/langversion:6")
set_property(TARGET vexillographer PROPERTY VS_DOTNET_REFERENCES
"System"
"System.Core"
"System.Data"
"System.Xml"
"System.Xml.Linq")
else()
set(VEXILLOGRAPHER_REFERENCES "-r:System,System.Core,System.Data,System.Xml,System.Xml.Linq")
set(VEXILLOGRAPHER_EXE "${CMAKE_CURRENT_BINARY_DIR}/vexillographer.exe")
add_custom_command(OUTPUT ${VEXILLOGRAPHER_EXE}
COMMAND ${MCS_EXECUTABLE} ARGS ${VEXILLOGRAPHER_REFERENCES} ${VEXILLOGRAPHER_SRCS} -target:exe -out:${VEXILLOGRAPHER_EXE}
DEPENDS ${VEXILLOGRAPHER_SRCS}
COMMENT "Compile Vexillographer")
add_custom_target(vexillographer DEPENDS ${VEXILLOGRAPHER_EXE})
endif()
# Find Python3
find_package(Python3 COMPONENTS Interpreter REQUIRED)

# Create a dummy target for vexillographer (for dependency tracking)
add_custom_target(vexillographer DEPENDS ${VEXILLOGRAPHER_SRCS})

function(vexillographer_compile)
set(CX_OPTIONS ALL)
Expand All @@ -33,19 +35,15 @@ function(vexillographer_compile)
if(NOT VX_OUTPUT)
set(VX_OUTPUT ${VX_OUT})
endif()
if(WIN32)
add_custom_command(
OUTPUT ${VX_OUTPUT}
COMMAND $<TARGET_FILE:vexillographer> ${CMAKE_SOURCE_DIR}/fdbclient/vexillographer/fdb.options ${VX_LANG} ${VX_OUT}
DEPENDS ${CMAKE_SOURCE_DIR}/fdbclient/vexillographer/fdb.options vexillographer
COMMENT "Generate FDBOptions ${VX_LANG} files")
else()
add_custom_command(
OUTPUT ${VX_OUTPUT}
COMMAND ${MONO_EXECUTABLE} ${VEXILLOGRAPHER_EXE} ${CMAKE_SOURCE_DIR}/fdbclient/vexillographer/fdb.options ${VX_LANG} ${VX_OUT}
DEPENDS ${CMAKE_SOURCE_DIR}/fdbclient/vexillographer/fdb.options vexillographer
COMMENT "Generate FDBOptions ${VX_LANG} files")
endif()

# Use Python vexillographer
add_custom_command(
OUTPUT ${VX_OUTPUT}
COMMAND ${Python3_EXECUTABLE} -m fdbclient.vexillographer ${CMAKE_SOURCE_DIR}/fdbclient/vexillographer/fdb.options ${VX_LANG} ${VX_OUT}
DEPENDS ${CMAKE_SOURCE_DIR}/fdbclient/vexillographer/fdb.options ${VEXILLOGRAPHER_SRCS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generate FDBOptions ${VX_LANG} files")

if(VX_ALL)
add_custom_target(${VX_TARGET} ALL DEPENDS ${VX_OUTPUT})
else()
Expand Down
3 changes: 3 additions & 0 deletions fdbclient/vexillographer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Vexillographer - FoundationDB options code generator."""

__version__ = "1.0.0"
83 changes: 83 additions & 0 deletions fdbclient/vexillographer/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""CLI entry point for vexillographer."""

import sys
import argparse
from pathlib import Path
from typing import Type

from .parser import parse_options
from .generators.base import BaseGenerator
from .generators.c import CGenerator
from .generators.cpp import CppGenerator
from .generators.java import JavaGenerator
from .generators.python_gen import PythonGenerator
from .generators.ruby import RubyGenerator


# Generator registry
GENERATORS = {
"c": CGenerator,
"cpp": CppGenerator,
"java": JavaGenerator,
"python": PythonGenerator,
"ruby": RubyGenerator,
}


def main() -> int:
"""Main entry point for vexillographer CLI."""
parser = argparse.ArgumentParser(
description="Generate language bindings from fdb.options XML file",
prog="vexillographer",
)
parser.add_argument("input_file", help="Path to fdb.options XML file")
parser.add_argument(
"language",
choices=list(GENERATORS.keys()),
help="Target language for code generation",
)
parser.add_argument("output", help="Output file path or directory (for Java)")

args = parser.parse_args()

try:
# Validate input file exists
input_path = Path(args.input_file)
if not input_path.exists():
print(f"Error: Input file not found: {args.input_file}", file=sys.stderr)
return 1

# Parse options from XML
print(f"Parsing {args.input_file}...", file=sys.stderr)
options = parse_options(args.input_file, args.language)
print(f"Parsed {len(options)} options", file=sys.stderr)

# Get the appropriate generator
generator_class: Type[BaseGenerator] = GENERATORS[args.language]
generator = generator_class(options)

# Generate output files
print(
f"Generating {args.language} bindings to {args.output}...", file=sys.stderr
)
generator.write_files(args.output)
print("Generation complete!", file=sys.stderr)

return 0

except FileNotFoundError as e:
print(f"Error: {e}", file=sys.stderr)
return 1
except ValueError as e:
print(f"Error parsing options: {e}", file=sys.stderr)
return 1
except Exception as e:
print(f"Unexpected error: {e}", file=sys.stderr)
import traceback

traceback.print_exc()
return 31


if __name__ == "__main__":
sys.exit(main())
95 changes: 0 additions & 95 deletions fdbclient/vexillographer/c.cs

This file was deleted.

105 changes: 0 additions & 105 deletions fdbclient/vexillographer/cpp.cs

This file was deleted.

5 changes: 5 additions & 0 deletions fdbclient/vexillographer/generators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Language-specific generators for vexillographer."""

from .base import BaseGenerator

__all__ = ["BaseGenerator"]
Loading