Move shared config structs to shared crate.
Bug: 184131523
Test: mm
Change-Id: I53e46a2985addbee9facd5b007778ae60c583900
diff --git a/virtualizationservice/Android.bp b/virtualizationservice/Android.bp
index 2d78018..bad7f46 100644
--- a/virtualizationservice/Android.bp
+++ b/virtualizationservice/Android.bp
@@ -13,6 +13,7 @@
"libandroid_logger",
"libanyhow",
"libcommand_fds",
+ "libcompositediskconfig",
"liblog_rust",
"libserde_json",
"libserde",
diff --git a/virtualizationservice/src/composite.rs b/virtualizationservice/src/composite.rs
index eb738a7..37428eb 100644
--- a/virtualizationservice/src/composite.rs
+++ b/virtualizationservice/src/composite.rs
@@ -14,12 +14,10 @@
//! Functions for running `mk_cdisk`.
-mod config;
-
use android_system_virtualizationservice::aidl::android::system::virtualizationservice::Partition::Partition as AidlPartition;
use anyhow::{bail, Context, Error};
use command_fds::{CommandFdExt, FdMapping};
-use config::{Config, Partition};
+use compositediskconfig::{Config, Partition};
use log::info;
use std::fs::File;
use std::os::unix::io::AsRawFd;
@@ -58,7 +56,9 @@
// Write config to stdin of mk_cdisk on a separate thread to avoid deadlock, as it may not read
// all of stdin before it blocks on writing to stdout.
- let writer_thread = thread::spawn(move || config_json.write_json(&stdin));
+ let writer_thread = thread::spawn(move || {
+ config_json.write_json(&stdin).context("Failed to write config JSON for mk_cdisk")
+ });
info!("Running {:?}", command);
let output = child.wait_with_output()?;
match writer_thread.join() {
diff --git a/virtualizationservice/src/composite/config.rs b/virtualizationservice/src/composite/config.rs
deleted file mode 100644
index 1a915ba..0000000
--- a/virtualizationservice/src/composite/config.rs
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 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.
-
-//! JSON configuration for running `mk_cdisk`.
-
-use anyhow::{Context, Error};
-use serde::{Deserialize, Serialize};
-use std::io::Write;
-use std::path::PathBuf;
-
-#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
-pub struct Config {
- /// The set of partitions to be assembled into a composite image.
- pub partitions: Vec<Partition>,
-}
-
-/// A partition to be assembled into a composite image.
-#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
-pub struct Partition {
- /// A label for the partition.
- pub label: String,
- /// The filename of the partition image.
- pub path: PathBuf,
- /// Whether the partition should be writable.
- #[serde(default)]
- pub writable: bool,
-}
-
-impl Config {
- pub fn write_json(&self, writer: impl Write) -> Result<(), Error> {
- serde_json::to_writer(writer, self).context("Failed to write config JSON for mk_cdisk")
- }
-}