Allow tlmgr to run in Linux (fix #406)
This commit is contained in:
committed by
GitHub
parent
89578a7fd9
commit
98657edb60
@@ -58,3 +58,4 @@
|
||||
# Arguments to pass yay when updating packages
|
||||
#yay_arguments = "--nodevel"
|
||||
#trizen_arguments = "--devel"
|
||||
#enable_tlmgr = true
|
||||
|
||||
@@ -60,6 +60,7 @@ pub struct Linux {
|
||||
yay_arguments: Option<String>,
|
||||
trizen_arguments: Option<String>,
|
||||
dnf_arguments: Option<String>,
|
||||
enable_tlmgr: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
@@ -439,6 +440,16 @@ impl Config {
|
||||
.and_then(|linux| linux.dnf_arguments.as_deref())
|
||||
}
|
||||
|
||||
/// Extra yay arguments
|
||||
#[allow(dead_code)]
|
||||
pub fn enable_tlmgr_linux(&self) -> bool {
|
||||
self.config_file
|
||||
.linux
|
||||
.as_ref()
|
||||
.and_then(|linux| linux.enable_tlmgr)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn use_predefined_git_repos(&self) -> bool {
|
||||
!self.opt.disable_predefined_git_repos && self.config_file.predefined_git_repos.unwrap_or(true)
|
||||
}
|
||||
|
||||
@@ -3,12 +3,10 @@ use crate::config::Config;
|
||||
use crate::executor::RunType;
|
||||
use crate::git::Git;
|
||||
use directories::BaseDirs;
|
||||
#[cfg(unix)]
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct ExecutionContext<'a> {
|
||||
run_type: RunType,
|
||||
#[cfg(unix)]
|
||||
sudo: &'a Option<PathBuf>,
|
||||
git: &'a Git,
|
||||
config: &'a Config,
|
||||
@@ -37,6 +35,7 @@ impl<'a> ExecutionContext<'a> {
|
||||
pub fn new(run_type: RunType, git: &'a Git, config: &'a Config, base_dirs: &'a BaseDirs) -> ExecutionContext<'a> {
|
||||
ExecutionContext {
|
||||
run_type,
|
||||
sudo: &None,
|
||||
config,
|
||||
git,
|
||||
base_dirs,
|
||||
@@ -51,7 +50,6 @@ impl<'a> ExecutionContext<'a> {
|
||||
&self.git
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn sudo(&self) -> &Option<PathBuf> {
|
||||
&self.sudo
|
||||
}
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -280,16 +280,7 @@ fn run() -> Result<()> {
|
||||
}
|
||||
|
||||
if config.should_run(Step::Tlmgr) {
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
runner.execute("tlmgr", || {
|
||||
generic::run_tlmgr_update(
|
||||
#[cfg(unix)]
|
||||
&sudo,
|
||||
#[cfg(windows)]
|
||||
&None,
|
||||
run_type,
|
||||
)
|
||||
})?;
|
||||
runner.execute("tlmgr", || generic::run_tlmgr_update(&ctx))?;
|
||||
}
|
||||
|
||||
if config.should_run(Step::Myrepos) {
|
||||
|
||||
@@ -117,8 +117,15 @@ pub fn run_stack_update(run_type: RunType) -> Result<()> {
|
||||
run_type.execute(&stack).arg("upgrade").check_run()
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub fn run_tlmgr_update(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
|
||||
pub fn run_tlmgr_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "linux")] {
|
||||
if !ctx.config().enable_tlmgr_linux() {
|
||||
return Err(SkipStep.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let tlmgr = utils::require("tlmgr")?;
|
||||
let kpsewhich = utils::require("kpsewhich")?;
|
||||
let tlmgr_directory = {
|
||||
@@ -142,9 +149,11 @@ pub fn run_tlmgr_update(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()>
|
||||
print_separator("TeX Live package manager");
|
||||
|
||||
let mut command = if directory_writable {
|
||||
run_type.execute(&tlmgr)
|
||||
ctx.run_type().execute(&tlmgr)
|
||||
} else {
|
||||
let mut c = run_type.execute(sudo.as_ref().ok_or(TopgradeError::SudoRequired)?);
|
||||
let mut c = ctx
|
||||
.run_type()
|
||||
.execute(ctx.sudo().as_ref().ok_or(TopgradeError::SudoRequired)?);
|
||||
c.arg(&tlmgr);
|
||||
c
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user