Merge "aconfig: add project scaffolding" am: e7a850e942
Original change: https://android-review.googlesource.com/c/platform/build/+/2563154 Change-Id: I88c6b05de525f296d879805e099f020f7c5e4fb4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
7b9a0b649c
7 changed files with 120 additions and 0 deletions
33
tools/aconfig/Android.bp
Normal file
33
tools/aconfig/Android.bp
Normal file
|
@ -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"],
|
||||||
|
}
|
0
tools/aconfig/MODULE_LICENSE_APACHE2
Normal file
0
tools/aconfig/MODULE_LICENSE_APACHE2
Normal file
5
tools/aconfig/OWNERS
Normal file
5
tools/aconfig/OWNERS
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
amhk@google.com
|
||||||
|
jham@google.com
|
||||||
|
joeo@google.com
|
||||||
|
opg@google.com
|
||||||
|
zhidou@google.com
|
5
tools/aconfig/PREUPLOAD.cfg
Normal file
5
tools/aconfig/PREUPLOAD.cfg
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[Builtin Hooks]
|
||||||
|
rustfmt = true
|
||||||
|
|
||||||
|
[Builtin Hooks Options]
|
||||||
|
rustfmt = --config-path=rustfmt.toml
|
23
tools/aconfig/protos/aconfig.proto
Normal file
23
tools/aconfig/protos/aconfig.proto
Normal file
|
@ -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;
|
||||||
|
}
|
1
tools/aconfig/rustfmt.toml
Symbolic link
1
tools/aconfig/rustfmt.toml
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../../soong/scripts/rustfmt.toml
|
53
tools/aconfig/src/main.rs
Normal file
53
tools/aconfig/src/main.rs
Normal file
|
@ -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<String, ParseError> {
|
||||||
|
let placeholder = parse_from_str::<Placeholder>(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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue