Skip to main content

detcore_model/
build_info.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! Machine-readable facts about a Hermit binary.
10
11use serde::Deserialize;
12use serde::Serialize;
13
14/// Compile-time Cargo features whose presence changes the public CLI surface.
15#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
16#[serde(deny_unknown_fields)]
17pub struct BuildFeatures {
18    pub dbt: bool,
19    pub e9patch: bool,
20    pub sabre: bool,
21}
22
23/// The build facts emitted by `hermit version --json`.
24#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
25#[serde(deny_unknown_fields)]
26pub struct BuildInfo {
27    pub schema: u64,
28    pub version: String,
29    pub build_date: Option<String>,
30    pub git_sha: String,
31    pub features: BuildFeatures,
32}
33
34impl BuildInfo {
35    pub const SCHEMA: u64 = 1;
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn unknown_fields_are_refused() {
44        let value = serde_json::json!({
45            "schema": BuildInfo::SCHEMA,
46            "version": "0.2.0",
47            "build_date": null,
48            "git_sha": "0123456789ab",
49            "features": {"dbt": false, "e9patch": false, "sabre": false},
50            "future": true,
51        });
52        let error = serde_json::from_value::<BuildInfo>(value).unwrap_err();
53        assert!(error.to_string().contains("unknown field `future`"));
54    }
55}