]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/issue-19371/foo.rs
debuginfo: Make debuginfo source location assignment more stable (Pt. 1)
[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 extern crate rustc;
12 extern crate rustc_driver;
13 extern crate syntax;
14
15 use rustc::session::{build_session, Session};
16 use rustc::session::config::{basic_options, build_configuration, Input, OutputTypeExe};
17 use rustc_driver::driver::{compile_input, CompileController};
18 use syntax::diagnostics::registry::Registry;
19
20 fn main() {
21     let src = r#"
22     fn main() {}
23     "#;
24
25     let args = std::os::args();
26
27     if args.len() < 4 {
28         panic!("expected rustc path");
29     }
30
31     let tmpdir = Path::new(args[1].as_slice());
32
33     let mut sysroot = Path::new(args[3].as_slice());
34     sysroot.pop();
35     sysroot.pop();
36
37     compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
38
39     compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
40 }
41
42 fn basic_sess(sysroot: Path) -> Session {
43     let mut opts = basic_options();
44     opts.output_types = vec![OutputTypeExe];
45     opts.maybe_sysroot = Some(sysroot);
46
47     let descriptions = Registry::new(&rustc::DIAGNOSTICS);
48     let sess = build_session(opts, None, descriptions);
49     sess
50 }
51
52 fn compile(code: String, output: Path, sysroot: Path) {
53     let sess = basic_sess(sysroot);
54     let cfg = build_configuration(&sess);
55     let control = CompileController::basic();
56
57     compile_input(sess,
58             cfg,
59             &Input::Str(code),
60             &None,
61             &Some(output),
62             None,
63             control);
64 }