blob: 390e50c2ab4c906bd57b1e93b1272809f0bb994f [file] [log] [blame]
Alan Stokes46a1dff2021-12-14 10:56:05 +00001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! Helpers for running odrefresh
18
Alan Stokes126fd512021-12-16 15:00:01 +000019use anyhow::{anyhow, Result};
Alan Stokes46a1dff2021-12-14 10:56:05 +000020use num_derive::FromPrimitive;
21use num_traits::FromPrimitive;
22
23/// The path to the odrefresh binary
24pub const ODREFRESH_PATH: &str = "/apex/com.android.art/bin/odrefresh";
25
Alan Stokes16fb8552022-02-10 15:07:27 +000026/// The path under which odrefresh writes compiled artifacts
27pub const ODREFRESH_OUTPUT_ROOT_DIR: &str = "/data/misc/apexdata/com.android.art";
28
29/// The directory under ODREFRESH_OUTPUT_ROOT_DIR where pending artifacts are written
30pub const PENDING_ARTIFACTS_SUBDIR: &str = "compos-pending";
31
32/// The directory under ODREFRESH_OUTPUT_ROOT_DIR where test artifacts are written
33pub const TEST_ARTIFACTS_SUBDIR: &str = "test-artifacts";
34
35/// The directory under ODREFRESH_OUTPUT_ROOT_DIR where the current (active) artifacts are stored
36pub const CURRENT_ARTIFACTS_SUBDIR: &str = "dalvik-cache";
37
Alan Stokes126fd512021-12-16 15:00:01 +000038// The highest "standard" exit code defined in sysexits.h (as EX__MAX); odrefresh error codes
39// start above here to avoid clashing.
Alan Stokes46a1dff2021-12-14 10:56:05 +000040// TODO: What if this changes?
41const EX_MAX: i8 = 78;
42
43/// The defined odrefresh exit codes - see art/odrefresh/include/odrefresh/odrefresh.h
44#[derive(Debug, PartialEq, Eq, FromPrimitive)]
45#[repr(i8)]
46pub enum ExitCode {
47 /// No compilation required, all artifacts look good
Alan Stokes126fd512021-12-16 15:00:01 +000048 Okay = 0,
Alan Stokes46a1dff2021-12-14 10:56:05 +000049 /// Compilation required
50 CompilationRequired = EX_MAX + 1,
51 /// New artifacts successfully generated
52 CompilationSuccess = EX_MAX + 2,
53 /// Compilation failed
54 CompilationFailed = EX_MAX + 3,
55 /// Removal of existing invalid artifacts failed
56 CleanupFailed = EX_MAX + 4,
57}
58
59impl ExitCode {
60 /// Map an integer to the corresponding ExitCode enum, if there is one
Alan Stokes126fd512021-12-16 15:00:01 +000061 pub fn from_i32(exit_code: i32) -> Result<Self> {
Alan Stokes46a1dff2021-12-14 10:56:05 +000062 FromPrimitive::from_i32(exit_code)
Alan Stokes126fd512021-12-16 15:00:01 +000063 .ok_or_else(|| anyhow!("Unexpected odrefresh exit code: {}", exit_code))
Alan Stokes46a1dff2021-12-14 10:56:05 +000064 }
65}