Skip to content

Commit bbbbdf0

Browse files
author
Hans Larsen
committed
fixup: version
1 parent 35192a3 commit bbbbdf0

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

dfx/src/config/cache.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::io::{Error, ErrorKind, Result};
22
use std::path::PathBuf;
33

4+
use crate::config::dfx_version;
45
use crate::util;
56

67
pub fn get_bin_cache_root() -> Result<PathBuf> {
@@ -31,14 +32,7 @@ pub fn get_bin_cache_root() -> Result<PathBuf> {
3132

3233
pub fn get_bin_cache(v: &str) -> Result<PathBuf> {
3334
let root = get_bin_cache_root()?;
34-
35-
match v {
36-
"0.2.0" => Ok(root.join("0.2.0")),
37-
v => Err(Error::new(
38-
ErrorKind::Other,
39-
format!("Unknown version: {}", v),
40-
)),
41-
}
35+
Ok(root.join(v))
4236
}
4337

4438
pub fn is_version_installed(v: &str) -> Result<bool> {
@@ -60,15 +54,14 @@ pub fn install_version(v: &str) -> Result<PathBuf> {
6054
return Ok(p);
6155
}
6256

63-
match v {
64-
"0.2.0" => {
65-
util::assets::binary_cache()?.unpack(p.as_path())?;
66-
Ok(p)
67-
}
68-
v => Err(Error::new(
57+
if v == dfx_version() {
58+
util::assets::binary_cache()?.unpack(p.as_path())?;
59+
Ok(p)
60+
} else {
61+
Err(Error::new(
6962
ErrorKind::Other,
7063
format!("Unknown version: {}", v),
71-
)),
64+
))
7265
}
7366
}
7467

dfx/src/config/mod.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
pub mod cache;
22
pub mod dfinity;
33

4-
pub const DFX_VERSION: &str = env!("CARGO_PKG_VERSION");
4+
static mut DFX_VERSION: Option<String> = None;
5+
pub fn dfx_version() -> &'static str {
6+
unsafe {
7+
match &DFX_VERSION {
8+
Some(x) => x.as_str(),
9+
None => {
10+
let version = env!("CARGO_PKG_VERSION");
11+
12+
#[cfg(debug_assertions)]
13+
{
14+
// In debug, add a timestamp of the compilation at the end of version to ensure all
15+
// debug runs are unique (and cached uniquely).
16+
DFX_VERSION = Some(format!(
17+
"{}-{}",
18+
version,
19+
std::env::var("DFX_TIMESTAMP_DEBUG_MODE_ONLY")
20+
.unwrap_or_else(|_| "local-debug".to_owned())
21+
));
22+
}
23+
24+
dfx_version()
25+
}
26+
}
27+
}
28+
}

dfx/src/lib/env.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::config::dfinity::Config;
2-
use crate::config::{cache, DFX_VERSION};
2+
use crate::config::{cache, dfx_version};
33
use crate::lib::api_client::{Client, ClientConfig};
44
use crate::lib::error::DfxResult;
55
use std::cell::RefCell;
@@ -116,7 +116,7 @@ impl InProjectEnvironment {
116116
version: config
117117
.get_config()
118118
.get_dfx()
119-
.unwrap_or_else(|| DFX_VERSION.to_owned()),
119+
.unwrap_or_else(|| dfx_version().to_owned()),
120120
config,
121121
client: RefCell::new(None),
122122
})
@@ -174,25 +174,8 @@ impl VersionEnv for GlobalEnvironment {
174174

175175
impl GlobalEnvironment {
176176
pub fn from_current_dir() -> DfxResult<GlobalEnvironment> {
177-
#[cfg(debug_assertions)]
178-
{
179-
// In debug, add a timestamp of the compilation at the end of version to ensure all
180-
// debug runs are unique (and cached uniquely).
181-
Ok(GlobalEnvironment {
182-
version: format!(
183-
"{}-{:?}",
184-
DFX_VERSION.to_owned(),
185-
std::env::var_os("DFX_TIMESTAMP_DEBUG_MODE_ONLY")
186-
.unwrap_or_else(|| std::ffi::OsString::from("local-debug"))
187-
),
188-
})
189-
}
190-
191-
#[cfg(not(debug_assertions))]
192-
{
193-
Ok(GlobalEnvironment {
194-
version: DFX_VERSION.to_owned(),
195-
})
196-
}
177+
Ok(GlobalEnvironment {
178+
version: dfx_version().to_owned(),
179+
})
197180
}
198181
}

0 commit comments

Comments
 (0)