Source code

Revision control

Other Tools

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 https://mozilla.org/MPL/2.0/. */
4
5
#[macro_use]
6
extern crate lazy_static;
7
#[cfg(feature = "gecko")]
8
extern crate bindgen;
9
#[cfg(feature = "gecko")]
10
extern crate log;
11
#[cfg(feature = "gecko")]
12
extern crate regex;
13
#[cfg(feature = "gecko")]
14
extern crate toml;
15
extern crate walkdir;
16
17
use std::env;
18
use std::path::Path;
19
use std::process::{exit, Command};
20
use walkdir::WalkDir;
21
22
#[cfg(feature = "gecko")]
23
mod build_gecko;
24
25
#[cfg(not(feature = "gecko"))]
26
mod build_gecko {
27
pub fn generate() {}
28
}
29
30
lazy_static! {
31
pub static ref PYTHON: String = env::var("PYTHON").ok().unwrap_or_else(|| {
32
let candidates = if cfg!(windows) {
33
["python2.7.exe", "python27.exe", "python.exe"]
34
} else {
35
["python2.7", "python2", "python"]
36
};
37
for &name in &candidates {
38
if Command::new(name)
39
.arg("--version")
40
.output()
41
.ok()
42
.map_or(false, |out| out.status.success())
43
{
44
return name.to_owned();
45
}
46
}
47
panic!(
48
"Can't find python (tried {})! Try fixing PATH or setting the PYTHON env var",
49
candidates.join(", ")
50
)
51
});
52
}
53
54
fn generate_properties(engine: &str) {
55
for entry in WalkDir::new("properties") {
56
let entry = entry.unwrap();
57
match entry.path().extension().and_then(|e| e.to_str()) {
58
Some("mako") | Some("rs") | Some("py") | Some("zip") => {
59
println!("cargo:rerun-if-changed={}", entry.path().display());
60
},
61
_ => {},
62
}
63
}
64
65
let script = Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap())
66
.join("properties")
67
.join("build.py");
68
69
let status = Command::new(&*PYTHON)
70
.arg(&script)
71
.arg(engine)
72
.arg("style-crate")
73
.status()
74
.unwrap();
75
if !status.success() {
76
exit(1)
77
}
78
}
79
80
fn main() {
81
let gecko = cfg!(feature = "gecko");
82
let servo = cfg!(feature = "servo");
83
let l2013 = cfg!(feature = "servo-layout-2013");
84
let l2020 = cfg!(feature = "servo-layout-2020");
85
let engine = match (gecko, servo, l2013, l2020) {
86
(true, false, false, false) => "gecko",
87
(false, true, true, false) => "servo-2013",
88
(false, true, false, true) => "servo-2020",
89
_ => panic!(
90
"\n\n\
91
The style crate requires enabling one of its 'servo' or 'gecko' feature flags \
92
and, in the 'servo' case, one of 'servo-layout-2013' or 'servo-layout-2020'.\
93
\n\n"
94
),
95
};
96
println!("cargo:rerun-if-changed=build.rs");
97
println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap());
98
generate_properties(engine);
99
build_gecko::generate();
100
}