mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
refactor: remove version::is_canary(), use ReleaseChannel instead (#25053)
In preparation for https://github.com/denoland/deno/pull/25014, this commit removes public `is_canary()` method and instead uses an enum `ReleaseChannel` to be able to designate more "kinds" of builds.
This commit is contained in:
parent
8749d651fb
commit
e8d57cd3fe
7 changed files with 113 additions and 74 deletions
|
@ -36,6 +36,7 @@ use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::args::resolve_no_prompt;
|
use crate::args::resolve_no_prompt;
|
||||||
|
use crate::shared::ReleaseChannel;
|
||||||
use crate::util::fs::canonicalize_path;
|
use crate::util::fs::canonicalize_path;
|
||||||
|
|
||||||
use super::flags_net;
|
use super::flags_net;
|
||||||
|
@ -1334,7 +1335,18 @@ pub fn clap_root() -> Command {
|
||||||
let long_version = format!(
|
let long_version = format!(
|
||||||
"{} ({}, {})\nv8 {}\ntypescript {}",
|
"{} ({}, {})\nv8 {}\ntypescript {}",
|
||||||
crate::version::deno(),
|
crate::version::deno(),
|
||||||
if crate::version::is_canary() {
|
// TODO(bartlomieju): alter what's printed here.
|
||||||
|
// I think it's best if we print as follows:
|
||||||
|
// <version>(+<short_git_hash>) (<release_channel>, <profile>, <target>)
|
||||||
|
// For stable it would be:
|
||||||
|
// v1.46.0 (stable, release, aarch64-apple-darwin)
|
||||||
|
// For rc it would be:
|
||||||
|
// v1.46.0-rc.2 (release candidate, release, aarch64-apple-darwin)
|
||||||
|
// For lts it would be:
|
||||||
|
// v2.1.13-lts (LTS (long term support), release, aarch64-apple-darwin)
|
||||||
|
// For canary it would be:
|
||||||
|
// v1.46.0+25bb59d (canary, release, aarch64-apple-darwin)
|
||||||
|
if matches!(crate::version::RELEASE_CHANNEL, ReleaseChannel::Canary) {
|
||||||
"canary"
|
"canary"
|
||||||
} else {
|
} else {
|
||||||
env!("PROFILE")
|
env!("PROFILE")
|
||||||
|
|
|
@ -20,6 +20,7 @@ mod node;
|
||||||
mod npm;
|
mod npm;
|
||||||
mod ops;
|
mod ops;
|
||||||
mod resolver;
|
mod resolver;
|
||||||
|
mod shared;
|
||||||
mod standalone;
|
mod standalone;
|
||||||
mod task_runner;
|
mod task_runner;
|
||||||
mod tools;
|
mod tools;
|
||||||
|
|
|
@ -18,6 +18,7 @@ mod js;
|
||||||
mod node;
|
mod node;
|
||||||
mod npm;
|
mod npm;
|
||||||
mod resolver;
|
mod resolver;
|
||||||
|
mod shared;
|
||||||
mod task_runner;
|
mod task_runner;
|
||||||
mod util;
|
mod util;
|
||||||
mod version;
|
mod version;
|
||||||
|
|
55
cli/shared.rs
Normal file
55
cli/shared.rs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
use deno_core::anyhow::bail;
|
||||||
|
use deno_core::error::AnyError;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
pub enum ReleaseChannel {
|
||||||
|
/// Stable version, eg. 1.45.4, 2.0.0, 2.1.0
|
||||||
|
Stable,
|
||||||
|
|
||||||
|
/// Pointing to a git hash
|
||||||
|
Canary,
|
||||||
|
|
||||||
|
/// Long term support release
|
||||||
|
#[allow(unused)]
|
||||||
|
Lts,
|
||||||
|
|
||||||
|
/// Release candidate, poiting to a git hash
|
||||||
|
Rc,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReleaseChannel {
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Self::Stable => "latest",
|
||||||
|
Self::Canary => "canary",
|
||||||
|
Self::Rc => "release candidate",
|
||||||
|
Self::Lts => "LTS (long term support)",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(bartlomieju): do not ever change these values, tools like `patchver`
|
||||||
|
// rely on them.
|
||||||
|
pub fn serialize(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Stable => "stable",
|
||||||
|
Self::Canary => "canary",
|
||||||
|
Self::Rc => "rc",
|
||||||
|
Self::Lts => "lts",
|
||||||
|
}
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(bartlomieju): do not ever change these values, tools like `patchver`
|
||||||
|
// rely on them.
|
||||||
|
pub fn deserialize(str_: &str) -> Result<Self, AnyError> {
|
||||||
|
Ok(match str_ {
|
||||||
|
"stable" => Self::Stable,
|
||||||
|
"canary" => Self::Canary,
|
||||||
|
"rc" => Self::Rc,
|
||||||
|
"lts" => Self::Lts,
|
||||||
|
unknown => bail!("Unrecognized release channel: {}", unknown),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,6 +53,7 @@ use crate::file_fetcher::FileFetcher;
|
||||||
use crate::http_util::HttpClientProvider;
|
use crate::http_util::HttpClientProvider;
|
||||||
use crate::npm::CliNpmResolver;
|
use crate::npm::CliNpmResolver;
|
||||||
use crate::npm::InnerCliNpmResolverRef;
|
use crate::npm::InnerCliNpmResolverRef;
|
||||||
|
use crate::shared::ReleaseChannel;
|
||||||
use crate::standalone::virtual_fs::VfsEntry;
|
use crate::standalone::virtual_fs::VfsEntry;
|
||||||
use crate::util::archive;
|
use crate::util::archive;
|
||||||
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
||||||
|
@ -416,10 +417,17 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
||||||
let target = compile_flags.resolve_target();
|
let target = compile_flags.resolve_target();
|
||||||
let binary_name = format!("denort-{target}.zip");
|
let binary_name = format!("denort-{target}.zip");
|
||||||
|
|
||||||
let binary_path_suffix = if crate::version::is_canary() {
|
let binary_path_suffix = match crate::version::RELEASE_CHANNEL {
|
||||||
format!("canary/{}/{}", crate::version::GIT_COMMIT_HASH, binary_name)
|
ReleaseChannel::Canary => {
|
||||||
} else {
|
format!("canary/{}/{}", crate::version::GIT_COMMIT_HASH, binary_name)
|
||||||
format!("release/v{}/{}", env!("CARGO_PKG_VERSION"), binary_name)
|
}
|
||||||
|
ReleaseChannel::Stable => {
|
||||||
|
format!("release/v{}/{}", env!("CARGO_PKG_VERSION"), binary_name)
|
||||||
|
}
|
||||||
|
_ => bail!(
|
||||||
|
"`deno compile` current doesn't support {} release channel",
|
||||||
|
crate::version::RELEASE_CHANNEL.name()
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let download_directory = self.deno_dir.dl_folder_path();
|
let download_directory = self.deno_dir.dl_folder_path();
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::colors;
|
||||||
use crate::factory::CliFactory;
|
use crate::factory::CliFactory;
|
||||||
use crate::http_util::HttpClient;
|
use crate::http_util::HttpClient;
|
||||||
use crate::http_util::HttpClientProvider;
|
use crate::http_util::HttpClientProvider;
|
||||||
|
use crate::shared::ReleaseChannel;
|
||||||
use crate::util::archive;
|
use crate::util::archive;
|
||||||
use crate::util::progress_bar::ProgressBar;
|
use crate::util::progress_bar::ProgressBar;
|
||||||
use crate::util::progress_bar::ProgressBarStyle;
|
use crate::util::progress_bar::ProgressBarStyle;
|
||||||
|
@ -146,7 +147,8 @@ impl VersionProvider for RealVersionProvider {
|
||||||
async fn get_current_exe_release_channel(
|
async fn get_current_exe_release_channel(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<ReleaseChannel, AnyError> {
|
) -> Result<ReleaseChannel, AnyError> {
|
||||||
if version::is_canary() {
|
// TODO(bartlomieju): remove hitting a remote server
|
||||||
|
if matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) {
|
||||||
// If this fails for whatever reason, just return an empty vector.
|
// If this fails for whatever reason, just return an empty vector.
|
||||||
// It's better to miss that than throw error here.
|
// It's better to miss that than throw error here.
|
||||||
let rc_versions = get_rc_versions(
|
let rc_versions = get_rc_versions(
|
||||||
|
@ -636,11 +638,12 @@ fn select_specific_version_for_upgrade(
|
||||||
) -> Result<Option<AvailableVersion>, AnyError> {
|
) -> Result<Option<AvailableVersion>, AnyError> {
|
||||||
match release_channel {
|
match release_channel {
|
||||||
ReleaseChannel::Stable => {
|
ReleaseChannel::Stable => {
|
||||||
let current_is_passed = if !version::is_canary() {
|
let current_is_passed =
|
||||||
version::deno() == version
|
if !matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) {
|
||||||
} else {
|
version::deno() == version
|
||||||
false
|
} else {
|
||||||
};
|
false
|
||||||
|
};
|
||||||
|
|
||||||
if !force && current_is_passed {
|
if !force && current_is_passed {
|
||||||
log::info!("Version {} is already installed", version::deno());
|
log::info!("Version {} is already installed", version::deno());
|
||||||
|
@ -691,15 +694,16 @@ async fn find_latest_version_to_upgrade(
|
||||||
let (maybe_newer_latest_version, current_version) = match release_channel {
|
let (maybe_newer_latest_version, current_version) = match release_channel {
|
||||||
ReleaseChannel::Stable => {
|
ReleaseChannel::Stable => {
|
||||||
let current_version = version::deno();
|
let current_version = version::deno();
|
||||||
let current_is_most_recent = if !version::is_canary() {
|
let current_is_most_recent =
|
||||||
let current = Version::parse_standard(current_version).unwrap();
|
if !matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) {
|
||||||
let latest =
|
let current = Version::parse_standard(current_version).unwrap();
|
||||||
Version::parse_standard(&latest_version_found.version_or_hash)
|
let latest =
|
||||||
.unwrap();
|
Version::parse_standard(&latest_version_found.version_or_hash)
|
||||||
current >= latest
|
.unwrap();
|
||||||
} else {
|
current >= latest
|
||||||
false
|
} else {
|
||||||
};
|
false
|
||||||
|
};
|
||||||
|
|
||||||
if !force && current_is_most_recent {
|
if !force && current_is_most_recent {
|
||||||
(None, current_version)
|
(None, current_version)
|
||||||
|
@ -751,53 +755,6 @@ async fn find_latest_version_to_upgrade(
|
||||||
Ok(maybe_newer_latest_version)
|
Ok(maybe_newer_latest_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
||||||
enum ReleaseChannel {
|
|
||||||
/// Stable version, eg. 1.45.4, 2.0.0, 2.1.0
|
|
||||||
Stable,
|
|
||||||
|
|
||||||
/// Pointing to a git hash
|
|
||||||
Canary,
|
|
||||||
|
|
||||||
/// Long term support release
|
|
||||||
#[allow(unused)]
|
|
||||||
Lts,
|
|
||||||
|
|
||||||
/// Release candidate, poiting to a git hash
|
|
||||||
Rc,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ReleaseChannel {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
match self {
|
|
||||||
Self::Stable => "latest",
|
|
||||||
Self::Canary => "canary",
|
|
||||||
Self::Rc => "release candidate",
|
|
||||||
Self::Lts => "LTS (long term support)",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn serialize(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::Stable => "stable",
|
|
||||||
Self::Canary => "canary",
|
|
||||||
Self::Rc => "rc",
|
|
||||||
Self::Lts => "lts",
|
|
||||||
}
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn deserialize(str_: &str) -> Result<Self, AnyError> {
|
|
||||||
Ok(match str_ {
|
|
||||||
"stable" => Self::Stable,
|
|
||||||
"canary" => Self::Canary,
|
|
||||||
"rc" => Self::Rc,
|
|
||||||
"lts" => Self::Lts,
|
|
||||||
unknown => bail!("Unrecognized release channel: {}", unknown),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a list of available RC release in format of (<commit_hash>, <version_name>)
|
// Return a list of available RC release in format of (<commit_hash>, <version_name>)
|
||||||
fn parse_rc_versions_text(
|
fn parse_rc_versions_text(
|
||||||
text: &str,
|
text: &str,
|
||||||
|
|
|
@ -1,10 +1,19 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
use crate::shared::ReleaseChannel;
|
||||||
|
|
||||||
pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
|
pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
|
||||||
pub const TYPESCRIPT: &str = env!("TS_VERSION");
|
pub const TYPESCRIPT: &str = env!("TS_VERSION");
|
||||||
|
// TODO(bartlomieju): ideally we could remove this const.
|
||||||
|
const IS_CANARY: bool = option_env!("DENO_CANARY").is_some();
|
||||||
|
pub const RELEASE_CHANNEL: ReleaseChannel = if IS_CANARY {
|
||||||
|
ReleaseChannel::Canary
|
||||||
|
} else {
|
||||||
|
ReleaseChannel::Stable
|
||||||
|
};
|
||||||
|
|
||||||
pub fn deno() -> &'static str {
|
pub fn deno() -> &'static str {
|
||||||
if is_canary() {
|
if IS_CANARY {
|
||||||
concat!(
|
concat!(
|
||||||
env!("CARGO_PKG_VERSION"),
|
env!("CARGO_PKG_VERSION"),
|
||||||
"+",
|
"+",
|
||||||
|
@ -17,7 +26,7 @@ pub fn deno() -> &'static str {
|
||||||
|
|
||||||
// Keep this in sync with `deno()` above
|
// Keep this in sync with `deno()` above
|
||||||
pub fn get_user_agent() -> &'static str {
|
pub fn get_user_agent() -> &'static str {
|
||||||
if is_canary() {
|
if IS_CANARY {
|
||||||
concat!(
|
concat!(
|
||||||
"Deno/",
|
"Deno/",
|
||||||
env!("CARGO_PKG_VERSION"),
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
@ -29,12 +38,8 @@ pub fn get_user_agent() -> &'static str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_canary() -> bool {
|
|
||||||
option_env!("DENO_CANARY").is_some()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn release_version_or_canary_commit_hash() -> &'static str {
|
pub fn release_version_or_canary_commit_hash() -> &'static str {
|
||||||
if is_canary() {
|
if IS_CANARY {
|
||||||
GIT_COMMIT_HASH
|
GIT_COMMIT_HASH
|
||||||
} else {
|
} else {
|
||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
|
|
Loading…
Reference in a new issue