2013-09-12 21:10:51 -04:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:
Stabilized APIs:
* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`
Deprecated APIs
* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`
Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
2015-10-22 16:28:45 -07:00
|
|
|
#![allow(deprecated)]
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
use clean;
|
|
|
|
|
2014-04-02 16:54:22 -07:00
|
|
|
use serialize::json;
|
2014-06-12 14:08:44 -07:00
|
|
|
use std::mem;
|
2014-05-22 16:57:53 -07:00
|
|
|
use std::string::String;
|
2015-03-27 13:22:26 -07:00
|
|
|
use std::path::PathBuf;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2016-03-07 15:42:29 -08:00
|
|
|
use rustc_back::dynamic_lib as dl;
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
pub type PluginJson = Option<(String, json::Json)>;
|
2013-08-15 16:28:54 -04:00
|
|
|
pub type PluginResult = (clean::Crate, PluginJson);
|
2014-02-14 17:23:01 +13:00
|
|
|
pub type PluginCallback = fn (clean::Crate) -> PluginResult;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
|
|
|
/// Manages loading and running of plugins
|
|
|
|
pub struct PluginManager {
|
2014-03-28 10:27:24 -07:00
|
|
|
dylibs: Vec<dl::DynamicLibrary> ,
|
|
|
|
callbacks: Vec<PluginCallback> ,
|
2013-08-15 16:28:54 -04:00
|
|
|
/// The directory plugins will be loaded from
|
2015-03-27 13:22:26 -07:00
|
|
|
pub prefix: PathBuf,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PluginManager {
|
|
|
|
/// Create a new plugin manager
|
2015-03-27 13:22:26 -07:00
|
|
|
pub fn new(prefix: PathBuf) -> PluginManager {
|
2013-08-15 16:28:54 -04:00
|
|
|
PluginManager {
|
2014-03-05 15:28:08 -08:00
|
|
|
dylibs: Vec::new(),
|
|
|
|
callbacks: Vec::new(),
|
2013-08-15 16:28:54 -04:00
|
|
|
prefix: prefix,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Load a plugin with the given name.
|
|
|
|
///
|
|
|
|
/// Turns `name` into the proper dynamic library filename for the given
|
|
|
|
/// platform. On windows, it turns into name.dll, on OS X, name.dylib, and
|
|
|
|
/// elsewhere, libname.so.
|
2014-05-22 16:57:53 -07:00
|
|
|
pub fn load_plugin(&mut self, name: String) {
|
2013-10-05 19:49:32 -07:00
|
|
|
let x = self.prefix.join(libname(name));
|
2013-08-15 16:28:54 -04:00
|
|
|
let lib_result = dl::DynamicLibrary::open(Some(&x));
|
|
|
|
let lib = lib_result.unwrap();
|
2014-06-12 14:08:44 -07:00
|
|
|
unsafe {
|
|
|
|
let plugin = lib.symbol("rustdoc_plugin_entrypoint").unwrap();
|
2014-06-25 12:47:34 -07:00
|
|
|
self.callbacks.push(mem::transmute::<*mut u8,PluginCallback>(plugin));
|
2014-06-12 14:08:44 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
self.dylibs.push(lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Load a normal Rust function as a plugin.
|
|
|
|
///
|
|
|
|
/// This is to run passes over the cleaned crate. Plugins run this way
|
|
|
|
/// correspond to the A-aux tag on Github.
|
2014-02-10 15:36:31 +01:00
|
|
|
pub fn add_plugin(&mut self, plugin: PluginCallback) {
|
2013-08-15 16:28:54 -04:00
|
|
|
self.callbacks.push(plugin);
|
|
|
|
}
|
|
|
|
/// Run all the loaded plugins over the crate, returning their results
|
2014-03-05 15:28:08 -08:00
|
|
|
pub fn run_plugins(&self, krate: clean::Crate) -> (clean::Crate, Vec<PluginJson> ) {
|
|
|
|
let mut out_json = Vec::new();
|
2014-02-05 22:15:24 +01:00
|
|
|
let mut krate = krate;
|
2015-01-31 12:20:46 -05:00
|
|
|
for &callback in &self.callbacks {
|
2014-02-05 22:15:24 +01:00
|
|
|
let (c, res) = callback(krate);
|
|
|
|
krate = c;
|
2013-08-15 16:28:54 -04:00
|
|
|
out_json.push(res);
|
|
|
|
}
|
2014-02-05 22:15:24 +01:00
|
|
|
(krate, out_json)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 21:26:45 -07:00
|
|
|
#[cfg(target_os = "windows")]
|
2014-05-22 16:57:53 -07:00
|
|
|
fn libname(mut n: String) -> String {
|
2013-08-15 16:28:54 -04:00
|
|
|
n.push_str(".dll");
|
2014-05-12 13:44:59 -07:00
|
|
|
n
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os="macos")]
|
2014-05-22 16:57:53 -07:00
|
|
|
fn libname(mut n: String) -> String {
|
2013-08-15 16:28:54 -04:00
|
|
|
n.push_str(".dylib");
|
2014-05-12 13:44:59 -07:00
|
|
|
n
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-09-29 00:29:09 -07:00
|
|
|
#[cfg(all(not(target_os="windows"), not(target_os="macos")))]
|
2014-05-22 16:57:53 -07:00
|
|
|
fn libname(n: String) -> String {
|
2015-06-08 16:55:35 +02:00
|
|
|
let mut i = String::from("lib");
|
2015-02-01 21:53:25 -05:00
|
|
|
i.push_str(&n);
|
2013-08-15 16:28:54 -04:00
|
|
|
i.push_str(".so");
|
2014-05-12 13:44:59 -07:00
|
|
|
i
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|