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

added plugin repository support in .rtx.toml #249

Merged
merged 1 commit into from
Mar 3, 2023
Merged
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
3 changes: 3 additions & 0 deletions .rtx.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ FOO = "bar"
nodejs = '18'
tiny = {version="1", foo="bar"}
golang = {version="latest", foo="bar"}

[plugins]
nodejs = 'https://github.com/jdxcode/rtx-nodejs'
4 changes: 2 additions & 2 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ where
match self.parse() {
Ok(val) => return Ok::<_, color_eyre::Report>(val),
Err(err) => {
warn!("failed to parse cache file: {} {}", path.display(), err);
warn!("failed to parse cache file: {} {:#}", path.display(), err);
}
}
}
let val = (fetch)()?;
if let Err(err) = self.write(val.clone()) {
warn!("failed to write cache file: {} {}", path.display(), err);
warn!("failed to write cache file: {} {:#}", path.display(), err);
}
Ok(val)
})?;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn commands(config: &Config) -> Vec<Command> {
Ok(commands) => commands,
Err(e) => {
warn!(
"failed to load external commands for plugin {}: {}",
"failed to load external commands for plugin {}: {:#}",
p.name, e
);
vec![]
Expand Down
2 changes: 1 addition & 1 deletion src/cli/hook_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl HookEnv {
Ok(Some(op)) => {
ops.push(op);
}
Err(err) => warn!("failed to update DIRENV_DIFF: {}", err),
Err(err) => warn!("failed to update DIRENV_DIFF: {:#}", err),
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Install {
None => {
let plugin = Plugin::new(&tv.plugin_name);
let mut pr = mpr.add();
match plugin.install(&config, None, &mut pr) {
match plugin.install(&config, &mut pr) {
Ok(_) => Arc::new(plugin),
Err(err) => {
pr.error();
Expand Down
7 changes: 4 additions & 3 deletions src/cli/plugins/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ impl PluginsInstall {
&self,
config: &Config,
name: &String,
git_url: &String,
git_url: &str,
mpr: &MultiProgressReport,
) -> Result<()> {
let plugin = Plugin::new(name);
let mut plugin = Plugin::new(name);
plugin.repo_url = Some(git_url.to_string());
if !self.force && plugin.is_installed() {
mpr.suspend(|| {
warn!("plugin {} already installed", name);
Expand All @@ -125,7 +126,7 @@ impl PluginsInstall {
if self.force {
plugin.uninstall(&pr)?;
}
plugin.install(config, Some(git_url), &mut pr)?;
plugin.install(config, &mut pr)?;
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/reshim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn make_symlink(target: &Path, link: &Path) -> Result<()> {
fs::remove_file(link)?;
}
symlink(target, link)?;
debug!("symlinked {} to {}", target.display(), link.display());
trace!("symlinked {} to {}", target.display(), link.display());
Ok(())
}

Expand All @@ -103,7 +103,7 @@ fn make_shim(target: &Path, shim: &Path) -> Result<()> {
let mut perms = shim.metadata()?.permissions();
perms.set_mode(0o755);
fs::set_permissions(shim, perms)?;
debug!(
trace!(
"shim created from {} to {}",
target.display(),
shim.display()
Expand Down
14 changes: 12 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Config {

impl Config {
pub fn load() -> Result<Self> {
let plugins = load_plugins()?;
let mut plugins = load_plugins()?;
let rtxrc = load_rtxrc()?;
let mut settings = rtxrc.settings();
let config_filenames = load_config_filenames(&IndexMap::new());
Expand Down Expand Up @@ -73,6 +73,16 @@ impl Config {
|| hook_env::should_exit_early(&config_filenames),
);

for cf in config_files.values() {
for (plugin_name, repo_url) in cf.plugins() {
plugins.entry(plugin_name.clone()).or_insert_with(|| {
let mut plugin = Plugin::new(&plugin_name);
plugin.repo_url = Some(repo_url);
Arc::new(plugin)
});
}
}

let config = Self {
env: load_env(&config_files),
aliases: load_aliases(&settings, &config_files),
Expand Down Expand Up @@ -235,7 +245,7 @@ fn load_all_config_files(
None => match parse_config_file(&f, settings, legacy_filenames, plugins) {
Ok(cf) => Some((f, cf)),
Err(err) => {
warn!("error parsing: {} {err}", f.display());
warn!("error parsing: {} {:#}", f.display(), err);
None
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn get_env_diff() -> EnvDiff {
let env = vars().collect::<HashMap<_, _>>();
match env.get("__RTX_DIFF") {
Some(raw) => EnvDiff::deserialize(raw).unwrap_or_else(|err| {
warn!("Failed to deserialize __RTX_DIFF: {}", err);
warn!("Failed to deserialize __RTX_DIFF: {:#}", err);
EnvDiff::default()
}),
None => EnvDiff::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/fake_asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn get_path_with_fake_asdf() -> String {
path.push(fake_asdf_path.to_string_lossy().to_string());
}
Err(e) => {
warn!("Failed to setup fake asdf: {}", e);
warn!("Failed to setup fake asdf: {:#}", e);
}
};
path.push(env::var("PATH").unwrap());
Expand Down
4 changes: 2 additions & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Git {
match get_git_version() {
Ok(version) => trace!("git version: {}", version),
Err(err) => warn!(
"failed to get git version: {}\n Git is required to use rtx.",
"failed to get git version: {:#}\n Git is required to use rtx.",
err
),
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Git {
}
Err(err) => {
warn!(
"failed to get remote url for {}: {}",
"failed to get remote url for {}: {:#}",
self.dir.display(),
err
);
Expand Down
23 changes: 10 additions & 13 deletions src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub type PluginName = String;
pub struct Plugin {
pub name: PluginName,
pub plugin_path: PathBuf,
pub repo_url: Option<String>,
cache_path: PathBuf,
downloads_path: PathBuf,
installs_path: PathBuf,
Expand Down Expand Up @@ -71,6 +72,7 @@ impl Plugin {
.with_fresh_file(plugin_path.join("bin/list-legacy-filenames")),
plugin_path,
cache_path,
repo_url: None,
}
}

Expand All @@ -90,14 +92,11 @@ impl Plugin {
git.get_remote_url()
}

pub fn install(
&self,
config: &Config,
repository: Option<&String>,
pr: &mut ProgressReport,
) -> Result<()> {
pub fn install(&self, config: &Config, pr: &mut ProgressReport) -> Result<()> {
self.decorate_progress_bar(pr);
let repository = repository
let repository = self
.repo_url
.as_ref()
.or_else(|| config.get_shorthands().get(&self.name))
.ok_or_else(|| eyre!("No repository found for plugin {}", self.name))?;
debug!("install {} {:?}", self.name, repository);
Expand Down Expand Up @@ -226,12 +225,10 @@ impl Plugin {
pub fn list_remote_versions(&self, settings: &Settings) -> Result<&Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| self.fetch_remote_versions(settings))
.with_context(|| {
format!(
"Failed listing remote versions for plugin {}",
style(&self.name).cyan().for_stderr()
)
})
.wrap_err(format!(
"Failed listing remote versions for plugin {}",
style(&self.name).cyan().for_stderr()
))
}

pub fn get_aliases(&self, settings: &Settings) -> Result<IndexMap<String, String>> {
Expand Down
2 changes: 1 addition & 1 deletion src/shorthands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn get_shorthands(settings: &Settings) -> Shorthands {
shorthands.extend(custom);
}
Err(err) => {
warn!("Failed to read shorthands file: {} {}", &f.display(), err);
warn!("Failed to read shorthands file: {} {:#}", &f.display(), err);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/toolset/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ToolsetBuilder {
if self.install_missing {
let mpr = MultiProgressReport::new(config.settings.verbose);
if let Err(e) = toolset.install_missing(config, mpr) {
warn!("Error installing runtimes: {}", e);
warn!("Error installing runtimes: {:#}", e);
};
}

Expand Down
35 changes: 17 additions & 18 deletions src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ impl Toolset {
.par_iter_mut()
.for_each(|(p, v)| {
let plugin = match config.plugins.get(&p.to_string()) {
Some(p) => p,
None => {
debug!("Plugin {} not found", p);
Some(p) if p.is_installed() => p,
_ => {
debug!("Plugin {} is not installed", p);
return;
}
};
Expand Down Expand Up @@ -176,23 +176,22 @@ impl Toolset {
missing_plugins: Vec<PluginName>,
mpr: &MultiProgressReport,
) -> Result<()> {
if missing_plugins.is_empty() {
return Ok(());
for plugin in &missing_plugins {
config
.plugins
.entry(plugin.clone())
.or_insert_with(|| Arc::new(Plugin::new(plugin)));
}
let plugins = missing_plugins
config.plugins.sort_keys();
missing_plugins
.into_par_iter()
.map(|plugin_name| {
let plugin = Plugin::new(&plugin_name);
if !plugin.is_installed() {
plugin.install(config, None, &mut mpr.add())?;
}
Ok(plugin)
.map(|p| config.plugins.get(&p).unwrap())
.filter(|p| !p.is_installed())
.map(|p| {
let mut pr = mpr.add();
p.install(config, &mut pr)
})
.collect::<Result<Vec<_>>>()?;
for plugin in plugins {
config.plugins.insert(plugin.name.clone(), Arc::new(plugin));
}
config.plugins.sort_keys();
Ok(())
}

Expand Down Expand Up @@ -268,7 +267,7 @@ impl Toolset {
.flat_map(|v| match v.exec_env() {
Ok(env) => env.clone().into_iter().collect(),
Err(e) => {
warn!("Error running exec-env: {}", e);
warn!("Error running exec-env: {:#}", e);
Vec::new()
}
})
Expand All @@ -293,7 +292,7 @@ impl Toolset {
.flat_map(|rtv| match rtv.list_bin_paths(&config.settings) {
Ok(paths) => paths,
Err(e) => {
warn!("Error listing bin paths for {}: {}", rtv, e);
warn!("Error listing bin paths for {}: {:#}", rtv, e);
Vec::new()
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/toolset/tool_version_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl ToolVersionList {
}
}
Err(err) => {
warn!("failed to resolve tool version: {}", err);
warn!("failed to resolve tool version: {:#}", err);
return;
}
}
Expand Down