]>
Commit | Line | Data |
---|---|---|
85aaf69f SL |
1 | // Copyright 2015 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 | // Test that the CompilerCalls interface to the compiler works. | |
12 | ||
d9579d0f | 13 | // ignore-cross-compile |
85aaf69f | 14 | |
c34b1796 | 15 | #![feature(rustc_private, path)] |
85aaf69f SL |
16 | #![feature(core)] |
17 | ||
18 | extern crate getopts; | |
19 | extern crate rustc; | |
20 | extern crate rustc_driver; | |
94b46f34 | 21 | extern crate rustc_codegen_utils; |
85aaf69f | 22 | extern crate syntax; |
3157f602 | 23 | extern crate rustc_errors as errors; |
85aaf69f | 24 | |
ea8adc8c | 25 | use rustc::middle::cstore::CrateStore; |
85aaf69f SL |
26 | use rustc::session::Session; |
27 | use rustc::session::config::{self, Input}; | |
28 | use rustc_driver::{driver, CompilerCalls, Compilation}; | |
94b46f34 | 29 | use rustc_codegen_utils::codegen_backend::CodegenBackend; |
5bcae85e | 30 | use syntax::ast; |
85aaf69f | 31 | |
c34b1796 | 32 | use std::path::PathBuf; |
85aaf69f | 33 | |
94b46f34 XL |
34 | struct TestCalls<'a> { |
35 | count: &'a mut u32 | |
85aaf69f SL |
36 | } |
37 | ||
94b46f34 | 38 | impl<'a> CompilerCalls<'a> for TestCalls<'a> { |
85aaf69f SL |
39 | fn early_callback(&mut self, |
40 | _: &getopts::Matches, | |
7453a54e | 41 | _: &config::Options, |
5bcae85e | 42 | _: &ast::CrateConfig, |
3157f602 | 43 | _: &errors::registry::Registry, |
9cc50fc6 | 44 | _: config::ErrorOutputType) |
85aaf69f | 45 | -> Compilation { |
94b46f34 | 46 | *self.count *= 2; |
85aaf69f SL |
47 | Compilation::Continue |
48 | } | |
49 | ||
50 | fn late_callback(&mut self, | |
94b46f34 | 51 | _: &CodegenBackend, |
85aaf69f SL |
52 | _: &getopts::Matches, |
53 | _: &Session, | |
ea8adc8c | 54 | _: &CrateStore, |
85aaf69f | 55 | _: &Input, |
c34b1796 AL |
56 | _: &Option<PathBuf>, |
57 | _: &Option<PathBuf>) | |
85aaf69f | 58 | -> Compilation { |
94b46f34 | 59 | *self.count *= 3; |
85aaf69f SL |
60 | Compilation::Stop |
61 | } | |
62 | ||
c34b1796 AL |
63 | fn some_input(&mut self, input: Input, input_path: Option<PathBuf>) |
64 | -> (Input, Option<PathBuf>) { | |
94b46f34 | 65 | *self.count *= 5; |
85aaf69f SL |
66 | (input, input_path) |
67 | } | |
68 | ||
69 | fn no_input(&mut self, | |
70 | _: &getopts::Matches, | |
71 | _: &config::Options, | |
5bcae85e | 72 | _: &ast::CrateConfig, |
c34b1796 AL |
73 | _: &Option<PathBuf>, |
74 | _: &Option<PathBuf>, | |
3157f602 | 75 | _: &errors::registry::Registry) |
c34b1796 | 76 | -> Option<(Input, Option<PathBuf>)> { |
85aaf69f SL |
77 | panic!("This shouldn't happen"); |
78 | } | |
79 | ||
94b46f34 | 80 | fn build_controller(self: Box<Self>, |
a7813a04 XL |
81 | _: &Session, |
82 | _: &getopts::Matches) | |
83 | -> driver::CompileController<'a> { | |
85aaf69f SL |
84 | panic!("This shouldn't be called"); |
85 | } | |
86 | } | |
87 | ||
88 | ||
89 | fn main() { | |
94b46f34 XL |
90 | let mut count = 1; |
91 | { | |
92 | let tc = TestCalls { count: &mut count }; | |
93 | // we should never get use this filename, but lets make sure they are valid args. | |
94 | let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()]; | |
95 | rustc_driver::run_compiler(&args, Box::new(tc), None, None); | |
96 | } | |
97 | assert_eq!(count, 30); | |
85aaf69f | 98 | } |