Skip to content

Commit

Permalink
Auto merge of #52194 - steveklabnik:remove-plugins, r=QuietMisdreavus…
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Jul 12, 2018
2 parents 3244d53 + 0df68d8 commit c946c25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 58 deletions.
21 changes: 11 additions & 10 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
}),
stable("plugin-path", |o| {
o.optmulti("", "plugin-path", "directory to load plugins from", "DIR")
o.optmulti("", "plugin-path", "removed", "DIR")
}),
stable("C", |o| {
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
Expand All @@ -178,7 +178,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
"PASSES")
}),
stable("plugins", |o| {
o.optmulti("", "plugins", "space separated list of plugins to also load",
o.optmulti("", "plugins", "removed",
"PLUGINS")
}),
stable("no-default", |o| {
Expand Down Expand Up @@ -741,9 +741,16 @@ where R: 'static + Send,
}
}

if !plugins.is_empty() {
eprintln!("WARNING: --plugins no longer functions; see CVE-2018-1000622");
}

if !plugin_path.is_none() {
eprintln!("WARNING: --plugin-path no longer functions; see CVE-2018-1000622");
}

// Load all plugins/passes into a PluginManager
let path = plugin_path.unwrap_or("/tmp/rustdoc/plugins".to_string());
let mut pm = plugins::PluginManager::new(PathBuf::from(path));
let mut pm = plugins::PluginManager::new();
for pass in &passes {
let plugin = match passes::PASSES.iter()
.position(|&(p, ..)| {
Expand All @@ -757,10 +764,6 @@ where R: 'static + Send,
};
pm.add_plugin(plugin);
}
info!("loading plugins...");
for pname in plugins {
pm.load_plugin(pname);
}

// Run everything!
info!("Executing passes/plugins");
Expand All @@ -776,8 +779,6 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler)
let deprecated_flags = [
"input-format",
"output-format",
"plugin-path",
"plugins",
"no-defaults",
"passes",
];
Expand Down
49 changes: 1 addition & 48 deletions src/librustdoc/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,20 @@

use clean;

use std::mem;
use std::string::String;
use std::path::PathBuf;

use rustc_metadata::dynamic_lib as dl;

pub type PluginResult = clean::Crate;
pub type PluginCallback = fn (clean::Crate) -> PluginResult;

/// Manages loading and running of plugins
pub struct PluginManager {
dylibs: Vec<dl::DynamicLibrary> ,
callbacks: Vec<PluginCallback> ,
/// The directory plugins will be loaded from
pub prefix: PathBuf,
}

impl PluginManager {
/// Create a new plugin manager
pub fn new(prefix: PathBuf) -> PluginManager {
pub fn new() -> PluginManager {
PluginManager {
dylibs: Vec::new(),
callbacks: Vec::new(),
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 macOS, name.dylib, and
/// elsewhere, libname.so.
pub fn load_plugin(&mut self, name: String) {
let x = self.prefix.join(libname(name));
let lib_result = dl::DynamicLibrary::open(Some(&x));
let lib = lib_result.unwrap();
unsafe {
let plugin = lib.symbol("rustdoc_plugin_entrypoint").unwrap();
self.callbacks.push(mem::transmute::<*mut u8,PluginCallback>(plugin));
}
self.dylibs.push(lib);
}

/// Load a normal Rust function as a plugin.
Expand All @@ -70,23 +43,3 @@ impl PluginManager {
krate
}
}

#[cfg(target_os = "windows")]
fn libname(mut n: String) -> String {
n.push_str(".dll");
n
}

#[cfg(target_os="macos")]
fn libname(mut n: String) -> String {
n.push_str(".dylib");
n
}

#[cfg(all(not(target_os="windows"), not(target_os="macos")))]
fn libname(n: String) -> String {
let mut i = String::from("lib");
i.push_str(&n);
i.push_str(".so");
i
}

0 comments on commit c946c25

Please sign in to comment.