movey_utils/
env.rs

1// Copyright (c) The Diem Core Contributors
2// Copyright (c) The Move Contributors
3// SPDX-License-Identifier: Apache-2.0
4
5use once_cell::sync::Lazy;
6
7/// An environment variable which can be set to cause the move compiler to generate
8/// file formats at a given version. Only version v5 and greater are supported.
9const BYTECODE_VERSION_ENV_VAR: &str = "MOVE_BYTECODE_VERSION";
10
11/// Get the bytecode version from the environment variable.
12// TODO: This should be configurable via toml and command line flags. See also #129.
13pub fn get_bytecode_version_from_env() -> Option<u32> {
14    std::env::var(BYTECODE_VERSION_ENV_VAR)
15        .ok()
16        .and_then(|s| s.parse::<u32>().ok())
17}
18
19pub fn read_env_var(v: &str) -> String {
20    std::env::var(v).unwrap_or_else(|_| String::new())
21}
22
23pub fn read_bool_env_var(v: &str) -> bool {
24    let val = read_env_var(v).to_lowercase();
25    val.parse::<bool>() == Ok(true) || val.parse::<usize>() == Ok(1)
26}
27
28pub static MOVE_HOME: Lazy<String> = Lazy::new(|| {
29    std::env::var("MOVE_HOME").unwrap_or_else(|_| {
30        format!(
31            "{}/.move",
32            dirs_next::home_dir()
33                .expect("user's home directory not found")
34                .to_str()
35                .unwrap()
36        )
37    })
38});