1#!/usr/bin/env fbpython 2# Copyright (c) Meta Platforms, Inc. and affiliates. 3# All rights reserved. 4# 5# This source code is licensed under the BSD-style license found in the 6# LICENSE file in the root directory of this source tree. 7 8import argparse 9import os 10import sys 11from typing import Any, List 12 13from tools_copy.code_analyzer import gen_oplist_copy_from_core 14 15 16def main(argv: List[Any]) -> None: 17 """This binary is a wrapper for //executorch/codegen/tools/gen_oplist_copy_from_core.py. 18 This is needed because we intend to error out for the case where `model_file_list_path` 19 is empty or invalid, so that the ExecuTorch build will fail when no selective build target 20 is provided as a dependency to ExecuTorch build. 21 """ 22 parser = argparse.ArgumentParser(description="Generate operator lists") 23 parser.add_argument( 24 "--output_dir", 25 help=("The directory to store the output yaml file (selected_operators.yaml)"), 26 required=True, 27 ) 28 parser.add_argument( 29 "--model_file_list_path", 30 help=( 31 "Path to a file that contains the locations of individual " 32 + "model YAML files that contain the set of used operators. This " 33 + "file path must have a leading @-symbol, which will be stripped " 34 + "out before processing." 35 ), 36 required=True, 37 ) 38 parser.add_argument( 39 "--allow_include_all_overloads", 40 help=( 41 "Flag to allow operators that include all overloads. " 42 + "If not set, operators registered without using the traced style will" 43 + "break the build." 44 ), 45 action="store_true", 46 default=False, 47 required=False, 48 ) 49 50 # check if the build has any dependency on any selective build target. If we have a target, BUCK shold give us either: 51 # 1. a yaml file containing selected ops (could be empty), or 52 # 2. a non-empty list of yaml files in the `model_file_list_path`. 53 # If none of the two things happened, the build target has no dependency on any selective build and we should error out. 54 options = parser.parse_args(argv) 55 if os.path.isfile(options.model_file_list_path): 56 pass 57 else: 58 assert ( 59 options.model_file_list_path[0] == "@" 60 ), "model_file_list_path is not a valid file path, or it doesn't start with '@'. This is likely a BUCK issue." 61 model_file_list_path = options.model_file_list_path[1:] 62 with open(model_file_list_path) as model_list_file: 63 model_file_names = model_list_file.read().split() 64 assert ( 65 len(model_file_names) > 0 66 ), "BUCK was not able to find any `et_operator_library` in the dependency graph of the current ExecuTorch " 67 "build. Please refer to Selective Build wiki page to add at least one." 68 gen_oplist_copy_from_core.main(argv) 69 70 71if __name__ == "__main__": 72 main(sys.argv[1:]) 73