]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/issue-19371/foo.rs
Register new snapshots
[rust.git] / src / test / run-make / issue-19371 / foo.rs
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
11 #![feature(rustc_private)]
12
13 extern crate rustc;
14 extern crate rustc_driver;
15 extern crate rustc_lint;
16 extern crate rustc_metadata;
17 extern crate syntax;
18
19 use rustc::session::{build_session, Session};
20 use rustc::session::config::{basic_options, build_configuration, Input, OutputType};
21 use rustc_driver::driver::{compile_input, CompileController};
22 use rustc_metadata::cstore::CStore;
23 use syntax::diagnostics::registry::Registry;
24 use syntax::parse::token;
25
26 use std::path::PathBuf;
27 use std::rc::Rc;
28
29 fn main() {
30     let src = r#"
31     fn main() {}
32     "#;
33
34     let args: Vec<String> = std::env::args().collect();
35
36     if args.len() < 4 {
37         panic!("expected rustc path");
38     }
39
40     let tmpdir = PathBuf::from(&args[1]);
41
42     let mut sysroot = PathBuf::from(&args[3]);
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
51 fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
52     let mut opts = basic_options();
53     opts.output_types.insert(OutputType::Exe, None);
54     opts.maybe_sysroot = Some(sysroot);
55
56     let descriptions = Registry::new(&rustc::DIAGNOSTICS);
57     let cstore = Rc::new(CStore::new(token::get_ident_interner()));
58     let sess = build_session(opts, None, descriptions, cstore.clone());
59     rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
60     (sess, cstore)
61 }
62
63 fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
64     let (sess, cstore) = basic_sess(sysroot);
65     let cfg = build_configuration(&sess);
66     let control = CompileController::basic();
67
68     compile_input(sess, &cstore,
69             cfg,
70             &Input::Str(code),
71             &None,
72             &Some(output),
73             None,
74             control);
75 }