From 6ba6f6c15c106768b914a7697a763e2232fa253a Mon Sep 17 00:00:00 2001 From: Chris Manchester Date: Wed, 17 Jul 2019 22:03:39 -0700 Subject: [PATCH] Add a version check for bubblewrap in the server. Fixes #316 --- Cargo.lock | 7 +++++++ Cargo.toml | 3 ++- src/bin/sccache-dist/build.rs | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 972d7e8dc..8ff38eefd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1752,6 +1752,7 @@ dependencies = [ "toml 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "version-compare 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2521,6 +2522,11 @@ name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "version-compare" +version = "0.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "version_check" version = "0.1.5" @@ -2925,6 +2931,7 @@ dependencies = [ "checksum uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dab5c5526c5caa3d106653401a267fed923e7046f35895ffcb5ca42db64942e6" "checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum version-compare 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "16dc2b8f2d402e72b9074db40ceee7c020042561e6ea0e2d4bc0354b60457603" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum vte 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f42f536e22f7fcbb407639765c8fd78707a33109301f834a594758bedd6e8cf" diff --git a/Cargo.toml b/Cargo.toml index ca2cf798a..b28f7dbb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,6 +89,7 @@ nix = { version = "0.11.0", optional = true } rouille = { version = "2.2", optional = true, default-features = false, features = ["ssl"] } syslog = { version = "4.0.1", optional = true } void = { version = "1", optional = true } +version-compare = { version = "0.0.8", optional = true } [patch.crates-io] # Waiting for https://github.com/tiny-http/tiny-http/pull/151 @@ -134,7 +135,7 @@ unstable = [] # Enables distributed support in the sccache client dist-client = ["ar", "flate2", "hyper", "hyperx", "reqwest", "rust-crypto", "url"] # Enables the sccache-dist binary -dist-server = ["arraydeque", "crossbeam-utils", "jsonwebtoken", "flate2", "libmount", "nix", "openssl", "reqwest", "rouille", "syslog", "void"] +dist-server = ["arraydeque", "crossbeam-utils", "jsonwebtoken", "flate2", "libmount", "nix", "openssl", "reqwest", "rouille", "syslog", "void", "version-compare"] # Enables dist tests with external requirements dist-tests = [] diff --git a/src/bin/sccache-dist/build.rs b/src/bin/sccache-dist/build.rs index f5735a47b..4e014d39a 100644 --- a/src/bin/sccache-dist/build.rs +++ b/src/bin/sccache-dist/build.rs @@ -26,6 +26,7 @@ use std::iter; use std::path::{self, Path, PathBuf}; use std::process::{ChildStdin, Command, Output, Stdio}; use std::sync::{Mutex}; +use version_compare::Version; use crate::errors::*; @@ -95,6 +96,26 @@ impl OverlayBuilder { bail!("not running as root") } + let out = Command::new(&bubblewrap).arg("--version").check_stdout_trim() + .chain_err(|| "Failed to execute bwrap for version check")?; + if let Some(s) = out.split_whitespace().nth(1) { + match (Version::from("0.3.0"), Version::from(s)) { + (Some(min), Some(seen)) => { + if seen < min { + bail!("bubblewrap 0.3.0 or later is required, got {:?} for {:?}", + out, bubblewrap); + } + }, + (_, _) => { + bail!("Unexpected version format running {:?}: got {:?}, expected \"bubblewrap x.x.x\"", + bubblewrap, out); + } + } + } else { + bail!("Unexpected version format running {:?}: got {:?}, expected \"bubblewrap x.x.x\"", + bubblewrap, out); + } + // TODO: pidfile let ret = Self { bubblewrap,