From efaf613497da355fa3afaeaa75eaf95b55991e4e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 9 Dec 2014 21:33:05 +0530 Subject: [PATCH] librustc::metadata : Allow passing a string to read_plugin_metadata --- src/librustc/metadata/creader.rs | 31 ++++++++++++++++++++++++------- src/librustc/plugin/load.rs | 4 ++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 310874c311b..7615ff82bd2 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -26,7 +26,7 @@ use syntax::abi; use syntax::attr; use syntax::attr::AttrMetaMethods; -use syntax::codemap::{Span, mk_sp}; +use syntax::codemap::{DUMMY_SP, Span, mk_sp}; use syntax::parse; use syntax::parse::token::InternedString; use syntax::parse::token; @@ -445,8 +445,20 @@ fn resolve_crate_deps(&mut self, } pub fn read_plugin_metadata<'b>(&'b mut self, - vi: &'b ast::ViewItem) -> PluginMetadata<'b> { - let info = self.extract_crate_info(vi).unwrap(); + krate: CrateOrString<'b>) -> PluginMetadata<'b> { + let (info, span) = match krate { + CrateOrString::Krate(c) => { + (self.extract_crate_info(c).unwrap(), c.span) + } + CrateOrString::Str(s) => { + (CrateInfo { + name: s.to_string(), + ident: s.to_string(), + id: ast::DUMMY_NODE_ID, + should_link: true, + }, DUMMY_SP) + } + }; let target_triple = &self.sess.opts.target_triple[]; let is_cross = target_triple != config::host_triple(); let mut should_link = info.should_link && !is_cross; @@ -455,7 +467,7 @@ pub fn read_plugin_metadata<'b>(&'b mut self, let name = info.name.clone(); let mut load_ctxt = loader::Context { sess: self.sess, - span: vi.span, + span: span, ident: &ident[], crate_name: &name[], hash: None, @@ -485,8 +497,8 @@ pub fn read_plugin_metadata<'b>(&'b mut self, let register = should_link && self.existing_match(info.name.as_slice(), None).is_none(); let metadata = if register { // Register crate now to avoid double-reading metadata - let (_, cmd, _) = self.register_crate(&None, &info.ident[], - &info.name[], vi.span, library); + let (_, cmd, _) = self.register_crate(&None, info.ident[], + info.name[], span, library); PMDSource::Registered(cmd) } else { // Not registering the crate; just hold on to the metadata @@ -498,12 +510,17 @@ pub fn read_plugin_metadata<'b>(&'b mut self, metadata: metadata, dylib: dylib, info: info, - vi_span: vi.span, + vi_span: span, target_only: target_only, } } } +pub enum CrateOrString<'a> { + Krate(&'a ast::ViewItem), + Str(&'a str) +} + impl<'a> PluginMetadata<'a> { /// Read exported macros pub fn exported_macros(&self) -> Vec { diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs index 87f5ba0246f..e1f5c10a1a4 100644 --- a/src/librustc/plugin/load.rs +++ b/src/librustc/plugin/load.rs @@ -11,7 +11,7 @@ //! Used by `rustc` when loading a plugin, or a crate with exported macros. use session::Session; -use metadata::creader::CrateReader; +use metadata::creader::{CrateOrString, CrateReader}; use plugin::registry::Registry; use std::mem; @@ -175,7 +175,7 @@ fn visit_view_item(&mut self, vi: &ast::ViewItem) { } if load_macros || load_registrar { - let pmd = self.reader.read_plugin_metadata(vi); + let pmd = self.reader.read_plugin_metadata(CrateOrString::Krate(vi)); if load_macros { macros = pmd.exported_macros(); }