Skip to content

Commit 873edca

Browse files
author
pmocher
committed
# This is a combination of 2 commits.
# This is the 1st commit message: resolved merge conflict # This is the commit message servo#2: refactor(build): generate revision via build.rs
1 parent f572f8f commit 873edca

File tree

6 files changed

+90
-34
lines changed

6 files changed

+90
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/compositing/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.0.1"
44
authors = ["The Servo Project Developers"]
55
license = "MPL-2.0"
66
publish = false
7+
build = "build.rs"
78

89
[lib]
910
name = "compositing"
@@ -29,3 +30,6 @@ style_traits = {path = "../style_traits"}
2930
time = "0.1.17"
3031
webrender = {git = "https://github.com/servo/webrender", features = ["capture"]}
3132
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
33+
34+
[build-dependencies]
35+
toml = "0.4.5"

components/compositing/build.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
extern crate toml;
6+
7+
use std::env;
8+
use std::fs::File;
9+
use std::io::{Read, Write};
10+
11+
const WEBRENDER_REVISION_TEMPLATE: &'static str =
12+
"/* This Source Code Form is subject to the terms of the Mozilla Public
13+
* License, v. 2.0. If a copy of the MPL was not distributed with this
14+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
15+
16+
/// auto-generated by cargo. do not manually modify.
17+
pub const REVISION: &'static str = ";
18+
19+
fn main() {
20+
let current_path = env::current_dir().expect("Failed to access path to lockfile");
21+
let lockfile_path = current_path.join("..").join("..").join("Cargo.lock");
22+
let revision_file_path = current_path.join("webrender_revision.rs");
23+
24+
let mut existing_revision_exported = String::new();
25+
match File::open(&revision_file_path) {
26+
Ok(mut f) => {
27+
f.read_to_string(&mut existing_revision_exported).unwrap_or_default();
28+
},
29+
Err(_) => ()
30+
}
31+
32+
let mut lockfile = String::new();
33+
File::open(lockfile_path).expect("Cannot open lockfile")
34+
.read_to_string(&mut lockfile)
35+
.expect("Failed to read lockfile");
36+
37+
match toml::from_str::<toml::value::Table>(&lockfile) {
38+
Ok(result) => {
39+
let packages = result.get("package").expect("Cargo lockfile should contain package list");
40+
41+
match *packages {
42+
toml::Value::Array(ref arr) => {
43+
let source = arr
44+
.iter()
45+
.find(|pkg| pkg.get("name").and_then(|name| name.as_str()).unwrap_or("") == "webrender")
46+
.and_then(|pkg| pkg.get("source").and_then(|source| source.as_str()))
47+
.unwrap_or("unknown");
48+
49+
let parsed: Vec<&str> = source.split("#").collect();
50+
let revision = if parsed.len() > 1 { parsed[1] } else { source };
51+
52+
if let Some(_) = existing_revision_exported.find(revision) {
53+
return
54+
}
55+
56+
let revision_contents = format!("{}\"{}\";", WEBRENDER_REVISION_TEMPLATE, revision);
57+
let mut revision_module_file = File::create(&revision_file_path).unwrap();
58+
write!(&mut revision_module_file, "{}", revision_contents).unwrap();
59+
},
60+
_ => panic!("Cannot find package definitions in lockfile")
61+
}
62+
},
63+
Err(e) => panic!(e)
64+
}
65+
}

components/compositing/compositor.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use servo_config::opts;
2424
use servo_geometry::{DeviceIndependentPixel, DeviceUintLength};
2525
use std::collections::HashMap;
2626
use std::env;
27-
use std::fs::File;
27+
use std::fs::{File, create_dir_all};
28+
use std::io::Write;
2829
use std::rc::Rc;
2930
use std::sync::mpsc::Sender;
3031
use std::time::{Duration, Instant};
@@ -1543,9 +1544,25 @@ impl<Window: WindowMethods> IOCompositor<Window> {
15431544
Ok(current_dir) => {
15441545
let capture_id = now().to_timespec().sec.to_string();
15451546
let capture_path = current_dir.join("capture_webrender").join(capture_id);
1547+
let revision_file_path = capture_path.join("wr.txt");
1548+
1549+
if let Err(err) = create_dir_all(&capture_path) {
1550+
println!("Unable to create path '{:?}' for capture: {:?}", capture_path, err);
1551+
return
1552+
}
1553+
15461554
self.webrender_api.save_capture(capture_path, webrender_api::CaptureBits::all());
1555+
1556+
match File::create(revision_file_path) {
1557+
Ok(mut file) => {
1558+
if let Err(err) = write!(&mut file, "{}", REVISION) {
1559+
println!("Unable to write webrender revision: {:?}", err)
1560+
}
1561+
}
1562+
Err(err) => println!("Capture triggered, creating webrender revision info skipped: {:?}", err)
1563+
}
15471564
},
1548-
Err(err) => println!("could not locate path to save captures: {:?}", err)
1565+
Err(err) => println!("Unable to locate path to save captures: {:?}", err)
15491566
}
15501567
}
15511568
}

components/compositing/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use style_traits::CSSPixel;
3939
mod compositor;
4040
pub mod compositor_thread;
4141
mod touch;
42+
mod webrender_revision;
4243
pub mod windowing;
4344

4445
pub struct SendableFrameTree {

python/servo/command_base.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -213,36 +213,6 @@ def set_osmesa_env(bin_path, env):
213213
return env
214214

215215

216-
def generate_webrender_revision():
217-
"""Read current package id of web render to generate revision"""
218-
219-
lockfile_path = path.join(os.getcwd(), "Cargo.lock")
220-
if not os.path.isfile(lockfile_path):
221-
return
222-
223-
with open(lockfile_path) as f:
224-
lockfile = toml.loads(f.read())
225-
226-
webrender_revision = ""
227-
for package in lockfile.get("package", []):
228-
pkgName = package.get("name")
229-
if ("webrender" == pkgName):
230-
webrender_revision = package.get("source")
231-
232-
revision = '''/* This Source Code Form is subject to the terms of the Mozilla Public
233-
* License, v. 2.0. If a copy of the MPL was not distributed with this
234-
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
235-
236-
/// auto-generated by mach. do not manually modify.
237-
pub const REVISION: &'static str = \"%s\";''' % webrender_revision
238-
239-
compositor_path = os.path.join(os.getcwd(), "components", "compositing", "webrender_revision.rs")
240-
241-
revision_file = open(compositor_path, "w")
242-
revision_file.write(revision)
243-
revision_file.close()
244-
245-
246216
class BuildNotFound(Exception):
247217
def __init__(self, message):
248218
self.message = message
@@ -690,8 +660,6 @@ def ensure_bootstrapped(self, target=None):
690660
if "msvc" in target_platform:
691661
Registrar.dispatch("bootstrap", context=self.context)
692662

693-
generate_webrender_revision()
694-
695663
self.context.bootstrapped = True
696664

697665
def ensure_clobbered(self, target_dir=None):

0 commit comments

Comments
 (0)