blob: cb756928f826704a96426d551b76dd2fde5a9093 [file] [log] [blame]
Mårten Kongstadfe753f52023-04-26 09:13:03 +02001/*
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 Kongstadbb520722023-04-26 13:16:41 +020029// ---- When building with the Android tool-chain ----
Mårten Kongstadfe753f52023-04-26 09:13:03 +020030#[cfg(not(feature = "cargo"))]
Mårten Kongstadfa23d292023-05-11 14:47:02 +020031pub use aconfig_protos::aconfig::Flag_declaration as ProtoFlagDeclaration;
Mårten Kongstadfe753f52023-04-26 09:13:03 +020032
Mårten Kongstadbb520722023-04-26 13:16:41 +020033#[cfg(not(feature = "cargo"))]
Mårten Kongstadfa23d292023-05-11 14:47:02 +020034pub use aconfig_protos::aconfig::Flag_declarations as ProtoFlagDeclarations;
Mårten Kongstad09c28d12023-05-04 13:29:26 +020035
36#[cfg(not(feature = "cargo"))]
Mårten Kongstadfa23d292023-05-11 14:47:02 +020037pub use aconfig_protos::aconfig::Flag_value as ProtoFlagValue;
Mårten Kongstadbb520722023-04-26 13:16:41 +020038
39#[cfg(not(feature = "cargo"))]
Mårten Kongstadfa23d292023-05-11 14:47:02 +020040pub use aconfig_protos::aconfig::Flag_values as ProtoFlagValues;
Mårten Kongstadbb520722023-04-26 13:16:41 +020041
Mårten Kongstad416330b2023-05-05 11:10:01 +020042#[cfg(not(feature = "cargo"))]
Mårten Kongstad30950782023-05-09 13:31:29 +020043pub use aconfig_protos::aconfig::Flag_permission as ProtoFlagPermission;
Mårten Kongstad416330b2023-05-05 11:10:01 +020044
Mårten Kongstadc68c4ea2023-05-05 16:20:09 +020045#[cfg(not(feature = "cargo"))]
46pub use aconfig_protos::aconfig::Flag_state as ProtoFlagState;
47
Mårten Kongstada1029092023-05-08 11:51:59 +020048#[cfg(not(feature = "cargo"))]
Mårten Kongstad30950782023-05-09 13:31:29 +020049pub use aconfig_protos::aconfig::Parsed_flags as ProtoParsedFlags;
Mårten Kongstada1029092023-05-08 11:51:59 +020050
51#[cfg(not(feature = "cargo"))]
Mårten Kongstad30950782023-05-09 13:31:29 +020052pub use aconfig_protos::aconfig::Parsed_flag as ProtoParsedFlag;
Mårten Kongstada1029092023-05-08 11:51:59 +020053
54#[cfg(not(feature = "cargo"))]
Mårten Kongstad30950782023-05-09 13:31:29 +020055pub use aconfig_protos::aconfig::Tracepoint as ProtoTracepoint;
Mårten Kongstada1029092023-05-08 11:51:59 +020056
Mårten Kongstadbb520722023-04-26 13:16:41 +020057// ---- When building with cargo ----
Mårten Kongstadfe753f52023-04-26 09:13:03 +020058#[cfg(feature = "cargo")]
59include!(concat!(env!("OUT_DIR"), "/aconfig_proto/mod.rs"));
60
61#[cfg(feature = "cargo")]
Mårten Kongstadfa23d292023-05-11 14:47:02 +020062pub use aconfig::Flag_declaration as ProtoFlagDeclaration;
Mårten Kongstadbb520722023-04-26 13:16:41 +020063
64#[cfg(feature = "cargo")]
Mårten Kongstadfa23d292023-05-11 14:47:02 +020065pub use aconfig::Flag_declarations as ProtoFlagDeclarations;
Mårten Kongstad09c28d12023-05-04 13:29:26 +020066
67#[cfg(feature = "cargo")]
Mårten Kongstadfa23d292023-05-11 14:47:02 +020068pub use aconfig::Flag_value as ProtoFlagValue;
Mårten Kongstadbb520722023-04-26 13:16:41 +020069
70#[cfg(feature = "cargo")]
Mårten Kongstadfa23d292023-05-11 14:47:02 +020071pub use aconfig::Flag_values as ProtoFlagValues;
Mårten Kongstadbb520722023-04-26 13:16:41 +020072
Mårten Kongstad416330b2023-05-05 11:10:01 +020073#[cfg(feature = "cargo")]
Mårten Kongstad30950782023-05-09 13:31:29 +020074pub use aconfig::Flag_permission as ProtoFlagPermission;
Mårten Kongstad416330b2023-05-05 11:10:01 +020075
Mårten Kongstadc68c4ea2023-05-05 16:20:09 +020076#[cfg(feature = "cargo")]
77pub use aconfig::Flag_state as ProtoFlagState;
78
Mårten Kongstada1029092023-05-08 11:51:59 +020079#[cfg(feature = "cargo")]
Mårten Kongstad30950782023-05-09 13:31:29 +020080pub use aconfig::Parsed_flags as ProtoParsedFlags;
Mårten Kongstada1029092023-05-08 11:51:59 +020081
82#[cfg(feature = "cargo")]
Mårten Kongstad30950782023-05-09 13:31:29 +020083pub use aconfig::Parsed_flag as ProtoParsedFlag;
Mårten Kongstada1029092023-05-08 11:51:59 +020084
85#[cfg(feature = "cargo")]
Mårten Kongstad30950782023-05-09 13:31:29 +020086pub use aconfig::Tracepoint as ProtoTracepoint;
Mårten Kongstada1029092023-05-08 11:51:59 +020087
Mårten Kongstadbb520722023-04-26 13:16:41 +020088// ---- Common for both the Android tool-chain and cargo ----
89use anyhow::Result;
90
91pub fn try_from_text_proto<T>(s: &str) -> Result<T>
92where
93 T: protobuf::MessageFull,
94{
95 // warning: parse_from_str does not check if required fields are set
96 protobuf::text_format::parse_from_str(s).map_err(|e| e.into())
97}