1
Fork 0

path2: Replace the path module outright

Remove the old path.
Rename path2 to path.
Update all clients for the new path.

Also make some miscellaneous changes to the Path APIs to help the
adoption process.
This commit is contained in:
Kevin Ballard 2013-09-26 17:21:59 -07:00
parent 6741241f40
commit 73d3d00ec4
63 changed files with 2501 additions and 2989 deletions

View file

@ -47,7 +47,6 @@ use std::rt::io::Reader;
use std::str;
use std::task;
use std::unstable::finally::Finally;
use std::util;
use std::vec;
use extra::arc::RWArc;
@ -256,16 +255,16 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
crate = cache.fold_crate(crate);
// Add all the static files
let dst = cx.dst.push(crate.name);
let mut dst = cx.dst.join_str(crate.name);
mkdir(&dst);
write(dst.push("jquery.js"), include_str!("static/jquery-2.0.3.min.js"));
write(dst.push("main.js"), include_str!("static/main.js"));
write(dst.push("main.css"), include_str!("static/main.css"));
write(dst.push("normalize.css"), include_str!("static/normalize.css"));
write(dst.join_str("jquery.js"), include_str!("static/jquery-2.0.3.min.js"));
write(dst.join_str("main.js"), include_str!("static/main.js"));
write(dst.join_str("main.css"), include_str!("static/main.css"));
write(dst.join_str("normalize.css"), include_str!("static/normalize.css"));
// Publish the search index
{
let dst = dst.push("search-index.js");
dst.push_str("search-index.js");
let mut w = BufferedWriter::new(dst.open_writer(io::CreateOrTruncate));
let w = &mut w as &mut io::Writer;
write!(w, "var searchIndex = [");
@ -293,9 +292,9 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
// Render all source files (this may turn into a giant no-op)
{
info2!("emitting source files");
let dst = cx.dst.push("src");
let dst = cx.dst.join_str("src");
mkdir(&dst);
let dst = dst.push(crate.name);
let dst = dst.join_str(crate.name);
mkdir(&dst);
let mut folder = SourceCollector {
dst: dst,
@ -325,7 +324,7 @@ fn write(dst: Path, contents: &str) {
fn mkdir(path: &Path) {
do io::io_error::cond.trap(|err| {
error2!("Couldn't create directory `{}`: {}",
path.to_str(), err.desc);
path.display(), err.desc);
fail2!()
}).inside {
if !path.is_dir() {
@ -335,18 +334,18 @@ fn mkdir(path: &Path) {
}
/// Takes a path to a source file and cleans the path to it. This canonicalizes
/// things like "." and ".." to components which preserve the "top down"
/// hierarchy of a static HTML tree.
fn clean_srcpath(src: &str, f: &fn(&str)) {
let p = Path(src);
for c in p.components.iter() {
if "." == *c {
continue
}
if ".." == *c {
f("up");
} else {
f(c.as_slice())
/// things like ".." to components which preserve the "top down" hierarchy of a
/// static HTML tree.
// FIXME (#9639): The closure should deal with &[u8] instead of &str
fn clean_srcpath(src: &[u8], f: &fn(&str)) {
let p = Path::from_vec(src);
if p.as_vec() != bytes!(".") {
for c in p.str_component_iter().map(|x|x.unwrap()) {
if ".." == c {
f("up");
} else {
f(c.as_slice())
}
}
}
}
@ -355,7 +354,7 @@ fn clean_srcpath(src: &str, f: &fn(&str)) {
/// rendering in to the specified source destination.
fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
// See if there's documentation generated into the local directory
let local_location = dst.push(e.name);
let local_location = dst.join_str(e.name);
if local_location.is_dir() {
return Local;
}
@ -414,7 +413,7 @@ impl<'self> DocFolder for SourceCollector<'self> {
impl<'self> SourceCollector<'self> {
/// Renders the given filename into its corresponding HTML source file.
fn emit_source(&mut self, filename: &str) -> bool {
let p = Path(filename);
let p = Path::from_str(filename);
// Read the contents of the file
let mut contents = ~[];
@ -445,17 +444,17 @@ impl<'self> SourceCollector<'self> {
// Create the intermediate directories
let mut cur = self.dst.clone();
let mut root_path = ~"../../";
do clean_srcpath(p.pop().to_str()) |component| {
cur = cur.push(component);
do clean_srcpath(p.dirname()) |component| {
cur.push_str(component);
mkdir(&cur);
root_path.push_str("../");
}
let dst = cur.push(*p.components.last() + ".html");
let w = dst.open_writer(io::CreateOrTruncate);
cur.push(p.filename().expect("source has no filename") + bytes!(".html"));
let w = cur.open_writer(io::CreateOrTruncate);
let mut w = BufferedWriter::new(w);
let title = format!("{} -- source", *dst.components.last());
let title = cur.with_filename_display_str(|s| format!("{} -- source", s.unwrap()));
let page = layout::Page {
title: title,
ty: "source",
@ -661,8 +660,8 @@ impl Context {
if s.len() == 0 {
fail2!("what {:?}", self);
}
let next = self.dst.push(s);
let prev = util::replace(&mut self.dst, next);
let prev = self.dst.clone();
self.dst.push_str(s);
self.root_path.push_str("../");
self.current.push(s);
@ -809,7 +808,7 @@ impl Context {
let item = Cell::new(item);
do self.recurse(name) |this| {
let item = item.take();
let dst = this.dst.push("index.html");
let dst = this.dst.join_str("index.html");
let writer = dst.open_writer(io::CreateOrTruncate);
render(writer.unwrap(), this, &item, false);
@ -827,7 +826,7 @@ impl Context {
// Things which don't have names (like impls) don't get special
// pages dedicated to them.
_ if item.name.is_some() => {
let dst = self.dst.push(item_path(&item));
let dst = self.dst.join_str(item_path(&item));
let writer = dst.open_writer(io::CreateOrTruncate);
render(writer.unwrap(), self, &item, true);
}
@ -881,7 +880,7 @@ impl<'self> fmt::Default for Item<'self> {
if it.cx.include_sources {
let mut path = ~[];
do clean_srcpath(it.item.source.filename) |component| {
do clean_srcpath(it.item.source.filename.as_bytes()) |component| {
path.push(component.to_owned());
}
let href = if it.item.source.loline == it.item.source.hiline {