Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider Nightly channels when checking for avaliable_channels #848

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use itertools::Itertools;
use juliaup::config_file::{load_config_db, JuliaupConfig, JuliaupConfigChannel};
use juliaup::global_paths::get_paths;
use juliaup::jsonstructs_versionsdb::JuliaupVersionDB;
use juliaup::operations::is_valid_channel;
use juliaup::versions_file::load_versions_db;
#[cfg(not(windows))]
use nix::{
Expand Down Expand Up @@ -174,29 +175,30 @@ fn get_julia_path_from_channel(
juliaupconfig_path: &Path,
juliaup_channel_source: JuliaupChannelSource,
) -> Result<(PathBuf, Vec<String>)> {
let channel_valid = is_valid_channel(versions_db, &channel.to_string())?;
let channel_info = config_data
.installed_channels
.get(channel)
.ok_or_else(|| match juliaup_channel_source {
JuliaupChannelSource::CmdLine => {
if versions_db.available_channels.contains_key(channel) {
if channel_valid {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::EnvVar=> {
if versions_db.available_channels.contains_key(channel) {
UserError { msg: format!("`{}` for environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
if channel_valid {
UserError { msg: format!("`{}` from environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` from environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::Override=> {
if versions_db.available_channels.contains_key(channel) {
UserError { msg: format!("`{}` for directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
if channel_valid {
UserError { msg: format!("`{}` from directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` from directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::Default => anyhow!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", channel)
Expand Down
3 changes: 2 additions & 1 deletion src/command_default.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::operations::is_valid_channel;
use crate::versions_file::load_versions_db;
use crate::{config_file::*, global_paths::GlobalPaths};
use anyhow::{bail, Context, Result};
Expand All @@ -9,7 +10,7 @@ pub fn run_command_default(channel: &str, paths: &GlobalPaths) -> Result<()> {
if !config_file.data.installed_channels.contains_key(channel) {
let version_db = load_versions_db(paths)
.with_context(|| "`default` command failed to load versions db.")?;
if !version_db.available_channels.contains_key(channel) {
if !is_valid_channel(&version_db, &channel.to_string())? {
bail!("'{}' is not a valid Julia version.", channel);
} else {
bail!(
Expand Down
3 changes: 2 additions & 1 deletion src/command_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::config_file::{load_mut_config_db, save_config_db};
use crate::global_paths::GlobalPaths;
#[cfg(not(windows))]
use crate::operations::create_symlink;
use crate::operations::is_valid_channel;
use crate::versions_file::load_versions_db;
use anyhow::{bail, Context, Result};
use path_absolutize::Absolutize;
Expand All @@ -24,7 +25,7 @@ pub fn run_command_link(
bail!("Channel name `{}` is already used.", channel)
}

if versiondb_data.available_channels.contains_key(channel) {
if is_valid_channel(&versiondb_data, &channel.to_string())? {
eprintln!("WARNING: The channel name `{}` is also a system channel. By linking your custom binary to this channel you are hiding this system channel.", channel);
}

Expand Down
21 changes: 21 additions & 0 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,27 @@ pub fn compatible_archs() -> Result<Vec<String>> {
}
}

// which nightly channels are compatible with the current system
fn compatible_nightly_channels() -> Result<Vec<String>> {
let archs: Vec<String> = compatible_archs()?;

let channels: Vec<String> = std::iter::once("nightly".to_string())
.chain(archs.into_iter().map(|arch| format!("nightly~{}", arch)))
.collect();
Ok(channels)
}

// considers the nightly channels as system channels
// XXX: does not account for PR channels
pub fn is_valid_channel(versions_db: &JuliaupVersionDB, channel: &String) -> Result<bool> {
let regular = versions_db.available_channels.contains_key(channel);

let nightly_chans = compatible_nightly_channels()?;

let nightly = nightly_chans.contains(channel);
Ok(regular || nightly)
}

// Identify the unversioned name of a nightly (e.g., `latest-macos-x86_64`) for a channel
pub fn channel_to_name(channel: &String) -> Result<String> {
let mut parts = channel.splitn(2, '~');
Expand Down
28 changes: 27 additions & 1 deletion tests/channel_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn channel_selection() {
.assert()
.failure()
.stderr(
"ERROR: Invalid Juliaup channel `1.7.4` in environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.\n",
"ERROR: Invalid Juliaup channel `1.7.4` from environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.\n",
);

Command::cargo_bin("julia")
Expand All @@ -125,4 +125,30 @@ fn channel_selection() {
.assert()
.failure()
.stderr("ERROR: Invalid Juliaup channel `1.8.6`. Please run `juliaup list` to get a list of valid channels and versions.\n");

// https://github.com/JuliaLang/juliaup/issues/766
Command::cargo_bin("julia")
.unwrap()
.arg("+1.8.2")
.arg("-e")
.arg("print(VERSION)")
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_CHANNEL", "1.7.4")
.assert()
.failure()
.stderr("`1.8.2` is not installed. Please run `juliaup add 1.8.2` to install channel or version.\n");

// https://github.com/JuliaLang/juliaup/issues/820
Command::cargo_bin("julia")
.unwrap()
.arg("+nightly")
.arg("-e")
.arg("print(VERSION)")
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_CHANNEL", "1.7.4")
.assert()
.failure()
.stderr("`nightly` is not installed. Please run `juliaup add nightly` to install channel or version.\n");
}