Bug 1551611 - Add macOS version information to the ReftestEnvironment. r=Gankro

Differential Revision: https://phabricator.services.mozilla.com/D31182

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kartikaya Gupta 2019-05-15 14:39:39 +00:00
Родитель b8b7813c1c
Коммит a30b01108f
4 изменённых файлов: 48 добавлений и 5 удалений

1
gfx/wr/Cargo.lock сгенерированный
Просмотреть файл

@ -1809,6 +1809,7 @@ dependencies = [
"osmesa-src 0.1.1 (git+https://github.com/servo/osmesa-src)",
"osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ron 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",

Просмотреть файл

@ -29,6 +29,7 @@ webrender = {path = "../webrender", features=["capture","replay","debugger","png
webrender_api = {path = "../webrender_api", features=["serialize","deserialize"]}
winit = "0.16"
serde = {version = "1.0", features = ["derive"] }
semver = "0.9.0"
[target.'cfg(target_os = "macos")'.dependencies]
core-graphics = "0.17.1"

Просмотреть файл

@ -4,14 +4,18 @@
use std::str::CharIndices;
// support arguments like '4', 'ab', '4.0'
// support arguments like '4', 'ab', '4.0', '>=10.14'
fn acceptable_arg_character(c: char) -> bool {
c.is_alphanumeric() || c == '.' || c == '-'
c.is_alphanumeric() || c == '.' || c == '-' || c == '<' || c == '>' || c == '='
}
// A crapy parser for parsing strings like "translate(1, 3)"
// A crapy parser for parsing strings like "translate(1, 3) blahblah"
// Returns a tuple with three components:
// - First component is the function name (e.g. "translate")
// - Second component is the list of arguments (e.g. vec!["1", "3"])
// - Third component is the rest of the string "blahblah"
pub fn parse_function(s: &str) -> (&str, Vec<&str>, &str) {
// XXX: This it not particular easy to read. Sorry.
// XXX: This is not particularly easy to read. Sorry.
struct Parser<'a> {
itr: CharIndices<'a>,
start: usize,

Просмотреть файл

@ -4,6 +4,7 @@
use crate::{WindowWrapper, NotifierEvent};
use base64;
use semver;
use image::load as load_piston_image;
use image::png::PNGEncoder;
use image::{ColorType, ImageFormat};
@ -14,6 +15,7 @@ use std::fmt::{Display, Error, Formatter};
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::mpsc::Receiver;
use webrender::RenderResults;
use webrender::api::*;
@ -349,6 +351,7 @@ struct YamlRenderOutput {
struct ReftestEnvironment {
pub platform: &'static str,
pub version: Option<semver::Version>,
pub mode: &'static str,
}
@ -356,12 +359,20 @@ impl ReftestEnvironment {
fn new() -> Self {
Self {
platform: Self::platform(),
version: Self::version(),
mode: Self::mode(),
}
}
fn has(&self, condition: &str) -> bool {
self.platform == condition || self.mode == condition
if self.platform == condition || self.mode == condition {
return true;
}
match (&self.version, &semver::VersionReq::parse(condition)) {
(None, _) => false,
(_, Err(_)) => false,
(Some(v), Ok(r)) => r.matches(v),
}
}
fn platform() -> &'static str {
@ -378,6 +389,32 @@ impl ReftestEnvironment {
}
}
fn version() -> Option<semver::Version> {
if cfg!(target_os = "macos") {
use std::str;
let version_bytes = Command::new("defaults")
.arg("read")
.arg("loginwindow")
.arg("SystemVersionStampAsString")
.output()
.expect("Failed to get macOS version")
.stdout;
let mut version_string = str::from_utf8(&version_bytes)
.expect("Failed to read macOS version")
.trim()
.to_string();
// On some machines this produces just the major.minor and on
// some machines this gives major.minor.patch. But semver requires
// the patch so we fake one if it's not there.
if version_string.chars().filter(|c| *c == '.').count() == 1 {
version_string.push_str(".0");
}
Some(semver::Version::parse(&version_string).expect(&format!("Failed to parse macOS version {}", version_string)))
} else {
None
}
}
fn mode() -> &'static str {
if cfg!(debug_assertions) {
"debug"