diff --git a/.gitignore b/.gitignore index 5699503d..9659b790 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /.idea/ /.vscode/ logs/ +/runtime/conf/ya-runtime-vm.json diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 46896b56..353b9f7c 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -110,6 +110,7 @@ pnet = "0.33" [build-dependencies] anyhow = "1.0" +serde_json = "1.0" [lib] name = "ya_runtime_vm" diff --git a/runtime/build.rs b/runtime/build.rs index 77ba8d3d..430d0ffc 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -1,18 +1,19 @@ use anyhow::Context; +use serde_json::{Map, Value}; use std::env; +use std::fs::File; use std::ops::Not; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; static RERUN_IF_CHANGED: &str = "cargo:rerun-if-changed"; -fn main() -> anyhow::Result<()> { +fn make_init(root_dir: &Path) -> anyhow::Result<()> { // skip build for CI if env::var("CI").is_ok() { return Ok(()); } - let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let init_dir = root_dir.join("init-container").canonicalize().unwrap(); let include_dir = init_dir.join("include"); let src_dir = init_dir.join("src"); @@ -52,3 +53,24 @@ fn main() -> anyhow::Result<()> { ); Ok(()) } + +fn update_conf(root_dir: &Path, version: String) { + let fname = root_dir.join("conf/ya-runtime-vm.json.in"); + let fin = File::open(fname).unwrap(); + let fname = root_dir.join("conf/ya-runtime-vm.json"); + let fout = File::create(fname).unwrap(); + + let mut json: Vec> = serde_json::from_reader(fin).unwrap(); + json[0].insert(String::from("version"), Value::from(version)); + serde_json::to_writer_pretty(fout, &json).unwrap(); +} + +fn main() -> anyhow::Result<()> { + let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); + let version = env::var("CARGO_PKG_VERSION").unwrap(); + + make_init(&root_dir)?; + update_conf(&root_dir, version); + + Ok(()) +} diff --git a/runtime/conf/ya-runtime-vm.json b/runtime/conf/ya-runtime-vm.json.in similarity index 86% rename from runtime/conf/ya-runtime-vm.json rename to runtime/conf/ya-runtime-vm.json.in index 991513a6..d10b9b63 100644 --- a/runtime/conf/ya-runtime-vm.json +++ b/runtime/conf/ya-runtime-vm.json.in @@ -1,7 +1,7 @@ [ { "name": "vm", - "version": "0.5.0", + "version": "@VERSION@", "supervisor-path": "exe-unit", "runtime-path": "ya-runtime-vm/ya-runtime-vm", "description": "vm runtime",