blob: f18a91db0c80b4c2bad271eaa3a287d6247bab39 [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 Kongstadbb520722023-04-26 13:16:41 +020031pub use aconfig_protos::aconfig::Android_config as ProtoAndroidConfig;
Mårten Kongstadfe753f52023-04-26 09:13:03 +020032
Mårten Kongstadbb520722023-04-26 13:16:41 +020033#[cfg(not(feature = "cargo"))]
Mårten Kongstad09c28d12023-05-04 13:29:26 +020034pub use aconfig_protos::aconfig::Value as ProtoValue;
35
36#[cfg(not(feature = "cargo"))]
Mårten Kongstadbb520722023-04-26 13:16:41 +020037pub use aconfig_protos::aconfig::Flag as ProtoFlag;
38
39#[cfg(not(feature = "cargo"))]
40pub use aconfig_protos::aconfig::Override_config as ProtoOverrideConfig;
41
42#[cfg(not(feature = "cargo"))]
43pub use aconfig_protos::aconfig::Override as ProtoOverride;
44
Mårten Kongstad416330b2023-05-05 11:10:01 +020045#[cfg(not(feature = "cargo"))]
46pub use aconfig_protos::aconfig::Permission as ProtoPermission;
47
Mårten Kongstadc68c4ea2023-05-05 16:20:09 +020048#[cfg(not(feature = "cargo"))]
49pub use aconfig_protos::aconfig::Flag_state as ProtoFlagState;
50
Mårten Kongstada1029092023-05-08 11:51:59 +020051#[cfg(not(feature = "cargo"))]
52pub use aconfig_protos::aconfig::Dump as ProtoDump;
53
54#[cfg(not(feature = "cargo"))]
55pub use aconfig_protos::aconfig::Dump_item as ProtoDumpItem;
56
57#[cfg(not(feature = "cargo"))]
58pub use aconfig_protos::aconfig::Dump_trace as ProtoDumpTracePoint;
59
Mårten Kongstadbb520722023-04-26 13:16:41 +020060// ---- When building with cargo ----
Mårten Kongstadfe753f52023-04-26 09:13:03 +020061#[cfg(feature = "cargo")]
62include!(concat!(env!("OUT_DIR"), "/aconfig_proto/mod.rs"));
63
64#[cfg(feature = "cargo")]
Mårten Kongstadbb520722023-04-26 13:16:41 +020065pub use aconfig::Android_config as ProtoAndroidConfig;
66
67#[cfg(feature = "cargo")]
Mårten Kongstad09c28d12023-05-04 13:29:26 +020068pub use aconfig::Value as ProtoValue;
69
70#[cfg(feature = "cargo")]
Mårten Kongstadbb520722023-04-26 13:16:41 +020071pub use aconfig::Flag as ProtoFlag;
72
73#[cfg(feature = "cargo")]
74pub use aconfig::Override_config as ProtoOverrideConfig;
75
76#[cfg(feature = "cargo")]
77pub use aconfig::Override as ProtoOverride;
78
Mårten Kongstad416330b2023-05-05 11:10:01 +020079#[cfg(feature = "cargo")]
80pub use aconfig::Permission as ProtoPermission;
81
Mårten Kongstadc68c4ea2023-05-05 16:20:09 +020082#[cfg(feature = "cargo")]
83pub use aconfig::Flag_state as ProtoFlagState;
84
Mårten Kongstada1029092023-05-08 11:51:59 +020085#[cfg(feature = "cargo")]
86pub use aconfig::Dump as ProtoDump;
87
88#[cfg(feature = "cargo")]
89pub use aconfig::Dump_item as ProtoDumpItem;
90
91#[cfg(feature = "cargo")]
92pub use aconfig::Dump_trace as ProtoDumpTracePoint;
93
Mårten Kongstadbb520722023-04-26 13:16:41 +020094// ---- Common for both the Android tool-chain and cargo ----
95use anyhow::Result;
96
97pub fn try_from_text_proto<T>(s: &str) -> Result<T>
98where
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}