Skip to content

Commit

Permalink
feat(Binaries): Allow glob patterns for binary paths; add r and `ch…
Browse files Browse the repository at this point in the history
…romium` binary specs
  • Loading branch information
nokome committed Dec 7, 2021
1 parent abcf8f3 commit 516d7a6
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 52 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rust/binaries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ structopt = { version = "0.3.25", optional = true }
tracing = { version = "0.1.29", optional = true }

binary-chrome = { path = "../binary-chrome", version = "0.0.0", optional = true }
binary-chromium = { path = "../binary-chromium", version = "0.0.0", optional = true }
binary-node = { path = "../binary-node", version = "0.0.0", optional = true }
binary-pandoc = { path = "../binary-pandoc", version = "0.0.0", optional = true }
binary-python = { path = "../binary-python", version = "0.0.0", optional = true }
binary-r = { path = "../binary-r", version = "0.0.0", optional = true }

[dev-dependencies]
test-utils = { path = "../test-utils", version = "0.0.0" }
40 changes: 16 additions & 24 deletions rust/binaries/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,21 @@ use tokio::sync::RwLock;
static BINARIES: Lazy<BTreeMap<String, Box<dyn BinaryTrait>>> = Lazy::new(|| {
let mut map: BTreeMap<String, Box<dyn BinaryTrait>> = BTreeMap::new();

#[cfg(feature = "binary-chrome")]
{
let bin = binary_chrome::ChromeBinary {};
map.insert(bin.spec().name, Box::new(bin));
}

#[cfg(feature = "binary-node")]
{
let bin = binary_node::NodeBinary {};
map.insert(bin.spec().name, Box::new(bin));
}

#[cfg(feature = "binary-pandoc")]
{
let bin = binary_pandoc::PandocBinary {};
map.insert(bin.spec().name, Box::new(bin));
macro_rules! binary_new {
($feat:literal, $bin:expr) => {
#[cfg(feature = $feat)]
{
map.insert($bin.spec().name, Box::new($bin));
}
};
}

#[cfg(feature = "binary-python")]
{
let bin = binary_python::PythonBinary {};
map.insert(bin.spec().name, Box::new(bin));
}
binary_new!("binary-chrome", binary_chrome::ChromeBinary {});
binary_new!("binary-chromium", binary_chromium::ChromiumBinary {});
binary_new!("binary-node", binary_node::NodeBinary {});
binary_new!("binary-pandoc", binary_pandoc::PandocBinary {});
binary_new!("binary-python", binary_python::PythonBinary {});
binary_new!("binary-r", binary_r::RBinary {});

map
});
Expand All @@ -66,7 +58,7 @@ pub async fn installation(name: &str, semver: &str) -> Result<BinaryInstallation
return Ok(installation.clone());
}

let unregistered: Box<dyn BinaryTrait> = Box::new(Binary::new(name, &[], &[]));
let unregistered: Box<dyn BinaryTrait> = Box::new(Binary::unregistered(name));
let binary = BINARIES.get(name).unwrap_or(&unregistered);

let semver = if semver == "*" {
Expand Down Expand Up @@ -201,7 +193,7 @@ pub mod commands {
async fn run(&self) -> Result {
// Try to get registered binary (because has potential aliases and extracting versions) but fall
// back to unregistered for others
let unregistered: Box<dyn BinaryTrait> = Box::new(Binary::new(&self.name, &[], &[]));
let unregistered: Box<dyn BinaryTrait> = Box::new(Binary::unregistered(&self.name));
let binary = BINARIES.get(&self.name).unwrap_or(&unregistered);
if self.semver.is_some() {
if let Ok(installation) = binary.installed(self.semver.clone()) {
Expand Down Expand Up @@ -316,7 +308,7 @@ pub mod commands {
impl Run for Uninstall {
async fn run(&self) -> Result {
// Fallback to unregistered since that is sufficient for uninstall
let unregistered: Box<dyn BinaryTrait> = Box::new(Binary::new(&self.name, &[], &[]));
let unregistered: Box<dyn BinaryTrait> = Box::new(Binary::unregistered(&self.name));
let binary = BINARIES.get(&self.name).unwrap_or(&unregistered);
binary.uninstall(self.version.clone()).await?;

Expand Down
2 changes: 1 addition & 1 deletion rust/binary-chrome/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "binary-chrome"
description = "A binary specification for Chrome/Chromium"
description = "A binary specification for Chrome"
version = "0.0.0"
edition = "2021"

Expand Down
6 changes: 5 additions & 1 deletion rust/binary-chrome/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ impl BinaryTrait for ChromeBinary {
fn spec(&self) -> Binary {
Binary::new(
"chrome",
&["chromium"],
&["Google Chrome"],
&[
"/Applications/Google Chrome.app/Contents/MacOS",
"C:/Program Files/Google/Chrome/Application",
],
// Version history at https://en.wikipedia.org/wiki/Google_Chrome_version_history.
// Rather than support installing multiple versions, we normally only support the
// most recent version in the stable channel.
Expand Down
8 changes: 8 additions & 0 deletions rust/binary-chromium/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "binary-chromium"
description = "A binary specification for Chromium"
version = "0.0.0"
edition = "2021"

[dependencies]
binary = { path = "../binary", version = "0.0.0", features = ["download-zip"] }
21 changes: 21 additions & 0 deletions rust/binary-chromium/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use binary::{
async_trait::async_trait,
Binary, BinaryTrait,
};

pub struct ChromiumBinary {}

#[async_trait]
impl BinaryTrait for ChromiumBinary {
fn spec(&self) -> Binary {
Binary::new(
"chromium",
&["Chromium"],
&[
"/Applications/Chromium.app/Contents/MacOS",
"C:/Program Files/Chromium/Application",
],
&[],
)
}
}
1 change: 1 addition & 0 deletions rust/binary-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl BinaryTrait for NodeBinary {
Binary::new(
"node",
&[],
&["C:/Program Files/nodejs"],
// Release list at https://nodejs.org/en/download/releases/
// Current strategy is to support the latest patch version of each minor version.
// Support for older minor versions may be progressively dropped if there are no
Expand Down
1 change: 1 addition & 0 deletions rust/binary-pandoc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl BinaryTrait for PandocBinary {
fn spec(&self) -> Binary {
Binary::new(
"pandoc",
&["C:/Users/*/AppData/Local/Pandoc"],
&[],
// Release list at https://github.com/jgm/pandoc/releases.
// Current strategy is to support the latest patch version of each minor version.
Expand Down
1 change: 1 addition & 0 deletions rust/binary-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl BinaryTrait for PythonBinary {
Binary::new(
"python",
&["python3"],
&["C:/Python3*"],
// Release list at https://www.python.org/downloads/.
// Current strategy is to support the latest patch version of each minor version.
&[
Expand Down
8 changes: 8 additions & 0 deletions rust/binary-r/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "binary-r"
description = "A binary specification for R"
version = "0.0.0"
edition = "2021"

[dependencies]
binary = { path = "../binary", version = "0.0.0" }
16 changes: 16 additions & 0 deletions rust/binary-r/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use binary::{async_trait::async_trait, Binary, BinaryTrait};

pub struct RBinary {}

#[async_trait]
impl BinaryTrait for RBinary {
#[rustfmt::skip]
fn spec(&self) -> Binary {
Binary::new(
"r",
&["R", "Rscript"],
&["C:/Program Files/R/R-*/bin"],
&[],
)
}
}
1 change: 1 addition & 0 deletions rust/binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ tar = { version = "0.4.37", optional = true }
xz2 = { version = "0.1.6", optional = true }
zip = { version = "0.5.13", optional = true }
dirs = "4.0.0"
glob = "0.3.0"

0 comments on commit 516d7a6

Please sign in to comment.