Skip to content

Run on Rust stable #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ branches:
- servo

language: rust
rust: nightly
rust:
- nightly
- beta
- stable
script: scripts/travis-build.sh
after_success: curl https://raw.githubusercontent.com/kmcallister/travis-doc-upload/master/travis-doc-upload.sh | sh

Expand Down
25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@ license = "MIT / Apache-2.0"
repository = "https://github.com/servo/html5ever"
description = "High-performance browser-grade HTML5 parser"
documentation = "https://kmcallister.github.io/docs/html5ever/html5ever/index.html"
build = "build.rs"

[lib]
name = "html5ever"

# https://github.com/rust-lang/cargo/issues/1512
doctest = false

[features]
unstable = ["html5ever_macros", "tendril/unstable", "string_cache/unstable", "string_cache_plugin", "rc/unstable"]

[dependencies]
time = "0"
log = "0"
phf = "0.7"
phf_macros = "0.7"
string_cache = "0"
string_cache_plugin = "0"
string_cache = "0.1.8"
string_cache_plugin = { version = "0.1.5", optional = true }
mac = "0"
tendril = "0.1"

[dependencies.html5ever_macros]
version = "0.1.0"
path = "macros"
tendril = "0.1.3"
rc = "0.1.1"

[dev-dependencies]
rustc-serialize = "0"
rustc-serialize = "0.3.15"

[dev-dependencies.html5ever_test_util]
version = "0.1.0"
path = "test_util"
[build-dependencies]
phf_codegen = "0.7.3"
rustc-serialize = "0.3.15"
html5ever_macros = { version = "0.1.0", path = "macros", optional = true }

[profile.dev]
debug = false
Expand Down
129 changes: 129 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright 2014-2015 The html5ever Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate phf_codegen;
extern crate rustc_serialize;

use rustc_serialize::json::{Json, Decoder};
use rustc_serialize::Decodable;
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;

fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();

let rules_rs = Path::new(&manifest_dir).join("src/tree_builder/rules.rs");
expand_match_tokens(
&rules_rs,
// Keep the expanded file in the source directory, so that `cargo publish` ships it.
&rules_rs.with_extension("expanded.rs"));

named_entities_to_phf(
&Path::new(&manifest_dir).join("data/entities.json"),
&Path::new(&env::var("OUT_DIR").unwrap()).join("named_entities.rs"))
}

#[cfg(feature = "unstable")]
fn expand_match_tokens(from: &Path, to: &Path) {
extern crate html5ever_macros;

html5ever_macros::pre_expand(from, to);
}

#[cfg(not(feature = "unstable"))]
fn expand_match_tokens(from: &Path, to: &Path) {
use std::io::stderr;
use std::process::exit;

if let Err(error) = check_hash(from, to) {
writeln!(
stderr(),
r"
{} is missing or not up to date with {}:
{}

Run `cargo build --features unstable` to update it.

If you’re using html5ever as a dependency, this is a bad release.
Please file an issue at https://github.com/servo/html5ever/issues/new
with the output of `cargo pkgid html5ever`.
",
to.file_name().unwrap().to_string_lossy(),
from.file_name().unwrap().to_string_lossy(),
error
).unwrap();
exit(1);
}
}

#[cfg(not(feature = "unstable"))]
fn check_hash(from: &Path, to: &Path) -> Result<(), String> {
use std::hash::{Hash, Hasher, SipHasher};
use std::io::Read;

// Unwrap here as the source file is expected to exist.
let mut file_from = File::open(from).unwrap();
let mut source = String::new();
let mut hasher = SipHasher::new();
file_from.read_to_string(&mut source).unwrap();
source.hash(&mut hasher);
let source_hash = hasher.finish();

// IO errors from here indicate we need to regenerate the expanded file.
let mut file_to = try!(File::open(to).map_err(|e| e.to_string()));
let mut expanded = String::new();
try!(file_to.read_to_string(&mut expanded).map_err(|e| e.to_string()));
let prefix = "// source SipHash: ";
let line = try!(expanded.lines().find(|line| line.starts_with(prefix))
.ok_or("source hash not found".to_string()));
let expected_hash = try!(line[prefix.len()..].parse::<u64>().map_err(|e| e.to_string()));
if source_hash == expected_hash {
Ok(())
} else {
Err("different hash".to_string())
}
}

fn named_entities_to_phf(from: &Path, to: &Path) {
// A struct matching the entries in entities.json.
#[derive(RustcDecodable)]
struct CharRef {
codepoints: Vec<u32>,
//characters: String, // Present in the file but we don't need it
}

let json = Json::from_reader(&mut File::open(from).unwrap()).unwrap();
let entities: HashMap<String, CharRef> = Decodable::decode(&mut Decoder::new(json)).unwrap();
let mut entities: HashMap<&str, (u32, u32)> = entities.iter().map(|(name, char_ref)| {
assert!(name.starts_with("&"));
assert!(char_ref.codepoints.len() <= 2);
(&name[1..], (char_ref.codepoints[0], *char_ref.codepoints.get(1).unwrap_or(&0)))
}).collect();

// Add every missing prefix of those keys, mapping to NULL characters.
for key in entities.keys().cloned().collect::<Vec<_>>() {
for n in 1 .. key.len() {
entities.entry(&key[..n]).or_insert((0, 0));
}
}
entities.insert("", (0, 0));

let mut phf_map = phf_codegen::Map::new();
for (key, value) in entities {
phf_map.entry(key, &format!("{:?}", value));
}

let mut file = File::create(to).unwrap();
write!(&mut file, "pub static NAMED_ENTITIES: Map<&'static str, (u32, u32)> = ").unwrap();
phf_map.build(&mut file).unwrap();
write!(&mut file, ";\n").unwrap();
}
1 change: 1 addition & 0 deletions capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tendril = "0.1"

[dependencies.html5ever]
path = "../"
features = ["unstable"]
26 changes: 0 additions & 26 deletions dom_sink/Cargo.toml

This file was deleted.

34 changes: 0 additions & 34 deletions dom_sink/src/common.rs

This file was deleted.

27 changes: 0 additions & 27 deletions dom_sink/src/lib.rs

This file was deleted.

Loading