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

feat(capture_webrender): write webrender revision into text #20320

Merged
merged 5 commits into from Mar 23, 2018

Some generated files are not rendered by default. Learn more.

@@ -4,6 +4,7 @@ version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
publish = false
build = "build.rs"

[lib]
name = "compositing"
@@ -29,3 +30,6 @@ style_traits = {path = "../style_traits"}
time = "0.1.17"
webrender = {git = "https://github.com/servo/webrender", features = ["capture"]}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}

[build-dependencies]
toml = "0.4.5"
@@ -0,0 +1,44 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

extern crate toml;

use std::env;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;

fn main() {
let lockfile_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("..").join("..").join("Cargo.lock");
let revision_file_path = Path::new(&env::var_os("OUT_DIR").unwrap()).join("webrender_revision.rs");

let mut lockfile = String::new();
File::open(lockfile_path).expect("Cannot open lockfile")
.read_to_string(&mut lockfile)
.expect("Failed to read lockfile");

match toml::from_str::<toml::value::Table>(&lockfile) {
Ok(result) => {
let packages = result.get("package").expect("Cargo lockfile should contain package list");

match *packages {
toml::Value::Array(ref arr) => {
let source = arr
.iter()
.find(|pkg| pkg.get("name").and_then(|name| name.as_str()).unwrap_or("") == "webrender")
.and_then(|pkg| pkg.get("source").and_then(|source| source.as_str()))
.unwrap_or("unknown");

let parsed: Vec<&str> = source.split("#").collect();
let revision = if parsed.len() > 1 { parsed[1] } else { source };

let mut revision_module_file = File::create(&revision_file_path).unwrap();
write!(&mut revision_module_file, "{}", format!("\"{}\"", revision)).unwrap();
},
_ => panic!("Cannot find package definitions in lockfile")
}
},
Err(e) => panic!(e)
}
}
@@ -24,7 +24,8 @@ use servo_config::opts;
use servo_geometry::{DeviceIndependentPixel, DeviceUintLength};
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::fs::{File, create_dir_all};
use std::io::Write;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use std::time::{Duration, Instant};
@@ -1540,9 +1541,26 @@ impl<Window: WindowMethods> IOCompositor<Window> {
Ok(current_dir) => {
let capture_id = now().to_timespec().sec.to_string();
let capture_path = current_dir.join("capture_webrender").join(capture_id);
let revision_file_path = capture_path.join("wr.txt");

if let Err(err) = create_dir_all(&capture_path) {
eprintln!("Unable to create path '{:?}' for capture: {:?}", capture_path, err);
return
}

self.webrender_api.save_capture(capture_path, webrender_api::CaptureBits::all());

match File::create(revision_file_path) {
Ok(mut file) => {
let revision = include!(concat!(env!("OUT_DIR"), "/webrender_revision.rs"));
if let Err(err) = write!(&mut file, "{}", revision) {
eprintln!("Unable to write webrender revision: {:?}", err)
}
}
Err(err) => eprintln!("Capture triggered, creating webrender revision info skipped: {:?}", err)
}
},
Err(err) => println!("could not locate path to save captures: {:?}", err)
Err(err) => eprintln!("Unable to locate path to save captures: {:?}", err)
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.