Bug 1430152 - Move geckodriver to in-tree mozversion. r?jgraham draft
authorAndreas Tolfsen <ato@sny.no>
Fri, 12 Jan 2018 16:09:28 +0000
changeset 721584 4047a16519ad6e76db2fa6e0717f3b20ee85ebc0
parent 721583 7e2e0484a193cc4823e0e7f73174469d93ce2917
child 746371 d31364432ca7da90556a6ed2ffa1d714dc3a0766
push id95877
push userbmo:ato@sny.no
push dateWed, 17 Jan 2018 13:53:34 +0000
reviewersjgraham
bugs1430152
milestone59.0a1
Bug 1430152 - Move geckodriver to in-tree mozversion. r?jgraham MozReview-Commit-ID: A8yb1joLYfv
testing/geckodriver/Cargo.lock
testing/geckodriver/Cargo.toml
third_party/rust/mozversion/.cargo-checksum.json
third_party/rust/mozversion/Cargo.toml
third_party/rust/mozversion/src/lib.rs
--- a/testing/geckodriver/Cargo.lock
+++ b/testing/geckodriver/Cargo.lock
@@ -127,17 +127,17 @@ version = "0.19.1"
 dependencies = [
  "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
  "clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "mozrunner 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "mozversion 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mozversion 0.1.2",
  "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
  "slog 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "slog-atomic 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "slog-stdlog 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "slog-stream 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
  "webdriver 0.33.0",
@@ -285,17 +285,16 @@ dependencies = [
  "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "winreg 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "mozversion"
 version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "rust-ini 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "msdos_time"
@@ -683,17 +682,16 @@ dependencies = [
 "checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
 "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
 "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376"
 "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
 "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
 "checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4"
 "checksum mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a17b8bbde1dc0fbf1c8b073192d7c6f89baa932173ece7c1447de5e9cc7cd7e"
 "checksum mozrunner 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff037ca681fa465d01c863f8b16d4a008997b35468059c06f1a4b828369600b"
-"checksum mozversion 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9fb3a40135553611560d3eb4a49479beaf0c91c5a93f723338c5b0edddf08f26"
 "checksum msdos_time 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "65ba9d75bcea84e07812618fedf284a64776c2f2ea0cad6bca7f69739695a958"
 "checksum num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "a311b77ebdc5dd4cf6449d81e4135d9f0e3b153839ac90e648a8ef538f923525"
 "checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba"
 "checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01"
 "checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070"
 "checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d"
 "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356"
 "checksum podio 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e5422a1ee1bc57cc47ae717b0137314258138f38fd5f3cea083f43a9725383a0"
--- a/testing/geckodriver/Cargo.toml
+++ b/testing/geckodriver/Cargo.toml
@@ -12,17 +12,17 @@ publish = false
 [dependencies]
 chrono = "^0.2"
 clap = { version = "^2.19", default-features = false, features = ["suggestions", "wrap_help"] }
 hyper = "0.10"
 lazy_static = "0.1"
 log = "0.3"
 mozprofile = "0.3.0"
 mozrunner = "0.5.0"
-mozversion = "0.1.2"
+mozversion = { path = "../mozbase/rust/mozversion" }
 regex = "0.2"
 rustc-serialize = "0.3"
 slog = "1"
 slog-atomic = "0.4"
 slog-stdlog = "1"
 slog-stream = "1"
 uuid = "0.1.18"
 webdriver = { path = "../webdriver" }
deleted file mode 100644
--- a/third_party/rust/mozversion/.cargo-checksum.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"files":{"Cargo.toml":"394d4d16c9ef5347a6572332b2ce927889da025df1885ae52419ae753f51ed75","src/lib.rs":"2e69f46b1e206ff07717cebcfc0ed5bd9cbe2fcc5a6f823fe1cadcef05ccb33c"},"package":"9fb3a40135553611560d3eb4a49479beaf0c91c5a93f723338c5b0edddf08f26"}
\ No newline at end of file
deleted file mode 100644
--- a/third_party/rust/mozversion/Cargo.toml
+++ /dev/null
@@ -1,14 +0,0 @@
-[package]
-name = "mozversion"
-version = "0.1.2"
-authors = ["James Graham <james@hoppipolla.co.uk>"]
-description = "Utility for accessing Firefox version metadata"
-keywords = ["mozilla", "firefox"]
-repository = "https://github.com/jgraham/mozversion"
-license = "MPL-2.0"
-
-
-[dependencies]
-regex = "0.2"
-rust-ini = "0.10.0"
-semver = "0.6"
\ No newline at end of file
deleted file mode 100644
--- a/third_party/rust/mozversion/src/lib.rs
+++ /dev/null
@@ -1,319 +0,0 @@
-extern crate ini;
-extern crate regex;
-extern crate semver;
-
-use ini::Ini;
-use regex::Regex;
-use platform::ini_path;
-use std::default::Default;
-use std::error;
-use std::fmt::{self, Display, Formatter};
-use std::path::Path;
-use std::str::FromStr;
-
-/// Details about the version of a Firefox build.
-#[derive(Clone, Default)]
-pub struct AppVersion {
-    /// Unique date-based id for a build
-    pub build_id: Option<String>,
-    /// Channel name
-    pub code_name: Option<String>,
-    /// Version number e.g. 55.0a1
-    pub version_string: Option<String>,
-    /// Url of the respoistory from which the build was made
-    pub source_repository: Option<String>,
-    /// Commit ID of the build
-    pub source_stamp: Option<String>,
-}
-
-impl AppVersion {
-    pub fn new() -> AppVersion {
-        Default::default()
-    }
-
-    fn update_from_application_ini(&mut self, ini_file: &Ini) {
-        if let Some(section) = ini_file.section(Some("App")) {
-            if let Some(build_id) = section.get("BuildID") {
-                self.build_id = Some(build_id.clone());
-            }
-            if let Some(code_name) = section.get("CodeName") {
-                self.code_name = Some(code_name.clone());
-            }
-            if let Some(version) = section.get("Version") {
-                self.version_string = Some(version.clone());
-            }
-            if let Some(source_repository) = section.get("SourceRepository") {
-                self.source_repository = Some(source_repository.clone());
-            }
-            if let Some(source_stamp) = section.get("SourceStamp") {
-                self.source_stamp = Some(source_stamp.clone());
-            }
-        }
-    }
-
-    fn update_from_platform_ini(&mut self, ini_file: &Ini) {
-        if let Some(section) = ini_file.section(Some("Build")) {
-            if let Some(build_id) = section.get("BuildID") {
-                self.build_id = Some(build_id.clone());
-            }
-            if let Some(version) = section.get("Milestone") {
-                self.version_string = Some(version.clone());
-            }
-            if let Some(source_repository) = section.get("SourceRepository") {
-                self.source_repository = Some(source_repository.clone());
-            }
-            if let Some(source_stamp) = section.get("SourceStamp") {
-                self.source_stamp = Some(source_stamp.clone());
-            }
-        }
-    }
-
-    pub fn version(&self) -> Option<Version> {
-        self.version_string
-            .as_ref()
-            .and_then(|x| Version::from_str(&*x).ok())
-    }
-}
-
-#[derive(Default, Clone)]
-/// Version number information
-pub struct Version {
-    /// Major version number (e.g. 55 in 55.0)
-    pub major: u64,
-    /// Minor version number (e.g. 1 in 55.1)
-    pub minor: u64,
-    /// Patch version number (e.g. 2 in 55.1.2)
-    pub patch: u64,
-    /// Prerelase information (e.g. Some(("a", 1)) in 55.0a1)
-    pub pre: Option<(String, u64)>,
-}
-
-impl Version {
-    pub fn from_str(version_string: &str) -> Result<Version, Error> {
-        let mut version: Version = Default::default();
-        let version_re = Regex::new(r"^(?P<major>\d+)\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?(?:(?P<pre0>[a-z]+)(?P<pre1>\d*))?$").unwrap();
-        if let Some(captures) = version_re.captures(version_string) {
-            match captures.name("major")
-                .and_then(|x| u64::from_str(x.as_str()).ok()) {
-                    Some(x) => version.major = x,
-                    None => return Err(Error::VersionError("No major version number found".into()))
-                }
-            match captures.name("minor")
-                .and_then(|x| u64::from_str(x.as_str()).ok()) {
-                    Some(x) => version.minor = x,
-                    None => return Err(Error::VersionError("No minor version number found".into()))
-                }
-            match captures.name("patch")
-                .and_then(|x| u64::from_str(x.as_str()).ok()) {
-                    Some(x) => version.patch = x,
-                    None => {}
-                }
-            if let Some(pre_0) = captures.name("pre0").map(|x| x.as_str().to_string()) {
-                if captures.name("pre1").is_some() {
-                    if let Some(pre_1) = captures.name("pre1")
-                        .and_then(|x| u64::from_str(x.as_str()).ok()) {
-                            version.pre = Some((pre_0, pre_1))
-                        } else {
-                            return Err(Error::VersionError("Failed to convert prelease number to u64".into()));
-                        }
-                } else {
-                    return Err(Error::VersionError("Failed to convert prelease number to u64".into()));
-                }
-            }
-        } else {
-            return Err(Error::VersionError("Failed to parse input as version string".into()))
-        }
-        Ok(version)
-    }
-
-    fn to_semver(&self) -> semver::Version {
-        // The way the semver crate handles prereleases isn't what we want here
-        // This should be fixed in the long term by implementing our own comparison
-        // operators, but for now just act as if prerelease metadata was missing, otherwise
-        // it is almost impossible to use this with nightly
-        semver::Version {
-            major: self.major,
-            minor: self.minor,
-            patch: self.patch,
-            pre: vec![],
-            build: vec![],
-        }
-    }
-
-    pub fn matches(&self, version_req: &str) -> Result<bool, Error> {
-        let req = try!(semver::VersionReq::parse(version_req));
-        Ok(req.matches(&self.to_semver()))
-    }
-}
-
-impl Display for Version {
-    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        match self.patch {
-            0 => try!(write!(f, "{}.{}", self.major, self.minor)),
-            _ => try!(write!(f, "{}.{}.{}", self.major, self.minor, self.patch))
-        }
-        if let Some(ref pre) = self.pre {
-            try!(write!(f, "{}{}", pre.0, pre.1));
-        };
-        Ok(())
-    }
-}
-
-/// Determine the version of Firefox given the path to a binary.
-///
-/// Given the path to a Firefox binary, read the associated application.ini
-/// and platform.ini files to extract information about the version of Firefox
-/// at that path.
-pub fn firefox_version(binary: &Path) -> Result<AppVersion, Error>  {
-    let mut version = AppVersion::new();
-    let mut updated = false;
-
-    if let Some(dir) = ini_path(binary) {
-        let mut application_ini = dir.clone();
-        application_ini.push("application.ini");
-
-        if Path::exists(&application_ini) {
-            let ini_file = Ini::load_from_file(application_ini).ok();
-            if let Some(ini) = ini_file {
-                updated = true;
-                version.update_from_application_ini(&ini);
-            }
-        }
-
-        let mut platform_ini = dir.clone();
-        platform_ini.push("platform.ini");
-
-        if Path::exists(&platform_ini) {
-            let ini_file = Ini::load_from_file(platform_ini).ok();
-            if let Some(ini) = ini_file {
-                updated = true;
-                version.update_from_platform_ini(&ini);
-            }
-        }
-
-        if !updated {
-            return Err(Error::MetadataError("Neither platform.ini nor application.ini found".into()))
-        }
-    } else {
-        return Err(Error::MetadataError("Invalid binary path".into()))
-    }
-    Ok(version)
-}
-
-#[derive(Debug)]
-pub enum Error {
-    /// Error parsing a version string
-    VersionError(String),
-    /// Error reading application metadata
-    MetadataError(String),
-    /// Error processing a string as a semver comparator
-    SemVerError(semver::ReqParseError)
-}
-
-impl Display for Error {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self {
-            &Error::VersionError(ref x) => {
-                try!("VersionError: ".fmt(f));
-                x.fmt(f)
-            },
-            &Error::MetadataError(ref x) => {
-                try!("MetadataError: ".fmt(f));
-                x.fmt(f)
-            },
-            &Error::SemVerError(ref e) => {
-                try!("SemVerError: ".fmt(f));
-                e.fmt(f)
-            }
-        }
-    }
-}
-
-impl From<semver::ReqParseError> for Error {
-    fn from(err: semver::ReqParseError) -> Error {
-        Error::SemVerError(err)
-    }
-}
-
-impl error::Error for Error {
-    fn description(&self) -> &str {
-        match self {
-            &Error::VersionError(ref x) => &*x,
-            &Error::MetadataError(ref x) => &*x,
-            &Error::SemVerError(ref e) => e.description(),
-        }
-    }
-
-    fn cause(&self) -> Option<&error::Error> {
-        match self {
-            &Error::SemVerError(ref e) => Some(e),
-            _ => None,
-        }
-    }
-}
-
-#[cfg(target_os = "macos")]
-mod platform {
-    use std::path::{Path, PathBuf};
-
-    pub fn ini_path(binary: &Path) -> Option<PathBuf> {
-        binary.canonicalize().ok()
-            .as_ref()
-            .and_then(|dir| dir.parent())
-            .and_then(|dir| dir.parent())
-            .map(|dir| dir.join("Resources"))
-    }
-}
-
-#[cfg(not(target_os = "macos"))]
-mod platform {
-    use std::path::{Path, PathBuf};
-
-    pub fn ini_path(binary: &Path) -> Option<PathBuf> {
-        binary.canonicalize().ok()
-            .as_ref()
-            .and_then(|dir| dir.parent())
-            .map(|dir| dir.to_path_buf())
-    }
-}
-
-#[cfg(test)]
-mod test {
-    use super::{Version};
-
-    fn parse_version(input: &str) -> String {
-        Version::from_str(input).unwrap().to_string()
-    }
-
-    fn compare(version: &str, comparison: &str) -> bool {
-        let v = Version::from_str(version).unwrap();
-        v.matches(comparison).unwrap()
-    }
-
-    #[test]
-    fn test_parser() {
-        assert!(parse_version("50.0a1") == "50.0a1");
-        assert!(parse_version("50.0.1a1") == "50.0.1a1");
-        assert!(parse_version("50.0.0") == "50.0");
-    }
-
-    #[test]
-    fn test_matches() {
-        assert!(compare("50.0", "=50"));
-        assert!(compare("50.1", "=50"));
-        assert!(compare("50.1", "=50.1"));
-        assert!(compare("50.1.1", "=50.1"));
-        assert!(compare("50.0.0", "=50.0.0"));
-        assert!(compare("51.0.0", ">50"));
-        assert!(compare("49.0", "<50"));
-        assert!(compare("50.0", "<50.1"));
-        assert!(compare("50.0.0", "<50.0.1"));
-        assert!(!compare("50.1.0", ">50"));
-        assert!(!compare("50.1.0", "<50"));
-        assert!(compare("50.1.0", ">=50,<51"));
-        assert!(compare("50.0a1", ">49.0"));
-        assert!(compare("50.0a2", "=50"));
-        //This is the weird one
-        assert!(!compare("50.0a2", ">50.0"));
-    }
-}