Remove the old interface that runs compiler with flags
Bug: 210998077
Test: atest ComposHostTestCases
Change-Id: I50bb4cb96e0eb4033c531d47f6620ba8ede78553
diff --git a/compos/src/compilation.rs b/compos/src/compilation.rs
index 9a23bf5..6db31b6 100644
--- a/compos/src/compilation.rs
+++ b/compos/src/compilation.rs
@@ -14,31 +14,27 @@
* limitations under the License.
*/
-use anyhow::{anyhow, bail, Context, Result};
-use log::{debug, error, info, warn};
+use anyhow::{bail, Context, Result};
+use log::{debug, info, warn};
use minijail::{self, Minijail};
use regex::Regex;
use std::env;
use std::ffi::OsString;
-use std::fs::{read_dir, File};
-use std::os::unix::io::{AsRawFd, RawFd};
+use std::fs::read_dir;
+use std::os::unix::io::AsRawFd;
use std::path::{self, Path, PathBuf};
use std::process::Command;
use crate::artifact_signer::ArtifactSigner;
use crate::compos_key_service::Signer;
-use crate::fsverity;
use authfs_aidl_interface::aidl::com::android::virt::fs::{
AuthFsConfig::{
AuthFsConfig, InputDirFdAnnotation::InputDirFdAnnotation,
- InputFdAnnotation::InputFdAnnotation, OutputDirFdAnnotation::OutputDirFdAnnotation,
- OutputFdAnnotation::OutputFdAnnotation,
+ OutputDirFdAnnotation::OutputDirFdAnnotation,
},
- IAuthFs::IAuthFs,
IAuthFsService::IAuthFsService,
};
use authfs_aidl_interface::binder::{ParcelFileDescriptor, Strong};
-use compos_aidl_interface::aidl::com::android::compos::FdAnnotation::FdAnnotation;
use compos_common::odrefresh::ExitCode;
const FD_SERVER_PORT: i32 = 3264; // TODO: support dynamic port
@@ -47,23 +43,6 @@
/// meaningless in the current process.
pub type PseudoRawFd = i32;
-pub enum CompilerOutput {
- /// Fs-verity digests of output files, if the compiler finishes successfully.
- Digests {
- oat: fsverity::Sha256Digest,
- vdex: fsverity::Sha256Digest,
- image: fsverity::Sha256Digest,
- },
- /// Exit code returned by the compiler, if not 0.
- ExitCode(i8),
-}
-
-struct CompilerOutputParcelFds {
- oat: ParcelFileDescriptor,
- vdex: ParcelFileDescriptor,
- image: ParcelFileDescriptor,
-}
-
pub struct OdrefreshContext<'a> {
system_dir_fd: i32,
output_dir_fd: i32,
@@ -259,131 +238,6 @@
Ok(())
}
-/// Runs the compiler with given flags with file descriptors described in `fd_annotation` retrieved
-/// via `authfs_service`. Returns exit code of the compiler process.
-pub fn compile_cmd(
- compiler_path: &Path,
- compiler_args: &[String],
- authfs_service: Strong<dyn IAuthFsService>,
- fd_annotation: &FdAnnotation,
-) -> Result<CompilerOutput> {
- // Mount authfs (via authfs_service). The authfs instance unmounts once the `authfs` variable
- // is out of scope.
- let authfs_config = build_authfs_config(fd_annotation);
- let authfs = authfs_service.mount(&authfs_config)?;
-
- // The task expects to receive FD numbers that match its flags (e.g. --zip-fd=42) prepared
- // on the host side. Since the local FD opened from authfs (e.g. /authfs/42) may not match
- // the task's expectation, prepare a FD mapping and let minijail prepare the correct FD
- // setup.
- let fd_mapping =
- open_authfs_files_for_fd_mapping(&authfs, &authfs_config).context("Open on authfs")?;
-
- let jail =
- spawn_jailed_task(compiler_path, compiler_args, fd_mapping).context("Spawn dex2oat")?;
- let jail_result = jail.wait();
-
- let parcel_fds = parse_compiler_args(&authfs, compiler_args)?;
- let oat_file: &File = parcel_fds.oat.as_ref();
- let vdex_file: &File = parcel_fds.vdex.as_ref();
- let image_file: &File = parcel_fds.image.as_ref();
-
- match jail_result {
- Ok(()) => Ok(CompilerOutput::Digests {
- oat: fsverity::measure(oat_file.as_raw_fd())?,
- vdex: fsverity::measure(vdex_file.as_raw_fd())?,
- image: fsverity::measure(image_file.as_raw_fd())?,
- }),
- Err(minijail::Error::ReturnCode(exit_code)) => {
- error!("dex2oat failed with exit code {}", exit_code);
- Ok(CompilerOutput::ExitCode(exit_code as i8))
- }
- Err(e) => {
- bail!("Unexpected minijail error: {}", e)
- }
- }
-}
-
-fn parse_compiler_args(
- authfs: &Strong<dyn IAuthFs>,
- args: &[String],
-) -> Result<CompilerOutputParcelFds> {
- const OAT_FD_PREFIX: &str = "--oat-fd=";
- const VDEX_FD_PREFIX: &str = "--output-vdex-fd=";
- const IMAGE_FD_PREFIX: &str = "--image-fd=";
- const APP_IMAGE_FD_PREFIX: &str = "--app-image-fd=";
-
- let mut oat = None;
- let mut vdex = None;
- let mut image = None;
-
- for arg in args {
- if let Some(value) = arg.strip_prefix(OAT_FD_PREFIX) {
- let fd = value.parse::<RawFd>().context("Invalid --oat-fd flag")?;
- debug_assert!(oat.is_none());
- oat = Some(authfs.openFile(fd, false)?);
- } else if let Some(value) = arg.strip_prefix(VDEX_FD_PREFIX) {
- let fd = value.parse::<RawFd>().context("Invalid --output-vdex-fd flag")?;
- debug_assert!(vdex.is_none());
- vdex = Some(authfs.openFile(fd, false)?);
- } else if let Some(value) = arg.strip_prefix(IMAGE_FD_PREFIX) {
- let fd = value.parse::<RawFd>().context("Invalid --image-fd flag")?;
- debug_assert!(image.is_none());
- image = Some(authfs.openFile(fd, false)?);
- } else if let Some(value) = arg.strip_prefix(APP_IMAGE_FD_PREFIX) {
- let fd = value.parse::<RawFd>().context("Invalid --app-image-fd flag")?;
- debug_assert!(image.is_none());
- image = Some(authfs.openFile(fd, false)?);
- }
- }
-
- Ok(CompilerOutputParcelFds {
- oat: oat.ok_or_else(|| anyhow!("Missing --oat-fd"))?,
- vdex: vdex.ok_or_else(|| anyhow!("Missing --vdex-fd"))?,
- image: image.ok_or_else(|| anyhow!("Missing --image-fd or --app-image-fd"))?,
- })
-}
-
-fn build_authfs_config(fd_annotation: &FdAnnotation) -> AuthFsConfig {
- AuthFsConfig {
- port: FD_SERVER_PORT,
- inputFdAnnotations: fd_annotation
- .input_fds
- .iter()
- .map(|fd| InputFdAnnotation { fd: *fd })
- .collect(),
- outputFdAnnotations: fd_annotation
- .output_fds
- .iter()
- .map(|fd| OutputFdAnnotation { fd: *fd })
- .collect(),
- ..Default::default()
- }
-}
-
-fn open_authfs_files_for_fd_mapping(
- authfs: &Strong<dyn IAuthFs>,
- config: &AuthFsConfig,
-) -> Result<Vec<(ParcelFileDescriptor, PseudoRawFd)>> {
- let mut fd_mapping = Vec::new();
-
- let results: Result<Vec<_>> = config
- .inputFdAnnotations
- .iter()
- .map(|annotation| Ok((authfs.openFile(annotation.fd, false)?, annotation.fd)))
- .collect();
- fd_mapping.append(&mut results?);
-
- let results: Result<Vec<_>> = config
- .outputFdAnnotations
- .iter()
- .map(|annotation| Ok((authfs.openFile(annotation.fd, true)?, annotation.fd)))
- .collect();
- fd_mapping.append(&mut results?);
-
- Ok(fd_mapping)
-}
-
fn spawn_jailed_task(
executable: &Path,
args: &[String],