diff options
author | Joel Galenson <jgalenson@google.com> | 2021-07-20 14:51:42 -0700 |
---|---|---|
committer | Joel Galenson <jgalenson@google.com> | 2021-07-21 09:08:26 -0700 |
commit | 0ab911157d6114e2b6c3d7c06a3b347c31688df7 (patch) | |
tree | 1ec443753fc298e36446d6030b59773fb529e29c /profcollectd | |
parent | b61c66e9bc6637db70eeb1b83429619a6aa13322 (diff) | |
download | extras-0ab911157d6114e2b6c3d7c06a3b347c31688df7.tar.gz |
Migrate to bionic's Rust property bindings.
Bug: 182498247
Test: Build
Change-Id: I3eff9ed3c22df96228c2410ae69f5871fc6a6d58
Diffstat (limited to 'profcollectd')
6 files changed, 5 insertions, 140 deletions
diff --git a/profcollectd/libprofcollectd/Android.bp b/profcollectd/libprofcollectd/Android.bp index 7fb1b567..798a3775 100644 --- a/profcollectd/libprofcollectd/Android.bp +++ b/profcollectd/libprofcollectd/Android.bp @@ -51,12 +51,12 @@ rust_library { "librand", "libserde", // Remove once b/179041241 is fixed. "libserde_json", + "libsystem_properties-rust", "libuuid", "libzip", ], rlibs: [ "libprofcollect_libflags_rust", - "libprofcollect_libbase_rust", "libsimpleperf_profcollect_rust", ], shared_libs: ["libsimpleperf_profcollect"], diff --git a/profcollectd/libprofcollectd/bindings/libbase/Android.bp b/profcollectd/libprofcollectd/bindings/libbase/Android.bp deleted file mode 100644 index 8e5fb1e0..00000000 --- a/profcollectd/libprofcollectd/bindings/libbase/Android.bp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (C) 2021 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. -// - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "system_extras_profcollectd_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["system_extras_profcollectd_license"], -} - -cc_library_static { - name: "libprofcollect_libbase", - srcs: ["properties.cpp"], - generated_headers: ["cxx-bridge-header"], - generated_sources: ["libprofcollect_libbase_bridge_code"], -} - -genrule { - name: "libprofcollect_libbase_bridge_code", - tools: ["cxxbridge"], - cmd: "$(location cxxbridge) $(in) >> $(out)", - srcs: ["lib.rs"], - out: ["libprofcollect_libbase_cxx_generated.cc"], -} - -rust_library { - name: "libprofcollect_libbase_rust", - crate_name: "profcollect_libbase_rust", - srcs: ["lib.rs"], - rustlibs: [ - "libcxx", - ], - static_libs: ["libprofcollect_libbase"], - shared_libs: [ - "libc++", - "libbase", - ], -} diff --git a/profcollectd/libprofcollectd/bindings/libbase/lib.rs b/profcollectd/libprofcollectd/bindings/libbase/lib.rs deleted file mode 100644 index bdd99a02..00000000 --- a/profcollectd/libprofcollectd/bindings/libbase/lib.rs +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (C) 2021 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. -// - -//! This module implements safe wrappers for GetProperty and SetProperty from libbase. - -pub use ffi::{GetProperty, SetProperty}; - -/// Safe wrappers for the GetProperty and SetProperty methods from libbase. -#[cxx::bridge] -mod ffi { - unsafe extern "C++" { - include!("properties.hpp"); - - /// Returns the current value of the system property `key`, - /// or `default_value` if the property is empty or doesn't exist. - fn GetProperty(key: &str, default_value: &str) -> String; - - /// Sets the system property `key` to `value`. - fn SetProperty(key: &str, value: &str); - } -} diff --git a/profcollectd/libprofcollectd/bindings/libbase/properties.cpp b/profcollectd/libprofcollectd/bindings/libbase/properties.cpp deleted file mode 100644 index 908f19d0..00000000 --- a/profcollectd/libprofcollectd/bindings/libbase/properties.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#include "../../../../../libbase/include/android-base/properties.h" -#include "properties.hpp" - -rust::String GetProperty(rust::Str key, rust::Str default_value) { - return android::base::GetProperty(std::string(key), std::string(default_value)); -} - -void SetProperty(rust::Str key, rust::Str value) { - android::base::SetProperty(std::string(key), std::string(value)); -} diff --git a/profcollectd/libprofcollectd/bindings/libbase/properties.hpp b/profcollectd/libprofcollectd/bindings/libbase/properties.hpp deleted file mode 100644 index c8ef1f64..00000000 --- a/profcollectd/libprofcollectd/bindings/libbase/properties.hpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#pragma once - -#include "rust/cxx.h" - -rust::String GetProperty(rust::Str, rust::Str); -void SetProperty(rust::Str, rust::Str); diff --git a/profcollectd/libprofcollectd/config.rs b/profcollectd/libprofcollectd/config.rs index 11098fe1..e7dac241 100644 --- a/profcollectd/libprofcollectd/config.rs +++ b/profcollectd/libprofcollectd/config.rs @@ -91,7 +91,7 @@ fn get_or_initialise_node_id() -> Result<MacAddr6> { let mut node_id = get_property(&PROFCOLLECT_NODE_ID_PROPERTY, MacAddr6::nil())?; if node_id.is_nil() { node_id = generate_random_node_id(); - set_property(&PROFCOLLECT_NODE_ID_PROPERTY, node_id); + set_property(&PROFCOLLECT_NODE_ID_PROPERTY, node_id)?; } Ok(node_id) @@ -121,16 +121,16 @@ where T::Err: Error + Send + Sync + 'static, { let default_value = default_value.to_string(); - let value = profcollect_libbase_rust::GetProperty(&key, &default_value); + let value = system_properties::read(key).unwrap_or(default_value); Ok(T::from_str(&value)?) } -fn set_property<T>(key: &str, value: T) +fn set_property<T>(key: &str, value: T) -> Result<()> where T: ToString, { let value = value.to_string(); - profcollect_libbase_rust::SetProperty(&key, &value); + system_properties::write(key, &value) } fn generate_random_node_id() -> MacAddr6 { |