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.
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.
11 #![feature(rustc_private, path, convert)]
14 extern crate rustc_driver
;
15 extern crate rustc_lint
;
18 use rustc
::session
::{build_session, Session}
;
19 use rustc
::session
::config
::{basic_options, build_configuration, Input, OutputTypeExe}
;
20 use rustc_driver
::driver
::{compile_input, CompileController}
;
21 use syntax
::diagnostics
::registry
::Registry
;
23 use std
::path
::PathBuf
;
30 let args
: Vec
<String
> = std
::env
::args().collect();
33 panic
!("expected rustc path");
36 let tmpdir
= PathBuf
::from(&args
[1]);
38 let mut sysroot
= PathBuf
::from(&args
[3]);
42 compile(src
.to_string(), tmpdir
.join("out"), sysroot
.clone());
44 compile(src
.to_string(), tmpdir
.join("out"), sysroot
.clone());
47 fn basic_sess(sysroot
: PathBuf
) -> Session
{
48 let mut opts
= basic_options();
49 opts
.output_types
= vec
![OutputTypeExe
];
50 opts
.maybe_sysroot
= Some(sysroot
);
52 let descriptions
= Registry
::new(&rustc
::diagnostics
::DIAGNOSTICS
);
53 let sess
= build_session(opts
, None
, descriptions
);
54 rustc_lint
::register_builtins(&mut sess
.lint_store
.borrow_mut(), Some(&sess
));
58 fn compile(code
: String
, output
: PathBuf
, sysroot
: PathBuf
) {
59 let sess
= basic_sess(sysroot
);
60 let cfg
= build_configuration(&sess
);
61 let control
= CompileController
::basic();