Skip to content

Commit

Permalink
Merge pull request #809 from JuliaLang/da/nightly
Browse files Browse the repository at this point in the history
Nightly
  • Loading branch information
davidanthoff authored Feb 2, 2024
2 parents e147ae7 + 31b0caa commit 320b968
Show file tree
Hide file tree
Showing 17 changed files with 665 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ path-absolutize = "3.1.0"
human-sort = "0.2.2"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.52.0", features = ["Win32_Foundation", "Win32_UI_Shell", "Win32_System_Console", "Services_Store", "Foundation", "Foundation_Collections", "Web_Http", "Storage_Streams",] }
windows = { version = "0.52.0", features = ["Win32_Foundation", "Win32_UI_Shell", "Win32_System_Console", "Services_Store", "Foundation", "Foundation_Collections", "Web_Http", "Web_Http_Headers", "Storage_Streams",] }

[target.'cfg(target_os = "macos")'.dependencies]
reqwest = { version = "0.11.18", default-features = false, features = ["blocking", "native-tls", "socks"] }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ The available system provided channels are:
- `lts`: always points to the latest long term supported version.
- `beta`: always points to the latest beta version if one exists. If a newer release candidate exists, it will point to that, and if there is neither a beta or rc candidate available it will point to the same version as the `release` channel.
- `rc`: same as `beta`, but only starts with release candidate versions.
- `nightly`: always points to the latest build from the `master` branch in the Julia repository.
- specific versions, e.g. `1.5.4`.
- minor version channels, e.g. `1.5`.
- major version channels, e.g. `1`.
Expand Down
35 changes: 34 additions & 1 deletion src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn get_julia_path_from_channel(

check_channel_uptodate(channel, version, versions_db).with_context(|| {
format!(
"The Julia launcher failed while checking whether the channe {} is up-to-date.",
"The Julia launcher failed while checking whether the channel {} is up-to-date.",
channel
)
})?;
Expand All @@ -227,6 +227,39 @@ fn get_julia_path_from_channel(
})?;
return Ok((absolute_path.into_path_buf(), Vec::new()));
}
JuliaupConfigChannel::DirectDownloadChannel {
path,
url: _,
local_etag,
server_etag,
version: _,
} => {
if local_etag != server_etag {
eprintln!(
"A new version of Julia for the `{}` channel is available. Run:",
channel
);
eprintln!();
eprintln!(" juliaup update");
eprintln!();
eprintln!("to install the latest Julia for the `{}` channel.", channel);
}

let absolute_path = juliaupconfig_path
.parent()
.unwrap()
.join(path)
.join("bin")
.join(format!("julia{}", std::env::consts::EXE_SUFFIX))
.normalize()
.with_context(|| {
format!(
"Failed to normalize path for Julia binary, starting from `{}`.",
juliaupconfig_path.display()
)
})?;
return Ok((absolute_path.into_path_buf(), Vec::new()));
}
}
}

Expand Down
40 changes: 39 additions & 1 deletion src/command_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ use crate::config_file::{load_mut_config_db, save_config_db, JuliaupConfigChanne
use crate::global_paths::GlobalPaths;
#[cfg(not(windows))]
use crate::operations::create_symlink;
use crate::operations::{install_version, update_version_db};
use crate::operations::{identify_nightly, install_nightly, install_version, update_version_db};
use crate::versions_file::load_versions_db;
use anyhow::{anyhow, Context, Result};

pub fn run_command_add(channel: &str, paths: &GlobalPaths) -> Result<()> {
if channel == "nightly" || channel.starts_with("nightly~") {
return add_nightly(channel, paths);
}

update_version_db(paths).with_context(|| "Failed to update versions db.")?;
let version_db =
load_versions_db(paths).with_context(|| "`add` command failed to load versions db.")?;
Expand Down Expand Up @@ -66,3 +70,37 @@ pub fn run_command_add(channel: &str, paths: &GlobalPaths) -> Result<()> {

Ok(())
}

fn add_nightly(channel: &str, paths: &GlobalPaths) -> Result<()> {
let mut config_file = load_mut_config_db(paths)
.with_context(|| "`add` command failed to load configuration data.")?;

if config_file.data.installed_channels.contains_key(channel) {
eprintln!("'{}' is already installed.", &channel);
return Ok(());
}

let name = identify_nightly(&channel.to_string())?;
let config_channel = install_nightly(channel, &name, paths)?;

config_file
.data
.installed_channels
.insert(channel.to_string(), config_channel.clone());

if config_file.data.default.is_none() {
config_file.data.default = Some(channel.to_string());
}

save_config_db(&mut config_file).with_context(|| {
format!(
"Failed to save configuration file from `add` command after '{channel}' was installed.",
)
})?;

#[cfg(not(windows))]
if config_file.data.settings.create_channel_symlinks {
create_symlink(&config_channel, &format!("julia-{}", channel), paths)?;
}
Ok(())
}
17 changes: 17 additions & 0 deletions src/command_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ pub fn run_command_api(command: &str, paths: &GlobalPaths) -> Result<()> {
Err(_) => continue,
}
}
JuliaupConfigChannel::DirectDownloadChannel { path, url: _, local_etag: _, server_etag: _, version } => {
JuliaupChannelInfo {
name: key.clone(),
file: paths.juliauphome
.join(path)
.join("bin")
.join(format!("julia{}", std::env::consts::EXE_SUFFIX))
.normalize()
.with_context(|| "Normalizing the path for an entry from the config file failed while running the getconfig1 API command.")?
.into_path_buf()
.to_string_lossy()
.to_string(),
args: Vec::new(),
version: version.clone(),
arch: "".to_string(),
}
}
};

match config_file.data.default {
Expand Down
20 changes: 20 additions & 0 deletions src/command_list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::operations::{compatible_nightly_archs, identify_nightly};
use crate::{global_paths::GlobalPaths, versions_file::load_versions_db};
use anyhow::{Context, Result};
use cli_table::{
Expand All @@ -19,6 +20,24 @@ pub fn run_command_list(paths: &GlobalPaths) -> Result<()> {
let versiondb_data =
load_versions_db(paths).with_context(|| "`list` command failed to load versions db.")?;

let nightly_channels: Vec<String> = std::iter::once("nightly".to_string())
.chain(
compatible_nightly_archs()?
.into_iter()
.map(|arch| format!("nightly~{}", arch)),
)
.collect();
let nightly_rows: Vec<ChannelRow> = nightly_channels
.into_iter()
.map(|channel| {
let nightly_name = identify_nightly(&channel).expect("Failed to identify nightly");
ChannelRow {
name: channel,
version: nightly_name,
}
})
.collect();

let rows_in_table: Vec<_> = versiondb_data
.available_channels
.iter()
Expand All @@ -29,6 +48,7 @@ pub fn run_command_list(paths: &GlobalPaths) -> Result<()> {
}
})
.sorted_by(|a, b| compare(&a.name, &b.name))
.chain(nightly_rows)
.collect();

print_stdout(
Expand Down
21 changes: 20 additions & 1 deletion src/command_remove.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(windows))]
use crate::operations::remove_symlink;
use crate::{
config_file::{load_mut_config_db, save_config_db},
config_file::{load_mut_config_db, save_config_db, JuliaupConfigChannel},
global_paths::GlobalPaths,
operations::garbage_collect_versions,
};
Expand Down Expand Up @@ -39,6 +39,25 @@ pub fn run_command_remove(channel: &str, paths: &GlobalPaths) -> Result<()> {
);
}

let x = config_file.data.installed_channels.get(channel).unwrap();

if let JuliaupConfigChannel::DirectDownloadChannel {
path,
url: _,
local_etag: _,
server_etag: _,
version: _,
} = x
{
let path_to_delete = paths.juliauphome.join(&path);

let display = path_to_delete.display();

if std::fs::remove_dir_all(&path_to_delete).is_err() {
eprintln!("WARNING: Failed to delete {}. You can try to delete at a later point by running `juliaup gc`.", display)
}
};

config_file.data.installed_channels.remove(channel);

#[cfg(not(windows))]
Expand Down
22 changes: 22 additions & 0 deletions src/command_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ pub fn run_command_status(paths: &GlobalPaths) -> Result<()> {
name: i.0.to_string(),
version: match i.1 {
JuliaupConfigChannel::SystemChannel { version } => version.clone(),
JuliaupConfigChannel::DirectDownloadChannel {
path: _,
url: _,
local_etag: _,
server_etag: _,
version,
} => {
format!("Development version {}", version)
}
JuliaupConfigChannel::LinkedChannel { command, args } => {
let mut combined_command = String::new();

Expand Down Expand Up @@ -95,6 +104,19 @@ pub fn run_command_status(paths: &GlobalPaths) -> Result<()> {
command: _,
args: _,
} => "".to_string(),
JuliaupConfigChannel::DirectDownloadChannel {
path: _,
url: _,
local_etag,
server_etag,
version: _,
} => {
if local_etag != server_etag {
"Update available".to_string()
} else {
"".to_string()
}
}
},
}
})
Expand Down
39 changes: 37 additions & 2 deletions src/command_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use crate::global_paths::GlobalPaths;
use crate::jsonstructs_versionsdb::JuliaupVersionDB;
#[cfg(not(windows))]
use crate::operations::create_symlink;
use crate::operations::garbage_collect_versions;
use crate::operations::{garbage_collect_versions, install_from_url};
use crate::operations::{install_version, update_version_db};
use crate::versions_file::load_versions_db;
use anyhow::{anyhow, bail, Context, Result};
use std::path::PathBuf;

fn update_channel(
config_db: &mut JuliaupConfig,
Expand All @@ -17,7 +18,7 @@ fn update_channel(
paths: &GlobalPaths,
) -> Result<()> {
let current_version =
config_db.installed_channels.get(channel).ok_or_else(|| anyhow!("Trying to get the installed version for a channel that does not exist in the config database."))?;
&config_db.installed_channels.get(channel).ok_or_else(|| anyhow!("Trying to get the installed version for a channel that does not exist in the config database."))?.clone();

match current_version {
JuliaupConfigChannel::SystemChannel { version } => {
Expand Down Expand Up @@ -71,6 +72,40 @@ fn update_channel(
);
}
}
JuliaupConfigChannel::DirectDownloadChannel {
path,
url,
local_etag,
server_etag,
version,
} => {
// We only do this so that we use `version` on both Windows and Linux to prevent a compiler warning/error
assert!(!version.is_empty());

if local_etag != server_etag {
let channel_data =
install_from_url(&url::Url::parse(url)?, &PathBuf::from(path), paths)?;

config_db
.installed_channels
.insert(channel.clone(), channel_data);

#[cfg(not(windows))]
if config_db.settings.create_channel_symlinks {
create_symlink(
&JuliaupConfigChannel::DirectDownloadChannel {
path: path.clone(),
url: url.clone(),
local_etag: local_etag.clone(),
server_etag: server_etag.clone(),
version: version.clone(),
},
&channel,
paths,
)?;
}
}
}
}

Ok(())
Expand Down
12 changes: 12 additions & 0 deletions src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ pub struct JuliaupConfigVersion {
#[derive(Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum JuliaupConfigChannel {
DirectDownloadChannel {
#[serde(rename = "Path")]
path: String,
#[serde(rename = "Url")]
url: String,
#[serde(rename = "LocalETag")]
local_etag: String,
#[serde(rename = "ServerETag")]
server_etag: String,
#[serde(rename = "Version")]
version: String,
},
SystemChannel {
#[serde(rename = "Version")]
version: String,
Expand Down
Loading

0 comments on commit 320b968

Please sign in to comment.