in proxygen/lib/utils/gen_trace_event_constants.py [0:0]
def main(argv):
# args parser
parser = optparse.OptionParser()
parser.add_option(
"--install_dir",
dest="install_dir",
type="string",
default=None,
help="Absolute path to generate files",
)
parser.add_option(
"--fbcode_dir",
dest="fbcode_dir",
type="string",
default=None,
help="Absolute path to fbcode directory",
)
parser.add_option(
"--input_files",
dest="input_files",
type="string",
default=None,
help="Relative path of input file",
)
parser.add_option(
"--output_scope",
dest="output_scope",
type="string",
default=None,
help="namespace / package of output file",
)
parser.add_option(
"--output_type",
dest="output_type",
type="choice",
choices=["java", "cpp"],
default=None,
help="File type to generate",
)
parser.add_option(
"--header_path",
dest="header_path",
type="string",
default=None,
help="Relative path to cpp header",
)
options, _ = parser.parse_args()
assert options.install_dir is not None, "Missing arg: --install_dir"
assert options.fbcode_dir is not None, "Missing arg: --fbcode_dir"
assert options.input_files is not None, "Missing arg: --input_files"
assert options.output_scope is not None, "Missing arg: --output_scope"
assert options.output_type is not None, "Missing arg: --output_type"
file_names = options.input_files.split(",")
for file_name in file_names:
# strip the file extension and use the file name for class name
class_name = os.path.basename(file_name).split(".")[0]
# parse items from source
items = []
with open(file_name, "r") as inf:
for line in inf:
sp = re.match(r"(.*), \"(.*)\"", line, re.I)
if sp:
items.append((sp.group(1), sp.group(2)))
if options.output_type == "java":
gen_java(items, class_name, options.install_dir, options.output_scope)
elif options.output_type == "cpp":
assert options.header_path is not None, "Missing arg: --header_path"
gen_cpp_header(items, class_name, options.install_dir, options.output_scope)
gen_cpp_source(
items,
class_name,
options.install_dir,
options.header_path,
options.output_scope,
)