diff --git a/tools/aconfig/Android.bp b/tools/aconfig/Android.bp new file mode 100644 index 0000000000..b3813bfe5e --- /dev/null +++ b/tools/aconfig/Android.bp @@ -0,0 +1,33 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +rust_protobuf_host { + name: "libaconfig_protos", + protos: ["protos/aconfig.proto"], + crate_name: "aconfig_protos", + source_stem: "aconfig_protos", + use_protobuf3: true, +} + +rust_defaults { + name: "aconfig.defaults", + edition: "2021", + clippy_lints: "android", + lints: "android", + srcs: ["src/main.rs"], + rustlibs: [ + "libaconfig_protos", + "libprotobuf", + ], +} + +rust_binary_host { + name: "aconfig", + defaults: ["aconfig.defaults"], +} + +rust_test_host { + name: "aconfig.test", + defaults: ["aconfig.defaults"], +} diff --git a/tools/aconfig/MODULE_LICENSE_APACHE2 b/tools/aconfig/MODULE_LICENSE_APACHE2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/aconfig/OWNERS b/tools/aconfig/OWNERS new file mode 100644 index 0000000000..4e05b0020e --- /dev/null +++ b/tools/aconfig/OWNERS @@ -0,0 +1,5 @@ +amhk@google.com +jham@google.com +joeo@google.com +opg@google.com +zhidou@google.com diff --git a/tools/aconfig/PREUPLOAD.cfg b/tools/aconfig/PREUPLOAD.cfg new file mode 100644 index 0000000000..75ed57ce3e --- /dev/null +++ b/tools/aconfig/PREUPLOAD.cfg @@ -0,0 +1,5 @@ +[Builtin Hooks] +rustfmt = true + +[Builtin Hooks Options] +rustfmt = --config-path=rustfmt.toml diff --git a/tools/aconfig/protos/aconfig.proto b/tools/aconfig/protos/aconfig.proto new file mode 100644 index 0000000000..989c39866c --- /dev/null +++ b/tools/aconfig/protos/aconfig.proto @@ -0,0 +1,23 @@ +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +// Placeholder proto file. Will be replaced by actual contents. + +syntax = "proto3"; + +package android.aconfig; + +message Placeholder { + string name = 1; +} diff --git a/tools/aconfig/rustfmt.toml b/tools/aconfig/rustfmt.toml new file mode 120000 index 0000000000..291e99b28f --- /dev/null +++ b/tools/aconfig/rustfmt.toml @@ -0,0 +1 @@ +../../../soong/scripts/rustfmt.toml \ No newline at end of file diff --git a/tools/aconfig/src/main.rs b/tools/aconfig/src/main.rs new file mode 100644 index 0000000000..2f7255edab --- /dev/null +++ b/tools/aconfig/src/main.rs @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//! `aconfig` is a build time tool to manage build time configurations, such as feature flags. + +use aconfig_protos::aconfig::Placeholder; +use protobuf::text_format::{parse_from_str, ParseError}; + +fn foo() -> Result { + let placeholder = parse_from_str::(r#"name: "aconfig""#)?; + Ok(placeholder.name) +} + +fn main() { + println!("{:?}", foo()); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_foo() { + assert_eq!("aconfig", foo().unwrap()); + } + + #[test] + fn test_binary_protobuf() { + use protobuf::Message; + let mut buffer = Vec::new(); + + let mut original = Placeholder::new(); + original.name = "test".to_owned(); + original.write_to_writer(&mut buffer).unwrap(); + + let copy = Placeholder::parse_from_reader(&mut buffer.as_slice()).unwrap(); + + assert_eq!(original, copy); + } +}