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

Add ldcup (ldc2 version manager) step #1053

Open
wants to merge 1 commit 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
18 changes: 18 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,24 @@
# (default: false)
# cleanup = false

[ldcup]
# Version strings passed to ldcup.
# These may be pinned versions such as "1.40.0" branches such as "master" or "latest".
# Each one will be updated in its own ldcup invocation.
# (default: ["ldc2-master"])
# target_versions = ["ldc2-master", "ldc2-latest", "opend-latest", "ldc2-1.40.0"]

# Specifies the directory that the ldc2 files will be installed to.
# If defined, passed with the --install-dir command line flag.
# If not defined, ldcup will use its default behaviour.
# (default: not defined)
# install_dir = "~/.dlang"

# If enabled, run `ldcup uninstall` after updating all versions.
# (default: false)
# cleanup = false


[vscode]
# If this is set and is a non-empty string, it specifies the profile the
# extensions should be updated for.
Expand Down
35 changes: 35 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub enum Step {
Kakoune,
Helix,
Krew,
Ldcup,
Lure,
Lensfun,
Macports,
Expand Down Expand Up @@ -471,6 +472,14 @@ pub struct Zigup {
cleanup: Option<bool>,
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
pub struct Ldcup {
target_versions: Option<Vec<String>>,
install_dir: Option<String>,
cleanup: Option<bool>,
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
pub struct VscodeConfig {
Expand Down Expand Up @@ -541,6 +550,9 @@ pub struct ConfigFile {
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
distrobox: Option<Distrobox>,

#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
ldcup: Option<Ldcup>,

#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
lensfun: Option<Lensfun>,

Expand Down Expand Up @@ -1674,6 +1686,29 @@ impl Config {
self.opt.custom_commands.iter().any(|s| s == name)
}

pub fn ldcup_target_versions(&self) -> Vec<String> {
self.config_file
.ldcup
.as_ref()
.and_then(|ldcup| ldcup.target_versions.clone())
.unwrap_or(vec!["ldc2-master".to_owned()])
}

pub fn ldcup_install_dir(&self) -> Option<&str> {
self.config_file
.ldcup
.as_ref()
.and_then(|ldcup| ldcup.install_dir.as_deref())
}

pub fn ldcup_cleanup(&self) -> bool {
self.config_file
.ldcup
.as_ref()
.and_then(|ldcup| ldcup.cleanup)
.unwrap_or(false)
}

pub fn lensfun_use_sudo(&self) -> bool {
self.config_file
.lensfun
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ fn run() -> Result<()> {
runner.execute(Step::Aqua, "aqua", || generic::run_aqua(&ctx))?;
runner.execute(Step::Bun, "bun", || generic::run_bun(&ctx))?;
runner.execute(Step::Zigup, "zigup", || generic::run_zigup(&ctx))?;
runner.execute(Step::Ldcup, "ldcup", || generic::run_ldcup(&ctx))?;

if should_run_powershell {
runner.execute(Step::Powershell, "Powershell Modules Update", || {
Expand Down
33 changes: 33 additions & 0 deletions src/steps/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,3 +1303,36 @@ pub fn run_zigup(ctx: &ExecutionContext) -> Result<()> {

Ok(())
}

pub fn run_ldcup(ctx: &ExecutionContext) -> Result<()> {
let ldcup = require("ldcup")?;
let config = ctx.config();

print_separator("ldcup");

let mut path_args = Vec::new();

if let Some(path) = config.ldcup_install_dir() {
path_args.push(format!("--install-dir={}", shellexpand::tilde(path).into_owned()));
}

for ldc_version in config.ldcup_target_versions() {
ctx.run_type()
.execute(&ldcup)
.args(&path_args)
.arg("install")
.arg(&ldc_version)
.status_checked()?;

if config.ldcup_cleanup() {
ctx.run_type()
.execute(&ldcup)
.args(&path_args)
.arg("uninstall")
.arg(&ldc_version)
.status_checked()?;
}
}

Ok(())
}