2023-12-05 20:02:29 -05:00
#!/usr/bin/env python3
# Copyright (c) FIRST and other WPILib contributors.
# Open Source Software; you can modify and/or share it under the terms of
# the WPILib BSD license file in the root directory of this project.
2024-11-02 19:09:32 -07:00
2024-06-18 10:40:37 -04:00
import argparse
2024-11-02 17:56:55 -07:00
import subprocess
2024-06-18 10:40:37 -04:00
from pathlib import Path
2023-12-05 20:02:29 -05:00
2024-06-18 10:40:37 -04:00
def generate_quickbuf (
protoc , quickbuf_plugin : Path , output_directory : Path , proto_dir : Path
) :
proto_files = proto_dir . glob ( " *.proto " )
2023-12-05 20:02:29 -05:00
for path in proto_files :
2024-06-18 10:40:37 -04:00
absolute_filename = path . absolute ( )
2025-07-06 05:24:09 -07:00
subprocess . check_call (
2023-12-05 20:02:29 -05:00
[
2024-06-18 10:40:37 -04:00
protoc ,
f " --plugin=protoc-gen-quickbuf= { quickbuf_plugin } " ,
f " --quickbuf_out=gen_descriptors=true: { output_directory . absolute ( ) } " ,
f " -I { absolute_filename . parent } " ,
2023-12-05 20:02:29 -05:00
absolute_filename ,
]
)
2025-11-07 19:56:21 -05:00
java_files = ( output_directory / " org/wpilib/math/proto " ) . glob ( " *.java " )
2023-12-05 20:02:29 -05:00
for java_file in java_files :
2024-06-18 10:40:37 -04:00
with ( java_file ) . open ( encoding = " utf-8 " ) as f :
content = f . read ( )
java_file . write_text (
" // Copyright (c) FIRST and other WPILib contributors. \n // Open Source Software; you can modify and/or share it under the terms of \n // the WPILib BSD license file in the root directory of this project. \n "
+ content ,
encoding = " utf-8 " ,
2024-10-28 22:28:58 -04:00
newline = " \n " ,
2024-06-18 10:40:37 -04:00
)
2024-11-02 19:09:32 -07:00
def main ( ) :
2024-06-18 10:40:37 -04:00
script_path = Path ( __file__ ) . resolve ( )
dirname = script_path . parent
parser = argparse . ArgumentParser ( )
parser . add_argument (
" --protoc " ,
help = " Protoc executable command " ,
default = " protoc " ,
)
parser . add_argument (
" --quickbuf_plugin " ,
help = " Path to the quickbuf protoc plugin " ,
required = True ,
)
parser . add_argument (
" --output_directory " ,
help = " Optional. If set, will output the generated files to this directory, otherwise it will use a path relative to the script " ,
default = dirname / " src/generated/main/java " ,
type = Path ,
)
parser . add_argument (
" --proto_directory " ,
help = " Optional. If set, will use this directory to glob for protobuf files " ,
default = dirname / " src/main/proto " ,
type = Path ,
)
2024-11-02 19:09:32 -07:00
args = parser . parse_args ( )
2024-06-18 10:40:37 -04:00
generate_quickbuf (
args . protoc , args . quickbuf_plugin , args . output_directory , args . proto_directory
)
if __name__ == " __main__ " :
2024-11-02 19:09:32 -07:00
main ( )