| 42 | } |
| 43 | |
| 44 | absl::StatusOr<RuntimeBuilder> EnvRuntime::CreateRuntimeBuilder() { |
| 45 | const std::vector<Config::ExtensionConfig>& extension_configs = |
| 46 | config_.GetExtensionConfigs(); |
| 47 | const Config::ExtensionConfig* optional_extension_config = nullptr; |
| 48 | for (const Config::ExtensionConfig& extension_config : extension_configs) { |
| 49 | if (extension_config.name == "optional") { |
| 50 | optional_extension_config = &extension_config; |
| 51 | runtime_options_.enable_qualified_type_identifiers = true; |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | CEL_ASSIGN_OR_RETURN( |
| 57 | RuntimeBuilder runtime_builder, |
| 58 | cel::CreateRuntimeBuilder(descriptor_pool_, runtime_options_)); |
| 59 | |
| 60 | if (!config_.GetStandardLibraryConfig().disable) { |
| 61 | CEL_RETURN_IF_ERROR(RegisterStandardFunctions( |
| 62 | runtime_builder.function_registry(), runtime_options_)); |
| 63 | } |
| 64 | |
| 65 | // Register optional extension functions first, because other extensions |
| 66 | // depend on it (e.g. regex). |
| 67 | if (optional_extension_config != nullptr) { |
| 68 | CEL_RETURN_IF_ERROR(extension_registry_.RegisterExtensionFunctions( |
| 69 | runtime_builder, runtime_options_, optional_extension_config->name, |
| 70 | optional_extension_config->version)); |
| 71 | } |
| 72 | |
| 73 | for (const Config::ExtensionConfig& extension_config : extension_configs) { |
| 74 | if (&extension_config == optional_extension_config) { |
| 75 | continue; |
| 76 | } |
| 77 | CEL_RETURN_IF_ERROR(extension_registry_.RegisterExtensionFunctions( |
| 78 | runtime_builder, runtime_options_, extension_config.name, |
| 79 | extension_config.version)); |
| 80 | } |
| 81 | return runtime_builder; |
| 82 | } |
| 83 | |
| 84 | absl::StatusOr<std::unique_ptr<Runtime>> EnvRuntime::NewRuntime() { |
| 85 | CEL_ASSIGN_OR_RETURN(RuntimeBuilder runtime_builder, CreateRuntimeBuilder()); |
nothing calls this directly
no test coverage detected