]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Pass optional additional plugins to compile_input
authorBrian Anderson <banderson@mozilla.com>
Sun, 20 Jul 2014 04:54:37 +0000 (21:54 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 21 Jul 2014 16:54:26 +0000 (09:54 -0700)
This provides a way for clients of the rustc library to add
their own features to the pipeline.

src/librustc/driver/driver.rs
src/librustc/driver/mod.rs
src/librustc/middle/typeck/infer/test.rs
src/librustc/plugin/load.rs
src/librustdoc/core.rs
src/librustdoc/test.rs

index 81ace4d015c8576101d566fb499694e4856eb5f7..311d9fb93a1211e231b2cd294bb4920034be31ef 100644 (file)
@@ -69,7 +69,8 @@ pub fn compile_input(sess: Session,
                      cfg: ast::CrateConfig,
                      input: &Input,
                      outdir: &Option<Path>,
-                     output: &Option<Path>) {
+                     output: &Option<Path>,
+                     addl_plugins: Option<Plugins>) {
     // We need nested scopes here, because the intermediate results can keep
     // large chunks of memory alive and we want to free them as soon as
     // possible to keep the peak memory usage low
@@ -85,7 +86,8 @@ pub fn compile_input(sess: Session,
             let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
                                            input);
             let (expanded_crate, ast_map)
-                = match phase_2_configure_and_expand(&sess, krate, id.as_slice()) {
+                = match phase_2_configure_and_expand(&sess, krate, id.as_slice(),
+                                                     addl_plugins) {
                     None => return,
                     Some(p) => p,
                 };
@@ -186,7 +188,8 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
 /// Returns `None` if we're aborting after handling -W help.
 pub fn phase_2_configure_and_expand(sess: &Session,
                                     mut krate: ast::Crate,
-                                    crate_name: &str)
+                                    crate_name: &str,
+                                    addl_plugins: Option<Plugins>)
                                     -> Option<(ast::Crate, syntax::ast_map::Map)> {
     let time_passes = sess.time_passes();
 
@@ -212,9 +215,10 @@ pub fn phase_2_configure_and_expand(sess: &Session,
     krate = time(time_passes, "configuration 1", krate, |krate|
                  front::config::strip_unconfigured_items(krate));
 
+    let mut addl_plugins = Some(addl_plugins);
     let Plugins { macros, registrars }
         = time(time_passes, "plugin loading", (), |_|
-               plugin::load::load_plugins(sess, &krate));
+               plugin::load::load_plugins(sess, &krate, addl_plugins.take_unwrap()));
 
     let mut registry = Registry::new(&krate);
 
@@ -697,7 +701,7 @@ pub fn pretty_print_input(sess: Session,
         PpmExpanded | PpmExpandedIdentified | PpmTyped | PpmFlowGraph(_) => {
             let (krate, ast_map)
                 = match phase_2_configure_and_expand(&sess, krate,
-                                                     id.as_slice()) {
+                                                     id.as_slice(), None) {
                     None => return,
                     Some(p) => p,
                 };
index ee490ad43ebad28c058555495f49c7633ebaa9af..a5df63a9e23fa813400889f76c807bf7a5a19ebe 100644 (file)
@@ -124,7 +124,7 @@ fn run_compiler(args: &[String]) {
         return;
     }
 
-    driver::compile_input(sess, cfg, &input, &odir, &ofile);
+    driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
 }
 
 /// Prints version information and returns None on success or an error
index c8f6836b20596cd9e98b0e6c10267a745dcc17d6..637af96b6321ab23cb2e0521922e89a8e345ff5d 100644 (file)
@@ -117,7 +117,7 @@ fn test_env(_test_name: &str,
     let input = driver::StrInput(source_string.to_string());
     let krate = driver::phase_1_parse_input(&sess, krate_config, &input);
     let (krate, ast_map) =
-        driver::phase_2_configure_and_expand(&sess, krate, "test")
+        driver::phase_2_configure_and_expand(&sess, krate, "test", None)
             .expect("phase 2 aborted");
 
     // run just enough stuff to build a tcx:
index 499cffa42aac9f124913adb549a0c81175765ffc..4f38c74893e46630c08420440a49160938272d37 100644 (file)
@@ -66,10 +66,24 @@ fn new(sess: &'a Session) -> PluginLoader<'a> {
 }
 
 /// Read plugin metadata and dynamically load registrar functions.
-pub fn load_plugins(sess: &Session, krate: &ast::Crate) -> Plugins {
+pub fn load_plugins(sess: &Session, krate: &ast::Crate,
+                    addl_plugins: Option<Plugins>) -> Plugins {
     let mut loader = PluginLoader::new(sess);
     visit::walk_crate(&mut loader, krate, ());
-    loader.plugins
+
+    let mut plugins = loader.plugins;
+
+    match addl_plugins {
+        Some(addl_plugins) => {
+            // Add in the additional plugins requested by the frontend
+            let Plugins { macros: addl_macros, registrars: addl_registrars } = addl_plugins;
+            plugins.macros.push_all_move(addl_macros);
+            plugins.registrars.push_all_move(addl_registrars);
+        }
+        None => ()
+    }
+
+    return plugins;
 }
 
 // note that macros aren't expanded yet, and therefore macros can't add plugins.
index e62c8b63a294070b0c873f5cccecc9775b22a24f..b1c715ae5b36a1aba7c49020c38eb41378faad04 100644 (file)
@@ -121,7 +121,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>)
                                      &input);
 
     let (krate, ast_map)
-        = phase_2_configure_and_expand(&sess, krate, name.as_slice())
+        = phase_2_configure_and_expand(&sess, krate, name.as_slice(), None)
             .expect("phase_2_configure_and_expand aborted in rustdoc!");
 
     let driver::driver::CrateAnalysis {
index 055019aa481ffebaf06edc9aab9f3a467be8efd8..8fe28d1eab824de877d5732ffe9ebde9c9484c4d 100644 (file)
@@ -69,7 +69,7 @@ pub fn run(input: &str,
     }));
     let krate = driver::phase_1_parse_input(&sess, cfg, &input);
     let (krate, _) = driver::phase_2_configure_and_expand(&sess, krate,
-                                                          "rustdoc-test")
+                                                          "rustdoc-test", None)
         .expect("phase_2_configure_and_expand aborted in rustdoc!");
 
     let ctx = box(GC) core::DocContext {
@@ -166,7 +166,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
     let out = Some(outdir.path().clone());
     let cfg = config::build_configuration(&sess);
     let libdir = sess.target_filesearch().get_lib_path();
-    driver::compile_input(sess, cfg, &input, &out, &None);
+    driver::compile_input(sess, cfg, &input, &out, &None, None);
 
     if no_run { return }