]> git.proxmox.com Git - rustc.git/blob - src/test/run-make/issue-19371/foo.rs
Imported Upstream version 1.6.0+dfsg1
[rustc.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 cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
59 let sess = build_session(opts, None, descriptions, cstore_);
60 rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
61 (sess, cstore)
62 }
63
64 fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
65 let (sess, cstore) = basic_sess(sysroot);
66 let cfg = build_configuration(&sess);
67 let control = CompileController::basic();
68
69 compile_input(sess, &cstore,
70 cfg,
71 &Input::Str(code),
72 &None,
73 &Some(output),
74 None,
75 control);
76 }