servo: Merge #20320 - feat(capture_webrender): write webrender revision into text (from kwonoj:feat-wr-revision); r=jdm

<!-- Please describe your changes on the following line: -->
Relates to https://github.com/servo/servo/pull/20315#issuecomment-373819735.

This PR try to generate `wr.txt` when trigger webrender capture. By reading gecko's implementation at [here](3b8e63c66a/gfx/doc/README.webrender (L53)), it seems gecko's build script generates txt file for containing revision of webrender and read it each time trigger capturing.

In this PR tries to similar in cruxwise with small differences:
- `cargo build` reads `cargo.lock`, export it into `${OUT_DIR}/`, included via macro in build time.
- when capturing triggered, those revision will be written as `wr.txt`.

Probably point of discussion & need to be updated in PR if necessary:
~- Is it acceptable `mach` generates module file on build bootstrapping? Should there be other recommendation?~ Now cargo build takes care of generation.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #20295 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

- This PR manually verified on local mac OS machine.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 91398cf559ddeec8974e04b0a92e464669436177

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 9751ea51ab25079d0f1ac3d0f228bb97b0a61568
This commit is contained in:
OJ Kwon 2018-03-23 02:30:49 -04:00
Родитель 21af10d5f4
Коммит 2873691765
4 изменённых файлов: 69 добавлений и 2 удалений

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

@ -431,6 +431,7 @@ dependencies = [
"servo_url 0.0.1",
"style_traits 0.0.1",
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender 0.57.0 (git+https://github.com/servo/webrender)",
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
]

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

@ -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};
@ -1543,9 +1544,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)
}
}
}