]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
b039eaaf | 11 | #![feature(rustc_private)] |
c34b1796 | 12 | |
1a4d82fc JJ |
13 | extern crate rustc; |
14 | extern crate rustc_driver; | |
c34b1796 | 15 | extern crate rustc_lint; |
92a42be0 | 16 | extern crate rustc_metadata; |
1a4d82fc JJ |
17 | extern crate syntax; |
18 | ||
19 | use rustc::session::{build_session, Session}; | |
b039eaaf | 20 | use rustc::session::config::{basic_options, build_configuration, Input, OutputType}; |
54a0048b | 21 | use rustc_driver::driver::{compile_input, CompileController, anon_src}; |
92a42be0 | 22 | use rustc_metadata::cstore::CStore; |
1a4d82fc | 23 | use syntax::diagnostics::registry::Registry; |
92a42be0 | 24 | use syntax::parse::token; |
1a4d82fc | 25 | |
c34b1796 | 26 | use std::path::PathBuf; |
92a42be0 | 27 | use std::rc::Rc; |
c34b1796 | 28 | |
1a4d82fc JJ |
29 | fn main() { |
30 | let src = r#" | |
31 | fn main() {} | |
32 | "#; | |
33 | ||
85aaf69f | 34 | let args: Vec<String> = std::env::args().collect(); |
1a4d82fc JJ |
35 | |
36 | if args.len() < 4 { | |
37 | panic!("expected rustc path"); | |
38 | } | |
39 | ||
c34b1796 | 40 | let tmpdir = PathBuf::from(&args[1]); |
1a4d82fc | 41 | |
c34b1796 | 42 | let mut sysroot = PathBuf::from(&args[3]); |
1a4d82fc JJ |
43 | sysroot.pop(); |
44 | sysroot.pop(); | |
45 | ||
46 | compile(src.to_string(), tmpdir.join("out"), sysroot.clone()); | |
47 | ||
48 | compile(src.to_string(), tmpdir.join("out"), sysroot.clone()); | |
49 | } | |
50 | ||
92a42be0 | 51 | fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) { |
1a4d82fc | 52 | let mut opts = basic_options(); |
b039eaaf | 53 | opts.output_types.insert(OutputType::Exe, None); |
1a4d82fc JJ |
54 | opts.maybe_sysroot = Some(sysroot); |
55 | ||
d9579d0f | 56 | let descriptions = Registry::new(&rustc::DIAGNOSTICS); |
92a42be0 | 57 | let cstore = Rc::new(CStore::new(token::get_ident_interner())); |
9cc50fc6 | 58 | let sess = build_session(opts, None, descriptions, cstore.clone()); |
c34b1796 | 59 | rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); |
92a42be0 | 60 | (sess, cstore) |
1a4d82fc JJ |
61 | } |
62 | ||
c34b1796 | 63 | fn compile(code: String, output: PathBuf, sysroot: PathBuf) { |
92a42be0 | 64 | let (sess, cstore) = basic_sess(sysroot); |
1a4d82fc | 65 | let cfg = build_configuration(&sess); |
85aaf69f | 66 | let control = CompileController::basic(); |
1a4d82fc | 67 | |
7453a54e | 68 | compile_input(&sess, &cstore, |
1a4d82fc | 69 | cfg, |
54a0048b | 70 | &Input::Str { name: anon_src(), input: code }, |
1a4d82fc JJ |
71 | &None, |
72 | &Some(output), | |
85aaf69f | 73 | None, |
7453a54e | 74 | &control); |
1a4d82fc | 75 | } |