style::properties : move generated file out of source tree, use new-style Cargo build script.

This commit is contained in:
Simon Sapin 2015-01-28 23:09:35 +01:00
parent d13d36f57f
commit 6e95bd8e50
7 changed files with 48 additions and 13 deletions

View file

@ -553,6 +553,11 @@ dependencies = [
"log 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mod_path"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "mozjs-sys"
version = "0.0.0"
@ -753,6 +758,7 @@ dependencies = [
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
"lazy_static 0.1.6 (git+https://github.com/Kimundi/lazy-static.rs)",
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"mod_path 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
"string_cache 0.0.0 (git+https://github.com/servo/string-cache)",
"string_cache_macros 0.0.0 (git+https://github.com/servo/string-cache)",

View file

@ -1,2 +0,0 @@
properties/mod.rs
properties/mod.rs.tmp

View file

@ -3,7 +3,7 @@ name = "style"
version = "0.0.1"
authors = ["The Servo Project Developers"]
build = "make -f makefile.cargo"
build = "build.rs"
[lib]
name = "style"
@ -34,4 +34,5 @@ git = "https://github.com/servo/string-cache"
text_writer = "0.1.1"
encoding = "0.2"
matches = "0.1"
url = "*"
url = "*"
mod_path = "0.1"

31
components/style/build.rs Normal file
View file

@ -0,0 +1,31 @@
/* 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/. */
use std::os;
use std::path::Path;
use std::io::process::{Command, ProcessExit, StdioContainer};
use std::io::File;
fn main() {
let python = if Command::new("python2.7").arg("--version").status() == Ok(ProcessExit::ExitStatus(0)) {
"python2.7"
} else {
"python"
};
let style = Path::new(file!()).dir_path();
let mako = style.join("Mako-0.9.1.zip");
let template = style.join("properties.mako.rs");
let result = Command::new(python)
.env("PYTHONPATH", mako.as_str().unwrap())
.env("TEMPLATE", template.as_str().unwrap())
.arg("-c")
.arg("from os import environ; from mako.template import Template; print(Template(filename=environ['TEMPLATE']).render())")
.stderr(StdioContainer::InheritFd(2))
.output()
.unwrap();
assert_eq!(result.status, ProcessExit::ExitStatus(0));
let out = Path::new(os::getenv("OUT_DIR").unwrap());
File::create(&out.join("properties.rs")).unwrap().write(&*result.output).unwrap();
}

View file

@ -34,13 +34,18 @@ extern crate lazy_static;
extern crate util;
#[plugin] #[no_link] extern crate mod_path;
pub mod stylesheets;
pub mod parser;
pub mod selectors;
pub mod selector_matching;
#[macro_use] pub mod values;
#[macro_use] pub mod properties;
// Generated from the properties.mako.rs template by build.rs
mod_path! properties (concat!(env!("OUT_DIR"), "/properties.rs"));
pub mod node;
pub mod media_queries;
pub mod font_face;

View file

@ -1,8 +0,0 @@
MAKO_ZIP = Mako-0.9.1.zip
PYTHON = $(shell which python2.7 2>/dev/null || echo python)
all: properties/mod.rs
properties/mod.rs: properties/mod.rs.mako
PYTHONPATH=$(MAKO_ZIP) $(PYTHON) -c "from mako.template import Template; print(Template(filename='$<').render())" > $@.tmp
mv $@.tmp $@

View file

@ -4,6 +4,8 @@
// This file is a Mako template: http://www.makotemplates.org/
#![macro_use]
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::fmt;