Mårten Kongstad | fe753f5 | 2023-04-26 09:13:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | // When building with the Android tool-chain |
| 18 | // |
| 19 | // - an external crate `aconfig_protos` will be generated |
| 20 | // - the feature "cargo" will be disabled |
| 21 | // |
| 22 | // When building with cargo |
| 23 | // |
| 24 | // - a local sub-module will be generated in OUT_DIR and included in this file |
| 25 | // - the feature "cargo" will be enabled |
| 26 | // |
| 27 | // This module hides these differences from the rest of aconfig. |
| 28 | |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 29 | // ---- When building with the Android tool-chain ---- |
Mårten Kongstad | fe753f5 | 2023-04-26 09:13:03 +0200 | [diff] [blame] | 30 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 31 | pub use aconfig_protos::aconfig::Namespace as ProtoNamespace; |
Mårten Kongstad | fe753f5 | 2023-04-26 09:13:03 +0200 | [diff] [blame] | 32 | |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 33 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 34 | pub use aconfig_protos::aconfig::Flag_value as ProtoFlagDefinitionValue; |
Mårten Kongstad | 09c28d1 | 2023-05-04 13:29:26 +0200 | [diff] [blame] | 35 | |
| 36 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 37 | pub use aconfig_protos::aconfig::Flag_definition as ProtoFlagDefinition; |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 38 | |
| 39 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 40 | pub use aconfig_protos::aconfig::Flag_overrides as ProtoFlagOverrides; |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 41 | |
| 42 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 43 | pub use aconfig_protos::aconfig::Flag_override as ProtoFlagOverride; |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 44 | |
Mårten Kongstad | 416330b | 2023-05-05 11:10:01 +0200 | [diff] [blame] | 45 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 46 | pub use aconfig_protos::aconfig::Flag_permission as ProtoFlagPermission; |
Mårten Kongstad | 416330b | 2023-05-05 11:10:01 +0200 | [diff] [blame] | 47 | |
Mårten Kongstad | c68c4ea | 2023-05-05 16:20:09 +0200 | [diff] [blame] | 48 | #[cfg(not(feature = "cargo"))] |
| 49 | pub use aconfig_protos::aconfig::Flag_state as ProtoFlagState; |
| 50 | |
Mårten Kongstad | a102909 | 2023-05-08 11:51:59 +0200 | [diff] [blame] | 51 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 52 | pub use aconfig_protos::aconfig::Parsed_flags as ProtoParsedFlags; |
Mårten Kongstad | a102909 | 2023-05-08 11:51:59 +0200 | [diff] [blame] | 53 | |
| 54 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 55 | pub use aconfig_protos::aconfig::Parsed_flag as ProtoParsedFlag; |
Mårten Kongstad | a102909 | 2023-05-08 11:51:59 +0200 | [diff] [blame] | 56 | |
| 57 | #[cfg(not(feature = "cargo"))] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 58 | pub use aconfig_protos::aconfig::Tracepoint as ProtoTracepoint; |
Mårten Kongstad | a102909 | 2023-05-08 11:51:59 +0200 | [diff] [blame] | 59 | |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 60 | // ---- When building with cargo ---- |
Mårten Kongstad | fe753f5 | 2023-04-26 09:13:03 +0200 | [diff] [blame] | 61 | #[cfg(feature = "cargo")] |
| 62 | include!(concat!(env!("OUT_DIR"), "/aconfig_proto/mod.rs")); |
| 63 | |
| 64 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 65 | pub use aconfig::Namespace as ProtoNamespace; |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 66 | |
| 67 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 68 | pub use aconfig::Flag_value as ProtoFlagDefinitionValue; |
Mårten Kongstad | 09c28d1 | 2023-05-04 13:29:26 +0200 | [diff] [blame] | 69 | |
| 70 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 71 | pub use aconfig::Flag_definition as ProtoFlagDefinition; |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 72 | |
| 73 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 74 | pub use aconfig::Flag_overrides as ProtoFlagOverrides; |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 75 | |
| 76 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 77 | pub use aconfig::Flag_override as ProtoFlagOverride; |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 78 | |
Mårten Kongstad | 416330b | 2023-05-05 11:10:01 +0200 | [diff] [blame] | 79 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 80 | pub use aconfig::Flag_permission as ProtoFlagPermission; |
Mårten Kongstad | 416330b | 2023-05-05 11:10:01 +0200 | [diff] [blame] | 81 | |
Mårten Kongstad | c68c4ea | 2023-05-05 16:20:09 +0200 | [diff] [blame] | 82 | #[cfg(feature = "cargo")] |
| 83 | pub use aconfig::Flag_state as ProtoFlagState; |
| 84 | |
Mårten Kongstad | a102909 | 2023-05-08 11:51:59 +0200 | [diff] [blame] | 85 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 86 | pub use aconfig::Parsed_flags as ProtoParsedFlags; |
Mårten Kongstad | a102909 | 2023-05-08 11:51:59 +0200 | [diff] [blame] | 87 | |
| 88 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 89 | pub use aconfig::Parsed_flag as ProtoParsedFlag; |
Mårten Kongstad | a102909 | 2023-05-08 11:51:59 +0200 | [diff] [blame] | 90 | |
| 91 | #[cfg(feature = "cargo")] |
Mårten Kongstad | 3095078 | 2023-05-09 13:31:29 +0200 | [diff] [blame] | 92 | pub use aconfig::Tracepoint as ProtoTracepoint; |
Mårten Kongstad | a102909 | 2023-05-08 11:51:59 +0200 | [diff] [blame] | 93 | |
Mårten Kongstad | bb52072 | 2023-04-26 13:16:41 +0200 | [diff] [blame] | 94 | // ---- Common for both the Android tool-chain and cargo ---- |
| 95 | use anyhow::Result; |
| 96 | |
| 97 | pub fn try_from_text_proto<T>(s: &str) -> Result<T> |
| 98 | where |
| 99 | T: protobuf::MessageFull, |
| 100 | { |
| 101 | // warning: parse_from_str does not check if required fields are set |
| 102 | protobuf::text_format::parse_from_str(s).map_err(|e| e.into()) |
| 103 | } |