mirror of
https://github.com/servo/servo.git
synced 2025-10-01 17:19:16 +01:00
Auto merge of #10749 - servo:split-mako, r=nox
Prepare related files to make it easier to split up the Mako template https://github.com/servo/servo/pull/10586#issuecomment-211490049 r? @nox <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10749) <!-- Reviewable:end -->
This commit is contained in:
commit
3bfa4cc741
12 changed files with 414 additions and 381 deletions
|
@ -3,10 +3,8 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Stdio, exit};
|
||||
use std::process::{Command, exit};
|
||||
|
||||
#[cfg(windows)]
|
||||
fn find_python() -> String {
|
||||
|
@ -31,32 +29,25 @@ fn find_python() -> String {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let python = match env::var("PYTHON") {
|
||||
Ok(python_path) => python_path,
|
||||
Err(_) => find_python(),
|
||||
};
|
||||
let python = env::var("PYTHON").ok().unwrap_or_else(find_python);
|
||||
|
||||
// Mako refuses to load templates outside the scope of the current working directory,
|
||||
// so we need to run it from the top source directory.
|
||||
let geckolib_dir = Path::new(file!()).parent().unwrap();
|
||||
let top_dir = geckolib_dir.join("..").join("..");
|
||||
|
||||
let style_template = Path::new("components/style/properties.mako.rs");
|
||||
let geckolib_template = Path::new("ports/geckolib/properties.mako.rs");
|
||||
let mako = Path::new("components/style/Mako-0.9.1.zip");
|
||||
let properties_dir = Path::new("components").join("style").join("properties");
|
||||
println!("cargo:rerun-if-changed={}", top_dir.join(&properties_dir).to_str().unwrap());
|
||||
println!("cargo:rerun-if-changed={}", geckolib_dir.join("properties.mako.rs").to_str().unwrap());
|
||||
|
||||
let result = Command::new(python)
|
||||
.current_dir(top_dir)
|
||||
.env("PYTHONPATH", &mako)
|
||||
.env("STYLE_TEMPLATE", &style_template)
|
||||
.env("GECKOLIB_TEMPLATE", &geckolib_template)
|
||||
.arg("ports/geckolib/generate_properties_rs.py")
|
||||
.stderr(Stdio::inherit())
|
||||
.output()
|
||||
let status = Command::new(python)
|
||||
.current_dir(&top_dir)
|
||||
.arg(&properties_dir.join("build.py"))
|
||||
.arg("gecko")
|
||||
.arg("geckolib")
|
||||
.status()
|
||||
.unwrap();
|
||||
if !result.status.success() {
|
||||
if !status.success() {
|
||||
exit(1)
|
||||
}
|
||||
let out = env::var("OUT_DIR").unwrap();
|
||||
File::create(&Path::new(&out).join("properties.rs")).unwrap().write_all(&result.stdout).unwrap();
|
||||
}
|
||||
|
|
|
@ -2,10 +2,14 @@
|
|||
* 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/. */
|
||||
|
||||
// STYLE_STRUCTS comes from components/style/properties.mako.rs; see build.rs for more details.
|
||||
// `data` comes from components/style/properties.mako.rs; see build.rs for more details.
|
||||
|
||||
<%!
|
||||
from data import to_rust_ident
|
||||
%>
|
||||
|
||||
use app_units::Au;
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for style_struct in data.style_structs:
|
||||
%if style_struct.gecko_ffi_name:
|
||||
use gecko_style_structs::${style_struct.gecko_ffi_name};
|
||||
use bindings::Gecko_Construct_${style_struct.gecko_ffi_name};
|
||||
|
@ -27,7 +31,7 @@ use style::properties::style_struct_traits::*;
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct GeckoComputedValues {
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: Arc<${style_struct.gecko_struct_name}>,
|
||||
% endfor
|
||||
|
||||
|
@ -38,7 +42,7 @@ pub struct GeckoComputedValues {
|
|||
}
|
||||
|
||||
impl ComputedValues for GeckoComputedValues {
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for style_struct in data.style_structs:
|
||||
type Concrete${style_struct.trait_name} = ${style_struct.gecko_struct_name};
|
||||
% endfor
|
||||
|
||||
|
@ -50,7 +54,7 @@ impl ComputedValues for GeckoComputedValues {
|
|||
shareable: bool,
|
||||
writing_mode: WritingMode,
|
||||
root_font_size: Au,
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: Arc<${style_struct.gecko_struct_name}>,
|
||||
% endfor
|
||||
) -> Self {
|
||||
|
@ -59,7 +63,7 @@ impl ComputedValues for GeckoComputedValues {
|
|||
shareable: shareable,
|
||||
writing_mode: writing_mode,
|
||||
root_font_size: root_font_size,
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: ${style_struct.ident},
|
||||
% endfor
|
||||
}
|
||||
|
@ -71,7 +75,7 @@ impl ComputedValues for GeckoComputedValues {
|
|||
CASCADE_PROPERTY.with(|x| f(x));
|
||||
}
|
||||
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for style_struct in data.style_structs:
|
||||
#[inline]
|
||||
fn clone_${style_struct.trait_name_lower}(&self) -> Arc<Self::Concrete${style_struct.trait_name}> {
|
||||
self.${style_struct.ident}.clone()
|
||||
|
@ -237,13 +241,13 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
|
|||
}
|
||||
</%def>
|
||||
|
||||
<%! MANUAL_STYLE_STRUCTS = [] %>
|
||||
<% data.manual_style_structs = [] %>
|
||||
<%def name="impl_trait(style_struct_name, skip_longhands=None, skip_additionals=None)">
|
||||
<%self:raw_impl_trait style_struct="${next(x for x in STYLE_STRUCTS if x.trait_name == style_struct_name)}"
|
||||
<%self:raw_impl_trait style_struct="${next(x for x in data.style_structs if x.trait_name == style_struct_name)}"
|
||||
skip_longhands="${skip_longhands}" skip_additionals="${skip_additionals}">
|
||||
${caller.body()}
|
||||
</%self:raw_impl_trait>
|
||||
<% MANUAL_STYLE_STRUCTS.append(style_struct_name) %>
|
||||
<% data.manual_style_structs.append(style_struct_name) %>
|
||||
</%def>
|
||||
|
||||
// Proof-of-concept for a style struct with some manually-implemented methods. We add
|
||||
|
@ -270,17 +274,17 @@ ${caller.body()}
|
|||
}
|
||||
</%self:impl_trait>
|
||||
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for style_struct in data.style_structs:
|
||||
${declare_style_struct(style_struct)}
|
||||
${impl_style_struct(style_struct)}
|
||||
% if not style_struct.trait_name in MANUAL_STYLE_STRUCTS:
|
||||
% if not style_struct.trait_name in data.manual_style_structs:
|
||||
<%self:raw_impl_trait style_struct="${style_struct}"></%self:raw_impl_trait>
|
||||
% endif
|
||||
% endfor
|
||||
|
||||
lazy_static! {
|
||||
pub static ref INITIAL_GECKO_VALUES: GeckoComputedValues = GeckoComputedValues {
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: ${style_struct.gecko_struct_name}::initial(),
|
||||
% endfor
|
||||
custom_properties: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue