]> git.proxmox.com Git - rustc.git/blob - src/test/run-make/issue-19371/foo.rs
New upstream version 1.12.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 rustc_errors;
18 extern crate syntax;
19
20 use rustc::dep_graph::DepGraph;
21 use rustc::session::{build_session, Session};
22 use rustc::session::config::{basic_options, build_configuration, Input,
23 OutputType, OutputTypes};
24 use rustc_driver::driver::{compile_input, CompileController, anon_src};
25 use rustc_metadata::cstore::CStore;
26 use rustc_errors::registry::Registry;
27
28 use std::path::PathBuf;
29 use std::rc::Rc;
30
31 fn main() {
32 let src = r#"
33 fn main() {}
34 "#;
35
36 let args: Vec<String> = std::env::args().collect();
37
38 if args.len() < 4 {
39 panic!("expected rustc path");
40 }
41
42 let tmpdir = PathBuf::from(&args[1]);
43
44 let mut sysroot = PathBuf::from(&args[3]);
45 sysroot.pop();
46 sysroot.pop();
47
48 compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
49
50 compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
51 }
52
53 fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
54 let mut opts = basic_options();
55 opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
56 opts.maybe_sysroot = Some(sysroot);
57
58 let descriptions = Registry::new(&rustc::DIAGNOSTICS);
59 let dep_graph = DepGraph::new(opts.build_dep_graph());
60 let cstore = Rc::new(CStore::new(&dep_graph));
61 let sess = build_session(opts, &dep_graph, None, descriptions, cstore.clone());
62 rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
63 (sess, cstore)
64 }
65
66 fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
67 let (sess, cstore) = basic_sess(sysroot);
68 let cfg = build_configuration(&sess, vec![]);
69 let control = CompileController::basic();
70
71 compile_input(&sess, &cstore,
72 cfg,
73 &Input::Str { name: anon_src(), input: code },
74 &None,
75 &Some(output),
76 None,
77 &control);
78 }