Use the name of the current executable to infer the C++ source file where the REGISTER_OP() call for the operator can be found. Returns the name of the file. Returns an empty string if the current executable's name does not follow a known pattern.
| 89 | // Returns an empty string if the current executable's name does not |
| 90 | // follow a known pattern. |
| 91 | string InferSourceFileName(const char* argv_zero) { |
| 92 | StringPiece command_str = io::Basename(argv_zero); |
| 93 | |
| 94 | // For built-in ops, the Bazel build creates a separate executable |
| 95 | // with the name gen_<op type>_ops_py_wrappers_cc containing the |
| 96 | // operators defined in <op type>_ops.cc |
| 97 | const char* kExecPrefix = "gen_"; |
| 98 | const char* kExecSuffix = "_py_wrappers_cc"; |
| 99 | if (absl::ConsumePrefix(&command_str, kExecPrefix) && |
| 100 | str_util::EndsWith(command_str, kExecSuffix)) { |
| 101 | command_str.remove_suffix(strlen(kExecSuffix)); |
| 102 | return strings::StrCat(command_str, ".cc"); |
| 103 | } else { |
| 104 | return string(""); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void PrintAllPythonOps(const std::vector<string>& op_list, |
| 109 | const std::vector<string>& api_def_dirs, |
no test coverage detected